2 * cmd_args.c = command-line argument processing
9 #include "ntp_stdlib.h"
10 #include "ntp_cmdargs.h"
13 * Definitions of things either imported from or exported to outside
15 extern char const *progname;
16 int listen_to_virtual_ips = 0;
18 static const char *ntp_options = "aAbc:dD:f:gk:l:LmnN:p:P:qr:s:t:v:V:x";
21 extern int check_netinfo;
26 * getstartup - search through the options looking for a debugging flag
35 extern int priority_done;
39 debug = 0; /* no debugging by default */
43 * This is a big hack. We don't really want to read command line
44 * configuration until everything else is initialized, since
45 * the ability to configure the system may depend on storage
46 * and the like having been initialized. Except that we also
47 * don't want to initialize anything until after detaching from
48 * the terminal, but we won't know to do that until we've
49 * parsed the command line. Do that now, crudely, and do it
50 * again later. Our ntp_getopt() is explicitly reusable, by the
51 * way. Your own mileage may vary.
53 * This hack is even called twice (to allow complete logging to file)
59 * Decode argument list
61 while ((c = ntp_getopt(argc, argv, ntp_options)) != EOF)
68 debug = (int)atol(ntp_optarg);
69 printf("Debug1: %s -> %x = %d\n", ntp_optarg, debug, debug);
74 msyslog(LOG_ERR, "ntpd not compiled with -DDEBUG option - no DEBUG support");
75 fprintf(stderr, "ntpd not compiled with -DDEBUG option - no DEBUG support");
80 listen_to_virtual_ips = 1;
86 new_file = fopen(ntp_optarg, "a");
87 if (new_file != NULL) {
89 msyslog(LOG_NOTICE, "logging to file %s", ntp_optarg);
90 if (syslog_file != NULL &&
91 fileno(syslog_file) != fileno(new_file))
92 (void)fclose(syslog_file);
94 syslog_file = new_file;
99 "Cannot open log file %s",
110 priority_done = strcmp(ntp_optarg, "high");
121 if (errflg || ntp_optind != argc) {
122 (void) fprintf(stderr, "usage: %s [ -abdgmnqx ] [ -c config_file ] [ -e e_delay ]\n", progname);
123 (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
124 (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
125 (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
126 #if defined(HAVE_SCHED_SETSCHEDULER)
127 (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
131 ntp_optind = 0; /* reset ntp_optind to restart ntp_getopt */
136 static char buf[BUFSIZ];
137 setvbuf(stdout, buf, _IOLBF, BUFSIZ);
146 * getCmdOpts - get command line options
154 extern char *config_file;
159 * Initialize, initialize
169 * Decode argument list
171 while ((c = ntp_getopt(argc, argv, ntp_options)) != EOF) {
174 proto_config(PROTO_AUTHENTICATE, 1, 0.);
178 proto_config(PROTO_AUTHENTICATE, 0, 0.);
182 proto_config(PROTO_BROADCLIENT, 1, 0.);
186 config_file = ntp_optarg;
202 debug = (int)atol(ntp_optarg);
203 printf("Debug2: %s -> %x = %d\n", ntp_optarg, debug, debug);
210 stats_config(STATS_FREQ_FILE, ntp_optarg);
218 getauthkeys(ntp_optarg);
221 case 'L': /* already done at pre-scan */
222 case 'l': /* already done at pre-scan */
226 proto_config(PROTO_MULTICAST_ADD, htonl(INADDR_NTP), 0.);
230 case 'n': /* already done at pre-scan */
233 case 'N': /* already done at pre-scan */
237 stats_config(STATS_PID_FILE, ntp_optarg);
241 #if defined(HAVE_SCHED_SETSCHEDULER)
242 config_priority = (int)atol(ntp_optarg);
243 config_priority_override = 1;
257 if (sscanf(ntp_optarg, "%lf", &tmp) != 1) {
259 "command line broadcast delay value %s undecodable",
262 proto_config(PROTO_BROADDELAY, 0, tmp);
268 stats_config(STATS_STATSDIR, ntp_optarg);
275 tkey = (int)atol(ntp_optarg);
276 if (tkey <= 0 || tkey > NTP_MAXKEY) {
278 "command line trusted key %s is invalid",
288 set_sys_var(ntp_optarg, strlen(ntp_optarg)+1,
289 RW | ((c == 'V') ? DEF : 0));
302 if (errflg || ntp_optind != argc) {
303 (void) fprintf(stderr, "usage: %s [ -abdgmnx ] [ -c config_file ] [ -e e_delay ]\n", progname);
304 (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
305 (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
306 (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
307 #if defined(HAVE_SCHED_SETSCHEDULER)
308 (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");