[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha6-1037-g193be43

Steven Danneman sdanneman at samba.org
Sat Feb 21 00:29:27 GMT 2009


The branch, master has been updated
       via  193be432a224918bf0fbecfb6705146476c15c07 (commit)
       via  116ce19b10a1fd60776764974ad50776ff7c4714 (commit)
      from  5bd7f9c61bb2fea1867ac6657c9b30799ba49d8f (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 193be432a224918bf0fbecfb6705146476c15c07
Author: Steven Danneman <steven.danneman at isilon.com>
Date:   Fri Feb 20 16:24:08 2009 -0800

    s3: Refactor of madvise() usage in c441f58d
    
    * move to reinit_after_fork() to protect all Samba daemons
    * only protect parent processes

commit 116ce19b10a1fd60776764974ad50776ff7c4714
Author: Steven Danneman <steven.danneman at isilon.com>
Date:   Fri Feb 20 15:10:21 2009 -0800

    Moved become_daemon() and close_low_fds() to shared util lib

-----------------------------------------------------------------------

Summary of changes:
 lib/util/become_daemon.c |   22 +++++++-------
 lib/util/util.h          |    9 ++++--
 source3/Makefile.in      |    3 +-
 source3/include/proto.h  |    2 -
 source3/lib/util.c       |   74 ++++-----------------------------------------
 source3/smbd/server.c    |    7 ----
 source4/smbd/server.c    |    2 +-
 7 files changed, 27 insertions(+), 92 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/become_daemon.c b/lib/util/become_daemon.c
index 034114e..5a97b65 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 7873f0e..4d4df21 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.
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 2df995f..98ed810 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -338,7 +338,8 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o ../lib/util/time.o \
 		   ../lib/util/util_file.o ../lib/util/data_blob.o \
 		   ../lib/util/util.o ../lib/util/fsusage.o \
 		   ../lib/util/params.o ../lib/util/talloc_stack.o \
-		   ../lib/util/genrand.o ../lib/util/util_net.o
+		   ../lib/util/genrand.o ../lib/util/util_net.o \
+		   ../lib/util/become_daemon.o
 
 CRYPTO_OBJ = ../lib/crypto/crc32.o ../lib/crypto/md5.o \
 			 ../lib/crypto/hmacmd5.o ../lib/crypto/arcfour.o \
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 1ac2ac2..587bb29 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1139,11 +1139,9 @@ int set_message_bcc(char *buf,int num_bytes);
 ssize_t message_push_blob(uint8 **outbuf, DATA_BLOB blob);
 char *unix_clean_name(TALLOC_CTX *ctx, const char *s);
 char *clean_name(TALLOC_CTX *ctx, const char *s);
-void close_low_fds(bool stderr_too);
 ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, SMB_OFF_T pos);
 int set_blocking(int fd, bool set);
 void smb_msleep(unsigned int t);
-void become_daemon(bool Fork, bool no_process_group);
 bool reinit_after_fork(struct messaging_context *msg_ctx,
 		       struct event_context *ev_ctx,
 		       bool parent_longlived);
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 6079e71..cda1fb4 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -798,43 +798,6 @@ char *clean_name(TALLOC_CTX *ctx, const char *s)
 }
 
 /*******************************************************************
- 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)
@@ -966,6 +899,13 @@ bool reinit_after_fork(struct messaging_context *msg_ctx,
 	 * numbers as each other */
 	set_need_random_reseed();
 
+#ifdef WITH_MADVISE_PROTECTED
+	/* Protect parent process from being killed by kernel when system
+	 * memory is low.  Child processes can still be killed */
+	if(!parent_longlived)
+		madvise(NULL,0,MADV_PROTECT);
+#endif
+
 	/* tdb needs special fork handling */
 	if (tdb_reopen_all(parent_longlived ? 1 : 0) == -1) {
 		DEBUG(0,("tdb_reopen_all failed.\n"));
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index e8ccba0..28ce80b 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -359,10 +359,6 @@ static void smbd_accept_connection(struct tevent_context *ev,
 		/* Child code ... */
 		am_parent = 0;
 
-#ifdef WITH_MADVISE_PROTECTED
-		madvise(NULL,0,MADV_PROTECT);
-#endif
-
 		/* Stop zombies, the parent explicitly handles
 		 * them, counting worker smbds. */
 		CatchChild();
@@ -1135,9 +1131,6 @@ extern void build_options(bool screen);
 	if (is_daemon && !interactive) {
 		DEBUG( 3, ( "Becoming a daemon.\n" ) );
 		become_daemon(Fork, no_process_group);
-#ifdef WITH_MADVISE_PROTECTED
-		madvise(NULL,0,MADV_PROTECT);
-#endif
 	}
 
 #if HAVE_SETPGID
diff --git a/source4/smbd/server.c b/source4/smbd/server.c
index 247a10f..d576782 100644
--- a/source4/smbd/server.c
+++ b/source4/smbd/server.c
@@ -277,7 +277,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 
 	if (opt_daemon) {
 		DEBUG(3,("Becoming a daemon.\n"));
-		become_daemon(true);
+		become_daemon(true, false);
 	}
 
 	cleanup_tmp_files(cmdline_lp_ctx);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list