34
* getstartup - search through the options looking for a debugging flag
43
extern int priority_done;
47
debug = 0; /* no debugging by default */
51
* This is a big hack. We don't really want to read command line
52
* configuration until everything else is initialized, since
53
* the ability to configure the system may depend on storage
54
* and the like having been initialized. Except that we also
55
* don't want to initialize anything until after detaching from
56
* the terminal, but we won't know to do that until we've
57
* parsed the command line. Do that now, crudely, and do it
58
* again later. Our ntp_getopt() is explicitly reusable, by the
59
* way. Your own mileage may vary.
61
* This hack is even called twice (to allow complete logging to file)
67
* Decode argument list
69
while ((c = ntp_getopt(argc, argv, ntp_options)) != EOF)
76
debug = (int)atol(ntp_optarg);
77
printf("Debug1: %s -> %x = %d\n", ntp_optarg, debug, debug);
82
msyslog(LOG_ERR, "ntpd not compiled with -DDEBUG option - no DEBUG support");
83
fprintf(stderr, "ntpd not compiled with -DDEBUG option - no DEBUG support\n");
88
listen_to_virtual_ips = 0;
94
if(strcmp(ntp_optarg, "stderr") == 0)
96
else if(strcmp(ntp_optarg, "stdout") == 0)
99
new_file = fopen(ntp_optarg, "a");
100
if (new_file != NULL) {
102
msyslog(LOG_NOTICE, "logging to file %s", ntp_optarg);
103
if (syslog_file != NULL &&
104
fileno(syslog_file) != fileno(new_file))
105
(void)fclose(syslog_file);
107
syslog_file = new_file;
112
"Cannot open log file %s",
134
if ( ! strcmp(ntp_optarg, "version") ) {
135
printf("%.80s: %.80s\n", progname, Version);
137
} else if ( ! strcmp(ntp_optarg, "help") ) {
141
} else if ( ! strcmp(ntp_optarg, "copyright") ) {
145
fprintf(stderr, "%.80s: Error unknown argument '--%.80s'\n",
156
if (errflg || ntp_optind != argc) {
157
(void) fprintf(stderr, "usage: %s [ -abdgmnqx ] [ -c config_file ] [ -e e_delay ]\n", progname);
158
(void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
159
(void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
160
(void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
161
#if defined(HAVE_SCHED_SETSCHEDULER)
162
(void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
165
(void) fprintf(stderr, "\t\t[ -u user[:group] ] [ -i chrootdir ]\n");
169
ntp_optind = 0; /* reset ntp_optind to restart ntp_getopt */
174
static char buf[BUFSIZ];
175
setvbuf(stdout, buf, _IOLBF, BUFSIZ);
184
34
* getCmdOpts - get command line options
192
extern char *config_file;
193
struct sockaddr_in inaddrntp;
42
extern const char *config_file;
44
tOptions *myOptions = &OPTSTRUCT;
198
47
* Initialize, initialize
208
* Decode argument list
210
while ((c = ntp_getopt(argc, argv, ntp_options)) != EOF) {
213
proto_config(PROTO_AUTHENTICATE, 1, 0., NULL);
217
proto_config(PROTO_AUTHENTICATE, 0, 0., NULL);
221
proto_config(PROTO_BROADCLIENT, 1, 0., NULL);
225
config_file = ntp_optarg;
51
switch (WHICH_IDX_IPV4) {
53
default_ai_family = AF_INET;
56
default_ai_family = AF_INET6;
59
/* ai_fam_templ = ai_fam_default; */
63
if (HAVE_OPT( AUTHREQ ))
64
proto_config(PROTO_AUTHENTICATE, 1, 0., NULL);
66
if (HAVE_OPT( AUTHNOREQ ))
67
proto_config(PROTO_AUTHENTICATE, 0, 0., NULL);
69
if (HAVE_OPT( BCASTSYNC ))
70
proto_config(PROTO_BROADCLIENT, 1, 0., NULL);
72
if (HAVE_OPT( CONFIGFILE )) {
73
config_file = OPT_ARG( CONFIGFILE );
226
74
#ifdef HAVE_NETINFO
241
debug = (int)atol(ntp_optarg);
242
printf("Debug2: %s -> %x = %d\n", ntp_optarg, debug, debug);
249
stats_config(STATS_FREQ_FILE, ntp_optarg);
262
chrootdir = ntp_optarg;
268
getauthkeys(ntp_optarg);
271
case 'L': /* already done at pre-scan */
272
case 'l': /* already done at pre-scan */
276
inaddrntp.sin_family = AF_INET;
277
inaddrntp.sin_port = htons(NTP_PORT);
278
inaddrntp.sin_addr.s_addr = htonl(INADDR_NTP);
279
proto_config(PROTO_MULTICAST_ADD, 0, 0., (struct sockaddr_storage*)&inaddrntp);
283
case 'n': /* already done at pre-scan */
286
case 'N': /* already done at pre-scan */
290
stats_config(STATS_PID_FILE, ntp_optarg);
294
#if defined(HAVE_SCHED_SETSCHEDULER)
295
config_priority = (int)atol(ntp_optarg);
296
config_priority_override = 1;
310
if (sscanf(ntp_optarg, "%lf", &tmp) != 1) {
312
"command line broadcast delay value %s undecodable",
315
proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
326
user = malloc(strlen(ntp_optarg) + 1);
330
(void)strncpy(user, ntp_optarg, strlen(ntp_optarg) + 1);
331
group = rindex(user, ':');
333
*group++ = '\0'; /* get rid of the ':' */
341
stats_config(STATS_STATSDIR, ntp_optarg);
348
tkey = (int)atol(ntp_optarg);
349
if (tkey <= 0 || tkey > NTP_MAXKEY) {
351
"command line trusted key %s is invalid",
361
set_sys_var(ntp_optarg, strlen(ntp_optarg)+1,
362
(u_short) (RW | ((c == 'V') ? DEF : 0)));
79
if (HAVE_OPT( DRIFTFILE ))
80
stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE ));
82
if (HAVE_OPT( PANICGATE ))
85
if (HAVE_OPT( JAILDIR )) {
88
chrootdir = OPT_ARG( JAILDIR );
94
if (HAVE_OPT( KEYFILE ))
95
getauthkeys(OPT_ARG( KEYFILE ));
97
if (HAVE_OPT( PIDFILE ))
98
stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE ));
100
if (HAVE_OPT( QUIT ))
103
if (HAVE_OPT( PROPAGATIONDELAY ))
106
const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY );
108
if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) {
110
"command line broadcast delay value %s undecodable",
113
proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
117
if (HAVE_OPT( STATSDIR ))
118
stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ));
120
if (HAVE_OPT( TRUSTEDKEY )) {
121
int ct = STACKCT_OPT( TRUSTEDKEY );
122
const char** pp = STACKLST_OPT( TRUSTEDKEY );
126
const char* p = *pp++;
129
if (tkey == 0 || tkey > NTP_MAXKEY) {
131
"command line trusted key %s is invalid",
139
if (HAVE_OPT( USER )) {
141
char *ntp_optarg = OPT_ARG( USER );
144
user = malloc(strlen(ntp_optarg) + 1);
148
(void)strncpy(user, ntp_optarg, strlen(ntp_optarg) + 1);
149
group = rindex(user, ':');
151
*group++ = '\0'; /* get rid of the ':' */
158
if (HAVE_OPT( VAR )) {
159
int ct = STACKCT_OPT( VAR );
160
const char** pp = STACKLST_OPT( VAR );
163
const char* my_ntp_optarg = *pp++;
165
set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
170
if (HAVE_OPT( DVAR )) {
171
int ct = STACKCT_OPT( DVAR );
172
const char** pp = STACKLST_OPT( DVAR );
175
const char* my_ntp_optarg = *pp++;
177
set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
178
(u_short) (RW | DEF));
182
if (HAVE_OPT( SLEW ))
185
if (HAVE_OPT( UPDATEINTERVAL )) {
186
long val = OPT_VALUE_UPDATEINTERVAL;
188
if ((val >= 60) || (val == 0))
189
interface_interval = val;
192
"command line interface update interval %ld must be 0 or longer than 60 seconds",
370
sscanf(ntp_optarg, "%lf", &ntp_node.bdly);
374
sscanf(ntp_optarg, "%lf", &ntp_node.snse);
378
sscanf(ntp_optarg, "%lf", &ntp_node.slew);
382
sscanf(ntp_optarg, "%lf", &ntp_node.clk_time);
386
sscanf(ntp_optarg, "%lf", &ntp_node.sim_time);
390
sscanf(ntp_optarg, "%lf", &ntp_node.ferr);
394
sscanf(ntp_optarg, "%lf", &ntp_node.fnse);
398
sscanf(ntp_optarg, "%lf", &ntp_node.ndly);
402
sscanf(ntp_optarg, "%lf", &ntp_node.pdly);
198
if (HAVE_OPT( SIMBROADCASTDELAY ))
199
sscanf(OPT_ARG( SIMBROADCASTDELAY ), "%lf", &ntp_node.bdly);
201
if (HAVE_OPT( PHASENOISE ))
202
sscanf(OPT_ARG( PHASENOISE ), "%lf", &ntp_node.snse);
204
if (HAVE_OPT( SIMSLEW ))
205
sscanf(OPT_ARG( SIMSLEW ), "%lf", &ntp_node.slew);
207
if (HAVE_OPT( SERVERTIME ))
208
sscanf(OPT_ARG( SERVERTIME ), "%lf", &ntp_node.clk_time);
210
if (HAVE_OPT( ENDSIMTIME ))
211
sscanf(OPT_ARG( ENDSIMTIME ), "%lf", &ntp_node.sim_time);
213
if (HAVE_OPT( FREQERR ))
214
sscanf(OPT_ARG( FREQERR ), "%lf", &ntp_node.ferr);
216
if (HAVE_OPT( WALKNOISE ))
217
sscanf(OPT_ARG( WALKNOISE ), "%lf", &ntp_node.fnse);
219
if (HAVE_OPT( NDELAY ))
220
sscanf(OPT_ARG( NDELAY ), "%lf", &ntp_node.ndly);
222
if (HAVE_OPT( PDELAY ))
223
sscanf(OPT_ARG( PDELAY ), "%lf", &ntp_node.pdly);
412
if (errflg || ntp_optind != argc) {
413
(void) fprintf(stderr, "usage: %s [ -abdgmnx ] [ -c config_file ] [ -e e_delay ]\n", progname);
414
(void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
415
(void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
416
(void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
417
#if defined(HAVE_SCHED_SETSCHEDULER)
418
(void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
421
(void) fprintf(stderr, "\t\t[ -u user[:group] ] [ -i chrootdir ]\n");
227
if (errflg || argc) {
228
printf("argc is <%d>\n", argc);
229
optionUsage(myOptions, 2);