diff options
author | 2008-01-06 08:09:17 +0000 | |
---|---|---|
committer | 2008-01-06 08:09:17 +0000 | |
commit | 21186444cd1411fbba30bbf274a3c8aaf6b060da (patch) | |
tree | b81430e876bf93e7a02aa786241820f4909a922a | |
parent | add stub for run() (diff) | |
download | scire-21186444cd1411fbba30bbf274a3c8aaf6b060da.tar.gz scire-21186444cd1411fbba30bbf274a3c8aaf6b060da.tar.bz2 scire-21186444cd1411fbba30bbf274a3c8aaf6b060da.zip |
fill out run() a bit more
svn path=/branches/new-fu/; revision=333
-rw-r--r-- | client/Scire.pm | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/client/Scire.pm b/client/Scire.pm index 455c8b1..deedcb6 100644 --- a/client/Scire.pm +++ b/client/Scire.pm @@ -1,5 +1,8 @@ package Scire::Job; +use POSIX qw/WEXITSTATUS WIFEXITED waitpid/; +use IPC::Open3 (open3); + sub new { my $proto = shift; my $class = ref($proto) || $proto; @@ -33,9 +36,50 @@ sub load_jobfile { } } +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, $outfile, $errfile) = @_; + 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 + } } package Scire::Communicator; |