BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.sbin / timed / timed / timed.c
index b8f7dc7..18e8f75 100644 (file)
@@ -38,7 +38,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)timed.c    8.1 (Berkeley) 6/6/93";
+static char sccsid[] = "@(#)timed.c    8.2 (Berkeley) 3/26/95";
 #endif /* not lint */
 
 #ifdef sgi
 #endif /* not lint */
 
 #ifdef sgi
@@ -147,7 +147,7 @@ main(argc, argv)
        struct netinfo *savefromnet;
        struct netent *nentp;
        struct nets *nt;
        struct netinfo *savefromnet;
        struct netent *nentp;
        struct nets *nt;
-       struct sockaddr_in server;
+       static struct sockaddr_in server;
        u_short port;
        char c;
        extern char *optarg;
        u_short port;
        char c;
        extern char *optarg;
@@ -234,44 +234,6 @@ main(argc, argv)
 #ifdef sgi
                case 'P':
                        timetrim_fn = optarg;
 #ifdef sgi
                case 'P':
                        timetrim_fn = optarg;
-                       timetrim_st = fopen(timetrim_fn, "r+");
-                       if (0 == timetrim_st) {
-                               if (errno != ENOENT) {
-                                       (void)fprintf(stderr,"timed: ");
-                                       perror(timetrim_fn);
-                                       timetrim_fn = 0;
-                               }
-                       } else {
-                               int i;
-                               long trim;
-                               double adj, ticks;
-
-                               i = fscanf(timetrim_st, timetrim_rpat,
-                                          &trim, &adj, &ticks);
-                               if (i < 1
-                                   || trim > MAX_TRIM
-                                   || trim < -MAX_TRIM
-                                   || i == 2
-                                   || (i == 3
-                                       && trim != rint(adj*CLK_TCK/ticks))) {
-                                       if (trace && i != EOF)
-                                               (void)fprintf(stderr,
-                                   "timed: unrecognized contents in %s\n",
-                                                             timetrim_fn);
-                               } else {
-                                       if (0 > syssgi(SGI_SETTIMETRIM,
-                                                      trim)) {
-                                        perror("timed: syssgi(SETTIMETRIM)");
-                                       } else {
-                                               timetrim = trim;
-                                       }
-                                       if (i == 3) {
-                                               tot_adj = adj;
-                                               tot_ticks -= ticks;
-                                       }
-                               }
-                               (void)fclose(timetrim_st);
-                       }
                        break;
 #endif /* sgi */
 
                        break;
 #endif /* sgi */
 
@@ -286,6 +248,46 @@ main(argc, argv)
                exit(1);
        }
 
                exit(1);
        }
 
+#ifdef sgi
+       if (timetrim_fn == 0) {
+               ;
+       } else if (0 == (timetrim_st = fopen(timetrim_fn, "r+"))) {
+               if (errno != ENOENT) {
+                       (void)fprintf(stderr,"timed: ");
+                       perror(timetrim_fn);
+                       timetrim_fn = 0;
+               }
+       } else {
+               int i;
+               long trim;
+               double adj, ticks;
+
+               i = fscanf(timetrim_st, timetrim_rpat,
+                          &trim, &adj, &ticks);
+               if (i < 1
+                   || trim > MAX_TRIM
+                   || trim < -MAX_TRIM
+                   || i == 2
+                   || (i == 3
+                       && trim != rint(adj*CLK_TCK/ticks))) {
+                       if (trace && i != EOF)
+                               (void)fprintf(stderr,
+                   "timed: unrecognized contents in %s\n",
+                                             timetrim_fn);
+               } else {
+                       if (0 > syssgi(SGI_SETTIMETRIM,
+                                      trim)) {
+                        perror("timed: syssgi(SETTIMETRIM)");
+                       } else {
+                               timetrim = trim;
+                       }
+                       if (i == 3)
+                               tot_ticks -= ticks;
+               }
+               (void)fclose(timetrim_st);
+       }
+#endif /* sgi */
+
        /* If we care about which machine is the master, then we must
         *      be willing to be a master
         */
        /* If we care about which machine is the master, then we must
         *      be willing to be a master
         */
@@ -312,6 +314,7 @@ main(argc, argv)
                exit(1);
        }
        port = srvp->s_port;
                exit(1);
        }
        port = srvp->s_port;
+       server.sin_addr.s_addr = INADDR_ANY;
        server.sin_port = srvp->s_port;
        server.sin_family = AF_INET;
        sock = socket(AF_INET, SOCK_DGRAM, 0);
        server.sin_port = srvp->s_port;
        server.sin_family = AF_INET;
        sock = socket(AF_INET, SOCK_DGRAM, 0);