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.
20 #include <ac/stdlib.h>
36 /* Haven't yet written the non-threaded version */
37 fputs( "slurpd currently requires threads support\n", stderr );
43 /* initialize thread package */
44 ldap_pvt_thread_initialize();
47 * Create and initialize globals. init_globals() also initializes
48 * the main replication queue.
50 if (( sglob = init_globals()) == NULL ) {
51 fprintf( stderr, "Out of memory initializing globals\n" );
56 * Process command-line args and fill in globals.
58 if ( doargs( argc, argv, sglob ) < 0 ) {
63 * Read slapd config file and initialize Re (per-replica) structs.
65 if ( slurpd_read_config( sglob->slapd_configfile ) < 0 ) {
67 "Errors encountered while processing config file \"%s\"\n",
68 sglob->slapd_configfile );
73 * Get any saved state information off the disk.
75 if ( sglob->st->st_read( sglob->st )) {
76 fprintf( stderr, "Malformed slurpd status file \"%s\"\n",
77 sglob->slurpd_status_file, 0, 0 );
82 * All readonly data should now be initialized.
83 * Check for any fatal error conditions before we get started
90 * Detach from the controlling terminal
91 * unless the -d flag is given or in one-shot mode.
93 if ( ! (sglob->no_detach || sglob->one_shot_mode) )
97 * Start threads - one thread for each replica
99 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
100 start_replica_thread( sglob->replicas[ i ]);
104 * Start the main file manager thread (in fm.c).
106 if ( ldap_pvt_thread_create( &(sglob->fm_tid),
107 0, fm, (void *) NULL ) != 0 )
109 Debug( LDAP_DEBUG_ANY, "file manager ldap_pvt_thread_create failed\n",
111 exit( EXIT_FAILURE );
116 * Wait for the fm thread to finish.
118 ldap_pvt_thread_join( sglob->fm_tid, (void *) NULL );
121 * Wait for the replica threads to finish.
123 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
124 ldap_pvt_thread_join( sglob->replicas[ i ]->ri_tid, (void *) NULL );
127 /* destroy the thread package */
128 ldap_pvt_thread_destroy();
130 Debug( LDAP_DEBUG_ANY, "slurpd: terminated.\n", 0, 0, 0 );
132 #endif /* !NO_THREADS */