]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/main.c
Rework test suite to use run script.
[openldap] / servers / slurpd / main.c
index 3220853fb7f0d97fb46ab51e0b37e29fa6deb1e4..5f53a89e6b9aea63e4126a77e8c708258a1dfc0a 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <ac/stdlib.h>
+#include <ac/unistd.h>
 
 #include "slurp.h"
 #include "globals.h"
@@ -160,7 +161,7 @@ int main( int argc, char **argv )
      */
     if ( sglob->st->st_read( sglob->st )) {
        fprintf( stderr, "Malformed slurpd status file \"%s\"\n",
-               sglob->slurpd_status_file, 0, 0 );
+               sglob->slurpd_status_file );
        SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 17 );
        rc = 1;
        goto stop;
@@ -176,15 +177,51 @@ int main( int argc, char **argv )
        goto stop;
     }
 
+
     /*
      * Detach from the controlling terminal
      * unless the -d flag is given or in one-shot mode.
      */
 #ifndef HAVE_WINSOCK
-    if ( ! (sglob->no_detach || sglob->one_shot_mode) )
-       lutil_detach( 0, 0 );
+       if ( ! (sglob->no_detach || sglob->one_shot_mode) ) {
+               lutil_detach( 0, 0 );
+       }
 #endif
 
+       if ( slurpd_pid_file != NULL ) {
+               FILE *fp = fopen( slurpd_pid_file, "w" );
+
+               if( fp != NULL ) {
+                       fprintf( fp, "%d\n", (int) getpid() );
+                       fclose( fp );
+
+               } else {
+               free(slurpd_pid_file);
+               slurpd_pid_file = NULL;
+               }
+       }
+
+       if ( slurpd_args_file != NULL ) {
+               FILE *fp = fopen( slurpd_args_file, "w" );
+
+               if( fp != NULL ) {
+                       for ( i = 0; i < argc; i++ ) {
+                               fprintf( fp, "%s ", argv[i] );
+                       }
+                       fprintf( fp, "\n" );
+                       fclose( fp );
+               } else {
+                       free(slurpd_args_file);
+                       slurpd_args_file = NULL;
+               }
+       }
+
+    if ( (rc = lutil_pair( sglob->wake_sds )) < 0 ) {
+       SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
+       rc = 1;
+       goto stop;
+    }
+       
 #ifdef HAVE_NT_EVENT_LOG
        if (is_NT_Service) lutil_LogStartedEvent( sglob->serverName, ldap_debug, sglob->slapd_configfile, "n/a" );
 #endif
@@ -256,6 +293,15 @@ stop:
 #else
     Debug( LDAP_DEBUG_ANY, "slurpd: terminated.\n", 0, 0, 0 );
 #endif
+
+    if ( slurpd_pid_file != NULL ) {
+       unlink( slurpd_pid_file );
+    }
+    if ( slurpd_args_file != NULL ) {
+       unlink( slurpd_args_file );
+    }
+
+
        MAIN_RETURN(rc);
 #endif /* !NO_THREADS */
 }