[BusyBox] vfork_daemon_rexec
Vladimir N. Oleynik
dzo at simtreas.ru
Wed Nov 26 07:30:19 UTC 2003
Russ,
> This is the behavior with inetd. Thats what the code does. It fails the
> execvp, then proceeds to set argv[0] to /bin/busybox
If this problem exist - this problem by busybox_main(). Not problem for
vfork_rexec().
> There are a lot of other problems as well. All the applets using
> vfork_daemon_rexec also call daemon, which returns after a failed fork
> on uclinux (does nothing). A working vfork_daemon_rexec might look like
> this:
>
> void vfork_daemon_rexec(int nochdir, int noclose,
> int argc, char **argv, char *foreground_opt)
> {
> int fd;
> char **vfork_args;
> int a = 0;
>
> if (setsid() == -1)
> return(-1);
>
> if (!nochdir)
> chdir("/");
>
> if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
> dup2(fd, STDIN_FILENO);
> dup2(fd, STDOUT_FILENO);
> dup2(fd, STDERR_FILENO);
> if (fd > 2)
> close(fd);
> }
This code present form daemon(3).
vfork_rexec() called after daemon().
> vfork_args = xcalloc(sizeof(char *), argc + 3);
> vfork_args[a++] = "/bin/busybox";
> while(*argv) {
> vfork_args[a++] = *argv;
> argv++;
> }
> vfork_args[a++] = foreground_opt;
> vfork_args[a] = NULL;
This up line don`t required, xcalloc always set to NULL.
> switch (vfork()) {
> case 0: /* child */
> /* Make certain we are not a session leader, or else we
> * might reacquire a controlling terminal */
Its interesteing only teoreticaly.
Real effect with small code full equivalent you can see from crond:
signal(SIGHUP, SIG_ING);
daemon(); /* this called setsid() */
vfrok_rexec();
signal(SIGHUP, sig_handler); /* if require */
--w
vodz
More information about the busybox
mailing list