diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-26 17:20:04 +0400 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-26 17:20:04 +0400 |
commit | bb7fcb4229fd5ff583039f26ca1c06340e3f09ea (patch) | |
tree | 5e4a6cc92e42ff7694ffc8b6a91434640e953726 /libbb/xfuncs.c | |
parent | f62c6fa1cae0f944243c57b0a776c29eb0c61f18 (diff) |
libbb: rework NOMMU helper API so that it makes more sense
and easier to use. Doesn't compile - need two more commits.
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r-- | libbb/xfuncs.c | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 1dcdbc065..14bd62a15 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -187,43 +187,6 @@ void xfflush_stdout(void) } } -// This does a fork/exec in one call, using vfork(). Return PID of new child, -// -1 for failure. Runs argv[0], searching path if that has no / in it. -pid_t spawn(char **argv) -{ - /* Why static? */ - static int failed; - pid_t pid; - - // Be nice to nommu machines. - failed = 0; - pid = vfork(); - if (pid < 0) return pid; - if (!pid) { - BB_EXECVP(argv[0], argv); - - // We're sharing a stack with blocked parent, let parent know we failed - // and then exit to unblock parent (but don't run atexit() stuff, which - // would screw up parent.) - - failed = errno; - _exit(0); - } - if (failed) { - errno = failed; - return -1; - } - return pid; -} - -// Die with an error message if we can't spawn a child process. -pid_t xspawn(char **argv) -{ - pid_t pid = spawn(argv); - if (pid < 0) bb_perror_msg_and_die("%s", *argv); - return pid; -} - // Wait for the specified child PID to exit, returning child's error return. int wait4pid(int pid) { @@ -510,47 +473,6 @@ DIR *xopendir(const char *path) return dp; } -#ifndef BB_NOMMU -// Die with an error message if we can't daemonize. -void xdaemon(int nochdir, int noclose) -{ - if (daemon(nochdir, noclose)) - bb_perror_msg_and_die("daemon"); -} -#endif - -void bb_sanitize_stdio_maybe_daemonize(int daemonize) -{ - int fd; - /* Mega-paranoid */ - fd = xopen(bb_dev_null, O_RDWR); - while ((unsigned)fd < 2) - fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ - if (daemonize) { - pid_t pid = fork(); - if (pid < 0) /* wtf? */ - bb_perror_msg_and_die("fork"); - if (pid) /* parent */ - exit(0); - /* child */ - /* if daemonizing, make sure we detach from stdio */ - setsid(); - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); - } - while (fd > 2) - close(fd--); /* close everything after fd#2 */ -} -void bb_sanitize_stdio(void) -{ - bb_sanitize_stdio_maybe_daemonize(0); -} -void bb_daemonize(void) -{ - bb_sanitize_stdio_maybe_daemonize(1); -} - // Die with an error message if we can't open a new socket. int xsocket(int domain, int type, int protocol) { |