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 | Static Private Attributes
RunParallel Class Reference

#include <run_parallel.h>

Collaboration diagram for RunParallel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 operator bool (void)
bool operator! (void)

Static Public Member Functions

static bool run (JobUser &user, const char *jobid, const char *const args[], Arc::Run **, bool su=true, bool job_proxy=true, RunPlugin *cred=NULL, RunPlugin::substitute_t subst=NULL, void *subst_arg=NULL)
static bool run (JobUser &user, const JobDescription &desc, const char *const args[], Arc::Run **, bool su=true)
static void kicker (void(*kicker_func)(void *), void *kicker_arg)

Private Member Functions

 RunParallel (JobUser &user, const char *jobid, bool su, bool job_proxy, RunPlugin *cred, RunPlugin::substitute_t subst, void *subst_arg)
 ~RunParallel (void)

Static Private Member Functions

static void initializer (void *arg)

Private Attributes

JobUseruser_
std::string jobid_
bool su_
bool job_proxy_
RunPlugincred_
RunPlugin::substitute_t subst_
void * subst_arg_

Static Private Attributes

static void(* kicker_func_ )(void *) = NULL
static void * kicker_arg_ = NULL

Detailed Description

Definition at line 10 of file run_parallel.h.


Constructor & Destructor Documentation

RunParallel::RunParallel ( JobUser user,
const char *  jobid,
bool  su,
bool  job_proxy,
RunPlugin cred,
RunPlugin::substitute_t  subst,
void *  subst_arg 
) [inline, private]

Definition at line 12 of file run_parallel.h.

:user_(user),jobid_(jobid?jobid:""),su_(su),job_proxy_(job_proxy),cred_(cred),subst_(subst),subst_arg_(subst_arg) { };

Here is the caller graph for this function:

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

Definition at line 13 of file run_parallel.h.

{ };

Member Function Documentation

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

Definition at line 97 of file run_parallel.cpp.

                                       {
#ifdef WIN32
#error This functionality is not available in Windows environement
#else
  // child
  RunParallel* it = (RunParallel*)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(it->su_))) {
    logger.msg(Arc::ERROR,"%s: Failed switching user",it->jobid_); sleep(10); exit(1);
  };
  if(it->cred_) {
    // run external plugin to acquire non-unix local credentials
    if(!it->cred_->run(it->subst_,it->subst_arg_)) {
      logger.msg(Arc::ERROR,"%s: Failed to run plugin",it->jobid_); sleep(10); _exit(1);
    };
    if(it->cred_->result() != 0) {
      logger.msg(Arc::ERROR,"%s: Plugin failed",it->jobid_); sleep(10); _exit(1);
    };
  };
  // close all handles inherited from parent
  if(max_files == RLIM_INFINITY) max_files=4096;
  for(int i=0;i<max_files;i++) { close(i); };
  int h;
  // set up stdin,stdout and stderr
  h=open("/dev/null",O_RDONLY); 
  if(h != 0) { if(dup2(h,0) != 0) { sleep(10); exit(1); }; close(h); };
  h=open("/dev/null",O_WRONLY);
  if(h != 1) { if(dup2(h,1) != 1) { sleep(10); exit(1); }; close(h); };
  std::string errlog;
  if(!(it->jobid_.empty())) { 
    errlog = it->user_.ControlDir() + "/job." + it->jobid_ + ".errors";
    h=open(errlog.c_str(),O_WRONLY | O_CREAT | O_APPEND,S_IRUSR | S_IWUSR);
    if(h==-1) { h=open("/dev/null",O_WRONLY); };
  }
  else { h=open("/dev/null",O_WRONLY); };
  if(h != 2) { if(dup2(h,2) != 2) { sleep(10); exit(1); }; close(h); };
  // setting environment  - TODO - better environment 
  if(it->job_proxy_) {
    Arc::SetEnv("GLOBUS_LOCATION",globus_loc());
    Arc::UnsetEnv("X509_USER_KEY");
    Arc::UnsetEnv("X509_USER_CERT");
    Arc::UnsetEnv("X509_USER_PROXY");
    Arc::UnsetEnv("X509_RUN_AS_SERVER");
    if(!(it->jobid_.empty())) {
      std::string proxy = it->user_.ControlDir() + "/job." + it->jobid_ + ".proxy";
      Arc::SetEnv("X509_USER_PROXY",proxy);
      // for Globus 2.2 set fake cert and key, or else it takes 
      // those from host in case of root user.
      // 2.4 needs names and 2.2 will work too.
      // 3.x requires fake ones again.
#if GLOBUS_IO_VERSION>=5
      Arc::SetEnv("X509_USER_KEY",(std::string("fake")));
      Arc::SetEnv("X509_USER_CERT",(std::string("fake")));
#else
      Arc::SetEnv("X509_USER_KEY",proxy);
      Arc::SetEnv("X509_USER_CERT",proxy);
#endif
    };
  };
  //# execv(args[0],args);
  //# perror("execv");
  //# std::cerr<<(jobid?jobid:"")<<"Failed to start external program: "<<args[0]<<std::endl;
  //# sleep(10); exit(1);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void RunParallel::kicker ( void(*)(void *)  kicker_func,
void *  kicker_arg 
) [inline, static]

Definition at line 29 of file run_parallel.h.

                                                                  {
    kicker_arg_=kicker_arg;
    kicker_func_=kicker_func;
  };

Here is the caller graph for this function:

RunParallel::operator bool ( void  ) [inline]

Definition at line 25 of file run_parallel.h.

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

Definition at line 26 of file run_parallel.h.

{ return false; };
bool RunParallel::run ( JobUser user,
const char *  jobid,
const char *const  args[],
Arc::Run **  ere,
bool  su = true,
bool  job_proxy = true,
RunPlugin cred = NULL,
RunPlugin::substitute_t  subst = NULL,
void *  subst_arg = NULL 
) [static]

Definition at line 67 of file run_parallel.cpp.

                                                                                                                                                                              {
  *ere=NULL;
  std::list<std::string> args_;
  for(int n = 0;args[n];++n) args_.push_back(std::string(args[n]));
  Arc::Run* re = new Arc::Run(args_);
  if((!re) || (!(*re))) {
    if(re) delete re;
    logger.msg(Arc::ERROR,"%s: Failure creating slot for child process",jobid?jobid:"");
    return false;
  };
  if(kicker_func_) re->AssignKicker(kicker_func_,kicker_arg_);
  RunParallel* rp = new RunParallel(user,jobid,su,job_proxy,cred,subst,subst_arg);
  if((!rp) || (!(*rp))) {
    if(rp) delete rp;
    delete re;
    logger.msg(Arc::ERROR,"%s: Failure creating data storage for child process",jobid?jobid:"");
    return false;
  };
  re->AssignInitializer(&initializer,rp);
  if(!re->Start()) {
    delete rp;
    delete re;
    logger.msg(Arc::ERROR,"%s: Failure starting child process",jobid?jobid:"");
    return false;
  };
  delete rp;
  *ere=re;
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool RunParallel::run ( JobUser user,
const JobDescription desc,
const char *const  args[],
Arc::Run **  ere,
bool  su = true 
) [static]

Definition at line 48 of file run_parallel.cpp.

                                                                                                            {
  RunPlugin* cred = user.CredPlugin();
  job_subst_t subs; subs.user=&user; subs.job=&desc; subs.reason="external";
  if((!cred) || (!(*cred))) { cred=NULL; };
  //RunPlugin* cred = NULL;
  if(user.get_uid() == 0) {
    JobUser tmp_user(desc.get_uid());
    if(!tmp_user.is_valid()) return false;
    tmp_user.SetControlDir(user.ControlDir());
    tmp_user.SetSessionRoot(user.SessionRoot(desc.get_id()));
    return run(tmp_user,desc.get_id().c_str(),args,ere,su,
                                        true,cred,&job_subst,&subs);
  };
  return run(user,desc.get_id().c_str(),args,ere,su,
                                      true,cred,&job_subst,&subs);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 18 of file run_parallel.h.

bool RunParallel::job_proxy_ [private]

Definition at line 17 of file run_parallel.h.

std::string RunParallel::jobid_ [private]

Definition at line 15 of file run_parallel.h.

void * RunParallel::kicker_arg_ = NULL [static, private]

Definition at line 23 of file run_parallel.h.

void(* RunParallel::kicker_func_)(void *) = NULL [static, private]

Definition at line 22 of file run_parallel.h.

bool RunParallel::su_ [private]

Definition at line 16 of file run_parallel.h.

Definition at line 19 of file run_parallel.h.

void* RunParallel::subst_arg_ [private]

Definition at line 20 of file run_parallel.h.

Definition at line 13 of file run_parallel.h.


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