summaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-10 21:38:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-10 21:38:30 +0000
commit335b63d8d1876ce4e172ebcc9d64544785682244 (patch)
tree14183fd728ce51ae10baee70f7d8f72c39d30649 /libbb/vfork_daemon_rexec.c
parent07c394e69b0cfa7cd30e97ffc6edb0d857905f45 (diff)
downloadbusybox-w32-335b63d8d1876ce4e172ebcc9d64544785682244.tar.gz
busybox-w32-335b63d8d1876ce4e172ebcc9d64544785682244.tar.bz2
busybox-w32-335b63d8d1876ce4e172ebcc9d64544785682244.zip
make a few struct bb_applet members conditional
rename sllep_and_die -> xfunc_die make fflush_stdout_and_exit NOFORK-safe fix some buglets found by randomconfig
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r--libbb/vfork_daemon_rexec.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 286ee2678..dabd1a6d6 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -16,7 +16,7 @@
16 */ 16 */
17 17
18#include <paths.h> 18#include <paths.h>
19#include "busybox.h" /* for struct BB_applet */ 19#include "busybox.h" /* for struct bb_applet */
20 20
21/* This does a fork/exec in one call, using vfork(). Returns PID of new child, 21/* This does a fork/exec in one call, using vfork(). Returns PID of new child,
22 * -1 for failure. Runs argv[0], searching path if that has no / in it. */ 22 * -1 for failure. Runs argv[0], searching path if that has no / in it. */
@@ -104,8 +104,9 @@ int spawn_and_wait(char **argv)
104{ 104{
105 int rc; 105 int rc;
106 106
107 if (ENABLE_FEATURE_EXEC_PREFER_APPLETS) { 107#if ENABLE_FEATURE_EXEC_PREFER_APPLETS
108 const struct BB_applet *a = find_applet_by_name(argv[0]); 108 {
109 const struct bb_applet *a = find_applet_by_name(argv[0]);
109 if (a && (a->nofork 110 if (a && (a->nofork
110#ifndef BB_NOMMU 111#ifndef BB_NOMMU
111 || a->noexec /* NOEXEC cannot be used on NOMMU */ 112 || a->noexec /* NOEXEC cannot be used on NOMMU */
@@ -120,19 +121,27 @@ int spawn_and_wait(char **argv)
120#endif 121#endif
121 { 122 {
122 int old_sleep = die_sleep; 123 int old_sleep = die_sleep;
124 int old_x = xfunc_error_retval;
123 die_sleep = -1; /* special flag */ 125 die_sleep = -1; /* special flag */
124 /* sleep_and_die() checks for it */ 126 /* xfunc_die() checks for it */
127
125 rc = setjmp(die_jmp); 128 rc = setjmp(die_jmp);
126 if (!rc) { 129 if (!rc) {
127 const struct BB_applet *old_a = current_applet; 130 const struct bb_applet *old_a = current_applet;
128 current_applet = a; 131 current_applet = a;
129 applet_name = a->name; 132 applet_name = a->name;
130// what else should we save/restore? 133// what else should we save/restore?
131 rc = a->main(argc, argv); 134 rc = a->main(argc, argv);
132 current_applet = old_a; 135 current_applet = old_a;
133 applet_name = old_a->name; 136 applet_name = old_a->name;
137 } else {
138 /* xfunc died in NOFORK applet */
139 if (rc == -111)
140 rc = 0;
134 } 141 }
142
135 die_sleep = old_sleep; 143 die_sleep = old_sleep;
144 xfunc_error_retval = old_x;
136 return rc; 145 return rc;
137 } 146 }
138#ifndef BB_NOMMU /* MMU only */ 147#ifndef BB_NOMMU /* MMU only */
@@ -145,9 +154,13 @@ int spawn_and_wait(char **argv)
145 run_current_applet_and_exit(argc, argv); 154 run_current_applet_and_exit(argc, argv);
146#endif 155#endif
147 } 156 }
157
148 } 158 }
149 rc = spawn(argv); 159 rc = spawn(argv);
150 w: 160 w:
161#else /* !FEATURE_EXEC_PREFER_APPLETS */
162 rc = spawn(argv);
163#endif /* FEATURE_EXEC_PREFER_APPLETS */
151 return wait4pid(rc); 164 return wait4pid(rc);
152} 165}
153 166