X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Ffm.c;h=37a0954619695cf9cb08293ae205114774738ffe;hb=4abbf9c610d4fbaeee0dbdceaad1e0f94ed8e8fe;hp=2d36838bb549dc4ed3086f44bcf955af03d370a6;hpb=42e0d83cb3a1a1c5b25183f1ab74ce7edbe25de7;p=openldap
diff --git a/servers/slurpd/fm.c b/servers/slurpd/fm.c
index 2d36838bb5..37a0954619 100644
--- a/servers/slurpd/fm.c
+++ b/servers/slurpd/fm.c
@@ -1,5 +1,18 @@
-/*
- * Copyright (c) 1996 Regents of the University of Michigan.
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 1998-2005 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
+ */
+/* Portions Copyright (c) 1996 Regents of the University of Michigan.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
@@ -9,55 +22,34 @@
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*/
+/* ACKNOWLEDGEMENTS:
+ * This work was originally developed by the University of Michigan
+ * (as part of U-MICH LDAP).
+ */
/*
* fm.c - file management routines.
*/
+#include "portable.h"
+
#include
-#include
-#include
+
+#include
+#include
+#include
+#include
+#include
#include "slurp.h"
#include "globals.h"
-extern void do_admin();
-
-static void set_shutdown();
-void do_nothing();
-
-/*
- * Externs
- */
-#ifdef NEEDPROTOS
-extern int file_nonempty( char * );
-extern int acquire_lock(char *, FILE **, FILE ** );
-extern int relinquish_lock(char *, FILE *, FILE * );
-#else /* NEEDPROTOS */
-extern int file_nonempty();
-extern int acquire_lock();
-extern int relinquish_lock();
-#endif /* NEEDPROTOS */
/*
* Forward references
*/
-#ifdef NEEDPROTOS
-static char *get_record( FILE * );
-static void populate_queue( char *f );
-static void set_shutdown();
-void do_nothing();
-#else /* NEEDPROTOS */
-static char *get_record();
-static void populate_queue();
-static void set_shutdown();
-void do_nothing();
-#endif /* NEEDPROTOS */
-
-#ifndef SYSERRLIST_IN_STDIO
-extern char *sys_errlist[];
-#endif /* SYSERRLIST_IN_STDIO */
-
+static char *get_record LDAP_P(( FILE * ));
+static void populate_queue LDAP_P(( char *f ));
/*
@@ -68,24 +60,26 @@ extern char *sys_errlist[];
* - adds items to the internal queue of replication work to do
* - signals the replication threads to let them know new work has arrived.
*/
-void
+void *
fm(
void *arg
)
{
int rc;
+ int i;
+ fd_set readfds;
/* Set up our signal handlers:
* SIG{TERM,INT,HUP} causes a shutdown
- * SIGUSR1 - does nothing, used to wake up sleeping threads.
- * SIGUSR2 - causes slurpd to read its administrative interface file.
- * (not yet implemented).
*/
- (void) SIGNAL( SIGUSR1, (void *) do_nothing );
- (void) SIGNAL( SIGUSR2, (void *) do_admin );
- (void) SIGNAL( SIGTERM, (void *) set_shutdown );
- (void) SIGNAL( SIGINT, (void *) set_shutdown );
- (void) SIGNAL( SIGHUP, (void *) set_shutdown );
+ (void) SIGNAL( SIGTERM, slurp_set_shutdown );
+ (void) SIGNAL( SIGINT, slurp_set_shutdown );
+#ifdef SIGHUP
+ (void) SIGNAL( SIGHUP, slurp_set_shutdown );
+#endif
+#if defined(SIGBREAK) && defined(HAVE_NT_SERVICE_MANAGER)
+ (void) SIGNAL( SIGBREAK, do_nothing );
+#endif
if ( sglob->one_shot_mode ) {
if ( file_nonempty( sglob->slapd_replogfile )) {
@@ -96,7 +90,7 @@ fm(
sglob->rq->rq_getcount( sglob->rq, RQ_COUNT_ALL ));
printf( "%d replication records to process.\n",
sglob->rq->rq_getcount( sglob->rq, RQ_COUNT_NZRC ));
- return;
+ return NULL;
}
/*
* There may be some leftover replication records in our own
@@ -107,6 +101,7 @@ fm(
populate_queue( sglob->slurpd_replogfile );
}
+ FD_ZERO( &readfds );
while ( !sglob->slurpd_shutdown ) {
if ( file_nonempty( sglob->slapd_replogfile )) {
@@ -125,7 +120,13 @@ fm(
}
}
} else {
- tsleep( sglob->no_work_interval );
+ struct timeval tv;
+
+ FD_SET( sglob->wake_sds[0], &readfds );
+ tv.tv_sec = sglob->no_work_interval;
+ tv.tv_usec = 0;
+
+ rc = select( sglob->wake_sds[0]+1, &readfds, NULL, NULL, &tv );
}
/* Garbage-collect queue */
@@ -145,7 +146,14 @@ fm(
}
}
}
+ sglob->rq->rq_lock( sglob->rq ); /* lock queue */
+ 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 */
Debug( LDAP_DEBUG_ARGS, "fm: exiting\n", 0, 0, 0 );
+ return NULL;
}
@@ -154,22 +162,13 @@ fm(
/*
* Set a global flag which signals that we're shutting down.
*/
-static void
-set_shutdown()
+RETSIGTYPE
+slurp_set_shutdown(int sig)
{
- int i;
-
sglob->slurpd_shutdown = 1; /* set flag */
- pthread_kill( sglob->fm_tid, SIGUSR1 ); /* wake up file mgr */
- sglob->rq->rq_lock( sglob->rq ); /* lock queue */
- pthread_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, (void *) set_shutdown ); /* reinstall handlers */
- (void) SIGNAL( SIGINT, (void *) set_shutdown );
- (void) SIGNAL( SIGHUP, (void *) set_shutdown );
+ tcp_write( sglob->wake_sds[1], "0", 1); /* wake up file mgr */
+
+ (void) SIGNAL_REINSTALL( sig, slurp_set_shutdown ); /* reinstall handlers */
}
@@ -178,10 +177,10 @@ set_shutdown()
/*
* A do-nothing signal handler.
*/
-void
-do_nothing()
+RETSIGTYPE
+do_nothing(int sig)
{
- (void) SIGNAL( SIGUSR1, (void *) do_nothing );
+ (void) SIGNAL_REINSTALL( sig, do_nothing );
}
@@ -197,7 +196,6 @@ populate_queue(
)
{
FILE *fp, *lfp;
- Rq *rq = sglob->rq;
char *p;
if ( acquire_lock( f, &fp, &lfp ) < 0 ) {
@@ -215,8 +213,7 @@ populate_queue(
Debug( LDAP_DEBUG_ANY,
"error: can't seek to offset %ld in file \"%s\"\n",
sglob->srpos, f, 0 );
- return;
- }
+ } else {
while (( p = get_record( fp )) != NULL ) {
if ( sglob->rq->rq_add( sglob->rq, p ) < 0 ) {
char *t;
@@ -229,9 +226,10 @@ populate_queue(
p, 0, 0 );
}
free( p );
- pthread_yield();
+ ldap_pvt_thread_yield();
}
sglob->srpos = ftell( fp );
+ }
(void) relinquish_lock( f, fp, lfp );
}
@@ -256,13 +254,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 );
}
-