Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
RunRedirected Class Reference

#include <run_redirected.h>

Collaboration diagram for RunRedirected:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 operator bool (void)
bool operator! (void)

Static Public Member Functions

static int run (JobUser &user, const char *cmdname, int in, int out, int err, char *const args[], int timeout)
static int run (JobUser &user, const char *cmdname, int in, int out, int err, const char *cmd, int timeoutd)

Private Member Functions

 RunRedirected (JobUser &user, const char *cmdname, int in, int out, int err)
 ~RunRedirected (void)

Static Private Member Functions

static void initializer (void *arg)

Private Attributes

JobUseruser_
std::string cmdname_
int stdin_
int stdout_
int stderr_

Detailed Description

Definition at line 10 of file run_redirected.h.


Constructor & Destructor Documentation

RunRedirected::RunRedirected ( JobUser user,
const char *  cmdname,
int  in,
int  out,
int  err 
) [inline, private]

Definition at line 12 of file run_redirected.h.

:user_(user),cmdname_(cmdname?cmdname:""),stdin_(in),stdout_(out),stderr_(err) { };

Here is the caller graph for this function:

RunRedirected::~RunRedirected ( void  ) [inline, private]

Definition at line 13 of file run_redirected.h.

{ };

Member Function Documentation

void RunRedirected::initializer ( void *  arg) [static, private]

Definition at line 77 of file run_redirected.cpp.

                                         {
#ifdef WIN32
#error This functionality is not available in Windows environement
#else
  // child
  RunRedirected* it = (RunRedirected*)arg;
  struct rlimit lim;
  int max_files;
  if(getrlimit(RLIMIT_NOFILE,&lim) == 0) { max_files=lim.rlim_cur; }
  else { max_files=4096; };
  // change user
  if(!(it->user_.SwitchUser(true))) {
    logger.msg(Arc::ERROR,"%s: Failed switching user",it->cmdname_); sleep(10); exit(1);
  };
  // set up stdin,stdout and stderr
  if(it->stdin_ != -1)  dup2(it->stdin_,0);
  if(it->stdout_ != -1) dup2(it->stdout_,1);
  if(it->stderr_ != -1) dup2(it->stderr_,2);
  // close all handles inherited from parent
  if(max_files == RLIM_INFINITY) max_files=4096;
  for(int i=3;i<max_files;i++) { close(i); };
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

RunRedirected::operator bool ( void  ) [inline]

Definition at line 21 of file run_redirected.h.

{ return true; };
bool RunRedirected::operator! ( void  ) [inline]

Definition at line 22 of file run_redirected.h.

{ return false; };
int RunRedirected::run ( JobUser user,
const char *  cmdname,
int  in,
int  out,
int  err,
char *const  args[],
int  timeout 
) [static]

Definition at line 17 of file run_redirected.cpp.

                                                                                                              {
  std::list<std::string> args_;
  for(int n = 0;args[n];++n) args_.push_back(std::string(args[n]));
  Arc::Run re(args_);
  if(!re) {
    logger.msg(Arc::ERROR,"%s: Failure creating slot for child process",cmdname?cmdname:"");
    return -1;
  };
  RunRedirected* rr = new RunRedirected(user,cmdname,in,out,err);
  if((!rr) || (!(*rr))) {
    if(rr) delete rr;
    logger.msg(Arc::ERROR,"%s: Failure creating data storage for child process",cmdname?cmdname:"");
    return -1;
  };
  re.AssignInitializer(&initializer,rr);
  re.KeepStdin(true);
  re.KeepStdout(true);
  re.KeepStderr(true);
  if(!re.Start()) {
    delete rr;
    logger.msg(Arc::ERROR,"%s: Failure starting child process",cmdname?cmdname:"");
    return -1;
  };
  delete rr;
  if(!re.Wait(timeout)) {
    logger.msg(Arc::ERROR,"%s: Failure waiting for child process to finish",cmdname?cmdname:"");
    return -1;
  };
  return re.Result();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int RunRedirected::run ( JobUser user,
const char *  cmdname,
int  in,
int  out,
int  err,
const char *  cmd,
int  timeoutd 
) [static]

Definition at line 48 of file run_redirected.cpp.

                                                                                                           {
  Arc::Run re(cmd);
  if(!re) {
    logger.msg(Arc::ERROR,"%s: Failure creating slot for child process",cmdname?cmdname:"");
    return -1;
  };
  RunRedirected* rr = new RunRedirected(user,cmdname,in,out,err);
  if((!rr) || (!(*rr))) {
    if(rr) delete rr;
    logger.msg(Arc::ERROR,"%s: Failure creating data storage for child process",cmdname?cmdname:"");
    return -1;
  };
  re.AssignInitializer(&initializer,rr);
  re.KeepStdin(true);
  re.KeepStdout(true);
  re.KeepStderr(true);
  if(!re.Start()) {
    delete rr;
    logger.msg(Arc::ERROR,"%s: Failure starting child process",cmdname?cmdname:"");
    return -1;
  };
  delete rr;
  if(!re.Wait(timeout)) {
    logger.msg(Arc::ERROR,"%s: Failure waiting for child process to finish",cmdname?cmdname:"");
    return -1;
  };
  return re.Result();
}

Here is the call graph for this function:


Member Data Documentation

std::string RunRedirected::cmdname_ [private]

Definition at line 15 of file run_redirected.h.

int RunRedirected::stderr_ [private]

Definition at line 18 of file run_redirected.h.

int RunRedirected::stdin_ [private]

Definition at line 16 of file run_redirected.h.

int RunRedirected::stdout_ [private]

Definition at line 17 of file run_redirected.h.

Definition at line 13 of file run_redirected.h.


The documentation for this class was generated from the following files: