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 );
41 /* initialize thread package */
42 ldap_pvt_thread_initialize();
45 * Create and initialize globals. init_globals() also initializes
46 * the main replication queue.
48 if (( sglob = init_globals()) == NULL ) {
49 fprintf( stderr, "Out of memory initializing globals\n" );
54 * Process command-line args and fill in globals.
56 if ( doargs( argc, argv, sglob ) < 0 ) {
61 * Read slapd config file and initialize Re (per-replica) structs.
63 if ( slurpd_read_config( sglob->slapd_configfile ) < 0 ) {
65 "Errors encountered while processing config file \"%s\"\n",
66 sglob->slapd_configfile );
71 * Get any saved state information off the disk.
73 if ( sglob->st->st_read( sglob->st )) {
74 fprintf( stderr, "Malformed slurpd status file \"%s\"\n",
75 sglob->slurpd_status_file, 0, 0 );
80 * All readonly data should now be initialized.
81 * Check for any fatal error conditions before we get started
88 * Detach from the controlling terminal, if debug level = 0,
89 * and if not in one-shot mode.
92 if (( ldap_debug == 0 ) && !sglob->one_shot_mode )
93 #else /* LDAP_DEBUG */
94 if ( !sglob->one_shot_mode )
95 #endif /* LDAP_DEBUG */
99 * Start threads - one thread for each replica
101 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
102 start_replica_thread( sglob->replicas[ i ]);
106 * Start the main file manager thread (in fm.c).
108 if ( ldap_pvt_thread_create( &(sglob->fm_tid),
109 0, fm, (void *) NULL ) != 0 )
111 Debug( LDAP_DEBUG_ANY, "file manager ldap_pvt_thread_create failed\n",
113 exit( EXIT_FAILURE );
118 * Wait for the fm thread to finish.
120 ldap_pvt_thread_join( sglob->fm_tid, (void *) NULL );
123 * Wait for the replica threads to finish.
125 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
126 ldap_pvt_thread_join( sglob->replicas[ i ]->ri_tid, (void *) NULL );
129 /* destroy the thread package */
130 ldap_pvt_thread_destroy();
132 Debug( LDAP_DEBUG_ANY, "slurpd: terminated.\n", 0, 0, 0 );
134 #endif /* !NO_THREADS */