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
@@ -22,6 +22,7 @@
22\bpm_to_blib\.ts$ 22\bpm_to_blib\.ts$
23\bpm_to_blib$ 23\bpm_to_blib$
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
26# Avoid Module::Build generated and utility files. 27# Avoid Module::Build generated and utility files.
27\bBuild$ 28\bBuild$
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
@@ -9,7 +9,7 @@ use Text::ParseWords;
9use Symbol 'gensym'; 9use Symbol 'gensym';
10use Carp; 10use Carp;
11 11
12our $VERSION = '1.00'; 12our $VERSION = '1.02';
13 13
14sub new { 14sub new {
15 my $class = shift; 15 my $class = shift;
@@ -31,7 +31,7 @@ sub new {
31 @servlist = ( $v ); 31 @servlist = ( $v );
32 } 32 }
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 }
36 36
37 if (my @select = grep { -x $_->[0] } 37 if (my @select = grep { -x $_->[0] }
@@ -44,23 +44,54 @@ sub new {
44 croak "No suitable httpd binary found"; 44 croak "No suitable httpd binary found";
45 } 45 }
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') {
52 $self->{status} = $env->status; 83 $self->{status} = $env->status;
53 $self->{error} = "Failed to inherit environment"; 84 $self->{error} = "Failed to inherit environment";
85 return $self;
54 } else { 86 } else {
55 croak sprintf("Got status %d trying to inherit environment", 87 croak sprintf("Got status %d trying to inherit environment",
56 $env->status); 88 $env->status);
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;
65 $self->_get_module_info unless $self->status; 96 $self->_get_module_info unless $self->status;
66 97
@@ -74,7 +105,6 @@ sub environ { shift->{environ} }
74sub probe { 105sub probe {
75 my ($self, $cb, @opt) = @_; 106 my ($self, $cb, @opt) = @_;
76 107
77 open(my $nullout, '>', File::Spec->devnull);
78 open(my $nullin, '<', File::Spec->devnull); 108 open(my $nullin, '<', File::Spec->devnull);
79 109
80 my $out = gensym; 110 my $out = gensym;
@@ -382,24 +412,26 @@ command line can also be used, e.g.:
382 412
383The default used in the absense of this attribute is: 413The 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>
388 424
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
398 $x = new Apache::Defaults(environ => /etc/apache2/envvars) 430 $x = new Apache::Defaults(environ => /etc/apache2/envvars)
399 431
400=item C<on_error> 432=item C<on_error>
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
404error occurs. If set to C<return>, the constructor will return a valid 436error occurs. If set to C<return>, the constructor will return a valid
405object. The B<httpd> exit status and diagnostics emitted to the stderr 437object. The B<httpd> exit status and diagnostics emitted to the stderr

Return to:

Send suggestions and report system problems to the System administrator.