2 * cmd_args.c = command-line argument processing
9 #include "ntp_stdlib.h"
10 #include "ntp_config.h"
11 #include "ntp_cmdargs.h"
13 #include "ntpd-opts.h"
16 * Definitions of things either imported from or exported to outside
18 extern char const *progname;
21 extern int check_netinfo;
26 * getCmdOpts - apply most command line options
28 * A few options are examined earlier in ntpd.c ntpdmain() and
29 * ports/winnt/ntpd/ntservice.c main().
37 extern const char *config_file;
41 * Initialize, initialize
45 if (ipv4_works && ipv6_works) {
48 else if (HAVE_OPT( IPV6 ))
50 } else if (!ipv4_works && !ipv6_works) {
51 msyslog(LOG_ERR, "Neither IPv4 nor IPv6 networking detected, fatal.");
53 } else if (HAVE_OPT( IPV4 ) && !ipv4_works)
54 msyslog(LOG_WARNING, "-4/--ipv4 ignored, IPv4 networking not found.");
55 else if (HAVE_OPT( IPV6 ) && !ipv6_works)
56 msyslog(LOG_WARNING, "-6/--ipv6 ignored, IPv6 networking not found.");
58 if (HAVE_OPT( AUTHREQ ))
59 proto_config(PROTO_AUTHENTICATE, 1, 0., NULL);
60 else if (HAVE_OPT( AUTHNOREQ ))
61 proto_config(PROTO_AUTHENTICATE, 0, 0., NULL);
63 if (HAVE_OPT( BCASTSYNC ))
64 proto_config(PROTO_BROADCLIENT, 1, 0., NULL);
66 if (HAVE_OPT( CONFIGFILE )) {
67 config_file = OPT_ARG( CONFIGFILE );
73 if (HAVE_OPT( DRIFTFILE ))
74 stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE ));
76 if (HAVE_OPT( PANICGATE ))
79 if (HAVE_OPT( FORCE_STEP_ONCE ))
80 force_step_once = TRUE;
83 if (HAVE_OPT( JAILDIR )) {
85 chrootdir = OPT_ARG( JAILDIR );
89 if (HAVE_OPT( KEYFILE ))
90 getauthkeys(OPT_ARG( KEYFILE ));
92 if (HAVE_OPT( PIDFILE ))
93 stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE ));
98 if (HAVE_OPT( PROPAGATIONDELAY ))
101 const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY );
103 if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) {
105 "command line broadcast delay value %s undecodable",
108 proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
112 if (HAVE_OPT( STATSDIR ))
113 stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ));
115 if (HAVE_OPT( TRUSTEDKEY )) {
116 int ct = STACKCT_OPT( TRUSTEDKEY );
117 const char** pp = STACKLST_OPT( TRUSTEDKEY );
121 const char* p = *pp++;
124 if (tkey == 0 || tkey > NTP_MAXKEY) {
126 "command line trusted key %s is invalid",
135 if (HAVE_OPT( USER )) {
137 user = estrdup(OPT_ARG( USER ));
138 group = strrchr(user, ':');
142 *group++ = '\0'; /* get rid of the ':' */
144 group = estrdup(group);
145 user = erealloc(user, len);
150 if (HAVE_OPT( VAR )) {
153 const char * v_assign;
155 ct = STACKCT_OPT( VAR );
156 pp = STACKLST_OPT( VAR );
160 set_sys_var(v_assign, strlen(v_assign) + 1, RW);
164 if (HAVE_OPT( DVAR )) {
165 int ct = STACKCT_OPT( DVAR );
166 const char** pp = STACKLST_OPT( DVAR );
169 const char* my_ntp_optarg = *pp++;
171 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
172 (u_short) (RW | DEF));
176 if (HAVE_OPT( SLEW ))
177 loop_config(LOOP_MAX, 600);
179 if (HAVE_OPT( UPDATEINTERVAL )) {
180 long val = OPT_VALUE_UPDATEINTERVAL;
183 interface_interval = val;
186 "command line interface update interval %ld must not be negative\n",
189 "command line interface update interval %ld must not be negative",
196 /* save list of servers from cmd line for config_peers() use */
198 cmdline_server_count = argc;
199 cmdline_servers = argv;
202 /* display usage & exit with any option processing errors */
204 optionUsage(&ntpdOptions, 2); /* does not return */