2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
30 * Initialize process structure.
33 Proc_InitStruct (PROC_STAT *proc)
41 * Fork a child process.
44 Proc_Fork(PROC_STAT *proc, int *pipefds, void (*cbfunc)(int, short))
49 assert(pipefds != NULL);
50 assert(cbfunc != NULL);
52 if (pipe(pipefds) != 0) {
53 Log(LOG_ALERT, "Can't create output pipe for child process: %s!",
62 Log(LOG_CRIT, "Can't fork child process: %s!", strerror(errno));
67 /* New child process: */
72 /* Old parent process: */
75 if (!io_setnonblock(pipefds[0])
76 || !io_event_create(pipefds[0], IO_WANTREAD, cbfunc)) {
77 Log(LOG_CRIT, "Can't register callback for child process: %s!",
84 proc->pipe_fd = pipefds[0];
89 * Kill forked child process.
92 Proc_Kill(PROC_STAT *proc)
95 assert(proc->pipe_fd >= 0);
97 io_close(proc->pipe_fd);
98 kill(proc->pid, SIGTERM);
99 Proc_InitStruct(proc);