From 116ce19b10a1fd60776764974ad50776ff7c4714 Mon Sep 17 00:00:00 2001 From: Steven Danneman Date: Fri, 20 Feb 2009 15:10:21 -0800 Subject: Moved become_daemon() and close_low_fds() to shared util lib --- source3/lib/util.c | 67 ------------------------------------------------------ 1 file changed, 67 deletions(-) (limited to 'source3/lib/util.c') diff --git a/source3/lib/util.c b/source3/lib/util.c index 6079e71063..baac26b9aa 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -797,43 +797,6 @@ char *clean_name(TALLOC_CTX *ctx, const char *s) return unix_clean_name(ctx, str); } -/******************************************************************* - Close the low 3 fd's and open dev/null in their place. -********************************************************************/ - -void close_low_fds(bool stderr_too) -{ -#ifndef VALGRIND - int fd; - int i; - - close(0); - close(1); - - if (stderr_too) - close(2); - - /* try and use up these file descriptors, so silly - library routines writing to stdout etc won't cause havoc */ - for (i=0;i<3;i++) { - if (i == 2 && !stderr_too) - continue; - - fd = sys_open("/dev/null",O_RDWR,0); - if (fd < 0) - fd = sys_open("/dev/null",O_WRONLY,0); - if (fd < 0) { - DEBUG(0,("Can't open /dev/null\n")); - return; - } - if (fd != i) { - DEBUG(0,("Didn't get file descriptor %d\n",i)); - return; - } - } -#endif -} - /******************************************************************* Write data into an fd at a given offset. Ignore seek errors. ********************************************************************/ @@ -924,36 +887,6 @@ void smb_msleep(unsigned int t) #endif } -/**************************************************************************** - Become a daemon, discarding the controlling terminal. -****************************************************************************/ - -void become_daemon(bool Fork, bool no_process_group) -{ - if (Fork) { - if (sys_fork()) { - _exit(0); - } - } - - /* detach from the terminal */ -#ifdef HAVE_SETSID - if (!no_process_group) setsid(); -#elif defined(TIOCNOTTY) - if (!no_process_group) { - int i = sys_open("/dev/tty", O_RDWR, 0); - if (i != -1) { - ioctl(i, (int) TIOCNOTTY, (char *)0); - close(i); - } - } -#endif /* HAVE_SETSID */ - - /* Close fd's 0,1,2. Needed if started by rsh */ - close_low_fds(False); /* Don't close stderr, let the debug system - attach it to the logfile */ -} - bool reinit_after_fork(struct messaging_context *msg_ctx, struct event_context *ev_ctx, bool parent_longlived) -- cgit