Contents of /trunk/mkinitrd-magellan/busybox/libbb/vfork_daemon_rexec.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (17 years ago) by niro
File MIME type: text/plain
File size: 1497 byte(s)
Sat Sep 1 22:45:15 2007 UTC (17 years ago) by niro
File MIME type: text/plain
File size: 1497 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * Rexec program for system have fork() as vfork() with foreground option |
4 | * |
5 | * Copyright (C) Vladimir N. Oleynik <dzo@simtreas.ru> |
6 | * Copyright (C) 2003 Russ Dill <Russ.Dill@asu.edu> |
7 | * |
8 | * daemon() portion taken from uClibc: |
9 | * |
10 | * Copyright (c) 1991, 1993 |
11 | * The Regents of the University of California. All rights reserved. |
12 | * |
13 | * Modified for uClibc by Erik Andersen <andersee@debian.org> |
14 | * |
15 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
16 | */ |
17 | |
18 | #include <paths.h> |
19 | #include "libbb.h" |
20 | |
21 | #ifdef BB_NOMMU |
22 | void vfork_daemon_rexec(int nochdir, int noclose, |
23 | int argc, char **argv, char *foreground_opt) |
24 | { |
25 | int fd; |
26 | char **vfork_args; |
27 | int a = 0; |
28 | |
29 | setsid(); |
30 | |
31 | if (!nochdir) |
32 | xchdir("/"); |
33 | |
34 | if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) { |
35 | dup2(fd, STDIN_FILENO); |
36 | dup2(fd, STDOUT_FILENO); |
37 | dup2(fd, STDERR_FILENO); |
38 | while (fd > 2) |
39 | close(fd--); |
40 | } |
41 | |
42 | vfork_args = xzalloc(sizeof(char *) * (argc + 3)); |
43 | vfork_args[a++] = CONFIG_BUSYBOX_EXEC_PATH; |
44 | while (*argv) { |
45 | vfork_args[a++] = *argv; |
46 | argv++; |
47 | } |
48 | vfork_args[a] = foreground_opt; |
49 | switch (vfork()) { |
50 | case 0: /* child */ |
51 | /* Make certain we are not a session leader, or else we |
52 | * might reacquire a controlling terminal */ |
53 | if (vfork()) |
54 | _exit(0); |
55 | execv(vfork_args[0], vfork_args); |
56 | bb_perror_msg_and_die("execv %s", vfork_args[0]); |
57 | case -1: /* error */ |
58 | bb_perror_msg_and_die("vfork"); |
59 | default: /* parent */ |
60 | exit(0); |
61 | } |
62 | } |
63 | #endif /* BB_NOMMU */ |