From 8cddf3d973323e0965ab0a3e190f131888a37e5c Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Sun, 6 Jan 2008 17:31:40 +0000 Subject: move Scire.pm to Scire/Job.pm and fix scireclient.pm to use the new paths svn path=/branches/new-fu/; revision=335 --- client/Scire.pm | 87 --------------------------------------------------- client/Scire/Job.pm | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ client/scireclient.pl | 3 +- 3 files changed, 89 insertions(+), 88 deletions(-) delete mode 100644 client/Scire.pm create mode 100644 client/Scire/Job.pm diff --git a/client/Scire.pm b/client/Scire.pm deleted file mode 100644 index 7319529..0000000 --- a/client/Scire.pm +++ /dev/null @@ -1,87 +0,0 @@ -package Scire::Job; - -use POSIX qw/WEXITSTATUS WIFEXITED waitpid/; -use IPC::Open3 (open3); - -sub new { - my $proto = shift; - my $class = ref($proto) || $proto; - my $filename = shift; - my $self = {}; - bless ($self, $class); - if(defined $filename) { - $self->load_jobfile($filename); - } - return $self; -} - -sub load_jobfile { - my $self = shift; - my $filename = shift; - $self->{filename} = $filename; - my $jobcontents; - my $jobdata; - open JOB, "< ${filename}" or die "Can't open file ${filename}"; - $jobcontents = join("", ); - close JOB; - $jobdata = eval($jobcontents); - ($@) and print "ERROR: Could not parse job file ${filename}!\n"; - if(defined $jobdata->{script}) { - for(keys %{$jobdata->{script}}) { - $self->{$_} = $jobdata->{script}->{$_}; - } - } - for(keys %{$jobdata}) { - $self->{$_} = $jobdata->{$_} unless($_ eq "script"); - } -} - -sub set_stdout_file { - my ($self, $outfile) = @_; - if(defined $outfile && $outfile) { - $self->{stdout_filename} = $outfile; - } -} - -sub set_stderr_file { - my ($self, $errfile) = @_; - if(defined $errfile && $errfile) { - $self->{stderr_filename} = $errfile; - } -} - -sub run { - my $self = shift; - - # XXX: write $self->{script_data} out to a file and mark it +x. We'll need - # to find a good location for this, since it can't be noexec. Perhaps the - # queue dir in the job directory will do, or maybe it will be configurable - - my $pid = fork(); - if($fork) { - # XXX: eventually, we'll move the waitpid() call to another function - # called something like is_running() and use WNOHANG instead of blocking - waitpid($pid, 0); - my $status = $?; - my $exitcode = -1; - if(WIFEXITED($status)) { - my $exitcode = WEXITSTATUS($status); - } - return $exitcode; - } else { - # XXX: we'll use setuid to drop privileges here - if(defined $self->{stdout_filename}) { - open STDOUT, '>', $self->{stdout_filename}; - } - if(defined $self->{stderr_filename}) { - open STDERR, '>', $self->{stderr_filename}; - } - # XXX: exec() to run our command. our STDOUT and STDERR have been - # redirected to the files specified, and the exit code is returned - # to the main process when we're done executing - } -} - - - -1; diff --git a/client/Scire/Job.pm b/client/Scire/Job.pm new file mode 100644 index 0000000..7319529 --- /dev/null +++ b/client/Scire/Job.pm @@ -0,0 +1,87 @@ +package Scire::Job; + +use POSIX qw/WEXITSTATUS WIFEXITED waitpid/; +use IPC::Open3 (open3); + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $filename = shift; + my $self = {}; + bless ($self, $class); + if(defined $filename) { + $self->load_jobfile($filename); + } + return $self; +} + +sub load_jobfile { + my $self = shift; + my $filename = shift; + $self->{filename} = $filename; + my $jobcontents; + my $jobdata; + open JOB, "< ${filename}" or die "Can't open file ${filename}"; + $jobcontents = join("", ); + close JOB; + $jobdata = eval($jobcontents); + ($@) and print "ERROR: Could not parse job file ${filename}!\n"; + if(defined $jobdata->{script}) { + for(keys %{$jobdata->{script}}) { + $self->{$_} = $jobdata->{script}->{$_}; + } + } + for(keys %{$jobdata}) { + $self->{$_} = $jobdata->{$_} unless($_ eq "script"); + } +} + +sub set_stdout_file { + my ($self, $outfile) = @_; + if(defined $outfile && $outfile) { + $self->{stdout_filename} = $outfile; + } +} + +sub set_stderr_file { + my ($self, $errfile) = @_; + if(defined $errfile && $errfile) { + $self->{stderr_filename} = $errfile; + } +} + +sub run { + my $self = shift; + + # XXX: write $self->{script_data} out to a file and mark it +x. We'll need + # to find a good location for this, since it can't be noexec. Perhaps the + # queue dir in the job directory will do, or maybe it will be configurable + + my $pid = fork(); + if($fork) { + # XXX: eventually, we'll move the waitpid() call to another function + # called something like is_running() and use WNOHANG instead of blocking + waitpid($pid, 0); + my $status = $?; + my $exitcode = -1; + if(WIFEXITED($status)) { + my $exitcode = WEXITSTATUS($status); + } + return $exitcode; + } else { + # XXX: we'll use setuid to drop privileges here + if(defined $self->{stdout_filename}) { + open STDOUT, '>', $self->{stdout_filename}; + } + if(defined $self->{stderr_filename}) { + open STDERR, '>', $self->{stderr_filename}; + } + # XXX: exec() to run our command. our STDOUT and STDERR have been + # redirected to the files specified, and the exit code is returned + # to the main process when we're done executing + } +} + + + +1; diff --git a/client/scireclient.pl b/client/scireclient.pl index 2415373..91bd1c5 100755 --- a/client/scireclient.pl +++ b/client/scireclient.pl @@ -5,7 +5,8 @@ use strict; use warnings; -use Scire; +use Scire::Job; +use Scire::Communicator; use Getopt::Long; use Data::Dumper; use File::Path; -- cgit v1.2.3-65-gdbad