File:  [ELWIX - Embedded LightWeight unIX -] / tftpd / src / exec.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Mon Feb 17 14:28:29 2014 UTC (10 years, 4 months ago) by misho
Branches: MAIN
CVS tags: tftp0_5, tftp0_4, tftp0_3, TFTP0_4, TFTP0_3, TFTP0_2, HEAD
version 0.2

    1: #include "global.h"
    2: #include "exec.h"
    3: 
    4: 
    5: void *
    6: execProg(sched_task_t *task)
    7: {
    8: 	pid_t pid, res;
    9: 	const char *str, *addr;
   10: 	char port[STRSIZ] = { [0 ... STRSIZ - 1] = 0 }, 
   11: 	     opc[STRSIZ] = { [0 ... STRSIZ - 1] = 0 };
   12: 	ait_val_t v = AIT_VAL_INITIALIZER(v);
   13: 	int stat;
   14: 
   15: 	ETRACE();
   16: 
   17: 	str = cfg_getAttribute(&cfg, "exec_on", TASK_ARG(task));
   18: 	if (!str)
   19: 		taskExit(task, NULL);
   20: 
   21: 	switch (pid = vfork()) {
   22: 		case -1:
   23: 			ESYSERR(0);
   24: 			break;
   25: 		case 0:
   26: 			snprintf(opc, STRSIZ, "%hu", (u_short) TASK_DATLEN(task));
   27: 			snprintf(port, STRSIZ, "%hu", (u_short) e_n2port(&cli.addr));
   28: 			addr = e_n2addr(&cli.addr, &v);
   29: 			EVERBOSE(1, "Execute %s %s %s %s %s %s %s", str, TASK_ARG(task), opc, 
   30: 					cli.file, cli.mode, addr, port);
   31: 			execl(_PATH_BSHELL, _PATH_BSHELL, str, TASK_ARG(task), opc, 
   32: 					cli.file, cli.mode, addr, port, NULL);
   33: 			AIT_FREE_VAL(&v);
   34: 			_exit(127);
   35: 			break;
   36: 		default:
   37: 			EVERBOSE(2, "Wait to finish executed program %s", str);
   38: 			do {
   39: 				res = waitpid(pid, &stat, 0);
   40: 			} while (res == -1 && errno == EINTR);
   41: 			break;
   42: 	}
   43: 
   44: 	taskExit(task, NULL);
   45: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>