Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/libbb/vfork_daemon_rexec.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/libbb/vfork_daemon_rexec.c
r2725 r3232 70 70 71 71 #if ENABLE_FEATURE_PREFER_APPLETS 72 void FAST_FUNC save_nofork_data(struct nofork_save_area *save) 72 struct nofork_save_area { 73 jmp_buf die_jmp; 74 const char *applet_name; 75 uint32_t option_mask32; 76 int die_sleep; 77 uint8_t xfunc_error_retval; 78 }; 79 static void save_nofork_data(struct nofork_save_area *save) 73 80 { 74 81 memcpy(&save->die_jmp, &die_jmp, sizeof(die_jmp)); … … 77 84 save->option_mask32 = option_mask32; 78 85 save->die_sleep = die_sleep; 79 save->saved = 1; 80 } 81 82 void FAST_FUNC restore_nofork_data(struct nofork_save_area *save) 86 } 87 static void restore_nofork_data(struct nofork_save_area *save) 83 88 { 84 89 memcpy(&die_jmp, &save->die_jmp, sizeof(die_jmp)); … … 89 94 } 90 95 91 int FAST_FUNC run_nofork_applet _prime(struct nofork_save_area *old,int applet_no, char **argv)96 int FAST_FUNC run_nofork_applet(int applet_no, char **argv) 92 97 { 93 98 int rc, argc; 99 struct nofork_save_area old; 100 101 save_nofork_data(&old); 94 102 95 103 applet_name = APPLET_NAME(applet_no); 96 104 97 105 xfunc_error_retval = EXIT_FAILURE; 98 99 /* Special flag for xfunc_die(). If xfunc will "die"100 * in NOFORK applet, xfunc_die() sees negative101 * die_sleep and longjmp here instead. */102 die_sleep = -1;103 106 104 107 /* In case getopt() or getopt32() was already called: … … 131 134 argc++; 132 135 136 /* Special flag for xfunc_die(). If xfunc will "die" 137 * in NOFORK applet, xfunc_die() sees negative 138 * die_sleep and longjmp here instead. */ 139 die_sleep = -1; 140 133 141 rc = setjmp(die_jmp); 134 142 if (!rc) { … … 139 147 /* Finally we can call NOFORK applet's main() */ 140 148 rc = applet_main[applet_no](argc, tmp_argv); 141 142 /* The whole reason behind nofork_save_area is that <applet>_main143 * may exit non-locally! For example, in hush Ctrl-Z tries144 * (modulo bugs) to dynamically create a child (backgrounded task)145 * if it detects that Ctrl-Z was pressed when a NOFORK was running.146 * Testcase: interactive "rm -i".147 * Don't fool yourself into thinking "and <applet>_main() returns148 * quickly here" and removing "useless" nofork_save_area code. */149 150 149 } else { /* xfunc died in NOFORK applet */ 151 150 /* in case they meant to return 0... */ … … 155 154 156 155 /* Restoring some globals */ 157 restore_nofork_data( old);156 restore_nofork_data(&old); 158 157 159 158 /* Other globals can be simply reset to defaults */ … … 166 165 return rc & 0xff; /* don't confuse people with "exitcodes" >255 */ 167 166 } 168 169 int FAST_FUNC run_nofork_applet(int applet_no, char **argv)170 {171 struct nofork_save_area old;172 173 /* Saving globals */174 save_nofork_data(&old);175 return run_nofork_applet_prime(&old, applet_no, argv);176 }177 167 #endif /* FEATURE_PREFER_APPLETS */ 178 168 … … 184 174 185 175 if (a >= 0 && (APPLET_IS_NOFORK(a) 186 # if BB_MMU176 # if BB_MMU 187 177 || APPLET_IS_NOEXEC(a) /* NOEXEC trick needs fork() */ 188 # endif178 # endif 189 179 )) { 190 # if BB_MMU180 # if BB_MMU 191 181 if (APPLET_IS_NOFORK(a)) 192 # endif182 # endif 193 183 { 194 184 return run_nofork_applet(a, argv); 195 185 } 196 # if BB_MMU186 # if BB_MMU 197 187 /* MMU only */ 198 188 /* a->noexec is true */ … … 203 193 xfunc_error_retval = EXIT_FAILURE; 204 194 run_applet_no_and_exit(a, argv); 205 # endif195 # endif 206 196 } 207 197 #endif /* FEATURE_PREFER_APPLETS */ … … 264 254 if (fork_or_rexec(argv)) 265 255 exit(EXIT_SUCCESS); /* parent */ 266 /* if daemonizing, make sure wedetach from stdio & ctty */256 /* if daemonizing, detach from stdio & ctty */ 267 257 setsid(); 268 258 dup2(fd, 0); 269 259 dup2(fd, 1); 270 260 dup2(fd, 2); 261 if (flags & DAEMON_DOUBLE_FORK) { 262 /* On Linux, session leader can acquire ctty 263 * unknowingly, by opening a tty. 264 * Prevent this: stop being a session leader. 265 */ 266 if (fork_or_rexec(argv)) 267 exit(EXIT_SUCCESS); /* parent */ 268 } 271 269 } 272 270 while (fd > 2) {
Note:
See TracChangeset
for help on using the changeset viewer.