BSD 4_3_Reno release
[unix-history] / usr / src / usr.sbin / timed / timed / timed.c
index c5ca2ac..2ba21a8 100644 (file)
@@ -2,17 +2,19 @@
  * Copyright (c) 1985 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1985 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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
@@ -22,7 +24,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)timed.c    2.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)timed.c    2.20 (Berkeley) 6/29/90";
 #endif /* not lint */
 
 #include "globals.h"
 #endif /* not lint */
 
 #include "globals.h"
@@ -94,7 +96,7 @@ char **argv;
        char *date();
        int n;
        int flag;
        char *date();
        int n;
        int flag;
-       char buf[BUFSIZ];
+       char buf[BUFSIZ], *cp, *cplim;
        struct ifconf ifc;
        struct ifreq ifreq, *ifr;
        register struct netinfo *ntp;
        struct ifconf ifc;
        struct ifreq ifreq, *ifr;
        register struct netinfo *ntp;
@@ -162,6 +164,10 @@ char **argv;
                } while (*++(*argv));
        }
 
                } while (*++(*argv));
        }
 
+#ifndef DEBUG
+       daemon(0, 0);
+#endif
+
        if (trace == ON) {
                fd = fopen(tracefile, "w");
                setlinebuf(fd);
        if (trace == ON) {
                fd = fopen(tracefile, "w");
                setlinebuf(fd);
@@ -235,9 +241,13 @@ char **argv;
                syslog(LOG_ERR, "get interface configuration: %m");
                exit(1);
        }
                syslog(LOG_ERR, "get interface configuration: %m");
                exit(1);
        }
-       n = ifc.ifc_len/sizeof(struct ifreq);
        ntp = NULL;
        ntp = NULL;
-       for (ifr = ifc.ifc_req; n > 0; n--, ifr++) {
+#define max(a, b) (a > b ? a : b)
+#define size(p)        max((p).sa_len, sizeof(p))
+       cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
+       for (cp = buf; cp < cplim;
+                       cp += sizeof (ifr->ifr_name) + size(ifr->ifr_addr)) {
+               ifr = (struct ifreq *)cp;
                if (ifr->ifr_addr.sa_family != AF_INET)
                        continue;
                ifreq = *ifr;
                if (ifr->ifr_addr.sa_family != AF_INET)
                        continue;
                ifreq = *ifr;
@@ -326,22 +336,6 @@ char **argv;
 
        /* election timer delay in secs. */
        delay2 = casual((long)MINTOUT, (long)MAXTOUT);
 
        /* election timer delay in secs. */
        delay2 = casual((long)MINTOUT, (long)MAXTOUT);
-#ifndef DEBUG
-       if (fork())
-               exit(0);
-       { int s;
-         for (s = getdtablesize(); s >= 0; --s)
-               (void) close(s);
-         (void) open("/dev/null", 0);
-         (void) dup2(0, 1);
-         (void) dup2(0, 2);
-         s = open("/dev/tty", 2);
-         if (s >= 0) {
-               (void) close(s);
-         }
-       }
-#endif
-
 
        if (Mflag) {
                /*
 
        if (Mflag) {
                /*
@@ -420,7 +414,6 @@ char **argv;
                        checkignorednets();
                }
                makeslave(firstslavenet());
                        checkignorednets();
                }
                makeslave(firstslavenet());
-               makeslave(firstslavenet());
                for (ntp = nettab; ntp != NULL; ntp = ntp->next)
                        if (ntp->status == MASTER)
                                ntp->status = IGNORE;
                for (ntp = nettab; ntp != NULL; ntp = ntp->next)
                        if (ntp->status == MASTER)
                                ntp->status = IGNORE;