+/* $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.
* fm.c - file management routines.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <signal.h>
+
+#include <ac/stdlib.h>
+#include <ac/string.h>
+#include <ac/signal.h>
#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 ));
+static RETSIGTYPE set_shutdown 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
)
/* 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 SIGSTKFLT
- (void) SIGNAL( SIGSTKFLT, (void *) do_nothing );
-#else
- (void) SIGNAL( SIGUSR1, (void *) do_nothing );
-#endif
-#ifdef SIGUNUSED
- (void) SIGNAL( SIGUNUSED, (void *) do_admin );
-#else
- (void) SIGNAL( SIGUSR2, (void *) do_admin );
+ (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
- (void) SIGNAL( SIGTERM, (void *) set_shutdown );
- (void) SIGNAL( SIGINT, (void *) set_shutdown );
- (void) SIGNAL( SIGHUP, (void *) set_shutdown );
if ( sglob->one_shot_mode ) {
if ( file_nonempty( sglob->slapd_replogfile )) {
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
}
}
} else {
- tsleep( sglob->no_work_interval );
+ ldap_pvt_thread_sleep( sglob->no_work_interval );
}
/* Garbage-collect queue */
}
}
Debug( LDAP_DEBUG_ARGS, "fm: exiting\n", 0, 0, 0 );
+ return NULL;
}
/*
* Set a global flag which signals that we're shutting down.
*/
-static void
-set_shutdown()
+static RETSIGTYPE
+set_shutdown(int sig)
{
int i;
sglob->slurpd_shutdown = 1; /* set flag */
-#ifdef SIGSTKFLT
- 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, (void *) set_shutdown ); /* reinstall handlers */
- (void) SIGNAL( SIGINT, (void *) set_shutdown );
- (void) SIGNAL( SIGHUP, (void *) set_shutdown );
+ (void) SIGNAL_REINSTALL( sig, set_shutdown ); /* reinstall handlers */
}
/*
* A do-nothing signal handler.
*/
-void
-do_nothing()
+RETSIGTYPE
+do_nothing(int sig)
{
-#ifdef SIGSTKFLT
- (void) SIGNAL( SIGSTKFLT, (void *) do_nothing );
-#else
- (void) SIGNAL( SIGUSR1, (void *) do_nothing );
-#endif
+ (void) SIGNAL_REINSTALL( sig, do_nothing );
}
)
{
FILE *fp, *lfp;
- Rq *rq = sglob->rq;
char *p;
if ( acquire_lock( f, &fp, &lfp ) < 0 ) {
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;
p, 0, 0 );
}
free( p );
- pthread_yield();
+ ldap_pvt_thread_yield();
}
sglob->srpos = ftell( fp );
+ }
(void) relinquish_lock( f, fp, lfp );
}
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 );
}
-