]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/fm.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / servers / slurpd / fm.c
index 5063927180dac1cb1eb9dfafa47abc22a4071e46..75c1afed027b74da2036f8bc638b748c3adeab35 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright (c) 1996 Regents of the University of Michigan.
  * All rights reserved.
@@ -17,8 +18,8 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>                    /* get free() */
 
+#include <ac/stdlib.h>
 #include <ac/string.h>
 #include <ac/signal.h>
 
@@ -52,14 +53,15 @@ fm(
     /* Set up our signal handlers:
      * SIG{TERM,INT,HUP} causes a shutdown
      * LDAP_SIGUSR1 - does nothing, used to wake up sleeping threads.
-     * LDAP_SIGUSR2 - causes slurpd to read its administrative interface file.
-     *           (not yet implemented).
+        * LDAP_SIGUSR2 - causes a shutdown
      */
     (void) SIGNAL( LDAP_SIGUSR1, do_nothing );
-    (void) SIGNAL( LDAP_SIGUSR2, do_admin );
+    (void) SIGNAL( LDAP_SIGUSR2, set_shutdown );
     (void) SIGNAL( SIGTERM, set_shutdown );
     (void) SIGNAL( SIGINT, set_shutdown );
+#ifdef SIGHUP
     (void) SIGNAL( SIGHUP, set_shutdown );
+#endif
 
     if ( sglob->one_shot_mode ) {
        if ( file_nonempty( sglob->slapd_replogfile )) {
@@ -99,7 +101,7 @@ fm(
                }
            }
        } else {
-           tsleep( sglob->no_work_interval );
+           ldap_pvt_thread_sleep( sglob->no_work_interval );
        }
 
        /* Garbage-collect queue */
@@ -130,21 +132,19 @@ fm(
  * Set a global flag which signals that we're shutting down.
  */
 static RETSIGTYPE
-set_shutdown(int x)
+set_shutdown(int sig)
 {
     int        i;
 
     sglob->slurpd_shutdown = 1;                                /* set flag */
-    pthread_kill( sglob->fm_tid, LDAP_SIGUSR1 );       /* wake up file mgr */
+    ldap_pvt_thread_kill( sglob->fm_tid, LDAP_SIGUSR1 );       /* wake up file mgr */
     sglob->rq->rq_lock( sglob->rq );                   /* lock queue */
-    pthread_cond_broadcast( &(sglob->rq->rq_more) );   /* wake repl threads */
+    ldap_pvt_thread_cond_broadcast( &(sglob->rq->rq_more) );   /* wake repl threads */
     for ( i = 0; i < sglob->num_replicas; i++ ) {
        (sglob->replicas[ i ])->ri_wake( sglob->replicas[ i ]);
     }
     sglob->rq->rq_unlock( sglob->rq );                 /* unlock queue */
-    (void) SIGNAL( SIGTERM, set_shutdown );    /* reinstall handlers */
-    (void) SIGNAL( SIGINT, set_shutdown );
-    (void) SIGNAL( SIGHUP, set_shutdown );
+    (void) SIGNAL( sig, set_shutdown );        /* reinstall handlers */
 }
 
 
@@ -154,9 +154,9 @@ set_shutdown(int x)
  * A do-nothing signal handler.
  */
 RETSIGTYPE
-do_nothing(int i)
+do_nothing(int sig)
 {
-    (void) SIGNAL( LDAP_SIGUSR1, do_nothing );
+    (void) SIGNAL( sig, do_nothing );
 }
 
 
@@ -172,7 +172,6 @@ populate_queue(
 )
 {
     FILE       *fp, *lfp;
-    Rq         *rq = sglob->rq;
     char       *p;
 
     if ( acquire_lock( f, &fp, &lfp ) < 0 ) {
@@ -203,7 +202,7 @@ populate_queue(
                    p, 0, 0 );
        }
        free( p );
-       pthread_yield();
+       ldap_pvt_thread_yield();
     }
     sglob->srpos = ftell( fp );
     }
@@ -231,12 +230,13 @@ get_record(
 
     while (( fgets( line, sizeof(line), fp ) != NULL ) &&
            (( len = strlen( line )) > 1 )) {
-       while ( lcur + len + 1 > lmax ) {
-           lmax += BUFSIZ;
-           buf = (char *) ch_realloc( buf, lmax );
-       }
-       strcpy( buf + lcur, line );
-       lcur += len;
+
+               while ( lcur + len + 1 > lmax ) {
+                   lmax += BUFSIZ;
+                   buf = (char *) ch_realloc( buf, lmax );
+               }
+               strcpy( buf + lcur, line );
+               lcur += len;
     }
     return( buf );
 }