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.pm49
1 files changed, 40 insertions, 9 deletions
diff --git a/lib/Apache/Defaults.pm b/lib/Apache/Defaults.pm
index 6108d23..5fa8217 100644
--- a/lib/Apache/Defaults.pm
+++ b/lib/Apache/Defaults.pm
@@ -6,13 +6,13 @@ use IPC::Open3;
use Shell::GetEnv;
use DateTime::Format::Strptime;
use Text::ParseWords;
use Symbol 'gensym';
use Carp;
-our $VERSION = '1.01';
+our $VERSION = '1.02';
sub new {
my $class = shift;
my $self = bless { on_error => 'croak' }, $class;
local %_ = @_;
my $v;
@@ -41,29 +41,60 @@ sub new {
$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;
}

Return to:

Send suggestions and report system problems to the System administrator.