main.c 11.3 KB
Newer Older
1
/* $OpenLDAP$ */
2
/*
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4
5
 * 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 */
Howard Chu's avatar
Howard Chu committed
31
32
LIBLUTIL_F (SERVICE_STATUS)		SLAPDServiceStatus;
LIBLUTIL_F (SERVICE_STATUS_HANDLE)	hSLAPDServiceStatus;
33
34
35
36
37
38
39
40
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
120
121
		"\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
122
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
123
124
125
126
127
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
		"\t-u user\tUser (id or name) to ran as\n"
#endif
    );
}
128

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

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

160
161
162
163
164
165
166
#ifdef CSRIMALLOC
	FILE *leakfile;
	if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
		leakfile = stderr;
	}
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
167
168
169
	g_argc = argc;
	g_argv = argv;

170
#ifdef HAVE_NT_SERVICE_MANAGER
171
	{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
172
		int *i;
173
		char *newConfigFile;
Howard Chu's avatar
Howard Chu committed
174
		char *newUrls;
175
		char *regService = NULL;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
176
177

		if ( is_NT_Service ) {
Howard Chu's avatar
Howard Chu committed
178
			NTservice = argv[0];
Kurt Zeilenga's avatar
Kurt Zeilenga committed
179
			CommenceStartupProcessing( NTservice, slap_sig_shutdown );
180
181
			if ( strcmp(NTservice, SERVICE_NAME) )
			    regService = NTservice;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
182
183
		}

184
		i = (int*)getRegParam( regService, "DebugLevel" );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
185
		if ( i != NULL ) 
186
		{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
187
			slap_debug = *i;
188
189
			Debug( LDAP_DEBUG_ANY, "new debug level from registry is: %d\n", slap_debug, 0, 0 );
		}
Howard Chu's avatar
Howard Chu committed
190

191
		newUrls = (char *) getRegParam(regService, "Urls");
Howard Chu's avatar
Howard Chu committed
192
193
194
195
196
197
198
199
200
201
		if (newUrls)
		{
		    if (urls)
			ch_free(urls);

		    urls = ch_strdup(newUrls);
		    Debug(LDAP_DEBUG_ANY, "new urls from registry: %s\n",
			  urls, 0, 0);
		}

202
		newConfigFile = (char*)getRegParam( regService, "ConfigFile" );
203
204
205
206
207
208
209
210
		if ( newConfigFile != NULL ) 
		{
			configfile = newConfigFile;
			Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
		}
	}
#endif

211
	while ( (i = getopt( argc, argv,
212
			     "d:f:h:s:"
213
214
215
#ifdef HAVE_CHROOT
				"r:"
#endif
216
217
218
#ifdef LOG_LOCAL4
			     "l:"
#endif
219
#ifdef SLAPD_BDB2
220
			     "t"
221
#endif
222
223
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
			     "u:g:"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
224
225
226
#endif
#ifdef LDAP_CONNECTIONLESS
				 "c"
227
#endif
228
#ifdef HAVE_NT_EVENT_LOG
229
				 "n:"
230
#endif
231
			     )) != EOF ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
232
		switch ( i ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
233
		case 'h':	/* listen URLs */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
234
			if ( urls != NULL ) free( urls );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
235
			urls = ch_strdup( optarg );
236
237
            break;

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

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

		case 's':	/* set syslog level */
			ldap_syslog = atoi( optarg );
			break;

257
258
#ifdef LOG_LOCAL4
		case 'l':	/* set syslog local user */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
259
260
			syslogUser = cnvt_str2int( optarg,
				syslog_types, DEFAULT_SYSLOG_USER );
261
262
263
			break;
#endif

264
265
#ifdef LDAP_CONNECTIONLESS
		case 'c':	/* do connectionless (udp) */
266
267
			/* udp = 1; */
			fprintf( stderr, "connectionless support not supported");
Kurt Zeilenga's avatar
Kurt Zeilenga committed
268
			exit( EXIT_FAILURE );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
269
			break;
270
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
271

272
273
#ifdef SLAPD_BDB2
		case 't':  /* timed server */
274
			serverMode |= SLAP_TIMED_MODE;
275
276
277
			break;
#endif

278
279
280
281
282
283
284
#ifdef HAVE_CHROOT
		case 'r':
			if( sandbox ) free(sandbox);
			sandbox = ch_strdup( optarg );
			break;
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
285
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
286
287
		case 'u':	/* user name */
			if( username ) free(username);
288
289
290
			username = ch_strdup( optarg );
			break;

291
292
		case 'g':	/* group name */
			if( groupname ) free(groupname);
293
294
			groupname = ch_strdup( optarg );
			break;
295
#endif /* SETUID && GETUID */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
296

297
#ifdef HAVE_NT_EVENT_LOG
298
		case 'n':  /* NT service name */
299
300
301
			NTservice = ch_strdup( optarg );
			break;
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
302
303
		default:
			usage( argv[0] );
304
305
306
			rc = 1;
			SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
			goto stop;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
307
308
309
		}
	}

Kurt Zeilenga's avatar
Kurt Zeilenga committed
310
	ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
311
312
313
	ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
	ldif_debug = slap_debug;

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

316
	if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) {
317
		serverName = ch_strdup( argv[0] );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
318
	} else {
319
		serverName = ch_strdup( serverName + 1 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
320
321
322
	}

#ifdef LOG_LOCAL4
323
	openlog( serverName, OPENLOG_OPTIONS, syslogUser );
324
#elif LOG_DEBUG
325
	openlog( serverName, OPENLOG_OPTIONS );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
326
327
#endif

328
	if( slapd_daemon_init( urls ) != 0 ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
329
330
331
332
		rc = 1;
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
		goto stop;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
333

334
335
336
337
338
339
340
341
#if defined(HAVE_CHROOT)
	if ( sandbox && chroot( sandbox ) ) {
		perror("chroot");
		rc = 1;
		goto stop;
	}
#endif

342
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
Kurt Zeilenga's avatar
Kurt Zeilenga committed
343
	if ( username != NULL || groupname != NULL ) {
344
		slap_init_user( username, groupname );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
345
	}
346
347
#endif

348
349
	extops_init();

350
351
352
353
354
355
356
357
#ifdef SLAPD_MODULES
	if ( module_init() != 0 ) {
		rc = 1;
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 17 );
		goto destroy;
	}
#endif

358
	if ( slap_init( serverMode, serverName ) != 0 ) {
359
		rc = 1;
360
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
361
362
363
364
365
		goto destroy;
	}

	if ( read_config( configfile ) != 0 ) {
		rc = 1;
366
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
367
368
369
		goto destroy;
	}

370
371
#ifdef HAVE_TLS
	ldap_pvt_tls_init();
Howard Chu's avatar
Howard Chu committed
372
373
374
375
376
377
378

	if (ldap_pvt_tls_init_def_ctx() != 0)
	{
		rc = 1;
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
		goto destroy;
	}
379
380
#endif

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

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

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

404
405
406
407
#ifdef CSRIMALLOC
	mal_leaktrace(1);
#endif

408
	if ( slap_startup( NULL )  != 0 ) {
409
		rc = 1;
Howard Chu's avatar
Howard Chu committed
410
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 21 );
411
412
		goto shutdown;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
413

Kurt Zeilenga's avatar
Kurt Zeilenga committed
414
	{
415
		FILE *fp;
416

417
		Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
418

419
420
421
422
423
		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
424
425
		}

426
427
428
429
430
		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
431
			}
432
433
434
435
			fprintf( fp, "\n" );
			fclose( fp );
		}
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
436

437
#ifdef HAVE_NT_EVENT_LOG
Howard Chu's avatar
Howard Chu committed
438
	if (is_NT_Service)
Kurt Zeilenga's avatar
Kurt Zeilenga committed
439
	LogSlapdStartedEvent( NTservice, slap_debug, configfile, urls );
440
441
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
442
	rc = slapd_daemon();
443

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

450
shutdown:
451
	/* remember an error during shutdown */
452
	rc |= slap_shutdown( NULL );
453

454
destroy:
455
456
457
	/* remember an error during destroy */
	rc |= slap_destroy();

458
459
460
461
#ifdef SLAPD_MODULES
	module_kill();
#endif

462
463
	extops_kill();

464
stop:
465
#ifdef HAVE_NT_EVENT_LOG
Howard Chu's avatar
Howard Chu committed
466
	if (is_NT_Service)
467
	LogSlapdStoppedEvent( NTservice );
468
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
469

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

472
#ifdef HAVE_NT_SERVICE_MANAGER
473
474
	ReportSlapdShutdownComplete();
#endif
475

476
#ifdef LOG_DEBUG
477
    closelog();
478
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
479
	slapd_daemon_destroy();
480

481
482
483
484
#ifdef CSRIMALLOC
	mal_dumpleaktrace( leakfile );
#endif

485
	MAIN_RETURN(rc);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
486
}
487
488


489
#ifdef LDAP_SIGCHLD
Hallvard Furuseth's avatar
Hallvard Furuseth committed
490
491
492
493
494
495
496
497
498

/*
 *  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
499
500

#ifdef WNOHANG
Hallvard Furuseth's avatar
Hallvard Furuseth committed
501
    errno = 0;
Hallvard Furuseth's avatar
Hallvard Furuseth committed
502
#ifdef HAVE_WAITPID
Hallvard Furuseth's avatar
Hallvard Furuseth committed
503
504
    while ( waitpid( (pid_t)-1, NULL, WNOHANG ) >= 0 || errno == EINTR )
	;	/* NULL */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
505
#else
Hallvard Furuseth's avatar
Hallvard Furuseth committed
506
507
    while ( wait3( NULL, WNOHANG, NULL ) >= 0 || errno == EINTR )
	;	/* NULL */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
508
#endif
509
#else
Hallvard Furuseth's avatar
Hallvard Furuseth committed
510
511
    (void) wait( NULL );
#endif
Hallvard Furuseth's avatar
Hallvard Furuseth committed
512
    (void) SIGNAL( sig, wait4child );
Hallvard Furuseth's avatar
Hallvard Furuseth committed
513
514
515
516
517
518
    errno = save_errno;
}

#endif /* SIGCHLD || SIGCLD */


519
520
521
522
523
524
525
526
#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
527
cnvt_str2int( char *stringVal, STRDISP_P dispatcher, int defaultVal )
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
{
    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
543
}
544
545

#endif  /* LOG_LOCAL4 */