[dhcp-agent-commits] dhcp-agent/src dhcp-daemon.c,1.5,1.6
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-07-17 13:12:57
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv1545/src Modified Files: dhcp-daemon.c Log Message: added routine to fork helper child Index: dhcp-daemon.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-daemon.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-daemon.c 25 May 2003 02:18:46 -0000 1.5 --- dhcp-daemon.c 17 Jul 2003 13:12:54 -0000 1.6 *************** *** 209,210 **** --- 209,251 ---- return; } + + int fork_and_exec(const char *path_to_exec) + { + int fdpair[2]; + + /* open socket pair. */ + if(socketpair(PF_UNIX, SOCK_STREAM, 0, fdpair) == -1) { + return -1; + } + + /* fork out. */ + switch(fork()) { + + case 0: /* child. */ + + /* close up stdin, stdout, stderr. */ + + close(0); + close(1); + close(2); + + dup2(fdpair[1], 0); + dup2(fdpair[1], 1); + dup2(fdpair[1], 2); + close(fdpair[0]); + execl(path_to_exec, NULL); + + /* we should never get here unless something is + * tragically broken. */ + + exit(1); + + case -1: /* error. */ + return -1; + + default: /* parent. */ + + close(fdpair[1]); + return fdpair[0]; + } + } |