main.c 11.4 KB
Newer Older
1
/* $OpenLDAP$ */
2
3
4
5
/*
 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
#include "portable.h"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
7
8
9

#include <stdio.h>

10
#include <ac/signal.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
11
12
13
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
14
#include <ac/unistd.h>
Hallvard Furuseth's avatar
Hallvard Furuseth committed
15
16
17
#include <ac/wait.h>
#include <ac/signal.h>
#include <ac/errno.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
18

19
#include "slap.h"
20
#include "lutil.h"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
21

22
#ifdef LDAP_SIGCHLD
Hallvard Furuseth's avatar
Hallvard Furuseth committed
23
24
25
static RETSIGTYPE wait4child( int sig );
#endif

26
#ifdef HAVE_NT_SERVICE_MANAGER
27
#define MAIN_RETURN(x) return
28
29
struct sockaddr_in	bind_addr;

30
/* in nt_main.c */
31
32
33
34
35
36
37
38
39
40
extern SERVICE_STATUS			SLAPDServiceStatus;
extern SERVICE_STATUS_HANDLE	hSLAPDServiceStatus;
extern ldap_pvt_thread_cond_t	started_event,		stopped_event;
extern int	  is_NT_Service;

void CommenceStartupProcessing( LPCTSTR serviceName,
							   void(*stopper)(int));
void ReportSlapdShutdownComplete( void );
void *getRegParam( char *svc, char *value );

41
42
43
44
45
46
47
#define SERVICE_EXIT( e, n )	do { \
	if ( is_NT_Service ) { \
		SLAPDServiceStatus.dwWin32ExitCode				= (e); \
		SLAPDServiceStatus.dwServiceSpecificExitCode	= (n); \
	} \
} while ( 0 )

48
49
#else
#define SERVICE_EXIT( e, n )
50
#define MAIN_RETURN(x) return(x)
51
52
#endif

53
#ifdef HAVE_NT_EVENT_LOG
54
55
56
57
void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
void LogSlapdStoppedEvent( char *svc );
#endif

58
59
60
61
62
/*
 * when more than one slapd is running on one machine, each one might have
 * it's own LOCAL for syslogging and must have its own pid/args files
 */

Kurt Zeilenga's avatar
Kurt Zeilenga committed
63
#ifndef HAVE_MKVERSION
Kurt Zeilenga's avatar
Kurt Zeilenga committed
64
65
const char Versionstr[] =
	OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Server (slapd)";
Kurt Zeilenga's avatar
Kurt Zeilenga committed
66
67
#endif

68
69
70
71
72
#ifdef LOG_LOCAL4

#define DEFAULT_SYSLOG_USER  LOG_LOCAL4

typedef struct _str2intDispatch {
73
74
75
	char    *stringVal;
	int      abbr;
	int      intVal;
76
77
78
79
80
} STRDISP, *STRDISP_P;


/* table to compute syslog-options to integer */
static STRDISP  syslog_types[] = {
81
82
83
84
85
86
87
88
89
	{ "LOCAL0", sizeof("LOCAL0"), LOG_LOCAL0 },
	{ "LOCAL1", sizeof("LOCAL1"), LOG_LOCAL1 },
	{ "LOCAL2", sizeof("LOCAL2"), LOG_LOCAL2 },
	{ "LOCAL3", sizeof("LOCAL3"), LOG_LOCAL3 },
	{ "LOCAL4", sizeof("LOCAL4"), LOG_LOCAL4 },
	{ "LOCAL5", sizeof("LOCAL5"), LOG_LOCAL5 },
	{ "LOCAL6", sizeof("LOCAL6"), LOG_LOCAL6 },
	{ "LOCAL7", sizeof("LOCAL7"), LOG_LOCAL7 },
	{ NULL }
90
91
};

Hallvard Furuseth's avatar
Hallvard Furuseth committed
92
static int   cnvt_str2int( char *, STRDISP_P, int );
93
94
95
96

#endif  /* LOG_LOCAL4 */


Hallvard Furuseth's avatar
Hallvard Furuseth committed
97
static void
98
usage( char *name )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
99
{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
100
101
102
	fprintf( stderr,
		"usage: %s options\n", name );
	fprintf( stderr,
103
#if LDAP_CONNECTIONLESS
Kurt Zeilenga's avatar
Kurt Zeilenga committed
104
		"\t-c\t\tEnable (experimental) Connectionless LDAP\n"
105
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
106
107
108
109
		"\t-d level\tDebug Level" "\n"
		"\t-f filename\tConfiguration File\n"
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
		"\t-g group\tGroup (id or name) to ran as\n"
110
#endif
111
		"\t-h URLs\tList of URLs to serve\n"
112
#ifdef LOG_LOCAL4
Kurt Zeilenga's avatar
Kurt Zeilenga committed
113
		"\t-l sysloguser\tSyslog User (default: LOCAL4)\n"
114
#endif
115
#ifdef HAVE_NT_EVENT_LOG
Kurt Zeilenga's avatar
Kurt Zeilenga committed
116
		"\t-n NTserviceName\tNT service name\n"
117
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
118

Kurt Zeilenga's avatar
Kurt Zeilenga committed
119
		"\t-p port\tLDAP Port\n"
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
120
#ifdef HAVE_TLS
Kurt Zeilenga's avatar
Kurt Zeilenga committed
121
122
123
124
125
		"\t-P port\tLDAP over TLS Port\n"
#endif
		"\t-s level\tSyslog Level\n"
#ifdef SLAPD_BDB2
		"\t-t\t\tEnable BDB2 timing\n"
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
126
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
127
128
129
130
131
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
		"\t-u user\tUser (id or name) to ran as\n"
#endif
    );
}
132

133
#ifdef HAVE_NT_SERVICE_MANAGER
134
135
136
137
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
#else
int main( int argc, char **argv )
#endif
138
{
139
	int		i, no_detach = 0;
Gary Williams's avatar
NT port    
Gary Williams committed
140
	int		rc;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
141
	char *urls = NULL;
142
143
144
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
	char *username = NULL;
	char *groupname = NULL;
145
#endif
146
147
#ifdef LOG_LOCAL4
    int     syslogUser = DEFAULT_SYSLOG_USER;
148
#endif
149
150

#ifdef HAVE_NT_EVENT_LOG
151
	char        *NTservice  = SERVICE_NAME;
152
153
#endif
#ifdef HAVE_NT_SERVICE_MANAGER
154
155
156
	char		*configfile = ".\\slapd.conf";
#else
	char		*configfile = SLAPD_DEFAULT_CONFIGFILE;
157
#endif
158
	char        *serverName;
159
	int         serverMode = SLAP_SERVER_MODE;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
160

Kurt Zeilenga's avatar
Kurt Zeilenga committed
161
	int port = LDAP_PORT;
162
#ifdef HAVE_TLS
Kurt Zeilenga's avatar
Kurt Zeilenga committed
163
	int tls_port = LDAPS_PORT;
164
165
166
#else
	int tls_port = 0;
#endif
167

168
169
170
171
172
173
174
#ifdef CSRIMALLOC
	FILE *leakfile;
	if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
		leakfile = stderr;
	}
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
175
176
177
	g_argc = argc;
	g_argv = argv;

178
#ifdef HAVE_NT_SERVICE_MANAGER
179
	{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
180
		int *i;
181
		char *newConfigFile;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
182
183
184
185
186

		if ( is_NT_Service ) {
			CommenceStartupProcessing( NTservice, slap_sig_shutdown );
		}

Kurt Zeilenga's avatar
Kurt Zeilenga committed
187
188
		i = (int*)getRegParam( NULL, "Port" );
		if ( i != NULL )
189
		{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
190
			port = *i;
191
192
			Debug ( LDAP_DEBUG_ANY, "new port from registry is: %d\n", port, 0, 0 );
		}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
193
194
195
196
197
198
199
200
201
202
#ifdef HAVE_TLS
		i = (int*)getRegParam( NULL, "TLSPort" );
		if ( i != NULL )
		{
			tls_port = *i;
			Debug ( LDAP_DEBUG_ANY, "new TLS port from registry is: %d\n", tls_port, 0, 0 );
		}
#endif
		i = (int*)getRegParam( NULL, "DebugLevel" );
		if ( i != NULL ) 
203
		{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
204
			slap_debug = *i;
205
206
207
208
209
210
211
212
213
214
215
			Debug( LDAP_DEBUG_ANY, "new debug level from registry is: %d\n", slap_debug, 0, 0 );
		}
		newConfigFile = (char*)getRegParam( NULL, "ConfigFile" );
		if ( newConfigFile != NULL ) 
		{
			configfile = newConfigFile;
			Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
		}
	}
#endif

216
	while ( (i = getopt( argc, argv,
217
			     "d:f:h:p:s:"
218
219
220
#ifdef LOG_LOCAL4
			     "l:"
#endif
221
#ifdef SLAPD_BDB2
222
			     "t"
223
#endif
224
225
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
			     "u:g:"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
226
227
228
#endif
#ifdef LDAP_CONNECTIONLESS
				 "c"
229
#endif
230
#ifdef HAVE_NT_EVENT_LOG
231
				 "n:"
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
232
233
#endif
#ifdef HAVE_TLS
Kurt Zeilenga's avatar
Kurt Zeilenga committed
234
			     "P:"
235
#endif
236
			     )) != EOF ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
237
		switch ( i ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
238
		case 'h':	/* listen URLs */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
239
			if ( urls != NULL ) free( urls );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
240
			urls = ch_strdup( optarg );
241
242
            break;

243
244
		case 'd':	/* set debug level and 'do not detach' flag */
			no_detach = 1;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
245
#ifdef LDAP_DEBUG
Kurt Zeilenga's avatar
Kurt Zeilenga committed
246
			slap_debug |= atoi( optarg );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
247
#else
248
249
250
			if ( atoi( optarg ) != 0 )
				fputs( "must compile with LDAP_DEBUG for debugging\n",
				       stderr );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
251
#endif
252
			break;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
253
254

		case 'f':	/* read config file */
255
			configfile = ch_strdup( optarg );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
256
257
			break;

258
		case 'p': {	/* port on which to listen */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
259
260
				int p = atoi( optarg );
				if(! p ) {
261
					fprintf(stderr, "-p %s must be numeric\n", optarg);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
262
263
				} else if( p < 0 || p >= 1<<16) {
					fprintf(stderr, "-p %s invalid\n", optarg);
264
				} else {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
265
					port = p;
266
267
				}
			} break;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
268

Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
269
270
#ifdef HAVE_TLS
		case 'P': {	/* port on which to listen for TLS */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
271
272
				int p = atoi( optarg );
				if(! p ) {
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
273
					fprintf(stderr, "-P %s must be numeric\n", optarg);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
274
275
				} else if( p < 0 || p >= 1<<16) {
					fprintf(stderr, "-P %s invalid\n", optarg);
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
276
				} else {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
277
					tls_port = p;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
278
279
280
281
				}
			} break;
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
282
283
284
285
		case 's':	/* set syslog level */
			ldap_syslog = atoi( optarg );
			break;

286
287
#ifdef LOG_LOCAL4
		case 'l':	/* set syslog local user */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
288
289
			syslogUser = cnvt_str2int( optarg,
				syslog_types, DEFAULT_SYSLOG_USER );
290
291
292
			break;
#endif

293
294
#ifdef LDAP_CONNECTIONLESS
		case 'c':	/* do connectionless (udp) */
295
296
			/* udp = 1; */
			fprintf( stderr, "connectionless support not supported");
Kurt Zeilenga's avatar
Kurt Zeilenga committed
297
			exit( EXIT_FAILURE );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
298
			break;
299
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
300

301
302
#ifdef SLAPD_BDB2
		case 't':  /* timed server */
303
			serverMode |= SLAP_TIMED_MODE;
304
305
306
			break;
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
307
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
308
309
		case 'u':	/* user name */
			if( username ) free(username);
310
311
312
			username = ch_strdup( optarg );
			break;

313
314
		case 'g':	/* group name */
			if( groupname ) free(groupname);
315
316
			groupname = ch_strdup( optarg );
			break;
317
#endif /* SETUID && GETUID */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
318

319
#ifdef HAVE_NT_EVENT_LOG
320
		case 'n':  /* NT service name */
321
322
323
			NTservice = ch_strdup( optarg );
			break;
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
324
325
		default:
			usage( argv[0] );
326
327
328
			rc = 1;
			SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
			goto stop;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
329
330
331
		}
	}

Kurt Zeilenga's avatar
Kurt Zeilenga committed
332
	ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
333
334
335
	ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
	ldif_debug = slap_debug;

Kurt Zeilenga's avatar
Kurt Zeilenga committed
336
337
	Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 );

338
	if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) {
339
		serverName = ch_strdup( argv[0] );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
340
	} else {
341
		serverName = ch_strdup( serverName + 1 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
342
343
344
	}

#ifdef LOG_LOCAL4
345
	openlog( serverName, OPENLOG_OPTIONS, syslogUser );
346
#elif LOG_DEBUG
347
	openlog( serverName, OPENLOG_OPTIONS );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
348
349
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
350
351
352
353
354
	if( slapd_daemon_init( urls, port, tls_port ) != 0 ) {
		rc = 1;
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
		goto stop;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
355

356
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
Kurt Zeilenga's avatar
Kurt Zeilenga committed
357
	if ( username != NULL || groupname != NULL ) {
358
		slap_init_user( username, groupname );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
359
	}
360
361
#endif

362
	if ( slap_init( serverMode, serverName ) != 0 ) {
363
		rc = 1;
364
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
365
366
367
368
369
		goto destroy;
	}

	if ( read_config( configfile ) != 0 ) {
		rc = 1;
370
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
371
372
373
		goto destroy;
	}

374
375
376
377
378
#ifdef HAVE_TLS
	ldap_pvt_tls_init();
	ldap_pvt_tls_init_def_ctx();
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
379
380
381
	(void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
	(void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );

382
#ifdef SIGPIPE
383
	(void) SIGNAL( SIGPIPE, SIG_IGN );
384
385
#endif
#ifdef SIGHUP
Kurt Zeilenga's avatar
Kurt Zeilenga committed
386
	(void) SIGNAL( SIGHUP, slap_sig_shutdown );
387
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
388
389
	(void) SIGNAL( SIGINT, slap_sig_shutdown );
	(void) SIGNAL( SIGTERM, slap_sig_shutdown );
390
391
#ifdef LDAP_SIGCHLD
	(void) SIGNAL( LDAP_SIGCHLD, wait4child );
Hallvard Furuseth's avatar
Hallvard Furuseth committed
392
#endif
393
#ifdef SIGBREAK
394
	/* SIGBREAK is generated when Ctrl-Break is pressed. */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
395
	(void) SIGNAL( SIGBREAK, slap_sig_shutdown );
396
#endif
397

398
#ifndef HAVE_WINSOCK
399
	lutil_detach( no_detach, 0 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
400
#endif /* HAVE_WINSOCK */
401

402
403
404
405
#ifdef CSRIMALLOC
	mal_leaktrace(1);
#endif

406
	if ( slap_startup( NULL )  != 0 ) {
407
		rc = 1;
408
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
409
410
		goto shutdown;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
411

Kurt Zeilenga's avatar
Kurt Zeilenga committed
412
	{
413
		FILE *fp;
414

415
		Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
416

417
418
419
420
421
		if (( slapd_pid_file != NULL ) &&
			(( fp = fopen( slapd_pid_file, "w" )) != NULL ))
		{
			fprintf( fp, "%d\n", (int) getpid() );
			fclose( fp );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
422
423
		}

424
425
426
427
428
		if (( slapd_args_file != NULL ) &&
			(( fp = fopen( slapd_args_file, "w" )) != NULL ))
		{
			for ( i = 0; i < g_argc; i++ ) {
				fprintf( fp, "%s ", g_argv[i] );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
429
			}
430
431
432
433
			fprintf( fp, "\n" );
			fclose( fp );
		}
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
434

435
#ifdef HAVE_NT_EVENT_LOG
Kurt Zeilenga's avatar
Kurt Zeilenga committed
436
	LogSlapdStartedEvent( NTservice, slap_debug, configfile, urls );
437
438
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
439
	rc = slapd_daemon();
440

441
#ifdef HAVE_NT_SERVICE_MANAGER
442
	/* Throw away the event that we used during the startup process. */
443
444
445
	if ( is_NT_Service )
		ldap_pvt_thread_cond_destroy( &started_event );
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
446

447
shutdown:
448
	/* remember an error during shutdown */
449
	rc |= slap_shutdown( NULL );
450

451
destroy:
452
453
454
	/* remember an error during destroy */
	rc |= slap_destroy();

455
stop:
456
#ifdef HAVE_NT_EVENT_LOG
457
	LogSlapdStoppedEvent( NTservice );
458
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
459

460
	Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
461

462
#ifdef HAVE_NT_SERVICE_MANAGER
463
464
	ReportSlapdShutdownComplete();
#endif
465

466
#ifdef LOG_DEBUG
467
    closelog();
468
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
469
	slapd_daemon_destroy();
470

471
472
473
474
#ifdef CSRIMALLOC
	mal_dumpleaktrace( leakfile );
#endif

475
	MAIN_RETURN(rc);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
476
}
477
478


479
#ifdef LDAP_SIGCHLD
Hallvard Furuseth's avatar
Hallvard Furuseth committed
480
481
482
483
484
485
486
487
488

/*
 *  Catch and discard terminated child processes, to avoid zombies.
 */

static RETSIGTYPE
wait4child( int sig )
{
    int save_errno = errno;
Hallvard Furuseth's avatar
Hallvard Furuseth committed
489
490

#ifdef WNOHANG
Hallvard Furuseth's avatar
Hallvard Furuseth committed
491
    errno = 0;
Hallvard Furuseth's avatar
Hallvard Furuseth committed
492
#ifdef HAVE_WAITPID
Hallvard Furuseth's avatar
Hallvard Furuseth committed
493
494
    while ( waitpid( (pid_t)-1, NULL, WNOHANG ) >= 0 || errno == EINTR )
	;	/* NULL */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
495
#else
Hallvard Furuseth's avatar
Hallvard Furuseth committed
496
497
    while ( wait3( NULL, WNOHANG, NULL ) >= 0 || errno == EINTR )
	;	/* NULL */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
498
#endif
499
#else
Hallvard Furuseth's avatar
Hallvard Furuseth committed
500
501
    (void) wait( NULL );
#endif
Hallvard Furuseth's avatar
Hallvard Furuseth committed
502
    (void) SIGNAL( sig, wait4child );
Hallvard Furuseth's avatar
Hallvard Furuseth committed
503
504
505
506
507
508
    errno = save_errno;
}

#endif /* SIGCHLD || SIGCLD */


509
510
511
512
513
514
515
516
#ifdef LOG_LOCAL4

/*
 *  Convert a string to an integer by means of a dispatcher table
 *  if the string is not in the table return the default
 */

static int
Hallvard Furuseth's avatar
Hallvard Furuseth committed
517
cnvt_str2int( char *stringVal, STRDISP_P dispatcher, int defaultVal )
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
{
    int        retVal = defaultVal;
    STRDISP_P  disp;

    for (disp = dispatcher; disp->stringVal; disp++) {

        if (!strncasecmp (stringVal, disp->stringVal, disp->abbr)) {

            retVal = disp->intVal;
            break;

        }
    }

    return (retVal);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
533
}
534
535

#endif  /* LOG_LOCAL4 */