+struct bb_applet;
+int execable_file(const char *name);
+char *find_execable(const char *filename);
+int exists_execable(const char *filename);
+
+#if ENABLE_FEATURE_PREFER_APPLETS
+int bb_execvp(const char *file, char *const argv[]);
+#define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd)
+#define BB_EXECLP(prog,cmd,...) \
+ execlp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, \
+ cmd, __VA_ARGS__)
+#else
+#define BB_EXECVP(prog,cmd) execvp(prog,cmd)
+#define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__)
+#endif
+
+/* NOMMU friendy fork+exec */
+pid_t spawn(char **argv);
+pid_t xspawn(char **argv);
+
+/* Unlike waitpid, waits ONLY for one process,
+ * It's safe to pass negative 'pids' from failed [v]fork -
+ * wait4pid will return -1 (and will not clobber [v]fork's errno).
+ * IOW: rc = wait4pid(spawn(argv));
+ * if (rc < 0) bb_perror_msg("%s", argv[0]);
+ * if (rc > 0) bb_error_msg("exit code: %d", rc);
+ */
+int wait4pid(int pid);
+int wait_pid(int *wstat, int pid);
+int wait_nohang(int *wstat);
+#define wait_crashed(w) ((w) & 127)
+#define wait_exitcode(w) ((w) >> 8)
+#define wait_stopsig(w) ((w) >> 8)
+#define wait_stopped(w) (((w) & 127) == 127)
+/* wait4pid(spawn(argv)) + NOFORK/NOEXEC (if configured) */
+int spawn_and_wait(char **argv);
+struct nofork_save_area {
+ const struct bb_applet *current_applet;
+ int xfunc_error_retval;
+ uint32_t option_mask32;
+ int die_sleep;
+ smallint saved;
+};
+void save_nofork_data(struct nofork_save_area *save);
+void restore_nofork_data(struct nofork_save_area *save);
+/* Does NOT check that applet is NOFORK, just blindly runs it */
+int run_nofork_applet(const struct bb_applet *a, char **argv);
+int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet *a, char **argv);
+
+/* Helpers for daemonization.
+ *
+ * bb_daemonize(flags) = daemonize, does not compile on NOMMU
+ *
+ * bb_daemonize_or_rexec(flags, argv) = daemonizes on MMU (and ignores argv),
+ * rexec's itself on NOMMU with argv passed as command line.
+ * Thus bb_daemonize_or_rexec may cause your <applet>_main() to be re-executed
+ * from the start. (It will detect it and not reexec again second time).
+ * You have to audit carefully that you don't do something twice as a result
+ * (opening files/sockets, parsing config files etc...)!
+ *
+ * Both of the above will redirect fd 0,1,2 to /dev/null and drop ctty
+ * (will do setsid()).
+ *
+ * forkexit_or_rexec(argv) = bare-bones "fork + parent exits" on MMU,
+ * "vfork + re-exec ourself" on NOMMU. No fd redirection, no setsid().
+ * Currently used for openvt. On MMU ignores argv.
+ *
+ * Helper for network daemons in foreground mode:
+ *
+ * bb_sanitize_stdio() = make sure that fd 0,1,2 are opened by opening them
+ * to /dev/null if they are not.
+ */
+enum {
+ DAEMON_CHDIR_ROOT = 1,
+ DAEMON_DEVNULL_STDIO = /* 2 */ 0, /* no users so far */
+ DAEMON_CLOSE_EXTRA_FDS = 4,
+ DAEMON_ONLY_SANITIZE = 8, /* internal use */
+};
+#if BB_MMU
+ void forkexit_or_rexec(void);
+# define forkexit_or_rexec(argv) forkexit_or_rexec()
+# define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags)
+# define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus)
+#else
+ void forkexit_or_rexec(char **argv);
+ extern bool re_execed;
+# define fork() BUG_fork_is_unavailable_on_nommu()
+# define daemon(a,b) BUG_daemon_is_unavailable_on_nommu()
+# define bb_daemonize(a) BUG_bb_daemonize_is_unavailable_on_nommu()
+#endif
+void bb_daemonize_or_rexec(int flags, char **argv);
+void bb_sanitize_stdio(void);
+
+
+// TODO: always error out?