* amd/amd.c (do_memory_locking): new function to encapsulate all
authorErez Zadok <ezk@cs.sunysb.edu>
Thu, 13 Jan 2005 22:30:37 +0000 (22:30 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Thu, 13 Jan 2005 22:30:37 +0000 (22:30 +0000)
of the memory-locking functionality, which was in main() before.
Also added a call to madvise(), just in case.
(main): call do_memory_locking() to pin process memory if amd.conf
asked for it, but do so after the main Amd process daemonizes,
because mlock/mlockall is not inherited by fork() by default.
Slightly restructured patch from Jonathan Chen
<jon+amd@spock.org>.

* configure.in: check for madvise(2).

AUTHORS
ChangeLog
NEWS
amd/amd.c
configure.in

diff --git a/AUTHORS b/AUTHORS
index 25e2c6c62a796c506b36bfc47141e3d71c578d17..aa61b31a4a832351106e8e4525c143cd9298fc97 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -383,3 +383,6 @@ August 3, 2004: pawd to recognize "linkx" type mounts.
 September 1, 2004: bug fix to avoid race condition in calls to mntctl on
 AIX.
 
+* Jonathan Chen <jon+amd@spock.org>
+October 22, 2004: patch/fix to move mlock/mlockall/plock code after the
+fork().
index 037b9b7fef007d019aa9c691aec7d6cde1aaa5a8..21b006a294855a9161c75cb213622e6124745e14 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2005-01-13  Erez Zadok  <ezk@cs.sunysb.edu>
 
+       * amd/amd.c (do_memory_locking): new function to encapsulate all
+       of the memory-locking functionality, which was in main() before.
+       Also added a call to madvise(), just in case.
+       (main): call do_memory_locking() to pin process memory if amd.conf
+       asked for it, but do so after the main Amd process daemonizes,
+       because mlock/mlockall is not inherited by fork() by default.
+       Slightly restructured patch from Jonathan Chen
+       <jon+amd@spock.org>.
+
+       * configure.in: check for madvise(2).
+
        * config.guess, config.sub: updates for latest official GNU
        versions.
 
diff --git a/NEWS b/NEWS
index 4886e1c0cf8df391ec98e6019f389bc631c96a33..631a89f2f57a88d1ca5becbf46a8382a739e2892 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,9 @@
        * recognize other mount types in pawd: host, linkx, and nfsx
        * allow exactly one of umount and unmount in type:=program
        * race condition between calls to mntctl() on AIX
+       * plock/mlockall wasn't inherited by fork(); moved after
+         daemonizing.
+
 
 *** Notes specific to am-utils version 6.1b4
 
index 2c47c0e35b3b5cb4864bf9e2a29ed80867d571cb..1e5dc49229e49747a4a3b82c5eab2ab86d58436c 100644 (file)
--- a/amd/amd.c
+++ b/amd/amd.c
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: amd.c,v 1.28 2005/01/03 20:56:45 ezk Exp $
+ * $Id: amd.c,v 1.29 2005/01/13 22:30:38 ezk Exp $
  *
  */
 
@@ -309,6 +309,50 @@ init_global_options(void)
 }
 
 
+/*
+ * Lock process text and data segment in memory (after forking the daemon)
+ */
+static void
+do_memory_locking(void)
+{
+#if defined(HAVE_PLOCK) || defined(HAVE_MLOCKALL)
+  int locked_ok = 0;
+#else /* not HAVE_PLOCK and not HAVE_MLOCKALL */
+  plog(XLOG_WARNING, "Process memory locking not supported by the OS");
+#endif /* not HAVE_PLOCK and not HAVE_MLOCKALL */
+#ifdef HAVE_PLOCK
+# ifdef _AIX
+  /*
+   * On AIX you must lower the stack size using ulimit() before calling
+   * plock.  Otherwise plock will reserve a lot of memory space based on
+   * your maximum stack size limit.  Since it is not easily possible to
+   * tell what should the limit be, I print a warning before calling
+   * plock().  See the manual pages for ulimit(1,3,4) on your AIX system.
+   */
+  plog(XLOG_WARNING, "AIX: may need to lower stack size using ulimit(3) before calling plock");
+# endif /* _AIX */
+  if (!locked_ok && plock(PROCLOCK) != 0)
+    plog(XLOG_WARNING, "Couldn't lock process pages in memory using plock(): %m");
+  else
+    locked_ok = 1;
+#endif /* HAVE_PLOCK */
+#ifdef HAVE_MLOCKALL
+  if (!locked_ok && mlockall(MCL_CURRENT|MCL_FUTURE) != 0)
+    plog(XLOG_WARNING, "Couldn't lock process pages in memory using mlockall(): %m");
+  else
+    locked_ok = 1;
+#endif /* HAVE_MLOCKALL */
+#if defined(HAVE_PLOCK) || defined(HAVE_MLOCKALL)
+  if (locked_ok)
+    plog(XLOG_INFO, "Locked process pages in memory");
+#endif /* HAVE_PLOCK || HAVE_MLOCKALL */
+
+#if defined(HAVE_MADVISE) && defined(MADV_PROTECT)
+    madvise(0, 0, MADV_PROTECT); /* may be redundant of the above worked out */
+#endif /* defined(HAVE_MADVISE) && defined(MADV_PROTECT) */
+}
+
+
 int
 main(int argc, char *argv[])
 {
@@ -503,43 +547,6 @@ main(int argc, char *argv[])
     going_down(1);
   }
 
-  /*
-   * Lock process text and data segment in memory.
-   */
-  if (gopt.flags & CFM_PROCESS_LOCK) {
-#if defined(HAVE_PLOCK) || defined(HAVE_MLOCKALL)
-    int locked_ok = 0;
-#else /* not HAVE_PLOCK and not HAVE_MLOCKALL */
-    plog(XLOG_WARNING, "Process memory locking not supported by the OS");
-#endif /* not HAVE_PLOCK and not HAVE_MLOCKALL */
-#ifdef HAVE_PLOCK
-# ifdef _AIX
-    /*
-     * On AIX you must lower the stack size using ulimit() before calling
-     * plock.  Otherwise plock will reserve a lot of memory space based on
-     * your maximum stack size limit.  Since it is not easily possible to
-     * tell what should the limit be, I print a warning before calling
-     * plock().  See the manual pages for ulimit(1,3,4) on your AIX system.
-     */
-    plog(XLOG_WARNING, "AIX: may need to lower stack size using ulimit(3) before calling plock");
-# endif /* _AIX */
-    if (!locked_ok && plock(PROCLOCK) != 0)
-      plog(XLOG_WARNING, "Couldn't lock process pages in memory using plock(): %m");
-    else
-      locked_ok = 1;
-#endif /* HAVE_PLOCK */
-#ifdef HAVE_MLOCKALL
-    if (!locked_ok && mlockall(MCL_CURRENT|MCL_FUTURE) != 0)
-      plog(XLOG_WARNING, "Couldn't lock process pages in memory using mlockall(): %m");
-    else
-      locked_ok = 1;
-#endif /* HAVE_MLOCKALL */
-#if defined(HAVE_PLOCK) || defined(HAVE_MLOCKALL)
-    if (locked_ok)
-      plog(XLOG_INFO, "Locked process pages in memory");
-#endif /* HAVE_PLOCK || HAVE_MLOCKALL */
-  }
-
 #ifdef HAVE_MAP_NIS
   /*
    * If the domain was specified then bind it here
@@ -555,6 +562,12 @@ main(int argc, char *argv[])
   if (!amuDebug(D_DAEMON))
     ppid = daemon_mode();
 
+  /*
+   * Lock process text and data segment in memory.
+   */
+  if (gopt.flags & CFM_PROCESS_LOCK) {
+    do_memory_locking();
+  }
   sprintf(pid_fsname, "%s:(pid%ld)", am_get_hostname(), (long) am_mypid);
 
   do_mapc_reload = clocktime() + gopt.map_reload_interval;
@@ -567,7 +580,10 @@ main(int argc, char *argv[])
     kill(ppid, SIGALRM);
 
 #ifdef HAVE_FS_AUTOFS
-  /* XXX this should be part of going_down(), but I can't move it there because it would be calling non-library code from the library... ugh */
+  /*
+   * XXX this should be part of going_down(), but I can't move it there
+   * because it would be calling non-library code from the library... ugh
+   */
   if (amd_use_autofs)
     destroy_autofs_service();
 #endif /* HAVE_FS_AUTOFS */
index e96dd193352e39e9d6bbeec025359f5845595409..5072a8be3c79e40dfa0d36f88182b972a795d6b1 100644 (file)
@@ -53,7 +53,7 @@ AH_BOTTOM([
 dnl
 dnl AC_CONFIG_AUX_DIR(m4)
 AC_PREREQ(2.52)
-AC_REVISION($Revision: 1.73 $)
+AC_REVISION($Revision: 1.74 $)
 AC_COPYRIGHT([Copyright (c) 1997-2005 Erez Zadok])
 dnl find out system type
 AC_MSG_NOTICE(*** SYSTEM TYPES ***)
@@ -283,6 +283,7 @@ AC_CHECK_FUNCS(                     \
        hesiod_init             \
        hesiod_reload           \
        hesiod_to_bind          \
+       madvise                 \
        memcmp                  \
        memcpy                  \
        memmove                 \