summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Changes8
-rw-r--r--MANIFEST.SKIP1
-rw-r--r--lib/Apache/Defaults.pm72
3 files changed, 59 insertions, 22 deletions
diff --git a/Changes b/Changes
index c7d5cbe..414580e 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,7 @@
11.02 2019-08-25
2 - Make sure constructor never croaks if on_error is set to 'return'
3 Improve diagnostics.
41.01 2018-07-17
5 - Prefer apachectl over invoking httpd directly.
11.00 2018-02-24 61.00 2018-02-24
2 7 - Initial release.
3* Initial release.
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
index 58696be..3fb78f0 100644
--- a/MANIFEST.SKIP
+++ b/MANIFEST.SKIP
@@ -24,2 +24,3 @@
24\bblibdirs\.ts$ # 6.18 through 6.25 generated this 24\bblibdirs\.ts$ # 6.18 through 6.25 generated this
25\bMANIFEST\.SKIP$
25 26
diff --git a/lib/Apache/Defaults.pm b/lib/Apache/Defaults.pm
index 70d5385..5fa8217 100644
--- a/lib/Apache/Defaults.pm
+++ b/lib/Apache/Defaults.pm
@@ -11,3 +11,3 @@ use Carp;
11 11
12our $VERSION = '1.00'; 12our $VERSION = '1.02';
13 13
@@ -33,3 +33,3 @@ sub new {
33 } else { 33 } else {
34 @servlist = qw(/usr/sbin/httpd /usr/sbin/apache2); 34 @servlist = qw(/usr/sbin/apachectl /usr/sbin/httpd /usr/sbin/apache2);
35 } 35 }
@@ -46,6 +46,37 @@ sub new {
46 46
47 if ($v = delete $_{environ}) { 47 my $envfile = delete $_{environ};
48 my $env = Shell::GetEnv->new('sh', ". $v", 48 croak "unrecognized arguments" if keys(%_);
49 { startup => 0 }); 49
50 if ($env->status) { 50 if ($envfile) {
51 unless (-f $envfile) {
52 if ($self->{on_error} eq 'return') {
53 $self->{status} = 127;
54 $self->{error} = "environment file $envfile does not exist";
55 return $self;
56 } else {
57 croak "environment file $envfile does not exist";
58 }
59 }
60 unless (-r $envfile) {
61 if ($self->{on_error} eq 'return') {
62 $self->{status} = 127;
63 $self->{error} = "environment file $envfile is not readable";
64 return $self;
65 } else {
66 croak "environment file $envfile is not readable";
67 }
68 }
69
70 my $env = eval {
71 Shell::GetEnv->new('sh', ". $envfile", { startup => 0 });
72 };
73 if ($@) {
74 if ($self->{on_error} eq 'return') {
75 $self->{status} = 127;
76 $self->{error} = $@;
77 return $self;
78 } else {
79 croak $@;
80 }
81 } elsif ($env->status) {
51 if ($self->{on_error} eq 'return') { 82 if ($self->{on_error} eq 'return') {
@@ -53,2 +84,3 @@ sub new {
53 $self->{error} = "Failed to inherit environment"; 84 $self->{error} = "Failed to inherit environment";
85 return $self;
54 } else { 86 } else {
@@ -57,8 +89,7 @@ sub new {
57 } 89 }
58 } 90 } else {
59 $self->{environ} = $env->envs; 91 $self->{environ} = $env->envs;
92 }
60 } 93 }
61 94
62 croak "unrecognized arguments" if keys(%_);
63
64 $self->_get_version_info unless $self->status; 95 $self->_get_version_info unless $self->status;
@@ -76,3 +107,2 @@ sub probe {
76 107
77 open(my $nullout, '>', File::Spec->devnull);
78 open(my $nullin, '<', File::Spec->devnull); 108 open(my $nullin, '<', File::Spec->devnull);
@@ -384,4 +414,10 @@ The default used in the absense of this attribute is:
384 414
385 [ '/usr/sbin/httpd', '/usr/sbin/apache2' ] 415 [ '/usr/sbin/apachectl', '/usr/sbin/httpd', '/usr/sbin/apache2' ]
386 416
417The use of B<apachectl> is preferred over directly invoking B<httpd> daemon,
418because the apache configuration file might contain referenmces to environment
419variables defined elsewhere, which will cause B<httpd> to fail. B<apachectl>
420takes care of this by including the file with variable definitions prior to
421calling B<httpd>. See also C<environ>, below.
422
387=item C<environ> 423=item C<environ>
@@ -389,9 +425,5 @@ The default used in the absense of this attribute is:
389Name of the shell script that sets the environment for B<httpd> invocation. 425Name of the shell script that sets the environment for B<httpd> invocation.
390 426Usually, this is the same script that is sourced by B<apachectl> prior to
391If invoked with the B<-V> option, B<httpd> attempts to read its configuration 427passing control over to B<httpd>. This option provides another solution to
392file and will fail if the latter contains references to the environment 428the environment problem mentioned above. E.g.:
393variables defined elsewhere. This is quite common in Debian-based
394distributions, which define the environment variables in file
395F</etc/apache2/envvars>. To avoid such failures, use the C<environ> attribute,
396e.g.:
397 429
@@ -401,3 +433,3 @@ e.g.:
401 433
402Controls the error handling. Allowed values are C<croak> and C<return>. 434Controls error handling. Allowed values are C<croak> and C<return>.
403If the value is C<croak> (the default), the method will I<croak> if an 435If the value is C<croak> (the default), the method will I<croak> if an

Return to:

Send suggestions and report system problems to the System administrator.