X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Ffm.c;h=37a0954619695cf9cb08293ae205114774738ffe;hb=8687dace5b3a5a8d2b44c087c8f0091ad0cbc298;hp=50740f25b5bf225ec1fba51078f7fcdba05edef2;hpb=3cbcf01cfdb77d6d8d575c1b23ca6db6a039ffa8;p=openldap diff --git a/servers/slurpd/fm.c b/servers/slurpd/fm.c index 50740f25b5..37a0954619 100644 --- a/servers/slurpd/fm.c +++ b/servers/slurpd/fm.c @@ -1,10 +1,18 @@ /* $OpenLDAP$ */ -/* - * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* 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 + * . */ -/* - * Copyright (c) 1996 Regents of the University of Michigan. +/* Portions Copyright (c) 1996 Regents of the University of Michigan. * All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -14,6 +22,10 @@ * 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. @@ -26,6 +38,8 @@ #include #include #include +#include +#include #include "slurp.h" #include "globals.h" @@ -52,21 +66,19 @@ fm( ) { int rc; + int i; + fd_set readfds; /* 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 a shutdown */ - (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); - (void) SIGNAL( LDAP_SIGUSR2, slurp_set_shutdown ); (void) SIGNAL( SIGTERM, slurp_set_shutdown ); (void) SIGNAL( SIGINT, slurp_set_shutdown ); #ifdef SIGHUP (void) SIGNAL( SIGHUP, slurp_set_shutdown ); #endif -#ifdef SIGBREAK - (void) SIGNAL( SIGBREAK, slurp_set_shutdown ); +#if defined(SIGBREAK) && defined(HAVE_NT_SERVICE_MANAGER) + (void) SIGNAL( SIGBREAK, do_nothing ); #endif if ( sglob->one_shot_mode ) { @@ -89,35 +101,32 @@ fm( populate_queue( sglob->slurpd_replogfile ); } + FD_ZERO( &readfds ); 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 { - ldap_pvt_thread_sleep( 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 */ @@ -128,26 +137,22 @@ 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 + 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 ); -#endif return NULL; } @@ -160,20 +165,9 @@ fm( RETSIGTYPE slurp_set_shutdown(int sig) { - int i; - -#if HAVE_NT_SERVICE_MANAGER && SIGBREAK - if (sig == SIGBREAK) return do_nothing( sig ); -#endif - sglob->slurpd_shutdown = 1; /* set flag */ - ldap_pvt_thread_kill( sglob->fm_tid, LDAP_SIGUSR1 ); /* wake up file mgr */ - 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 */ + tcp_write( sglob->wake_sds[1], "0", 1); /* wake up file mgr */ + (void) SIGNAL_REINSTALL( sig, slurp_set_shutdown ); /* reinstall handlers */ } @@ -205,15 +199,9 @@ populate_queue( 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; } @@ -222,15 +210,9 @@ 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 ); -#endif } else { while (( p = get_record( fp )) != NULL ) { if ( sglob->rq->rq_add( sglob->rq, p ) < 0 ) { @@ -239,15 +221,9 @@ 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 ); ldap_pvt_thread_yield();