diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-07-17 10:29:32 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-07-17 10:29:32 +0300 |
commit | 447c9ac19f0ecac9a728de36409cc8d7afdf3001 (patch) | |
tree | 98614ebfddcaf79dc910b598fe14b0195eda5f23 | |
parent | d9bdc9cfcb2f10ea3642b6150e1c4fddbf9facdb (diff) | |
download | apache-defaults-447c9ac19f0ecac9a728de36409cc8d7afdf3001.tar.gz apache-defaults-447c9ac19f0ecac9a728de36409cc8d7afdf3001.tar.bz2 |
Prefer apachectl over httpdv1.01
* lib/Apache/Defaults.pm: Version 1.01
(new): Try to use apachectl first. This ensures the correct environment
will be used.
* Changes: Update.
-rw-r--r-- | Changes | 5 | ||||
-rw-r--r-- | MANIFEST.SKIP | 1 | ||||
-rw-r--r-- | lib/Apache/Defaults.pm | 25 |
3 files changed, 17 insertions, 14 deletions
@@ -1,3 +1,4 @@ | |||
1 | 1.01 2018-07-17 | ||
2 | - Prefer apachectl over invoking httpd directly. | ||
1 | 1.00 2018-02-24 | 3 | 1.00 2018-02-24 |
2 | 4 | - Initial release. | |
3 | * Initial release. | ||
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 58696be..3fb78f0 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP | |||
@@ -19,12 +19,13 @@ | |||
19 | \bMakefile$ | 19 | \bMakefile$ |
20 | \bblib/ | 20 | \bblib/ |
21 | \bMakeMaker-\d | 21 | \bMakeMaker-\d |
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$ |
28 | \b_build/ | 29 | \b_build/ |
29 | \bBuild.bat$ | 30 | \bBuild.bat$ |
30 | \bBuild.COM$ | 31 | \bBuild.COM$ |
diff --git a/lib/Apache/Defaults.pm b/lib/Apache/Defaults.pm index 70d5385..6108d23 100644 --- a/lib/Apache/Defaults.pm +++ b/lib/Apache/Defaults.pm | |||
@@ -6,13 +6,13 @@ use IPC::Open3; | |||
6 | use Shell::GetEnv; | 6 | use Shell::GetEnv; |
7 | use DateTime::Format::Strptime; | 7 | use DateTime::Format::Strptime; |
8 | use Text::ParseWords; | 8 | 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.01'; |
13 | 13 | ||
14 | sub new { | 14 | sub new { |
15 | my $class = shift; | 15 | my $class = shift; |
16 | my $self = bless { on_error => 'croak' }, $class; | 16 | my $self = bless { on_error => 'croak' }, $class; |
17 | local %_ = @_; | 17 | local %_ = @_; |
18 | my $v; | 18 | my $v; |
@@ -28,13 +28,13 @@ sub new { | |||
28 | if (ref($v) eq 'ARRAY') { | 28 | if (ref($v) eq 'ARRAY') { |
29 | @servlist = @$v; | 29 | @servlist = @$v; |
30 | } else { | 30 | } else { |
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] } |
38 | map { [ shellwords($_) ] } @servlist) { | 38 | map { [ shellwords($_) ] } @servlist) { |
39 | $self->{server} = shift @select; | 39 | $self->{server} = shift @select; |
40 | } elsif ($self->{on_error} eq 'return') { | 40 | } elsif ($self->{on_error} eq 'return') { |
@@ -71,13 +71,12 @@ sub server { shift->{server}[0] } | |||
71 | sub server_command { @{shift->{server}} } | 71 | sub server_command { @{shift->{server}} } |
72 | sub environ { shift->{environ} } | 72 | sub environ { shift->{environ} } |
73 | 73 | ||
74 | sub probe { | 74 | sub probe { |
75 | my ($self, $cb, @opt) = @_; | 75 | my ($self, $cb, @opt) = @_; |
76 | 76 | ||
77 | open(my $nullout, '>', File::Spec->devnull); | ||
78 | open(my $nullin, '<', File::Spec->devnull); | 77 | open(my $nullin, '<', File::Spec->devnull); |
79 | 78 | ||
80 | my $out = gensym; | 79 | my $out = gensym; |
81 | my $err = gensym; | 80 | my $err = gensym; |
82 | local %ENV = %{$self->{environ}} if $self->{environ}; | 81 | local %ENV = %{$self->{environ}} if $self->{environ}; |
83 | if (my $pid = open3($nullin, $out, $err, | 82 | if (my $pid = open3($nullin, $out, $err, |
@@ -379,30 +378,32 @@ them that exists on disk and has executable privileges will be used. Full | |||
379 | command line can also be used, e.g.: | 378 | command line can also be used, e.g.: |
380 | 379 | ||
381 | server => '/usr/sbin/httpd -d /etc/httpd' | 380 | server => '/usr/sbin/httpd -d /etc/httpd' |
382 | 381 | ||
383 | The default used in the absense of this attribute is: | 382 | The default used in the absense of this attribute is: |
384 | 383 | ||
385 | [ '/usr/sbin/httpd', '/usr/sbin/apache2' ] | 384 | [ '/usr/sbin/apachectl', '/usr/sbin/httpd', '/usr/sbin/apache2' ] |
386 | 385 | ||
386 | The use of B<apachectl> is preferred over directly invoking B<httpd> daemon, | ||
387 | because the apache configuration file might contain referenmces to environment | ||
388 | variables defined elsewhere, which will cause B<httpd> to fail. B<apachectl> | ||
389 | takes care of this by including the file with variable definitions prior to | ||
390 | calling B<httpd>. See also C<environ>, below. | ||
391 | |||
387 | =item C<environ> | 392 | =item C<environ> |
388 | 393 | ||
389 | Name of the shell script that sets the environment for B<httpd> invocation. | 394 | Name of the shell script that sets the environment for B<httpd> invocation. |
390 | 395 | 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 | 396 | 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 | 397 | 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 | 398 | ||
398 | $x = new Apache::Defaults(environ => /etc/apache2/envvars) | 399 | $x = new Apache::Defaults(environ => /etc/apache2/envvars) |
399 | 400 | ||
400 | =item C<on_error> | 401 | =item C<on_error> |
401 | 402 | ||
402 | Controls the error handling. Allowed values are C<croak> and C<return>. | 403 | 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 | 404 | 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 | 405 | 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 | 406 | object. The B<httpd> exit status and diagnostics emitted to the stderr |
406 | will be available via the B<status> and B<error> methods. | 407 | will be available via the B<status> and B<error> methods. |
407 | 408 | ||
408 | =back | 409 | =back |