summaryrefslogtreecommitdiffabout
path: root/lib/Apache/Defaults.pm
Side-by-side diff
Diffstat (limited to 'lib/Apache/Defaults.pm') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/Apache/Defaults.pm72
1 files changed, 52 insertions, 20 deletions
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;
-our $VERSION = '1.00';
+our $VERSION = '1.02';
@@ -33,3 +33,3 @@ sub new {
} else {
- @servlist = qw(/usr/sbin/httpd /usr/sbin/apache2);
+ @servlist = qw(/usr/sbin/apachectl /usr/sbin/httpd /usr/sbin/apache2);
}
@@ -46,6 +46,37 @@ sub new {
- 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') {
@@ -53,2 +84,3 @@ sub new {
$self->{error} = "Failed to inherit environment";
+ return $self;
} else {
@@ -57,8 +89,7 @@ sub new {
}
- }
- $self->{environ} = $env->envs;
+ } else {
+ $self->{environ} = $env->envs;
+ }
}
- croak "unrecognized arguments" if keys(%_);
-
$self->_get_version_info unless $self->status;
@@ -76,3 +107,2 @@ sub probe {
- open(my $nullout, '>', File::Spec->devnull);
open(my $nullin, '<', File::Spec->devnull);
@@ -384,4 +414,10 @@ 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>
@@ -389,9 +425,5 @@ The default used in the absense of this attribute is:
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.:
@@ -401,3 +433,3 @@ e.g.:
-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

Return to:

Send suggestions and report system problems to the System administrator.