log date changes to wtmp. no rounding cause timed zeroes tv_usec
authorJay Lepreau <lepreau@ucbvax.Berkeley.EDU>
Sun, 18 May 1986 12:09:27 +0000 (04:09 -0800)
committerJay Lepreau <lepreau@ucbvax.Berkeley.EDU>
Sun, 18 May 1986 12:09:27 +0000 (04:09 -0800)
SCCS-vsn: usr.sbin/timed/timed/master.c 2.7
SCCS-vsn: usr.sbin/timed/timed/slave.c 2.11

usr/src/usr.sbin/timed/timed/master.c
usr/src/usr.sbin/timed/timed/slave.c

index 0333d95..580a6d9 100644 (file)
@@ -5,12 +5,14 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)master.c   2.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)master.c   2.7 (Berkeley) %G%";
 #endif not lint
 
 #include "globals.h"
 #include <protocols/timed.h>
 #endif not lint
 
 #include "globals.h"
 #include <protocols/timed.h>
+#include <sys/file.h>
 #include <setjmp.h>
 #include <setjmp.h>
+#include <utmp.h>
 
 extern int machup;
 extern int measure_delta;
 
 extern int machup;
 extern int measure_delta;
@@ -40,6 +42,7 @@ master()
        long pollingtime;
        struct timeval wait;
        struct timeval time;
        long pollingtime;
        struct timeval wait;
        struct timeval time;
+       struct timeval otime;
        struct timezone tzone;
        struct tsp *msg, to;
        struct sockaddr_in saveaddr;
        struct timezone tzone;
        struct tsp *msg, to;
        struct sockaddr_in saveaddr;
@@ -110,11 +113,13 @@ loop:
                         */
                        (void)strcpy(olddate, date());
                        (void)gettimeofday(&time, &tzone);
                         */
                        (void)strcpy(olddate, date());
                        (void)gettimeofday(&time, &tzone);
+                       otime = time;
                        time.tv_sec = msg->tsp_time.tv_sec;
                        time.tv_usec = msg->tsp_time.tv_usec;
                        time.tv_sec++;
                        (void)settimeofday(&time, &tzone);
                        syslog(LOG_NOTICE, "date changed from: %s", olddate);
                        time.tv_sec = msg->tsp_time.tv_sec;
                        time.tv_usec = msg->tsp_time.tv_usec;
                        time.tv_sec++;
                        (void)settimeofday(&time, &tzone);
                        syslog(LOG_NOTICE, "date changed from: %s", olddate);
+                       logwtmp(otime, time);
                        msg->tsp_type = TSP_DATEACK;
                        msg->tsp_vers = TSPVERSION;
                        (void)strcpy(msg->tsp_name, hostname);
                        msg->tsp_type = TSP_DATEACK;
                        msg->tsp_vers = TSPVERSION;
                        (void)strcpy(msg->tsp_name, hostname);
@@ -143,6 +148,7 @@ loop:
                                 */
                                (void)strcpy(olddate, date());
                                (void)gettimeofday(&time, &tzone);
                                 */
                                (void)strcpy(olddate, date());
                                (void)gettimeofday(&time, &tzone);
+                               otime = time;
                                time.tv_sec = msg->tsp_time.tv_sec;
                                time.tv_usec = msg->tsp_time.tv_usec;
                                time.tv_sec++;
                                time.tv_sec = msg->tsp_time.tv_sec;
                                time.tv_usec = msg->tsp_time.tv_usec;
                                time.tv_sec++;
@@ -150,6 +156,7 @@ loop:
                                syslog(LOG_NOTICE,
                                    "date changed by %s from: %s",
                                    msg->tsp_name, olddate);
                                syslog(LOG_NOTICE,
                                    "date changed by %s from: %s",
                                    msg->tsp_name, olddate);
+                               logwtmp(otime, time);
                                spreadtime();
                                pollingtime = 0;
                        }
                                spreadtime();
                                pollingtime = 0;
                        }
@@ -527,3 +534,28 @@ newslave(ind, seq)
                }
        }
 }
                }
        }
 }
+
+char *wtmpfile = "/usr/adm/wtmp";
+struct utmp wtmp[2] = {
+       { "|", "", "", 0 },
+       { "{", "", "", 0 }
+};
+
+/*
+ * Rounding doesn't work well because new time is always
+ * truncated, but oldtime is normally distributed.
+ */
+logwtmp(otime, ntime)
+struct timeval otime, ntime;
+{
+       int f;
+
+       if (otime.tv_sec == ntime.tv_sec)
+               return;
+       wtmp[0].ut_time = otime.tv_sec; /* +(otime.tv_usec + 500000)/1000000;*/
+       wtmp[1].ut_time = ntime.tv_sec; /* +(ntime.tv_usec + 500000)/1000000;*/
+       if ((f = open(wtmpfile, O_WRONLY|O_APPEND)) >= 0) {
+               (void) write(f, (char *)wtmp, sizeof(wtmp));
+               (void) close(f);
+       }
+}
index 1be68f8..e42b881 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)slave.c    2.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)slave.c    2.11 (Berkeley) %G%";
 #endif not lint
 
 #include "globals.h"
 #endif not lint
 
 #include "globals.h"
@@ -26,7 +26,7 @@ slave()
        struct tsp *msg, to, *readmsg();
        struct sockaddr_in saveaddr, msaveaddr;
        struct timeval wait;
        struct tsp *msg, to, *readmsg();
        struct sockaddr_in saveaddr, msaveaddr;
        struct timeval wait;
-       struct timeval time, mytime;
+       struct timeval time, mytime, otime;
        struct tsp *answer, *acksend();
        int timeout();
        char *date();
        struct tsp *answer, *acksend();
        int timeout();
        char *date();
@@ -205,10 +205,12 @@ loop:
                        seq = msg->tsp_seq;
 
                        (void)strcpy(olddate, date());
                        seq = msg->tsp_seq;
 
                        (void)strcpy(olddate, date());
+                       (void)gettimeofday(&otime, (struct timezone *)0);
                        (void)settimeofday(&msg->tsp_time,
                                (struct timezone *)0);
                        syslog(LOG_NOTICE, "date changed by %s from: %s",
                                msg->tsp_name, olddate);
                        (void)settimeofday(&msg->tsp_time,
                                (struct timezone *)0);
                        syslog(LOG_NOTICE, "date changed by %s from: %s",
                                msg->tsp_name, olddate);
+                       logwtmp(otime, msg->tsp_time);
                        if ((status & SUBMASTER) == SUBMASTER)
                                spreadtime();
                        (void)gettimeofday(&time, (struct timezone *)0);
                        if ((status & SUBMASTER) == SUBMASTER)
                                spreadtime();
                        (void)gettimeofday(&time, (struct timezone *)0);