X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Ffm.c;h=37a0954619695cf9cb08293ae205114774738ffe;hb=8687dace5b3a5a8d2b44c087c8f0091ad0cbc298;hp=5523616ed16d0984ef5a41054b69e3968ad2bb27;hpb=a8a05cbe48f55fcb9132352a923435ce177ca1b1;p=openldap diff --git a/servers/slurpd/fm.c b/servers/slurpd/fm.c index 5523616ed1..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,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. @@ -17,10 +34,12 @@ #include "portable.h" #include -#include /* get free() */ +#include #include #include +#include +#include #include "slurp.h" #include "globals.h" @@ -31,7 +50,6 @@ */ static char *get_record LDAP_P(( FILE * )); static void populate_queue LDAP_P(( char *f )); -static RETSIGTYPE set_shutdown LDAP_P((int)); /* @@ -48,18 +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, set_shutdown ); - (void) SIGNAL( SIGTERM, set_shutdown ); - (void) SIGNAL( SIGINT, set_shutdown ); + (void) SIGNAL( SIGTERM, slurp_set_shutdown ); + (void) SIGNAL( SIGINT, slurp_set_shutdown ); #ifdef SIGHUP - (void) SIGNAL( SIGHUP, set_shutdown ); + (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 ) { @@ -82,6 +101,7 @@ fm( populate_queue( sglob->slurpd_replogfile ); } + FD_ZERO( &readfds ); while ( !sglob->slurpd_shutdown ) { if ( file_nonempty( sglob->slapd_replogfile )) { @@ -100,7 +120,13 @@ fm( } } } 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 */ @@ -120,6 +146,12 @@ 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; } @@ -130,20 +162,13 @@ fm( /* * Set a global flag which signals that we're shutting down. */ -static RETSIGTYPE -set_shutdown(int sig) +RETSIGTYPE +slurp_set_shutdown(int sig) { - int i; - 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 */ - (void) SIGNAL( sig, set_shutdown ); /* reinstall handlers */ + tcp_write( sglob->wake_sds[1], "0", 1); /* wake up file mgr */ + + (void) SIGNAL_REINSTALL( sig, slurp_set_shutdown ); /* reinstall handlers */ } @@ -155,7 +180,7 @@ set_shutdown(int sig) RETSIGTYPE do_nothing(int sig) { - (void) SIGNAL( sig, do_nothing ); + (void) SIGNAL_REINSTALL( sig, do_nothing ); } @@ -171,7 +196,6 @@ populate_queue( ) { FILE *fp, *lfp; - Rq *rq = sglob->rq; char *p; if ( acquire_lock( f, &fp, &lfp ) < 0 ) { @@ -230,12 +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 ); }