Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/ntp/ntpdate Make "-s" option silent again, fixes PR bin...



details:   https://anonhg.NetBSD.org/src/rev/9ea01718cc5f
branches:  trunk
changeset: 556559:9ea01718cc5f
user:      keihan <keihan%NetBSD.org@localhost>
date:      Sat Dec 20 16:12:27 2003 +0000

description:
Make "-s" option silent again, fixes PR bin/23707.

This has been fixed in current ntp-dev and also includes
some whitespace fixes.  NTP bug report available at:

http://bugzilla.ntp.org/show_bug.cgi?id=263

diffstat:

 dist/ntp/ntpdate/ntpdate.c |  285 ++++++++++++++++++++++----------------------
 1 files changed, 145 insertions(+), 140 deletions(-)

diffs (truncated from 545 to 300 lines):

diff -r 8552ccfa787c -r 9ea01718cc5f dist/ntp/ntpdate/ntpdate.c
--- a/dist/ntp/ntpdate/ntpdate.c        Sat Dec 20 14:24:29 2003 +0000
+++ b/dist/ntp/ntpdate/ntpdate.c        Sat Dec 20 16:12:27 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntpdate.c,v 1.3 2003/12/04 16:23:38 drochner Exp $     */
+/*     $NetBSD: ntpdate.c,v 1.4 2003/12/20 16:12:27 keihan Exp $       */
 
 /*
  * ntpdate - set the time of day by polling one or more NTP servers
@@ -73,8 +73,8 @@
 
 #ifdef SYS_WINNT
 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
-#define EAFNOSUPPORT    WSAEAFNOSUPPORT
-#define EPFNOSUPPORT    WSAEPFNOSUPPORT
+#define EAFNOSUPPORT   WSAEAFNOSUPPORT
+#define EPFNOSUPPORT   WSAEPFNOSUPPORT
 #define TARGET_RESOLUTION 1  /* Try for 1-millisecond accuracy
                                on Windows NT timers. */
 #pragma comment(lib, "winmm")
@@ -326,7 +326,7 @@
        l_fp tmp;
        int errflg;
        int c;
-        int nfound;
+       int nfound;
 
 #ifdef HAVE_NETINFO
        ni_namelist *netinfoservers;
@@ -575,11 +575,11 @@
 
        while (complete_servers < sys_numservers) {
 #ifdef HAVE_POLL_H
-                struct pollfd* rdfdes;
-                rdfdes = fdmask;
+               struct pollfd* rdfdes;
+               rdfdes = fdmask;
 #else
                fd_set rdfdes;
-                rdfdes = fdmask;
+               rdfdes = fdmask;
 #endif
 
                if (alarm_flag) {               /* alarmed? */
@@ -593,10 +593,10 @@
                         * Nothing to do.        Wait for something.
                         */
 #ifdef HAVE_POLL_H
-                        nfound = poll(rdfdes, (unsigned int)nbsock, timeout.tv_sec * 1000);
+                       nfound = poll(rdfdes, (unsigned int)nbsock, timeout.tv_sec * 1000);
 
 #else
-                        nfound = select(maxfd, &rdfdes, (fd_set *)0,
+                       nfound = select(maxfd, &rdfdes, (fd_set *)0,
                                        (fd_set *)0, &timeout);
 #endif
                        if (nfound > 0)
@@ -678,8 +678,8 @@
 
 /*
  * transmit - transmit a packet to the given server, or mark it completed.
- *               This is called by the timeout routine and by the receive
- *               procedure.
+ *             This is called by the timeout routine and by the receive
+ *             procedure.
  */
 static void
 transmit(
@@ -712,7 +712,7 @@
        }
 
        /*
-        * If we're here, send another message to the server.    Fill in
+        * If we're here, send another message to the server.  Fill in
         * the packet and let 'er rip.
         */
        xpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
@@ -781,7 +781,7 @@
        int is_authentic;
 
        if (debug)
-                printf("receive(%s)\n", stoa(&rbufp->recv_srcadr));
+               printf("receive(%s)\n", stoa(&rbufp->recv_srcadr));
        /*
         * Check to see if the packet basically looks like something
         * intended for us.
@@ -1062,29 +1062,29 @@
                if (server->delay == 0) {
                        if (debug)
                                printf("%s: Server dropped: no data\n", ntoa(&server->srcadr));
-                       continue;   /* no data */
+                       continue;       /* no data */
                }
                if (server->stratum > NTP_INFIN) {
                        if (debug)
                                printf("%s: Server dropped: strata too high\n", ntoa(&server->srcadr));
-                       continue;   /* stratum no good */
+                       continue;       /* stratum no good */
                }
                if (server->delay > NTP_MAXWGT) {
                        if (debug)
                                printf("%s: Server dropped: server too far away\n", 
-                                      ntoa(&server->srcadr));
-                       continue;   /* too far away */
+                                       ntoa(&server->srcadr));
+                       continue;       /* too far away */
                }
                if (server->leap == LEAP_NOTINSYNC) {
                        if (debug)
                                printf("%s: Server dropped: Leap not in sync\n", ntoa(&server->srcadr));
-                       continue;   /* he's in trouble */
+                       continue;       /* he's in trouble */
                }
                if (!L_ISHIS(&server->org, &server->reftime)) {
                        if (debug)
                                printf("%s: Server dropped: server is very broken\n", 
                                       ntoa(&server->srcadr));
-                       continue;   /* very broken host */
+                       continue;       /* very broken host */
                }
                if ((server->org.l_ui - server->reftime.l_ui)
                    >= NTP_MAXAGE) {
@@ -1241,7 +1241,7 @@
        }
 
        /*
-        * That's it.    Return our server.
+        * That's it.  Return our server.
         */
        return sys_server;
 }
@@ -1318,7 +1318,7 @@
 /* XXX ELIMINATE: merge BIG slew into adj_systime in lib/systime.c */
 /*
  * addserver - determine a server's address and allocate a new structure
- *                for it.
+ *             for it.
  */
 static void
 addserver(
@@ -1326,39 +1326,44 @@
        )
 {
        register struct server *server;
-        /* Address infos structure to store result of getaddrinfo */
-        struct addrinfo *addrResult;
-        /* Address infos structure to store hints for getaddrinfo */
-        struct addrinfo hints;
-        /* Error variable for getaddrinfo */
-        int error;
-        /* Service name */
-        char service[5];
+       /* Address infos structure to store result of getaddrinfo */
+       struct addrinfo *addrResult;
+       /* Address infos structure to store hints for getaddrinfo */
+       struct addrinfo hints;
+       /* Error variable for getaddrinfo */
+       int error;
+       /* Service name */
+       char service[5];
        strcpy(service, "ntp");
 
-        /* Get host address. Looking for UDP datagram connection. */
-        memset(&hints, 0, sizeof(hints));
-        hints.ai_family = ai_fam_templ;
-        hints.ai_socktype = SOCK_DGRAM;
+       /* Get host address. Looking for UDP datagram connection. */
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_family = ai_fam_templ;
+       hints.ai_socktype = SOCK_DGRAM;
 
-        printf("Looking for host %s and service %s\n", serv, service);
+#ifdef DEBUG
+       if (debug)
+               printf("Looking for host %s and service %s\n", serv, service);
+#endif
 
-        error = getaddrinfo(serv, service, &hints, &addrResult);
-        if (error != 0) {
-                fprintf(stderr, "Error : %s\n", gai_strerror(error));
+       error = getaddrinfo(serv, service, &hints, &addrResult);
+       if (error != 0) {
+               fprintf(stderr, "Error : %s\n", gai_strerror(error));
                msyslog(LOG_ERR, "can't find host %s\n", serv);
                return;
        }
-        else {
-                fprintf(stderr, "host found : %s\n", stohost((struct sockaddr_storage*)addrResult->ai_addr));
-        }
+#ifdef DEBUG
+       else if (debug) {
+               fprintf(stderr, "host found : %s\n", stohost((struct sockaddr_storage*)addrResult->ai_addr));
+       }
+#endif
 
        server = (struct server *)emalloc(sizeof(struct server));
        memset((char *)server, 0, sizeof(struct server));
 
-        /* For now we only get the first returned server of the addrinfo list */
-        memset(&(server->srcadr), 0, sizeof(struct sockaddr_storage));
-        memcpy(&(server->srcadr), addrResult->ai_addr, addrResult->ai_addrlen);
+       /* For now we only get the first returned server of the addrinfo list */
+       memset(&(server->srcadr), 0, sizeof(struct sockaddr_storage));
+       memcpy(&(server->srcadr), addrResult->ai_addr, addrResult->ai_addrlen);
        server->event_time = ++sys_numservers;
        if (sys_servers == NULL)
                sys_servers = server;
@@ -1391,21 +1396,21 @@
        for (server = sys_servers; server != NULL; 
             server = server->next_server) {
                
-                if (memcmp(addr, &server->srcadr, SOCKLEN(addr))==0)
+               if (memcmp(addr, &server->srcadr, SOCKLEN(addr))==0)
                        return server;
-                /* Multicast compatibility to verify here... I'm not sure it's working */
-                if(addr->ss_family == AF_INET) {
-                        if (IN_MULTICAST(ntohl(((struct sockaddr_in*)addr)->sin_addr.s_addr)))
-                                mc_server = server;
-                }
-                else {
+               /* Multicast compatibility to verify here... I'm not sure it's working */
+               if(addr->ss_family == AF_INET) {
+                       if (IN_MULTICAST(ntohl(((struct sockaddr_in*)addr)->sin_addr.s_addr)))
+                               mc_server = server;
+               }
+               else {
 #ifdef AF_INET6
-                        if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)(&server->srcadr))->sin6_addr))
+                       if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)(&server->srcadr))->sin6_addr))
                        mc_server = server;
 #else
-                        return 0;
+                       return 0;
 #endif
-                }
+               }
        }
 
        if (mc_server != NULL) {        
@@ -1420,7 +1425,7 @@
                server = (struct server *)emalloc(sizeof(struct server));
                memset((char *)server, 0, sizeof(struct server));
 
-                memcpy(&server->srcadr, &addr, sizeof(struct sockaddr_storage));
+               memcpy(&server->srcadr, &addr, sizeof(struct sockaddr_storage));
 
                server->event_time = ++sys_numservers;
 
@@ -1561,7 +1566,7 @@
        }
        /* get the LUID for system-time privilege. */
        LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
-       tkp.PrivilegeCount = 1;  /* one privilege to set */
+       tkp.PrivilegeCount = 1;         /* one privilege to set */
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        /* get set-time privilege for this process. */
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0);
@@ -1583,7 +1588,7 @@
        }
        /* get the LUID for system-time privilege. */
        LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
-       tkp.PrivilegeCount = 1;  /* one privilege to set */
+       tkp.PrivilegeCount = 1;         /* one privilege to set */
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        /* get set-time privilege for this process. */
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0);
@@ -1609,11 +1614,11 @@
 
        /* start the timer event */
        wTimerID = timeSetEvent(
-               (UINT) (1000/TIMER_HZ),    /* Delay */
-               wTimerRes,                       /* Resolution */
-               (LPTIMECALLBACK) alarming, /* Callback function */
-               (DWORD) dwUser,          /* User data */
-               TIME_PERIODIC);          /* Event type (periodic) */
+               (UINT) (1000/TIMER_HZ),         /* Delay */
+               wTimerRes,                      /* Resolution */
+               (LPTIMECALLBACK) alarming,      /* Callback function */
+               (DWORD) dwUser,                 /* User data */
+               TIME_PERIODIC);                 /* Event type (periodic) */
        if (wTimerID == 0) {
                msyslog(LOG_ERR, "timeSetEvent failed: %m");
                exit(1);
@@ -1644,10 +1649,10 @@
 static void
 init_io(void)
 {
-        struct addrinfo *res, *ressave;
-        struct addrinfo hints;
+       struct addrinfo *res, *ressave;
+       struct addrinfo hints;
        char service[5];
-        int optval = 1;
+       int optval = 1;
 
        /*
         * Init buffer free list and stat counters
@@ -1660,53 +1665,53 @@
 
        strcpy(service, "ntp");



Home | Main Index | Thread Index | Old Index