Wed Dec 26 18:31:29 2018 UTC ()
PR/53813: Edgar Pettijohn: Print usage message if no servers are found.


(christos)
diff -r1.12 -r1.13 src/external/bsd/ntp/dist/ntpdate/ntpdate.c

cvs diff -r1.12 -r1.13 src/external/bsd/ntp/dist/ntpdate/ntpdate.c (expand / switch to unified diff)

--- src/external/bsd/ntp/dist/ntpdate/ntpdate.c 2018/09/29 21:52:34 1.12
+++ src/external/bsd/ntp/dist/ntpdate/ntpdate.c 2018/12/26 18:31:29 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ntpdate.c,v 1.12 2018/09/29 21:52:34 christos Exp $ */ 1/* $NetBSD: ntpdate.c,v 1.13 2018/12/26 18:31:29 christos Exp $ */
2 2
3/* 3/*
4 * ntpdate - set the time of day by polling one or more NTP servers 4 * ntpdate - set the time of day by polling one or more NTP servers
5 */ 5 */
6 6
7#ifdef HAVE_CONFIG_H 7#ifdef HAVE_CONFIG_H
8# include <config.h> 8# include <config.h>
9#endif 9#endif
10 10
11#ifdef HAVE_NETINFO 11#ifdef HAVE_NETINFO
12#include <netinfo/ni.h> 12#include <netinfo/ni.h>
13#endif 13#endif
14 14
@@ -423,26 +423,27 @@ ntpdatemain ( @@ -423,26 +423,27 @@ ntpdatemain (
423 verbose = 1; 423 verbose = 1;
424 break; 424 break;
425 case 'u': 425 case 'u':
426 unpriv_port = 1; 426 unpriv_port = 1;
427 break; 427 break;
428 case '?': 428 case '?':
429 ++errflg; 429 ++errflg;
430 break; 430 break;
431 default: 431 default:
432 break; 432 break;
433 } 433 }
434 434
435 if (errflg) { 435 if (errflg) {
 436usage:
436 (void) fprintf(stderr, 437 (void) fprintf(stderr,
437 "usage: %s [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] server ...\n", 438 "usage: %s [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] server ...\n",
438 progname); 439 progname);
439 exit(2); 440 exit(2);
440 } 441 }
441 442
442 /* 443 /*
443 * If number of Samples (-p) not specified by user: 444 * If number of Samples (-p) not specified by user:
444 * - if a simple_query (-q) just ONE will do 445 * - if a simple_query (-q) just ONE will do
445 * - otherwise the normal is DEFSAMPLES 446 * - otherwise the normal is DEFSAMPLES
446 */ 447 */
447 if (sys_samples == 0) 448 if (sys_samples == 0)
448 sys_samples = (simple_query ? 1 : DEFSAMPLES); 449 sys_samples = (simple_query ? 1 : DEFSAMPLES);
@@ -499,27 +500,27 @@ ntpdatemain ( @@ -499,27 +500,27 @@ ntpdatemain (
499 if (debug) msyslog(LOG_DEBUG, 500 if (debug) msyslog(LOG_DEBUG,
500 "Adding time server %s from NetInfo configuration.", 501 "Adding time server %s from NetInfo configuration.",
501 netinfoservers->ni_namelist_val[servercount]); 502 netinfoservers->ni_namelist_val[servercount]);
502 addserver(netinfoservers->ni_namelist_val[servercount++]); 503 addserver(netinfoservers->ni_namelist_val[servercount++]);
503 } 504 }
504 } 505 }
505 ni_namelist_free(netinfoservers); 506 ni_namelist_free(netinfoservers);
506 free(netinfoservers); 507 free(netinfoservers);
507 } 508 }
508#endif 509#endif
509 510
510 if (sys_numservers == 0) { 511 if (sys_numservers == 0) {
511 msyslog(LOG_ERR, "no servers can be used, exiting"); 512 msyslog(LOG_ERR, "no servers can be used, exiting");
512 exit(1); 513 goto usage;
513 } 514 }
514 515
515 /* 516 /*
516 * Initialize the time of day routines and the I/O subsystem 517 * Initialize the time of day routines and the I/O subsystem
517 */ 518 */
518 if (sys_authenticate) { 519 if (sys_authenticate) {
519 init_auth(); 520 init_auth();
520 if (!authreadkeys(key_file)) { 521 if (!authreadkeys(key_file)) {
521 msyslog(LOG_ERR, "no key file <%s>, exiting", key_file); 522 msyslog(LOG_ERR, "no key file <%s>, exiting", key_file);
522 exit(1); 523 exit(1);
523 } 524 }
524 authtrust(sys_authkey, 1); 525 authtrust(sys_authkey, 1);
525 if (!authistrusted(sys_authkey)) { 526 if (!authistrusted(sys_authkey)) {