X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Ffm.c;h=30ac5845d6428a5f073e816967dc942e97da02e9;hb=ca8ab9d8099e89e1338e721f129eb118866edb72;hp=2aed9e602ea46bed0e5f48d8aeb95119e1e81a3d;hpb=2a869f5a99f537b246ba8640502e2a86117cb6e8;p=openldap diff --git a/servers/slurpd/fm.c b/servers/slurpd/fm.c index 2aed9e602e..30ac5845d6 100644 --- a/servers/slurpd/fm.c +++ b/servers/slurpd/fm.c @@ -1,3 +1,8 @@ +/* $OpenLDAP$ */ +/* + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* * Copyright (c) 1996 Regents of the University of Michigan. * All rights reserved. @@ -18,6 +23,7 @@ #include +#include #include #include @@ -25,21 +31,12 @@ #include "globals.h" -/* - * Externs - */ -extern RETSIGTYPE do_admin LDAP_P((int)); -extern int file_nonempty LDAP_P(( char * )); -extern int acquire_lock LDAP_P((char *, FILE **, FILE ** )); -extern int relinquish_lock LDAP_P((char *, FILE *, FILE * )); - /* * Forward references */ static char *get_record LDAP_P(( FILE * )); static void populate_queue LDAP_P(( char *f )); static RETSIGTYPE set_shutdown LDAP_P((int)); -RETSIGTYPE do_nothing LDAP_P((int)); /* @@ -50,7 +47,7 @@ RETSIGTYPE do_nothing LDAP_P((int)); * - 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 ) @@ -59,20 +56,16 @@ fm( /* Set up our signal handlers: * SIG{TERM,INT,HUP} causes a shutdown - * SIG(STKFLT|USR1) - does nothing, used to wake up sleeping threads. - * SIG(UNUSED|USR2) - causes slurpd to read its administrative interface file. - * (not yet implemented). + * LDAP_SIGUSR1 - does nothing, used to wake up sleeping threads. + * LDAP_SIGUSR2 - causes a shutdown */ -#ifdef HAVE_LINUX_THREADS - (void) SIGNAL( SIGSTKFLT, do_nothing ); - (void) SIGNAL( SIGUNUSED, do_admin ); -#else - (void) SIGNAL( SIGUSR1, do_nothing ); - (void) SIGNAL( SIGUSR2, do_admin ); -#endif + (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); + (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 )) { @@ -83,7 +76,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 @@ -98,21 +91,31 @@ fm( while ( !sglob->slurpd_shutdown ) { if ( file_nonempty( sglob->slapd_replogfile )) { /* New work found - copy to slurpd replog file */ +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ARGS, + "fm: new work in %s\n", sglob->slapd_replogfile, 0, 0 ); +#else Debug( LDAP_DEBUG_ARGS, "new work in %s\n", sglob->slapd_replogfile, 0, 0 ); +#endif if (( rc = copy_replog( sglob->slapd_replogfile, sglob->slurpd_replogfile )) == 0 ) { populate_queue( sglob->slurpd_replogfile ); } else { if ( rc < 0 ) { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, CRIT, + "fm: Fatal error while copying replication log\n" , 0, 0, 0); +#else Debug( LDAP_DEBUG_ANY, "Fatal error while copying replication log\n", 0, 0, 0 ); +#endif sglob->slurpd_shutdown = 1; } } } else { - tsleep( sglob->no_work_interval ); + ldap_pvt_thread_sleep( sglob->no_work_interval ); } /* Garbage-collect queue */ @@ -123,16 +126,27 @@ fm( FILE *fp, *lfp; if (( rc = acquire_lock( sglob->slurpd_replogfile, &fp, &lfp )) < 0 ) { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ERR, + "fm: Error: cannot acquire lock on \"%s\" for trimming\n", + sglob->slurpd_replogfile, 0, 0 ); +#else Debug( LDAP_DEBUG_ANY, "Error: cannot acquire lock on \"%s\" for trimming\n", sglob->slurpd_replogfile, 0, 0 ); +#endif } else { sglob->rq->rq_write( sglob->rq, fp ); (void) relinquish_lock( sglob->slurpd_replogfile, fp, lfp ); } } } +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, RESULTS, "fm: exiting\n", 0, 0, 0 ); +#else Debug( LDAP_DEBUG_ARGS, "fm: exiting\n", 0, 0, 0 ); +#endif + return NULL; } @@ -142,25 +156,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 */ -#ifdef HAVE_LINUX_THREADS - pthread_kill( sglob->fm_tid, SIGSTKFLT ); /* wake up file mgr */ -#else - pthread_kill( sglob->fm_tid, SIGUSR1 ); /* wake up file mgr */ -#endif + 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_REINSTALL( sig, set_shutdown ); /* reinstall handlers */ } @@ -170,13 +178,9 @@ set_shutdown(int x) * A do-nothing signal handler. */ RETSIGTYPE -do_nothing(int i) +do_nothing(int sig) { -#ifdef HAVE_LINUX_THREADS - (void) SIGNAL( SIGSTKFLT, do_nothing ); -#else - (void) SIGNAL( SIGUSR1, do_nothing ); -#endif + (void) SIGNAL_REINSTALL( sig, do_nothing ); } @@ -192,13 +196,18 @@ populate_queue( ) { FILE *fp, *lfp; - Rq *rq = sglob->rq; char *p; if ( acquire_lock( f, &fp, &lfp ) < 0 ) { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ERR, + "populate_queue: error: can't lock file \"%s\": %s\n", + f, sys_errlist[ errno ], 0 ); +#else Debug( LDAP_DEBUG_ANY, "error: can't lock file \"%s\": %s\n", f, sys_errlist[ errno ], 0 ); +#endif return; } @@ -207,11 +216,16 @@ populate_queue( * the queue. */ if ( fseek( fp, sglob->srpos, 0 ) < 0 ) { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ERR, + "populate_queue: error: can't seek to offset %ld in file \"%s\"\n", + sglob->srpos, f, 0 ); +#else Debug( LDAP_DEBUG_ANY, "error: can't seek to offset %ld in file \"%s\"\n", sglob->srpos, f, 0 ); - return; - } +#endif + } else { while (( p = get_record( fp )) != NULL ) { if ( sglob->rq->rq_add( sglob->rq, p ) < 0 ) { char *t; @@ -219,14 +233,21 @@ populate_queue( if (( t = strchr( p, '\n' )) != NULL ) { *t = '\0'; } +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ERR, + "populate_queue: error: malformed replog entry " + "(begins with \"%s\")\n", p, 0, 0 ); +#else Debug( LDAP_DEBUG_ANY, "error: malformed replog entry (begins with \"%s\")\n", p, 0, 0 ); +#endif } free( p ); - pthread_yield(); + ldap_pvt_thread_yield(); } sglob->srpos = ftell( fp ); + } (void) relinquish_lock( f, fp, lfp ); } @@ -251,13 +272,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 ); } -