[Saga-devel] saga SVN commit 3372: /trunk/adaptors/default/job/
amerzky at cct.lsu.edu
amerzky at cct.lsu.edu
Sat Jan 24 08:49:03 CST 2009
User: amerzky
Date: 2009/01/24 08:49 AM
Modified:
/trunk/adaptors/default/job/
impl_posix_job.cpp
Log:
add support for environment
A
File Changes:
Directory: /trunk/adaptors/default/job/
=======================================
File [modified]: impl_posix_job.cpp
Delta lines: +36 -1
===================================================================
--- trunk/adaptors/default/job/impl_posix_job.cpp 2009-01-24 09:16:25 UTC (rev 3371)
+++ trunk/adaptors/default/job/impl_posix_job.cpp 2009-01-24 14:48:54 UTC (rev 3372)
@@ -180,6 +180,7 @@
// we need these for execve
std::string exe;
char** cargs = NULL;
+ char** cenv = NULL;
// if the child dies before it can release the semaphores,
// the main thread will hang. Thus we need to do
@@ -290,6 +291,40 @@
cargs[args.size () + 1] = NULL;
+
+ // set up environment
+ std::vector <std::string> env;
+ if ( jd_.attribute_exists
+ (saga::job::attributes::description_environment ) )
+ {
+ env = jd_.get_vector_attribute (saga::job::attributes::description_environment);
+ }
+
+ cenv = (char**) ::calloc (env.size () + 1, sizeof (char*));
+
+ if ( NULL == cenv )
+ {
+ log ("calloc failed", strerror (errno));
+ SAGA_ADAPTOR_THROW_NO_CONTEXT (std::string ("calloc failed: ") + strerror (errno),
+ saga::NoSuccess);
+ }
+
+ for ( unsigned int j = 0; j < env.size (); j++ )
+ {
+ cenv[j] = ::strdup (env[j].c_str ());
+
+ log ("setenv", env[j]);
+
+ if ( NULL == cenv[j] )
+ {
+ log ("strdup failed", strerror (errno));
+ SAGA_ADAPTOR_THROW_NO_CONTEXT (std::string ("strdup failed: ") + strerror (errno),
+ saga::NoSuccess);
+ }
+ }
+
+ cenv[env.size () + 1] = NULL;
+
log (" == running ", cmd);
// FIXME: we actually need a sync point with the parent
@@ -325,7 +360,7 @@
}
// finally, run the child program
- ::execv (exe.c_str (), cargs);
+ ::execve (exe.c_str (), cargs, cenv);
// Nonono - thats wrong!
log ("execv failed", strerror (errno));
More information about the saga-devel
mailing list