main.c 12.6 KB
Newer Older
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1
#include "portable.h"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
2
3
4

#include <stdio.h>

5
#include <ac/signal.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
7
8
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
9
#include <ac/unistd.h>
Hallvard Furuseth's avatar
Hallvard Furuseth committed
10
11
12
#include <ac/wait.h>
#include <ac/signal.h>
#include <ac/errno.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
13

14
#include "ldap_defaults.h"
15
#include "slap.h"
16
#include "lutil.h"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
17

18
#ifdef LDAP_SIGCHLD
Hallvard Furuseth's avatar
Hallvard Furuseth committed
19
20
21
static RETSIGTYPE wait4child( int sig );
#endif

22
#ifdef HAVE_WINSOCK
23
#define MAIN_RETURN(x) return
24
25
struct sockaddr_in	bind_addr;

26
/* in nt_main.c */
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, short port, int udp );
void LogSlapdStoppedEvent( char *svc );

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

#define SERVICE_EXIT( e, n ) \
		if ( is_NT_Service ) \
{ \
			SLAPDServiceStatus.dwWin32ExitCode				= e; \
			SLAPDServiceStatus.dwServiceSpecificExitCode	= n; \
} 
#else
#define SERVICE_EXIT( e, n )
48
#define MAIN_RETURN(x) return(x)
49
50
51
#endif

short port = LDAP_PORT;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
52
53
54
#ifdef HAVE_TLS
short tls_port = LDAP_TLS_PORT;
#endif
55
56
57
58
59
/*
 * 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
60
#ifndef HAVE_MKVERSION
Kurt Zeilenga's avatar
Kurt Zeilenga committed
61
62
const char Versionstr[] =
	OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Server (slapd)";
Kurt Zeilenga's avatar
Kurt Zeilenga committed
63
64
#endif

65
66
67
68
69
#ifdef LOG_LOCAL4

#define DEFAULT_SYSLOG_USER  LOG_LOCAL4

typedef struct _str2intDispatch {
70
71
72
	char    *stringVal;
	int      abbr;
	int      intVal;
73
74
75
76
77
78
79
80
81
82
83
84
85
} STRDISP, *STRDISP_P;


/* table to compute syslog-options to integer */
static STRDISP  syslog_types[] = {
    { "LOCAL0",         6, LOG_LOCAL0 },
    { "LOCAL1",         6, LOG_LOCAL1 },
    { "LOCAL2",         6, LOG_LOCAL2 },
    { "LOCAL3",         6, LOG_LOCAL3 },
    { "LOCAL4",         6, LOG_LOCAL4 },
    { "LOCAL5",         6, LOG_LOCAL5 },
    { "LOCAL6",         6, LOG_LOCAL6 },
    { "LOCAL7",         6, LOG_LOCAL7 },
86
    { NULL }
87
88
};

Hallvard Furuseth's avatar
Hallvard Furuseth committed
89
static int   cnvt_str2int( char *, STRDISP_P, int );
90
91
92
93

#endif  /* LOG_LOCAL4 */


Hallvard Furuseth's avatar
Hallvard Furuseth committed
94
static void
95
usage( char *name )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
96
{
97
	fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]", name );
98
    fprintf( stderr, "\n        [-a bind-address] [-i] [-u]" );
99
#ifdef HAVE_WINSOCK
100
	fprintf( stderr, " [-n NTserviceName]" );
101
#endif
102
103
104
#if LDAP_CONNECTIONLESS
	fprintf( stderr, " [-c]" );
#endif
105
106
107
#ifdef SLAPD_BDB2
    fprintf( stderr, " [-t]" );
#endif
108
109
#ifdef LOG_LOCAL4
    fprintf( stderr, " [-l sysloguser]" );
110
#endif
111
112
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
    fprintf( stderr, " [-u user] [-g group]" );
113
114
#endif
    fprintf( stderr, "\n" );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
115
116
}

117
time_t starttime;
118
struct sockaddr_in	bind_addr;
119
ber_int_t tcps;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
120
121
122
123
#ifdef HAVE_TLS
struct sockaddr_in	tls_bind_addr;
ber_int_t tls_tcps;
#endif
124

125
126
127
128
129
#ifdef HAVE_WINSOCK
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
#else
int main( int argc, char **argv )
#endif
130
{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
131
132
	int		i;
	int		inetd = 0;
Gary Williams's avatar
NT port    
Gary Williams committed
133
	int		rc;
134
	struct slapd_args args;
135
	int		udp;
136
137
138
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
	char *username = NULL;
	char *groupname = NULL;
139
#endif
140
141
#ifdef LOG_LOCAL4
    int     syslogUser = DEFAULT_SYSLOG_USER;
142
#endif
143
#ifdef HAVE_WINSOCK
144
	char        *NTservice  = SERVICE_NAME;
145
146
147
	char		*configfile = ".\\slapd.conf";
#else
	char		*configfile = SLAPD_DEFAULT_CONFIGFILE;
148
#endif
149
	char        *serverName;
150
	int         serverMode = SLAP_SERVER_MODE;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
151
	int		use_tls_port = 0;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
152

153
154
155
	(void) memset( (void*) &bind_addr, '\0', sizeof(bind_addr));
	bind_addr.sin_family = AF_INET;
	bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
156
	bind_addr.sin_port = htons(port);
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
157
158
159
160
161
#ifdef HAVE_TLS
	tls_bind_addr.sin_family = AF_INET;
	tls_bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
	tls_bind_addr.sin_port = htons(tls_port);
#endif
162

Kurt Zeilenga's avatar
Kurt Zeilenga committed
163
164
165
	g_argc = argc;
	g_argv = argv;

166
167
168
169
170
171
#ifdef HAVE_WINSOCK
	{
		int *newPort;
		int *newDebugLevel;
		char *newConfigFile;
		ldap_debug = 0xffff;
172
		if ( is_NT_Service ) CommenceStartupProcessing( NTservice, slap_set_shutdown );
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
		newPort = (int*)getRegParam( NULL, "Port" );
		if ( newPort != NULL )
		{
			port = *newPort;
			bind_addr.sin_port = htons(port);
			Debug ( LDAP_DEBUG_ANY, "new port from registry is: %d\n", port, 0, 0 );
		}
		newDebugLevel = (int*)getRegParam( NULL, "DebugLevel" );
		if ( newDebugLevel != NULL ) 
		{
			slap_debug = *newDebugLevel;
			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

195
	while ( (i = getopt( argc, argv,
196
			     "d:f:ia:p:s:u"
197
198
199
#ifdef LOG_LOCAL4
			     "l:"
#endif
200
#ifdef SLAPD_BDB2
201
			     "t"
202
#endif
203
204
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
			     "u:g:"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
205
206
207
#endif
#ifdef LDAP_CONNECTIONLESS
				 "c"
208
209
#endif
#ifdef HAVE_WINSOCK
210
				 "n:"
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
211
212
#endif
#ifdef HAVE_TLS
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
213
			     "P:T"
214
#endif
215
			     )) != EOF ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
216
		switch ( i ) {
217
		case 'a':	/* bind address */
Gary Williams's avatar
NT port    
Gary Williams committed
218
#ifdef HAVE_WINSOCK
219
			if(!(bind_addr.sin_addr.S_un.S_addr = inet_addr(optarg)))
Gary Williams's avatar
NT port    
Gary Williams committed
220
#else
221
			if(!inet_aton(optarg, &bind_addr.sin_addr))
Gary Williams's avatar
NT port    
Gary Williams committed
222
#endif
223
			{
224
225
				fprintf(stderr, "invalid address (%s) for -a option", optarg);
			}
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
226
227
228
229
230
231
232
#ifdef HAVE_TLS
#ifdef HAVE_WINSOCK
			tls_bind_addr.sin_addr.S_un.S_addr = inet_addr(optarg);
#else
			inet_aton(optarg, &tls_bind_addr.sin_addr);
#endif
#endif
233
234
            break;

Kurt Zeilenga's avatar
Kurt Zeilenga committed
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#ifdef LDAP_DEBUG
		case 'd':	/* turn on debugging */
			if ( optarg[0] == '?' ) {
				printf( "Debug levels:\n" );
				printf( "\tLDAP_DEBUG_TRACE\t%d\n",
				    LDAP_DEBUG_TRACE );
				printf( "\tLDAP_DEBUG_PACKETS\t%d\n",
				    LDAP_DEBUG_PACKETS );
				printf( "\tLDAP_DEBUG_ARGS\t\t%d\n",
				    LDAP_DEBUG_ARGS );
				printf( "\tLDAP_DEBUG_CONNS\t%d\n",
				    LDAP_DEBUG_CONNS );
				printf( "\tLDAP_DEBUG_BER\t\t%d\n",
				    LDAP_DEBUG_BER );
				printf( "\tLDAP_DEBUG_FILTER\t%d\n",
				    LDAP_DEBUG_FILTER );
				printf( "\tLDAP_DEBUG_CONFIG\t%d\n",
				    LDAP_DEBUG_CONFIG );
				printf( "\tLDAP_DEBUG_ACL\t\t%d\n",
				    LDAP_DEBUG_ACL );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
255
				printf( "\tLDAP_DEBUG_STATS\t%d\n",
Kurt Zeilenga's avatar
Kurt Zeilenga committed
256
				    LDAP_DEBUG_STATS );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
257
				printf( "\tLDAP_DEBUG_STATS2\t%d\n",
Kurt Zeilenga's avatar
Kurt Zeilenga committed
258
				    LDAP_DEBUG_STATS2 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
259
				printf( "\tLDAP_DEBUG_SHELL\t%d\n",
Kurt Zeilenga's avatar
Kurt Zeilenga committed
260
				    LDAP_DEBUG_SHELL );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
261
				printf( "\tLDAP_DEBUG_PARSE\t%d\n",
Kurt Zeilenga's avatar
Kurt Zeilenga committed
262
263
264
265
266
				    LDAP_DEBUG_PARSE );
				printf( "\tLDAP_DEBUG_ANY\t\t%d\n",
				    LDAP_DEBUG_ANY );
				exit( 0 );
			} else {
267
				slap_debug |= atoi( optarg );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
268
269
270
271
272
273
274
275
276
277
			}
			break;
#else
		case 'd':	/* turn on debugging */
			fprintf( stderr,
			    "must compile with LDAP_DEBUG for debugging\n" );
			break;
#endif

		case 'f':	/* read config file */
278
			configfile = ch_strdup( optarg );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
279
280
281
282
283
284
			break;

		case 'i':	/* run from inetd */
			inetd = 1;
			break;

285
		case 'p': {	/* port on which to listen */
286
				port = (short)atoi( optarg );
287
288
289
290
291
292
				if(! port ) {
					fprintf(stderr, "-p %s must be numeric\n", optarg);
				} else {
					bind_addr.sin_port = htons(port);
				}
			} break;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
293

Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
294
295
296
297
298
299
300
301
302
303
304
#ifdef HAVE_TLS
		case 'P': {	/* port on which to listen for TLS */
				tls_port = (short)atoi( optarg );
				if(! tls_port ) {
					fprintf(stderr, "-P %s must be numeric\n", optarg);
				} else {
					tls_bind_addr.sin_port = htons(tls_port);
				}
			} break;
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
305
306
307
308
		case 's':	/* set syslog level */
			ldap_syslog = atoi( optarg );
			break;

309
310
311
312
313
314
315
#ifdef LOG_LOCAL4
		case 'l':	/* set syslog local user */
			syslogUser = cnvt_str2int( optarg, syslog_types,
                                           DEFAULT_SYSLOG_USER );
			break;
#endif

316
317
#ifdef LDAP_CONNECTIONLESS
		case 'c':	/* do connectionless (udp) */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
318
319
			udp = 1;
			break;
320
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
321

322
323
324
325
326
327
#ifdef SLAPD_BDB2
		case 't':  /* timed server */
			serverMode = SLAP_TIMEDSERVER_MODE;
			break;
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
328
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
329
330
		case 'u':	/* user name */
			if( username ) free(username);
331
332
333
			username = ch_strdup( optarg );
			break;

334
335
		case 'g':	/* group name */
			if( groupname ) free(groupname);
336
337
			groupname = ch_strdup( optarg );
			break;
338
#endif /* SETUID && GETUID */
339
#ifdef HAVE_WINSOCK
340
		case 'n':  /* NT service name */
341
342
			NTservice = ch_strdup( optarg );
			break;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
343
344
345
346
#endif
#ifdef HAVE_TLS
		case 'T':  /* Bind on TLS port */
			use_tls_port = 1;
347
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
348
349
		default:
			usage( argv[0] );
350
351
352
			rc = 1;
			SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
			goto stop;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
353
354
355
		}
	}

Kurt Zeilenga's avatar
Kurt Zeilenga committed
356
	ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
357
358
359
	ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
	ldif_debug = slap_debug;

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

362
	if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) {
363
		serverName = ch_strdup( argv[0] );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
364
	} else {
365
		serverName = ch_strdup( serverName + 1 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
366
367
368
	}

#ifdef LOG_LOCAL4
369
	openlog( serverName, OPENLOG_OPTIONS, syslogUser );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
370
#else
371
	openlog( serverName, OPENLOG_OPTIONS );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
372
373
#endif

374
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
375
376
377
378
	if ( username != NULL || groupname != NULL )
		slap_init_user( username, groupname );
#endif

379
	if ( slap_init( serverMode, serverName ) != 0 ) {
380
		rc = 1;
381
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
382
383
384
385
386
		goto destroy;
	}

	if ( read_config( configfile ) != 0 ) {
		rc = 1;
387
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
388
389
390
		goto destroy;
	}

391
	tcps = set_socket( inetd ? NULL : &bind_addr );
392
393
	if ( tcps == -1 )
		goto destroy;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
394
#ifdef HAVE_TLS
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
395
396
397
398
399
400
401
	if ( use_tls_port ) {
		tls_tcps = set_socket( inetd ? NULL : &tls_bind_addr );
		if ( tls_tcps == -1 )
			goto destroy;
	} else {
		tls_tcps = -1;
	}
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
402
#endif
403

404
405
	(void) SIGNAL( LDAP_SIGUSR1, slap_do_nothing );
	(void) SIGNAL( LDAP_SIGUSR2, slap_set_shutdown );
406
#ifdef SIGPIPE
407
	(void) SIGNAL( SIGPIPE, SIG_IGN );
408
409
#endif
#ifdef SIGHUP
410
	(void) SIGNAL( SIGHUP, slap_set_shutdown );
411
#endif
412
413
	(void) SIGNAL( SIGINT, slap_set_shutdown );
	(void) SIGNAL( SIGTERM, slap_set_shutdown );
414
415
#ifdef LDAP_SIGCHLD
	(void) SIGNAL( LDAP_SIGCHLD, wait4child );
Hallvard Furuseth's avatar
Hallvard Furuseth committed
416
#endif
417
#ifdef SIGBREAK
418
	/* SIGBREAK is generated when Ctrl-Break is pressed. */
419
420
	(void) SIGNAL( SIGBREAK, slap_set_shutdown );
#endif
421

422
#ifndef HAVE_WINSOCK
423
	if(!inetd) {
424
425
426
427
428
#ifdef LDAP_DEBUG
		lutil_detach( ldap_debug, 0 );
#else
		lutil_detach( 0, 0 );
#endif
429
	}
430
#endif /* HAVE_WINSOC */
431

432
433
	if ( slap_startup(-1)  != 0 ) {
		rc = 1;
434
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
435
436
		goto shutdown;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
437

438
439
	if(!inetd) {
		FILE *fp;
440

441
		args.addr = &bind_addr;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
442
443
444
#ifdef HAVE_TLS
		args.tls_addr = &tls_bind_addr;
#endif
445

446
		Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
447

448
449
450
451
452
		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
453
454
		}

455
456
457
458
459
		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
460
			}
461
462
463
			fprintf( fp, "\n" );
			fclose( fp );
		}
464
465
466

	} else {
		args.addr = NULL;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
467
468
469
#ifdef HAVE_TLS
		args.tls_addr = NULL;
#endif
470
	}
471
	args.tcps = tcps;
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
472
473
474
#ifdef HAVE_TLS
	args.tls_tcps = tls_tcps;
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
475

476
	time( &starttime );
477
#ifdef HAVE_WINSOCK
478
	LogSlapdStartedEvent( NTservice, slap_debug, configfile, port, udp );
479
480
481
482
483
#endif

	rc = slapd_daemon( &args );

#ifdef HAVE_WINSOCK
484
	/* Throw away the event that we used during the startup process. */
485
486
487
	if ( is_NT_Service )
		ldap_pvt_thread_cond_destroy( &started_event );
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
488

489
shutdown:
490
491
	/* remember an error during shutdown */
	rc |= slap_shutdown(-1);
492
destroy:
493
494
495
	/* remember an error during destroy */
	rc |= slap_destroy();

496
497
stop:
#ifdef HAVE_WINSOCK
498
	LogSlapdStoppedEvent( NTservice );
499
#endif
500
	Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
501
502
503
#ifdef HAVE_WINSOCK
	ReportSlapdShutdownComplete();
#endif
504

505
    closelog();
506

507
	MAIN_RETURN(rc);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
508
}
509
510


511
#ifdef LDAP_SIGCHLD
Hallvard Furuseth's avatar
Hallvard Furuseth committed
512
513
514
515
516
517
518
519
520

/*
 *  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
521
522

#ifdef WNOHANG
Hallvard Furuseth's avatar
Hallvard Furuseth committed
523
    errno = 0;
Hallvard Furuseth's avatar
Hallvard Furuseth committed
524
#ifdef HAVE_WAITPID
Hallvard Furuseth's avatar
Hallvard Furuseth committed
525
526
    while ( waitpid( (pid_t)-1, NULL, WNOHANG ) >= 0 || errno == EINTR )
	;	/* NULL */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
527
#else
Hallvard Furuseth's avatar
Hallvard Furuseth committed
528
529
    while ( wait3( NULL, WNOHANG, NULL ) >= 0 || errno == EINTR )
	;	/* NULL */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
530
#endif
531
#else
Hallvard Furuseth's avatar
Hallvard Furuseth committed
532
533
    (void) wait( NULL );
#endif
Hallvard Furuseth's avatar
Hallvard Furuseth committed
534
    (void) SIGNAL( sig, wait4child );
Hallvard Furuseth's avatar
Hallvard Furuseth committed
535
536
537
538
539
540
    errno = save_errno;
}

#endif /* SIGCHLD || SIGCLD */


541
542
543
544
545
546
547
548
#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
549
cnvt_str2int( char *stringVal, STRDISP_P dispatcher, int defaultVal )
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
{
    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);

} /* cnvt_str2int */

#endif  /* LOG_LOCAL4 */