<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -35,6 +35,7 @@ Stuart Herbert &lt;stuart@gentoo.org&gt;
 
 Brion Vibber &lt;brion@pobox.com&gt;
   -- debugging abstraction in PHP client
+  -- debugging the failure of daemon mode on FreeBSD
 
 Brad Whitaker &lt;whitaker@danga.com&gt;
   -- compression support for the Perl API</diff>
      <filename>CONTRIBUTORS</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,9 @@
+2003-10-23
+	* Shift init code around to fix daemon mode on FreeBSD,
+	* and drop root only after creating the server socket (to
+	* allow the use of privileged ports)
+	* version 1.1.10pre
+
 2003-10-09
 	* BSD compile fixes from Ryan T. Dean
 	* version 1.1.9</diff>
      <filename>ChangeLog</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 AC_PREREQ(2.52)
-AC_INIT(memcached, 1.1.9, brad@danga.com)
+AC_INIT(memcached, 1.1.10pre, brad@danga.com)
 AC_CANONICAL_SYSTEM
 AC_CONFIG_SRCDIR(memcached.c)
 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)</diff>
      <filename>configure.ac</filename>
    </modified>
    <modified>
      <diff>@@ -1305,21 +1305,18 @@ int main (int argc, char **argv) {
         }
     }
 
-    /* initialize other stuff */
-    item_init();
-    event_init();
-    stats_init();
-    assoc_init();
-    conn_init();
-    slabs_init(settings.maxbytes);
+    /* 
+     * initialization order: first create the listening socket
+     * (may need root on low ports), then drop root if needed,
+     * then daemonise if needed, then init libevent (in some cases
+     * descriptors created by libevent wouldn't survive forking).
+     */
 
-    /* lock paged memory if needed */
-    if (lock_memory) {
-#ifdef HAVE_MLOCKALL
-        mlockall(MCL_CURRENT | MCL_FUTURE);
-#else
-        fprintf(stderr, &quot;warning: mlockall() not supported on this platform.  proceeding without.\n&quot;);
-#endif
+    /* create the listening socket and bind it */
+    l_socket = server_socket(settings.port);
+    if (l_socket == -1) {
+        fprintf(stderr, &quot;failed to listen\n&quot;);
+        exit(1);
     }
 
     /* lose root privileges if we have them */
@@ -1338,6 +1335,7 @@ int main (int argc, char **argv) {
         }
     }
 
+    /* daemonize if requested */
     if (daemonize) {
         int res;
         res = daemon(0, settings.verbose);
@@ -1347,6 +1345,24 @@ int main (int argc, char **argv) {
         }
     }
 
+
+    /* initialize other stuff */
+    item_init();
+    event_init();
+    stats_init();
+    assoc_init();
+    conn_init();
+    slabs_init(settings.maxbytes);
+
+    /* lock paged memory if needed */
+    if (lock_memory) {
+#ifdef HAVE_MLOCKALL
+        mlockall(MCL_CURRENT | MCL_FUTURE);
+#else
+        fprintf(stderr, &quot;warning: mlockall() not supported on this platform.  proceeding without.\n&quot;);
+#endif
+    }
+
     /*
      * ignore SIGPIPE signals; we can use errno==EPIPE if we
      * need that information
@@ -1359,13 +1375,6 @@ int main (int argc, char **argv) {
         exit(1); 
     }
 
-    /* create the listening socket and bind it */
-    l_socket = server_socket(settings.port);
-    if (l_socket == -1) {
-        fprintf(stderr, &quot;failed to listen\n&quot;);
-        exit(1);
-    }
-
     /* create the initial listening connection */
     if (!(l_conn = conn_new(l_socket, conn_listening, EV_READ | EV_PERSIST))) {
         fprintf(stderr, &quot;failed to create listening connection&quot;);</diff>
      <filename>memcached.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2b6bec19bd46f480e59bc5cac592ff1f03379b81</id>
    </parent>
  </parents>
  <author>
    <name>Brion Vibber</name>
    <email>brion@pobox.com</email>
  </author>
  <url>http://github.com/dustin/memcached/commit/ed0f5b0eacd1643003d0fbf12ed7825d9ff3a7b1</url>
  <id>ed0f5b0eacd1643003d0fbf12ed7825d9ff3a7b1</id>
  <committed-date>2003-10-22T18:54:19-07:00</committed-date>
  <authored-date>2003-10-22T18:54:19-07:00</authored-date>
  <message>Shift init stuff around in main(). Fixes a problem on FreeBSD where
a kqeueue descriptor didn't surive fork() performed by daemonising
(fix by Brion Vibber).

Moves server socket creation to happen prior to losing root privs,
so that listening on priviledged ports is possible.

Bump version to 1.1.10pre.


git-svn-id: http://code.sixapart.com/svn/memcached/trunk@152 b0b603af-a30f-0410-a34e-baf09ae79d0b</message>
  <tree>3b7a58f65c9a0c88503e7c7d2feb35ae01150a02</tree>
  <committer>
    <name>Brion Vibber</name>
    <email>brion@pobox.com</email>
  </committer>
</commit>
