diff options
-rw-r--r-- | Changes | 10 | ||||
-rw-r--r-- | MANIFEST.SKIP | 1 | ||||
-rw-r--r-- | Makefile.PL | 4 | ||||
-rw-r--r-- | lib/Apache/Defaults.pm | 70 |
4 files changed, 64 insertions, 21 deletions
@@ -1,3 +1,9 @@ | |||
1 | 1.03 2021-02-12 | ||
2 | - Change bugtracker address. | ||
3 | 1.02 2019-08-25 | ||
4 | - Make sure constructor never croaks if on_error is set to 'return' | ||
5 | Improve diagnostics. | ||
6 | 1.01 2018-07-17 | ||
7 | - Prefer apachectl over invoking httpd directly. | ||
1 | 1.00 2018-02-24 | 8 | 1.00 2018-02-24 |
2 | 9 | - 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/Makefile.PL b/Makefile.PL index 9918d74..7cdd45a 100644 --- a/Makefile.PL +++ b/Makefile.PL | |||
@@ -27,6 +27,10 @@ WriteMakefile(NAME => 'Apache::Defaults', | |||
27 | url => 'git://git.gnu.org.ua/apache-defaults.git', | 27 | url => 'git://git.gnu.org.ua/apache-defaults.git', |
28 | web => 'http://git.gnu.org.ua/cgit/apache-defaults.git' | 28 | web => 'http://git.gnu.org.ua/cgit/apache-defaults.git' |
29 | }, | 29 | }, |
30 | bugtracker => { | ||
31 | web => 'https://puszcza.gnu.org.ua/bugs/?group=apache-defaults', | ||
32 | mailto => 'gray+apache-defaults@gnu.org.ua' | ||
33 | } | ||
30 | }, | 34 | }, |
31 | provides => Module::Metadata->provides(version => '1.4', | 35 | provides => Module::Metadata->provides(version => '1.4', |
32 | dir => 'lib') | 36 | dir => 'lib') |
diff --git a/lib/Apache/Defaults.pm b/lib/Apache/Defaults.pm index 70d5385..0978456 100644 --- a/lib/Apache/Defaults.pm +++ b/lib/Apache/Defaults.pm | |||
@@ -9,7 +9,7 @@ use Text::ParseWords; | |||
9 | use Symbol 'gensym'; | 9 | use Symbol 'gensym'; |
10 | use Carp; | 10 | use Carp; |
11 | 11 | ||
12 | our $VERSION = '1.00'; | 12 | our $VERSION = '1.03'; |
13 | 13 | ||
14 | sub new { | 14 | sub 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,22 +44,53 @@ 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; |
60 | } | 92 | } |
61 | 93 | } | |
62 | croak "unrecognized arguments" if keys(%_); | ||
63 | 94 | ||
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; |
@@ -74,7 +105,6 @@ sub environ { shift->{environ} } | |||
74 | sub probe { | 105 | sub 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 | ||
383 | The default used in the absense of this attribute is: | 413 | 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' ] |
416 | |||
417 | The use of B<apachectl> is preferred over directly invoking B<httpd> daemon, | ||
418 | because the apache configuration file might contain referenmces to environment | ||
419 | variables defined elsewhere, which will cause B<httpd> to fail. B<apachectl> | ||
420 | takes care of this by including the file with variable definitions prior to | ||
421 | calling B<httpd>. See also C<environ>, below. | ||
386 | 422 | ||
387 | =item C<environ> | 423 | =item C<environ> |
388 | 424 | ||
389 | Name of the shell script that sets the environment for B<httpd> invocation. | 425 | Name of the shell script that sets the environment for B<httpd> invocation. |
390 | 426 | Usually, this is the same script that is sourced by B<apachectl> prior to | |
391 | If invoked with the B<-V> option, B<httpd> attempts to read its configuration | 427 | passing control over to B<httpd>. This option provides another solution to |
392 | file and will fail if the latter contains references to the environment | 428 | the environment problem mentioned above. E.g.: |
393 | variables defined elsewhere. This is quite common in Debian-based | ||
394 | distributions, which define the environment variables in file | ||
395 | F</etc/apache2/envvars>. To avoid such failures, use the C<environ> attribute, | ||
396 | e.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 | ||
402 | Controls the error handling. Allowed values are C<croak> and C<return>. | 434 | Controls error handling. Allowed values are C<croak> and C<return>. |
403 | If the value is C<croak> (the default), the method will I<croak> if an | 435 | If the value is C<croak> (the default), the method will I<croak> if an |
404 | error occurs. If set to C<return>, the constructor will return a valid | 436 | error occurs. If set to C<return>, the constructor will return a valid |
405 | object. The B<httpd> exit status and diagnostics emitted to the stderr | 437 | object. The B<httpd> exit status and diagnostics emitted to the stderr |