* debian/patches/service-operational-before-detach: New patch replacing
    old one of same name as previous could cause database corruption,
    based on upstream commits. (LP: #727973)

Patch attached.
Description: Wait for database startup before parent exits.
 This patch replaces the previous one named the same name,
 but is based on upstream commits; as the previous applied
 patch could cause database corruption.
 .
 Patch is based on upstream commits as described below:
 libraries/liblutil/detach.c 1.25 -> 1.26
 include/lutil.h 1.81 -> 1.82
 servers/slapd/main.c 1.276 -> 1.278
 .
Forwarded: not-needed
Origin: upstream, commit:1.26
Origin: upstream, commit:1.82
Origin: upstream, commit:1.278
Bug: http://www.openldap.org/its/index.cgi/?findid=6848
Bug-Ubuntu: https://launchpad.net/bugs/727973
Bug-Debian: http://bugs.debian.org/589915
Reviewed-by: Dave Walker (Daviey) <davewal...@ubuntu.com>
Last-Update: 2011-03-02

--- a/include/lutil.h
+++ b/include/lutil.h
@@ -48,7 +48,7 @@
        size_t));
 
 /* detach.c */
-LDAP_LUTIL_F( void )
+LDAP_LUTIL_F( int )
 lutil_detach LDAP_P((
        int debug,
        int do_close));
--- a/libraries/liblutil/detach.c
+++ b/libraries/liblutil/detach.c
@@ -49,10 +49,10 @@
 
 #include "lutil.h"
 
-void
+int
 lutil_detach( int debug, int do_close )
 {
-       int             i, sd, nbits;
+       int             i, sd, nbits, pid;
 
 #ifdef HAVE_SYSCONF
        nbits = sysconf( _SC_OPEN_MAX );
@@ -71,10 +71,11 @@
        if ( debug == 0 ) {
                for ( i = 0; i < 5; i++ ) {
 #ifdef HAVE_THR
-                       switch ( fork1() )
+                       pid = fork1();
 #else
-                       switch ( fork() )
+                       pid = fork();
 #endif
+                       switch ( pid )
                        {
                        case -1:
                                sleep( 5 );
@@ -84,7 +85,7 @@
                                break;
 
                        default:
-                               _exit( EXIT_SUCCESS );
+                               return pid;
                        }
                        break;
                }
@@ -139,4 +140,5 @@
 #ifdef SIGPIPE
        (void) SIGNAL( SIGPIPE, SIG_IGN );
 #endif
+       return 0;
 }
--- a/servers/slapd/main.c
+++ b/servers/slapd/main.c
@@ -364,6 +364,9 @@
        int syslogUser = SLAP_DEFAULT_SYSLOG_USER;
 #endif
        
+#ifndef HAVE_WINSOCK
+       int pid, waitfds[2];
+#endif
        int g_argc = argc;
        char **g_argv = argv;
 
@@ -826,7 +829,7 @@
        if( rc != 0) {
                Debug( LDAP_DEBUG_ANY,
                    "main: TLS init failed: %d\n",
-                   0, 0, 0 );
+                   rc, 0, 0 );
                rc = 1;
                SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
                goto destroy;
@@ -881,7 +884,24 @@
 #endif
 
 #ifndef HAVE_WINSOCK
-       lutil_detach( no_detach, 0 );
+       if ( lutil_pair( waitfds ) < 0 ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "main: lutil_pair failed: %d\n",
+                       0, 0, 0 );
+               rc = 1;
+               goto destroy;
+       }
+       pid = lutil_detach( no_detach, 0 );
+       if ( pid ) {
+               char buf[4];
+               rc = EXIT_SUCCESS;
+               close( waitfds[1] );
+               if ( read( waitfds[0], buf, 1 ) != 1 )
+                       rc = EXIT_FAILURE;
+               _exit( rc );
+       } else {
+               close( waitfds[0] );
+       }
 #endif /* HAVE_WINSOCK */
 
 #ifdef CSRIMALLOC
@@ -952,6 +972,11 @@
 
        Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
 
+#ifndef HAVE_WINSOCK
+       write( waitfds[1], "1", 1 );
+       close( waitfds[1] );
+#endif
+
 #ifdef HAVE_NT_EVENT_LOG
        if (is_NT_Service)
        lutil_LogStartedEvent( serverName, slap_debug, configfile ?

Reply via email to