summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes10
-rw-r--r--MANIFEST.SKIP1
-rw-r--r--Makefile.PL4
-rw-r--r--lib/Apache/Defaults.pm72
4 files changed, 65 insertions, 22 deletions
diff --git a/Changes b/Changes
index c7d5cbe..5add4d6 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,9 @@
+1.03 2021-02-12
+ - Change bugtracker address.
+1.02 2019-08-25
+ - Make sure constructor never croaks if on_error is set to 'return'
+ Improve diagnostics.
+1.01 2018-07-17
+ - Prefer apachectl over invoking httpd directly.
1.00 2018-02-24
-
-* Initial release.
+ - Initial release.
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
index 58696be..3fb78f0 100644
--- a/MANIFEST.SKIP
+++ b/MANIFEST.SKIP
@@ -13,24 +13,25 @@
\bDescrip.MMS$
\bDESCRIP.MMS$
\bdescrip.mms$
# Avoid Makemaker generated and utility files.
\bMANIFEST\.bak
\bMakefile$
\bblib/
\bMakeMaker-\d
\bpm_to_blib\.ts$
\bpm_to_blib$
\bblibdirs\.ts$ # 6.18 through 6.25 generated this
+\bMANIFEST\.SKIP$
# Avoid Module::Build generated and utility files.
\bBuild$
\b_build/
\bBuild.bat$
\bBuild.COM$
\bBUILD.COM$
\bbuild.com$
# Avoid temp and backup files.
~$
\.old$
diff --git a/Makefile.PL b/Makefile.PL
index 9918d74..7cdd45a 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -18,17 +18,21 @@ WriteMakefile(NAME => 'Apache::Defaults',
'Test' => 0,
'File::Temp' => '0.23',
},
MIN_PERL_VERSION => 5.014002,
META_MERGE => {
'meta-spec' => { version => 2},
resources => {
repository => {
type => 'git',
url => 'git://git.gnu.org.ua/apache-defaults.git',
web => 'http://git.gnu.org.ua/cgit/apache-defaults.git'
},
+ bugtracker => {
+ web => 'https://puszcza.gnu.org.ua/bugs/?group=apache-defaults',
+ mailto => 'gray+apache-defaults@gnu.org.ua'
+ }
},
provides => Module::Metadata->provides(version => '1.4',
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
@@ -1,89 +1,119 @@
package Apache::Defaults;
use strict;
use warnings;
use File::Spec;
use IPC::Open3;
use Shell::GetEnv;
use DateTime::Format::Strptime;
use Text::ParseWords;
use Symbol 'gensym';
use Carp;
-our $VERSION = '1.00';
+our $VERSION = '1.03';
sub new {
my $class = shift;
my $self = bless { on_error => 'croak' }, $class;
local %_ = @_;
my $v;
if (my $v = delete $_{on_error}) {
croak "invalid on_error value"
unless grep { $_ eq $v } qw(croak return);
$self->{on_error} = $v;
}
my @servlist;
if ($v = delete $_{server}) {
if (ref($v) eq 'ARRAY') {
@servlist = @$v;
} else {
@servlist = ( $v );
}
} else {
- @servlist = qw(/usr/sbin/httpd /usr/sbin/apache2);
+ @servlist = qw(/usr/sbin/apachectl /usr/sbin/httpd /usr/sbin/apache2);
}
if (my @select = grep { -x $_->[0] }
map { [ shellwords($_) ] } @servlist) {
$self->{server} = shift @select;
} elsif ($self->{on_error} eq 'return') {
$self->{status} = 127;
$self->{error} = "No suitable httpd binary found";
} else {
croak "No suitable httpd binary found";
}
- if ($v = delete $_{environ}) {
- my $env = Shell::GetEnv->new('sh', ". $v",
- { startup => 0 });
- if ($env->status) {
+ my $envfile = delete $_{environ};
+ croak "unrecognized arguments" if keys(%_);
+
+ if ($envfile) {
+ unless (-f $envfile) {
+ if ($self->{on_error} eq 'return') {
+ $self->{status} = 127;
+ $self->{error} = "environment file $envfile does not exist";
+ return $self;
+ } else {
+ croak "environment file $envfile does not exist";
+ }
+ }
+ unless (-r $envfile) {
+ if ($self->{on_error} eq 'return') {
+ $self->{status} = 127;
+ $self->{error} = "environment file $envfile is not readable";
+ return $self;
+ } else {
+ croak "environment file $envfile is not readable";
+ }
+ }
+
+ my $env = eval {
+ Shell::GetEnv->new('sh', ". $envfile", { startup => 0 });
+ };
+ if ($@) {
+ if ($self->{on_error} eq 'return') {
+ $self->{status} = 127;
+ $self->{error} = $@;
+ return $self;
+ } else {
+ croak $@;
+ }
+ } elsif ($env->status) {
if ($self->{on_error} eq 'return') {
$self->{status} = $env->status;
$self->{error} = "Failed to inherit environment";
+ return $self;
} else {
croak sprintf("Got status %d trying to inherit environment",
$env->status);
}
- }
- $self->{environ} = $env->envs;
+ } else {
+ $self->{environ} = $env->envs;
+ }
}
- croak "unrecognized arguments" if keys(%_);
-
$self->_get_version_info unless $self->status;
$self->_get_module_info unless $self->status;
return $self;
}
sub server { shift->{server}[0] }
sub server_command { @{shift->{server}} }
sub environ { shift->{environ} }
sub probe {
my ($self, $cb, @opt) = @_;
- open(my $nullout, '>', File::Spec->devnull);
open(my $nullin, '<', File::Spec->devnull);
my $out = gensym;
my $err = gensym;
local %ENV = %{$self->{environ}} if $self->{environ};
if (my $pid = open3($nullin, $out, $err,
$self->server_command, @opt)) {
while (<$out>) {
chomp;
last unless &{$cb}($_);
}
waitpid($pid, 0);
@@ -373,42 +403,44 @@ them. Attributes (I<%attrs>) are:
=item C<server>
Full pathname of the B<httpd> binary to inspect. The argument can also be
a reference to the list of possible pathnames. In this case, the first of
them that exists on disk and has executable privileges will be used. Full
command line can also be used, e.g.:
server => '/usr/sbin/httpd -d /etc/httpd'
The default used in the absense of this attribute is:
- [ '/usr/sbin/httpd', '/usr/sbin/apache2' ]
+ [ '/usr/sbin/apachectl', '/usr/sbin/httpd', '/usr/sbin/apache2' ]
+The use of B<apachectl> is preferred over directly invoking B<httpd> daemon,
+because the apache configuration file might contain referenmces to environment
+variables defined elsewhere, which will cause B<httpd> to fail. B<apachectl>
+takes care of this by including the file with variable definitions prior to
+calling B<httpd>. See also C<environ>, below.
+
=item C<environ>
Name of the shell script that sets the environment for B<httpd> invocation.
-
-If invoked with the B<-V> option, B<httpd> attempts to read its configuration
-file and will fail if the latter contains references to the environment
-variables defined elsewhere. This is quite common in Debian-based
-distributions, which define the environment variables in file
-F</etc/apache2/envvars>. To avoid such failures, use the C<environ> attribute,
-e.g.:
+Usually, this is the same script that is sourced by B<apachectl> prior to
+passing control over to B<httpd>. This option provides another solution to
+the environment problem mentioned above. E.g.:
$x = new Apache::Defaults(environ => /etc/apache2/envvars)
=item C<on_error>
-Controls the error handling. Allowed values are C<croak> and C<return>.
+Controls error handling. Allowed values are C<croak> and C<return>.
If the value is C<croak> (the default), the method will I<croak> if an
error occurs. If set to C<return>, the constructor will return a valid
object. The B<httpd> exit status and diagnostics emitted to the stderr
will be available via the B<status> and B<error> methods.
=back
=head2 status
$x = new Apache::Defaults(on_error => 'return');
if ($x->status) {
die $x->error;

Return to:

Send suggestions and report system problems to the System administrator.