2 * Copyright (c) 1996 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
15 * main.c - main routine for slurpd.
34 /* Haven't yet written the non-threaded version */
35 fputs( "slurpd currently requires threads support\n", stderr );
44 * Create and initialize globals. init_globals() also initializes
45 * the main replication queue.
47 if (( sglob = init_globals()) == NULL ) {
48 fprintf( stderr, "Out of memory initializing globals\n" );
53 * Process command-line args and fill in globals.
55 if ( doargs( argc, argv, sglob ) < 0 ) {
60 * Read slapd config file and initialize Re (per-replica) structs.
62 if ( slurpd_read_config( sglob->slapd_configfile ) < 0 ) {
64 "Errors encountered while processing config file \"%s\"\n",
65 sglob->slapd_configfile );
70 * Get any saved state information off the disk.
72 if ( sglob->st->st_read( sglob->st )) {
73 fprintf( stderr, "Malformed slurpd status file \"%s\"\n",
74 sglob->slurpd_status_file, 0, 0 );
79 * All readonly data should now be initialized.
80 * Check for any fatal error conditions before we get started
87 * Detach from the controlling terminal, if debug level = 0,
88 * and if not in one-shot mode.
91 if (( ldap_debug == 0 ) && !sglob->one_shot_mode )
92 #else /* LDAP_DEBUG */
93 if ( !sglob->one_shot_mode )
94 #endif /* LDAP_DEBUG */
97 #if defined( HAVE_LWP )
99 * Need to start a scheduler thread under SunOS 4
101 start_lwp_scheduler();
102 #endif /* HAVE_LWP */
106 * Start threads - one thread for each replica
108 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
109 start_replica_thread( sglob->replicas[ i ]);
113 * Start the main file manager thread (in fm.c).
115 if ( pthread_create( &(sglob->fm_tid), NULL, fm, (void *) NULL )
117 Debug( LDAP_DEBUG_ANY, "file manager pthread_create failed\n",
124 * Wait for the fm thread to finish.
126 #ifdef HAVE_PTHREADS_FINAL
127 pthread_join( sglob->fm_tid, (void *) NULL );
129 pthread_join( sglob->fm_tid, (void *) &status );
132 * Wait for the replica threads to finish.
134 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
135 #ifdef HAVE_PTHREADS_FINAL
136 pthread_join( sglob->replicas[ i ]->ri_tid, (void *) NULL );
138 pthread_join( sglob->replicas[ i ]->ri_tid, (void *) &status );
141 Debug( LDAP_DEBUG_ANY, "slurpd: terminating normally\n", 0, 0, 0 );
142 sglob->slurpd_shutdown = 1;
145 #endif /* !NO_THREADS */