3 * Copyright (c) 1996 Regents of the University of Michigan.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that this notice is preserved and that due credit is given
8 * to the University of Michigan at Ann Arbor. The name of the University
9 * may not be used to endorse or promote products derived from this
10 * software without specific prior written permission. This software
11 * is provided ``as is'' without express or implied warranty.
16 * main.c - main routine for slurpd.
21 #include <ac/stdlib.h>
37 /* Haven't yet written the non-threaded version */
38 fputs( "slurpd currently requires threads support\n", stderr );
44 /* initialize thread package */
45 ldap_pvt_thread_initialize();
48 * Create and initialize globals. init_globals() also initializes
49 * the main replication queue.
51 if (( sglob = init_globals()) == NULL ) {
52 fprintf( stderr, "Out of memory initializing globals\n" );
57 * Process command-line args and fill in globals.
59 if ( doargs( argc, argv, sglob ) < 0 ) {
64 * Read slapd config file and initialize Re (per-replica) structs.
66 if ( slurpd_read_config( sglob->slapd_configfile ) < 0 ) {
68 "Errors encountered while processing config file \"%s\"\n",
69 sglob->slapd_configfile );
74 * Get any saved state information off the disk.
76 if ( sglob->st->st_read( sglob->st )) {
77 fprintf( stderr, "Malformed slurpd status file \"%s\"\n",
78 sglob->slurpd_status_file, 0, 0 );
83 * All readonly data should now be initialized.
84 * Check for any fatal error conditions before we get started
91 * Detach from the controlling terminal
92 * unless the -d flag is given or in one-shot mode.
94 if ( ! (sglob->no_detach || sglob->one_shot_mode) )
98 * Start threads - one thread for each replica
100 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
101 start_replica_thread( sglob->replicas[ i ]);
105 * Start the main file manager thread (in fm.c).
107 if ( ldap_pvt_thread_create( &(sglob->fm_tid),
108 0, fm, (void *) NULL ) != 0 )
110 Debug( LDAP_DEBUG_ANY, "file manager ldap_pvt_thread_create failed\n",
112 exit( EXIT_FAILURE );
117 * Wait for the fm thread to finish.
119 ldap_pvt_thread_join( sglob->fm_tid, (void *) NULL );
122 * Wait for the replica threads to finish.
124 for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
125 ldap_pvt_thread_join( sglob->replicas[ i ]->ri_tid, (void *) NULL );
128 /* destroy the thread package */
129 ldap_pvt_thread_destroy();
131 Debug( LDAP_DEBUG_ANY, "slurpd: terminated.\n", 0, 0, 0 );
133 #endif /* !NO_THREADS */