2 * Rexec program for system have fork() as vfork() with foregound option
4 * Copyright (C) Vladimir N. Oleynik <dzo@simtreas.ru>
5 * Copyright (C) 2003 Russ Dill <Russ.Dill@asu.edu>
7 * daemon() portion taken from uclibc:
9 * Copyright (c) 1991, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Modified for uClibc by Erik Andersen <andersee@debian.org>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #if defined(__uClinux__)
37 void vfork_daemon_rexec(int nochdir, int noclose,
38 int argc, char **argv, char *foreground_opt)
49 if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
50 dup2(fd, STDIN_FILENO);
51 dup2(fd, STDOUT_FILENO);
52 dup2(fd, STDERR_FILENO);
57 vfork_args = xcalloc(sizeof(char *), argc + 3);
58 vfork_args[a++] = "/bin/busybox";
60 vfork_args[a++] = *argv;
63 vfork_args[a] = foreground_opt;
66 /* Make certain we are not a session leader, or else we
67 * might reacquire a controlling terminal */
70 execv(vfork_args[0], vfork_args);
71 bb_perror_msg_and_die("execv %s", vfork_args[0]);
73 bb_perror_msg_and_die("vfork");