--- tftpd/src/exec.c 2014/02/14 15:42:18 1.1.2.1 +++ tftpd/src/exec.c 2014/02/17 10:12:26 1.1.2.4 @@ -1,3 +1,42 @@ #include "global.h" +#include "exec.h" +void * +execProg(sched_task_t *task) +{ + pid_t pid, res; + const char *str; + 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)); + execl(_PATH_BSHELL, _PATH_BSHELL, "-c", str, TASK_ARG(task), opc, + cli.file, cli.mode, e_n2addr(&cli.addr, &v), port, NULL); + AIT_FREE_VAL(&v); + _exit(127); + break; + default: + EVERBOSE(1, "Execute %s", str); + do { + res = waitpid(pid, &stat, 0); + } while (res == -1 && errno == EINTR); + break; + } + + taskExit(task, NULL); +}