version 1.1, 2014/02/14 15:42:18
|
version 1.2, 2014/02/17 14:28:29
|
Line 0
|
Line 1
|
|
#include "global.h" |
|
#include "exec.h" |
|
|
|
|
|
void * |
|
execProg(sched_task_t *task) |
|
{ |
|
pid_t pid, res; |
|
const char *str, *addr; |
|
char port[STRSIZ] = { [0 ... STRSIZ - 1] = 0 }, |
|
opc[STRSIZ] = { [0 ... STRSIZ - 1] = 0 }; |
|
ait_val_t v = AIT_VAL_INITIALIZER(v); |
|
int stat; |
|
|
|
ETRACE(); |
|
|
|
str = cfg_getAttribute(&cfg, "exec_on", TASK_ARG(task)); |
|
if (!str) |
|
taskExit(task, NULL); |
|
|
|
switch (pid = vfork()) { |
|
case -1: |
|
ESYSERR(0); |
|
break; |
|
case 0: |
|
snprintf(opc, STRSIZ, "%hu", (u_short) TASK_DATLEN(task)); |
|
snprintf(port, STRSIZ, "%hu", (u_short) e_n2port(&cli.addr)); |
|
addr = e_n2addr(&cli.addr, &v); |
|
EVERBOSE(1, "Execute %s %s %s %s %s %s %s", str, TASK_ARG(task), opc, |
|
cli.file, cli.mode, addr, port); |
|
execl(_PATH_BSHELL, _PATH_BSHELL, str, TASK_ARG(task), opc, |
|
cli.file, cli.mode, addr, port, NULL); |
|
AIT_FREE_VAL(&v); |
|
_exit(127); |
|
break; |
|
default: |
|
EVERBOSE(2, "Wait to finish executed program %s", str); |
|
do { |
|
res = waitpid(pid, &stat, 0); |
|
} while (res == -1 && errno == EINTR); |
|
break; |
|
} |
|
|
|
taskExit(task, NULL); |
|
} |