1 /* vi: set sw=4 ts=4: */
3 * Rexec program for system have fork() as vfork() with foreground option
5 * Copyright (C) Vladimir N. Oleynik <dzo@simtreas.ru>
6 * Copyright (C) 2003 Russ Dill <Russ.Dill@asu.edu>
8 * daemon() portion taken from uClibc:
10 * Copyright (c) 1991, 1993
11 * The Regents of the University of California. All rights reserved.
13 * Modified for uClibc by Erik Andersen <andersee@debian.org>
15 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
26 void vfork_daemon_rexec(int nochdir, int noclose,
27 int argc, char **argv, char *foreground_opt)
38 if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) {
39 dup2(fd, STDIN_FILENO);
40 dup2(fd, STDOUT_FILENO);
41 dup2(fd, STDERR_FILENO);
46 vfork_args = xcalloc(sizeof(char *), argc + 3);
47 vfork_args[a++] = "/bin/busybox";
49 vfork_args[a++] = *argv;
52 vfork_args[a] = foreground_opt;
55 /* Make certain we are not a session leader, or else we
56 * might reacquire a controlling terminal */
59 execv(vfork_args[0], vfork_args);
60 bb_perror_msg_and_die("execv %s", vfork_args[0]);
62 bb_perror_msg_and_die("vfork");