rctx_t rctx;
DEBUG2("Armageddon request by <%s> (exit=%d)",initiator->filepos,exitcode);
- xbt_os_mutex_lock(armageddon_mutex);
+ xbt_os_mutex_acquire(armageddon_mutex);
if (armageddon_initiator != NULL) {
VERB0("Armageddon already started. Let it go");
- xbt_os_mutex_unlock(initiator->interruption);
- xbt_os_mutex_unlock(armageddon_mutex);
+ xbt_os_mutex_release(initiator->interruption);
+ xbt_os_mutex_release(armageddon_mutex);
return;
}
DEBUG1("Armageddon request by <%s> got the lock. Let's go amok",initiator->filepos);
armageddon_initiator = initiator;
- xbt_os_mutex_unlock(armageddon_mutex);
+ xbt_os_mutex_release(armageddon_mutex);
/* Kill any background commands */
while (xbt_dynar_length(bg_jobs)) {
xbt_dynar_pop(bg_jobs,&rctx);
if (rctx != initiator) {
INFO2("Kill <%s> because <%s> failed",rctx->filepos,initiator->filepos);
- xbt_os_mutex_lock(rctx->interruption);
+ xbt_os_mutex_acquire(rctx->interruption);
rctx->interrupted = 1;
- xbt_os_mutex_unlock(rctx->interruption);
+ xbt_os_mutex_release(rctx->interruption);
if (!rctx->reader_done) {
kill(rctx->pid,SIGTERM);
usleep(100);
* Memory management
*/
+# ifdef __APPLE__
+/* under darwin, the environment gets added to the process at startup time. So, it's not defined at library link time, forcing us to extra tricks */
+# include <crt_externs.h>
+# define environ (*_NSGetEnviron())
+# else
+ /* the environment, as specified by the opengroup, used to initialize the process properties */
+ extern char **environ;
+# endif
+
void rctx_empty(rctx_t rc) {
+ int i;
+ char **env_it=environ;
+
if (rc->cmd)
free(rc->cmd);
rc->cmd = NULL;
if (rc->filepos)
free(rc->filepos);
+ if (rc->env)
+ free(rc->env);
+
+ for (i=0;*env_it;i++,env_it++);
+ i++;
+ rc->env_size = i;
+ rc->env = malloc(i*sizeof(char*));
+ memcpy(rc->env,environ,i*sizeof(char*));
+
rc->filepos = NULL;
rc->is_empty = 1;
rc->is_background = 0;
xbt_strbuff_empty(rc->output_got);
}
+
rctx_t rctx_new() {
rctx_t res = xbt_new0(s_rctx_t,1);
free(rctx->cmd);
if (rctx->filepos)
free(rctx->filepos);
+ if (rctx->env)
+ free(rctx->env);
xbt_os_mutex_destroy(rctx->interruption);
xbt_strbuff_free(rctx->input);
xbt_strbuff_free(rctx->output_got);
} else if (!strncmp(line,"output display",strlen("output display"))) {
rctx->output = e_output_display;
VERB1("[%s] (ignore output of next command)", filepos);
+
+ } else if (!strncmp(line,"setenv ",strlen("setenv "))) {
+ rctx->env = realloc(rctx->env,++(rctx->env_size)*sizeof(char*));
+ rctx->env[rctx->env_size-2] = xbt_strdup(line+strlen("setenv "));
+ rctx->env[rctx->env_size-1] = NULL;
+ VERB1("[%s] (ignore output of next command)", filepos);
} else {
ERROR2("%s: Malformed metacommand: %s",filepos,line);
dup2(child_out[1],2);
close(child_out[1]);
- execlp ("/bin/sh", "sh", "-c", rctx->cmd, NULL);
+ execle ("/bin/sh", "sh", "-c", rctx->cmd, NULL, rctx->env);
}
rctx->is_stoppable = 1;
now = time(NULL);
}
- xbt_os_mutex_lock(rctx->interruption);
+ xbt_os_mutex_acquire(rctx->interruption);
if (!rctx->interrupted && rctx->end_time > 0 && rctx->end_time < now) {
INFO1("<%s> timeouted. Kill the process.",rctx->filepos);
rctx->timeout = 1;
xbt_os_thread_join(rctx->writer,NULL);
xbt_os_thread_join(rctx->reader,NULL);
- /* xbt_os_mutex_unlock(rctx->interruption);
+ /* xbt_os_mutex_release(rctx->interruption);
if (rctx->interrupted)
return NULL;
- xbt_os_mutex_lock(rctx->interruption);*/
+ xbt_os_mutex_acquire(rctx->interruption);*/
xbt_strbuff_chomp(rctx->output_got);
xbt_strbuff_chomp(rctx->output_wanted);
}
}
- xbt_os_mutex_unlock(rctx->interruption);
+ xbt_os_mutex_release(rctx->interruption);
return NULL;
}