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 pthread_attr_init( &attr );
117 #if !defined(HAVE_PTHREADS_D4)
118 /* POSIX_THREADS or compatible
119 * This is a draft 10 or standard pthreads implementation
121 if ( pthread_create( &(sglob->fm_tid), &attr, fm, (void *) NULL )
123 Debug( LDAP_DEBUG_ANY, "file manager pthread_create failed\n",
128 #else /* !PTHREADS_FINAL */
130 * This is a draft 4 or earlier pthreads implementation
132 if ( pthread_create( &(sglob->fm_tid), attr, fm, (void *) NULL )
134 Debug( LDAP_DEBUG_ANY, "file manager pthread_create failed\n",
139 #endif /* !PTHREADS_FINAL */
141 pthread_attr_destroy( &attr );
144 * Wait for the fm thread to finish.
146 #ifdef HAVE_PTHREADS_FINAL
147 pthread_join( sglob->fm_tid, (void *) NULL );
149 pthread_join( sglob->fm_tid, (void *) &status );
152 * Wait for the replica threads to finish.
154 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
155 #ifdef HAVE_PTHREADS_FINAL
156 pthread_join( sglob->replicas[ i ]->ri_tid, (void *) NULL );
158 pthread_join( sglob->replicas[ i ]->ri_tid, (void *) &status );
161 Debug( LDAP_DEBUG_ANY, "slurpd: terminating normally\n", 0, 0, 0 );
162 sglob->slurpd_shutdown = 1;
165 #endif /* !NO_THREADS */