s3: Refactor of madvise() usage in c441f58d
authorSteven Danneman <steven.danneman@isilon.com>
Sat, 21 Feb 2009 00:24:08 +0000 (16:24 -0800)
committerSteven Danneman <steven.danneman@isilon.com>
Sat, 21 Feb 2009 00:30:13 +0000 (16:30 -0800)
* move to reinit_after_fork() to protect all Samba daemons
* only protect parent processes

source3/lib/util.c
source3/smbd/server.c

index baac26b9aa81626f47e31695f36c9e7776a2bd81..cda1fb474de72ef14ab1af9ff5c0143481da29bb 100644 (file)
@@ -899,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"));
index e8ccba0873aef5bd4ee968ede959fb6ec17bd745..28ce80b6c80640554f4d6c35756121fc70817645 100644 (file)
@@ -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