BSD 4_3_Reno release
[unix-history] / usr / src / usr.sbin / timed / timed / slave.c
index 6edd157..1ed85b4 100644 (file)
@@ -1,20 +1,34 @@
 /*
  * Copyright (c) 1985 Regents of the University of California.
 /*
  * Copyright (c) 1985 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * Neither the name of the University nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)slave.c    2.13 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)slave.c    2.21 (Berkeley) 6/1/90";
+#endif /* not lint */
 
 #include "globals.h"
 #include <protocols/timed.h>
 #include <setjmp.h>
 
 #include "globals.h"
 #include <protocols/timed.h>
 #include <setjmp.h>
+#include "pathnames.h"
 
 extern jmp_buf jmpenv;
 
 
 extern jmp_buf jmpenv;
 
-extern short sequence;
+extern u_short sequence;
 
 slave()
 {
 
 slave()
 {
@@ -25,8 +39,7 @@ slave()
        char candidate[MAXHOSTNAMELEN];
        struct tsp *msg, to, *readmsg();
        struct sockaddr_in saveaddr, msaveaddr;
        char candidate[MAXHOSTNAMELEN];
        struct tsp *msg, to, *readmsg();
        struct sockaddr_in saveaddr, msaveaddr;
-       struct timeval wait;
-       struct timeval time, mytime, otime;
+       struct timeval time, wait;
        struct tsp *answer, *acksend();
        int timeout();
        char *date();
        struct tsp *answer, *acksend();
        int timeout();
        char *date();
@@ -40,7 +53,6 @@ slave()
        extern int Mflag;
        extern int justquit;
 #ifdef MEASURE
        extern int Mflag;
        extern int justquit;
 #ifdef MEASURE
-       int tempstat;
        extern FILE *fp;
 #endif
        if (slavenet) {
        extern FILE *fp;
 #endif
        if (slavenet) {
@@ -57,8 +69,10 @@ slave()
 
        if (status & MASTER) {
 #ifdef MEASURE
 
        if (status & MASTER) {
 #ifdef MEASURE
-               fp = fopen("/usr/adm/timed.masterlog", "w");
-               setlinebuf(fp);
+               if (fp == NULL) {
+                       fp = fopen(_PATH_MASTERLOG, "w");
+                       setlinebuf(fp);
+               }
 #endif
                syslog(LOG_INFO, "THIS MACHINE IS A SUBMASTER");
                if (trace) {
 #endif
                syslog(LOG_INFO, "THIS MACHINE IS A SUBMASTER");
                if (trace) {
@@ -111,16 +125,14 @@ loop:
                                                ntp->status = IGNORE;
                                }
                        }
                                                ntp->status = IGNORE;
                                }
                        }
-#ifdef MEASURE
-                       tempstat = status;
-#endif
                        setstatus();
 #ifdef MEASURE
                        /*
                         * Check to see if we just became master
                        setstatus();
 #ifdef MEASURE
                        /*
                         * Check to see if we just became master
+                        * (file not open)
                         */
                         */
-                       if ((status & MASTER) && !(tempstat & MASTER)) {
-                               fp = fopen("/usr/adm/timed.masterlog", "w");
+                       if (fp == NULL) {
+                               fp = fopen(_PATH_MASTERLOG, "w");
                                setlinebuf(fp);
                        }
 #endif
                                setlinebuf(fp);
                        }
 #endif
@@ -203,12 +215,12 @@ loop:
                        seq = msg->tsp_seq;
 
                        (void)strcpy(olddate, date());
                        seq = msg->tsp_seq;
 
                        (void)strcpy(olddate, date());
-                       (void)gettimeofday(&otime, (struct timezone *)0);
+                       logwtmp("|", "date", "");
                        (void)settimeofday(&msg->tsp_time,
                                (struct timezone *)0);
                        (void)settimeofday(&msg->tsp_time,
                                (struct timezone *)0);
+                       logwtmp("{", "date", "");
                        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, 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);
@@ -258,7 +270,6 @@ loop:
                        break;
                case TSP_SETDATE:
                        saveaddr = from;
                        break;
                case TSP_SETDATE:
                        saveaddr = from;
-                       msg->tsp_time.tv_usec = 0;
                        msg->tsp_type = TSP_SETDATEREQ;
                        msg->tsp_vers = TSPVERSION;
                        (void)strcpy(msg->tsp_name, hostname);
                        msg->tsp_type = TSP_SETDATEREQ;
                        msg->tsp_vers = TSPVERSION;
                        (void)strcpy(msg->tsp_name, hostname);
@@ -436,7 +447,10 @@ loop:
                case TSP_QUIT:
                        /* become slave */
 #ifdef MEASURE
                case TSP_QUIT:
                        /* become slave */
 #ifdef MEASURE
-                       (void)fclose(fp);
+                       if (fp != NULL) {
+                               (void)fclose(fp);
+                               fp = NULL;
+                       }
 #endif
                        longjmp(jmpenv, 2);
                        break;
 #endif
                        longjmp(jmpenv, 2);
                        break;
@@ -499,8 +513,6 @@ loop:
                             * we are master on.  There must be two masters
                             * in this case.
                             */
                             * we are master on.  There must be two masters
                             * in this case.
                             */
-                           if (trace)
-                               fprintf(fd, "loop kill %x %x\n", fromnet->my_addr.s_addr, from.sin_addr.s_addr);
                            if (fromnet->my_addr.s_addr == from.sin_addr.s_addr)
                                break;
                            for (;;) {
                            if (fromnet->my_addr.s_addr == from.sin_addr.s_addr)
                                break;
                            for (;;) {