X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Fvfork_daemon_rexec.c;h=26d1826e015518b0e750ccb8d8a389accd5b39b6;hb=9af7c9d6b62ceb07a9ba24cee0cf4a08c689235e;hp=2fd70ba1acc73c8e291ebab5d374086f2402eaaa;hpb=a1fece2c70898a1180f0506df6695e3077510731;p=oweals%2Fbusybox.git diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 2fd70ba1a..26d1826e0 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c @@ -1,64 +1,49 @@ +/* vi: set sw=4 ts=4: */ /* - * Rexec program for system have fork() as vfork() with foregound option + * Rexec program for system have fork() as vfork() with foreground option * * Copyright (C) Vladimir N. Oleynik * Copyright (C) 2003 Russ Dill * - * daemon() portion taken from uclibc: + * daemon() portion taken from uClibc: * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Modified for uClibc by Erik Andersen * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ -#include -#include -#include #include #include "libbb.h" - -#if defined(__uClinux__) +#ifdef BB_NOMMU void vfork_daemon_rexec(int nochdir, int noclose, int argc, char **argv, char *foreground_opt) { int fd; char **vfork_args; int a = 0; - + setsid(); - + if (!nochdir) - chdir("/"); + xchdir("/"); - if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { + if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); - if (fd > 2) - close(fd); + while (fd > 2) + close(fd--); } - vfork_args = xcalloc(sizeof(char *), argc + 3); - vfork_args[a++] = "/bin/busybox"; - while(*argv) { - vfork_args[a++] = *argv; - argv++; + vfork_args = xzalloc(sizeof(char *) * (argc + 3)); + vfork_args[a++] = CONFIG_BUSYBOX_EXEC_PATH; + while (*argv) { + vfork_args[a++] = *argv; + argv++; } vfork_args[a] = foreground_opt; switch (vfork()) { @@ -73,6 +58,6 @@ void vfork_daemon_rexec(int nochdir, int noclose, bb_perror_msg_and_die("vfork"); default: /* parent */ exit(0); - } + } } -#endif /* uClinux */ +#endif /* BB_NOMMU */