aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-14 01:29:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-14 01:29:06 +0000
commit7a431b3715299854fb423ec00d5fafc0e2c7f07b (patch)
tree4e90c9d364485ef13c2e429ab22b9b925d50ea04 /libbb
parent150f402b36197d822f8a7dd835231cd67b77e959 (diff)
downloadbusybox-w32-7a431b3715299854fb423ec00d5fafc0e2c7f07b.tar.gz
busybox-w32-7a431b3715299854fb423ec00d5fafc0e2c7f07b.tar.bz2
busybox-w32-7a431b3715299854fb423ec00d5fafc0e2c7f07b.zip
By popular request reinstate fakeidentd's standalone mode.
Since this is also needed for other applets like telnetd, introduce generic driver for such things. It even supports inetd-wait ('linger') mode, when inetd hands out listen socket to child and waits to it to die, instead of handing out accepted socket and continuing listening itself (nowait mode). Code growth ~200 bytes. NB: our inetd doesn't support wait mode yet (or mabe it is buggy).
Diffstat (limited to 'libbb')
-rw-r--r--libbb/xfuncs.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 207537929..6a6bdced3 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -509,6 +509,30 @@ void xdaemon(int nochdir, int noclose)
509} 509}
510#endif 510#endif
511 511
512void bb_sanitize_stdio(int daemonize)
513{
514 int fd;
515 /* Mega-paranoid */
516 fd = xopen(bb_dev_null, O_RDWR);
517 while (fd < 2)
518 fd = dup(fd); /* have 0,1,2 open at least to /dev/null */
519 if (daemonize) {
520 pid_t pid = fork();
521 if (pid < 0) /* wtf? */
522 bb_perror_msg_and_die("fork");
523 if (pid) /* parent */
524 exit(0);
525 /* child */
526 setsid();
527 /* if daemonizing, make sure we detach from stdio */
528 dup2(fd, 0);
529 dup2(fd, 1);
530 dup2(fd, 2);
531 }
532 while (fd > 2)
533 close(fd--); /* close everything after fd#2 */
534}
535
512// Die with an error message if we can't open a new socket. 536// Die with an error message if we can't open a new socket.
513int xsocket(int domain, int type, int protocol) 537int xsocket(int domain, int type, int protocol)
514{ 538{