fixes init script for non ipv6 enabled systems #472755
[packages/xinetd.git] / xinetd / options.c
1 /*
2  * (c) Copyright 1992 by Panagiotis Tsirigotis
3  * (c) Sections Copyright 1998-2001 by Rob Braun
4  * All rights reserved.  The file named COPYRIGHT specifies the terms 
5  * and conditions for redistribution.
6  */
7
8 #include "config.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "str.h"
14 #include "sio.h"
15 #include "options.h"
16 #include "main.h"
17 #include "util.h"
18 #include "internals.h" /* for enable_periodic_check() */
19
20 /*
21  * $Id: options.c,v 1.7 2005/10/05 21:45:41 bbraun Exp $
22  */
23
24
25 int filelog_option ;
26 char * filelog_option_arg ;
27 int syslog_option ;
28 char * syslog_option_arg ;
29 int logprocs_option ;
30 unsigned logprocs_option_arg ;
31 int stayalive_option=0;
32 char *program_name ;
33 int inetd_compat = 0 ;
34 int dont_fork = 0;
35
36 #ifdef __GNUC__
37 __attribute__ ((noreturn))
38 #endif
39 static void usage(void);
40
41 int opt_recognize( int argc, char *argv[] )
42 {
43    int arg, arg_1 ;
44    unsigned int uarg_1;
45    unsigned long long ullarg_1;
46
47    program_name = strrchr( argv[ 0 ], '/' ) ;
48    program_name = ( program_name == NULL ) ? argv[ 0 ] : program_name + 1 ;
49
50    for ( arg = 1 ; arg < argc ; arg++ )
51       if ( argv[ arg ][ 0 ] == '-' && argv[ arg ][ 1 ] != 0 )
52       {
53          if ( strcmp( &argv[ arg ][ 1 ], "d" ) == 0 ) 
54             debug.on = 1 ;
55          else if ( strcmp( &argv[ arg ][ 1 ], "f" ) == 0 ) 
56          {
57             if ( ++arg == argc )
58                usage() ;
59             ps.ros.config_file = argv[ arg ];
60          }
61          else if ( strcmp( &argv[ arg ][ 1 ], "filelog" ) == 0 ) 
62          {
63             if ( ++arg == argc )
64                usage() ;
65             filelog_option_arg = ( argv[ arg ] ) ;
66             filelog_option = 1 ;
67          }
68          else if ( strcmp( &argv[ arg ][ 1 ], "syslog" ) == 0 ) 
69          {
70             if ( ++arg == argc )
71                usage() ;
72             syslog_option_arg = ( argv[ arg ] ) ;
73             syslog_option = 1 ;
74          }
75          else if ( strcmp( &argv[ arg ][ 1 ], "reuse" ) == 0 ) 
76             ; /* This is now a null option, kept for compatibility */
77          else if ( strcmp( &argv[ arg ][ 1 ], "limit" ) == 0 ) 
78          {
79             if ( ++arg == argc )
80                usage() ;
81             if ( parse_ull( argv[ arg ], 10, NUL, &ullarg_1 ) || ullarg_1 < 0 )
82                usage() ;
83             ps.ros.process_limit = (rlim_t)ullarg_1 ;
84             if( ps.ros.process_limit != ullarg_1 )
85                usage() ;
86          }
87          else if ( strcmp( &argv[ arg ][ 1 ], "pidfile" ) == 0 ) {
88             if( ++arg ==argc )
89                usage () ;
90             ps.ros.pid_file = (char *)new_string( argv[arg] );
91          }
92          else if ( strcmp( &argv[ arg ][ 1 ], "stayalive" )==0)
93             stayalive_option = 1;
94          else if ( strcmp( &argv[ arg ][ 1 ], "dontfork" )==0) {
95             dont_fork = 1;
96             stayalive_option = 1;
97          }
98          else if ( strcmp( &argv[ arg ][ 1 ], "logprocs" ) == 0 ) {
99             if ( ++arg == argc )
100                usage() ;
101             if ( parse_uint( argv[ arg ], 10, NUL, &uarg_1 ) || uarg_1 < 0 )
102                usage() ;
103             logprocs_option_arg = uarg_1 ;
104             logprocs_option = 1 ;
105          }
106          else if ( strcmp( &argv[ arg ][ 1 ], "shutdownprocs" ) == 0 ) 
107          {
108             if ( ++arg == argc )
109                usage() ;
110             Sprint(2, "The shutdownprocs option has been deprecated.\n");
111          }
112          else if ( strcmp( &argv[ arg ][ 1 ], "cc" ) == 0 ) {
113             if ( ++arg == argc )
114                usage() ;
115             if ( parse_int( argv[ arg ], 10, NUL, &arg_1 ) || arg_1 < 0 )
116                usage() ;
117             ps.ros.cc_interval = arg_1;
118             enable_periodic_check( arg_1 ) ;
119          }
120          else if ( strcmp( &argv[ arg ][ 1 ], "version" ) == 0 ) {
121             fprintf(stderr, "%s", program_version);
122 #ifdef LIBWRAP       
123             fprintf(stderr, " libwrap");
124 #endif            
125 #ifdef HAVE_LOADAVG
126             fprintf(stderr, " loadavg");
127 #endif          
128             fprintf(stderr, "\n");
129             exit(0);
130          }
131          else if ( strcmp ( &argv[ arg ][ 1 ], "inetd_compat" ) == 0 )
132             inetd_compat = 1;
133       }
134       else
135          break ;
136
137    if ( filelog_option + syslog_option > 1 )
138       usage() ;
139
140    if ( argc - arg != 0 )
141       usage() ;
142    return( arg ) ;
143 }
144
145 static void usage(void)
146 {
147    Sprint( 2, "Usage: %s [-d] [-f config_file] [-filelog filename] [-syslog facility] [-reuse] [-limit proc_limit] [-pidfile filename] [-logprocs limit] [-shutdownprocs limit] [-cc interval]\n", program_name ) ;
148    exit( 1 ) ;
149 }
150