summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteven Danneman <steven.danneman@isilon.com>2009-02-20 15:10:21 -0800
committerSteven Danneman <steven.danneman@isilon.com>2009-02-20 16:30:12 -0800
commit116ce19b10a1fd60776764974ad50776ff7c4714 (patch)
tree9b89a37dbcc8b4d7ebed324d5960f3fd550fc3d6 /lib
parent5bd7f9c61bb2fea1867ac6657c9b30799ba49d8f (diff)
downloadsamba-116ce19b10a1fd60776764974ad50776ff7c4714.tar.gz
samba-116ce19b10a1fd60776764974ad50776ff7c4714.tar.bz2
samba-116ce19b10a1fd60776764974ad50776ff7c4714.zip
Moved become_daemon() and close_low_fds() to shared util lib
Diffstat (limited to 'lib')
-rw-r--r--lib/util/become_daemon.c22
-rw-r--r--lib/util/util.h9
2 files changed, 17 insertions, 14 deletions
diff --git a/lib/util/become_daemon.c b/lib/util/become_daemon.c
index 034114eade..5a97b65407 100644
--- a/lib/util/become_daemon.c
+++ b/lib/util/become_daemon.c
@@ -28,14 +28,15 @@
/*******************************************************************
Close the low 3 fd's and open dev/null in their place.
********************************************************************/
-static void close_low_fds(bool stderr_too)
+
+_PUBLIC_ void close_low_fds(bool stderr_too)
{
#ifndef VALGRIND
int fd;
int i;
close(0);
- close(1);
+ close(1);
if (stderr_too)
close(2);
@@ -61,11 +62,11 @@ static void close_low_fds(bool stderr_too)
#endif
}
-/**
+/****************************************************************************
Become a daemon, discarding the controlling terminal.
-**/
+****************************************************************************/
-_PUBLIC_ void become_daemon(bool Fork)
+_PUBLIC_ void become_daemon(bool Fork, bool no_process_group)
{
if (Fork) {
if (fork()) {
@@ -73,14 +74,14 @@ _PUBLIC_ void become_daemon(bool Fork)
}
}
- /* detach from the terminal */
+ /* detach from the terminal */
#ifdef HAVE_SETSID
- setsid();
+ if (!no_process_group) setsid();
#elif defined(TIOCNOTTY)
- {
- int i = open("/dev/tty", O_RDWR, 0);
+ if (!no_process_group) {
+ int i = sys_open("/dev/tty", O_RDWR, 0);
if (i != -1) {
- ioctl(i, (int) TIOCNOTTY, (char *)0);
+ ioctl(i, (int) TIOCNOTTY, (char *)0);
close(i);
}
}
@@ -90,4 +91,3 @@ _PUBLIC_ void become_daemon(bool Fork)
close_low_fds(false); /* Don't close stderr, let the debug system
attach it to the logfile */
}
-
diff --git a/lib/util/util.h b/lib/util/util.h
index 7873f0e769..4d4df21600 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -724,12 +724,15 @@ _PUBLIC_ int idr_remove(struct idr_context *idp, int id);
/* The following definitions come from lib/util/become_daemon.c */
-#if _SAMBA_BUILD_ == 4
+/**
+ Close the low 3 fd's and open dev/null in their place
+**/
+_PUBLIC_ void close_low_fds(bool stderr_too);
+
/**
Become a daemon, discarding the controlling terminal.
**/
-_PUBLIC_ void become_daemon(bool fork);
-#endif
+_PUBLIC_ void become_daemon(bool fork, bool no_process_group);
/**
* Load a ini-style file.