aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-01-14 01:29:06 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-01-14 01:29:06 +0000
commitd32f7b0c9d494a1e8d515863c2bf07367dfd8e13 (patch)
tree4e90c9d364485ef13c2e429ab22b9b925d50ea04 /libbb
parenta8ce712c3cd70a63253f93a240bfe1650e7d6865 (diff)
downloadbusybox-w32-d32f7b0c9d494a1e8d515863c2bf07367dfd8e13.tar.gz
busybox-w32-d32f7b0c9d494a1e8d515863c2bf07367dfd8e13.tar.bz2
busybox-w32-d32f7b0c9d494a1e8d515863c2bf07367dfd8e13.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). git-svn-id: svn://busybox.net/trunk/busybox@17275 69ca8d6d-28ef-0310-b511-8ec308f3f277
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{