create the pid_file dir if it does not exist
- steal the _create_resource_dir sub to create a generic dir - re-use it to create the pid dir - with a few more trace() diagnostics too
This commit is contained in:
parent
c3cf4cdfbb
commit
e2753e5f8b
2 changed files with 19 additions and 9 deletions
2
Changes
2
Changes
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
|
* create dir for pid_file if it does not exist
|
||||||
|
|
||||||
0.001000 2013-02-26 SymKat <symkat@symkat.com>
|
0.001000 2013-02-26 SymKat <symkat@symkat.com>
|
||||||
* fixed a warning on "uninitialized value $called_with in substitution"
|
* fixed a warning on "uninitialized value $called_with in substitution"
|
||||||
(Kromg)
|
(Kromg)
|
||||||
|
|
|
@ -131,16 +131,21 @@ sub redirect_filehandles {
|
||||||
|
|
||||||
sub _create_resource_dir {
|
sub _create_resource_dir {
|
||||||
my ( $self ) = @_;
|
my ( $self ) = @_;
|
||||||
|
$self->_create_dir($self->resource_dir);
|
||||||
|
}
|
||||||
|
|
||||||
return 0 unless $self->resource_dir;
|
sub _create_dir {
|
||||||
|
my ( $self, $dir ) = @_;
|
||||||
|
|
||||||
if ( -d $self->resource_dir ) {
|
return 0 unless $dir;
|
||||||
$self->trace( "Resource dir exists (" . $self->resource_dir . ")" );
|
|
||||||
|
if ( -d $dir ) {
|
||||||
|
$self->trace( "Dir exists (" . $dir . ") - no need to create" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my ( $created ) = make_path(
|
my ( $created ) = make_path(
|
||||||
$self->resource_dir,
|
$dir,
|
||||||
{
|
{
|
||||||
uid => $self->uid,
|
uid => $self->uid,
|
||||||
group => $self->gid,
|
group => $self->gid,
|
||||||
|
@ -155,14 +160,13 @@ sub _create_resource_dir {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $created eq $self->resource_dir ) {
|
if ( $created eq $dir ) {
|
||||||
$self->trace( "Created resource dir (" . $self->resource_dir . ")" );
|
$self->trace( "Created dir (" . $dir . ")" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->trace( "_create_resource_dir() failed and I don't know why" );
|
$self->trace( "_create_dir() for $dir failed and I don't know why" );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _double_fork {
|
sub _double_fork {
|
||||||
|
@ -256,7 +260,6 @@ sub _launch_program {
|
||||||
sub write_pid {
|
sub write_pid {
|
||||||
my ( $self ) = @_;
|
my ( $self ) = @_;
|
||||||
|
|
||||||
|
|
||||||
# Create the PID file as the user we currently are,
|
# Create the PID file as the user we currently are,
|
||||||
# and change the permissions to our target UID/GID.
|
# and change the permissions to our target UID/GID.
|
||||||
|
|
||||||
|
@ -270,10 +273,15 @@ sub write_pid {
|
||||||
|
|
||||||
sub _write_pid {
|
sub _write_pid {
|
||||||
my ( $self ) = @_;
|
my ( $self ) = @_;
|
||||||
|
|
||||||
|
my ($volume, $dir, $file) = File::Spec->splitpath($self->pid_file);
|
||||||
|
return 0 if not $self->_create_dir($dir);
|
||||||
|
|
||||||
open my $sf, ">", $self->pid_file
|
open my $sf, ">", $self->pid_file
|
||||||
or die "Failed to write " . $self->pid_file . ": $!";
|
or die "Failed to write " . $self->pid_file . ": $!";
|
||||||
print $sf $self->pid;
|
print $sf $self->pid;
|
||||||
close $sf;
|
close $sf;
|
||||||
|
$self->trace( "Wrote pid (" . $self->pid . ") to pid file (" . $self->pid_file . ")" );
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue