add Berkeley copyright
[unix-history] / usr / src / usr.sbin / rwhod / rwhod.c
index cbdc363..5a39fad 100644 (file)
@@ -1,12 +1,37 @@
+/*
+ * Copyright (c) 1983 The 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.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rwhod.c    4.6 82/11/15";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)rwhod.c    5.11 (Berkeley) %G%";
+#endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <sys/file.h>
 
 
+#include <net/if.h>
 #include <netinet/in.h>
 
 #include <nlist.h>
 #include <netinet/in.h>
 
 #include <nlist.h>
@@ -16,15 +41,20 @@ static char sccsid[] = "@(#)rwhod.c 4.6 82/11/15";
 #include <utmp.h>
 #include <ctype.h>
 #include <netdb.h>
 #include <utmp.h>
 #include <ctype.h>
 #include <netdb.h>
+#include <syslog.h>
+#include <protocols/rwhod.h>
 
 
-#include "rwhod.h"
+/*
+ * Alarm interval. Don't forget to change the down time check in ruptime
+ * if this is changed.
+ */
+#define AL_INTERVAL (3 * 60)
 
 struct sockaddr_in sin = { AF_INET };
 
 extern errno;
 
 
 struct sockaddr_in sin = { AF_INET };
 
 extern errno;
 
-char   *localnet = "localnet";
-char   *myname = "myname";
+char   myname[32];
 
 struct nlist nl[] = {
 #define        NL_AVENRUN      0
 
 struct nlist nl[] = {
 #define        NL_AVENRUN      0
@@ -34,27 +64,52 @@ struct      nlist nl[] = {
        0
 };
 
        0
 };
 
+/*
+ * We communicate with each neighbor in
+ * a list constructed at the time we're
+ * started up.  Neighbors are currently
+ * directly connected via a hardware interface.
+ */
+struct neighbor {
+       struct  neighbor *n_next;
+       char    *n_name;                /* interface name */
+       char    *n_addr;                /* who to send to */
+       int     n_addrlen;              /* size of address */
+       int     n_flags;                /* should forward?, interface flags */
+};
+
+struct neighbor *neighbors;
 struct whod mywd;
 struct whod mywd;
+struct servent *sp;
 int    s, utmpf, kmemf = -1;
 
 int    s, utmpf, kmemf = -1;
 
+#define        WHDRSIZE        (sizeof (mywd) - sizeof (mywd.wd_we))
+#define        RWHODIR         "/usr/spool/rwho"
+
 int    onalrm();
 int    onalrm();
-char   *strcpy(), *sprintf();
+char   *strcpy(), *malloc();
 long   lseek();
 int    getkmem();
 long   lseek();
 int    getkmem();
+struct in_addr inet_makeaddr();
 
 main()
 {
        struct sockaddr_in from;
 
 main()
 {
        struct sockaddr_in from;
+       struct stat st;
        char path[64];
        char path[64];
-       int addr;
-       struct servent *sp;
+       int on = 1;
+       char *cp;
+       extern char *index();
 
 
+       if (getuid()) {
+               fprintf(stderr, "rwhod: not super user\n");
+               exit(1);
+       }
        sp = getservbyname("who", "udp");
        if (sp == 0) {
                fprintf(stderr, "rwhod: udp/who: unknown service\n");
                exit(1);
        }
        sp = getservbyname("who", "udp");
        if (sp == 0) {
                fprintf(stderr, "rwhod: udp/who: unknown service\n");
                exit(1);
        }
-       sp->s_port = htons(sp->s_port);
 #ifndef DEBUG
        if (fork())
                exit(0);
 #ifndef DEBUG
        if (fork())
                exit(0);
@@ -71,80 +126,114 @@ main()
          }
        }
 #endif
          }
        }
 #endif
-       (void) chdir("/dev");
-       (void) signal(SIGHUP, getkmem);
-       if (getuid()) {
-               fprintf(stderr, "rwhod: not super user\n");
-               exit(1);
-       }
-       addr = rhost(&localnet);
-       if (addr == -1) {
-               fprintf(stderr, "rwhod: no localnet\n");
+       if (chdir(RWHODIR) < 0) {
+               perror(RWHODIR);
                exit(1);
        }
                exit(1);
        }
-       sin.sin_addr.s_addr = addr;
-       if (rhost(&myname) == -1) {
-               fprintf(stderr, "rwhod: don't know \"myname\"\n");
+       (void) signal(SIGHUP, getkmem);
+       openlog("rwhod", LOG_PID, LOG_DAEMON);
+       /*
+        * Establish host name as returned by system.
+        */
+       if (gethostname(myname, sizeof (myname) - 1) < 0) {
+               syslog(LOG_ERR, "gethostname: %m");
                exit(1);
        }
                exit(1);
        }
-       strncpy(mywd.wd_hostname, myname, sizeof (mywd.wd_hostname) - 1);
-       utmpf = open("/etc/utmp", 0);
+       if ((cp = index(myname, '.')) != NULL)
+               *cp = '\0';
+       strncpy(mywd.wd_hostname, myname, sizeof (myname) - 1);
+       utmpf = open("/etc/utmp", O_RDONLY);
        if (utmpf < 0) {
                (void) close(creat("/etc/utmp", 0644));
        if (utmpf < 0) {
                (void) close(creat("/etc/utmp", 0644));
-               utmpf = open("/etc/utmp", 0);
+               utmpf = open("/etc/utmp", O_RDONLY);
        }
        if (utmpf < 0) {
        }
        if (utmpf < 0) {
-               perror("rwhod: /etc/utmp");
+               syslog(LOG_ERR, "/etc/utmp: %m");
                exit(1);
        }
                exit(1);
        }
-       sin.sin_port = sp->s_port;
        getkmem();
        getkmem();
-       if ((s = socket(AF_INET, SOCK_DGRAM, 0, 0)) < 0) {
-               perror("rwhod: socket");
+       if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+               syslog(LOG_ERR, "socket: %m");
                exit(1);
        }
                exit(1);
        }
-       if (bind(s, &sin, sizeof (sin), 0) < 0) {
-               perror("rwhod: bind");
+       if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
+               syslog(LOG_ERR, "setsockopt SO_BROADCAST: %m");
+               exit(1);
+       }
+       sin.sin_port = sp->s_port;
+       if (bind(s, &sin, sizeof (sin)) < 0) {
+               syslog(LOG_ERR, "bind: %m");
                exit(1);
        }
                exit(1);
        }
-       sigset(SIGALRM, onalrm);
+       if (!configure(s))
+               exit(1);
+       signal(SIGALRM, onalrm);
        onalrm();
        for (;;) {
                struct whod wd;
        onalrm();
        for (;;) {
                struct whod wd;
-               int cc, whod, len=sizeof (from);
+               int cc, whod, len = sizeof (from);
 
 
-               cc = recvfrom(s, (char *)&wd, sizeof (struct whod), 0, &from, &len);
+               cc = recvfrom(s, (char *)&wd, sizeof (struct whod), 0,
+                       &from, &len);
                if (cc <= 0) {
                        if (cc < 0 && errno != EINTR)
                if (cc <= 0) {
                        if (cc < 0 && errno != EINTR)
-                               perror("rwhod: recv");
+                               syslog(LOG_WARNING, "recv: %m");
                        continue;
                }
                if (from.sin_port != sp->s_port) {
                        continue;
                }
                if (from.sin_port != sp->s_port) {
-                       fprintf(stderr, "rwhod: %d: bad from port\n",
+                       syslog(LOG_WARNING, "%d: bad from port",
                                ntohs(from.sin_port));
                        continue;
                }
 #ifdef notdef
                if (gethostbyname(wd.wd_hostname) == 0) {
                                ntohs(from.sin_port));
                        continue;
                }
 #ifdef notdef
                if (gethostbyname(wd.wd_hostname) == 0) {
-                       fprintf(stderr, "rwhod: %s: unknown host\n",
+                       syslog(LOG_WARNING, "%s: unknown host",
                                wd.wd_hostname);
                        continue;
                }
 #endif
                                wd.wd_hostname);
                        continue;
                }
 #endif
+               if (wd.wd_vers != WHODVERSION)
+                       continue;
+               if (wd.wd_type != WHODTYPE_STATUS)
+                       continue;
                if (!verify(wd.wd_hostname)) {
                if (!verify(wd.wd_hostname)) {
-                       fprintf(stderr, "rwhod: malformed host name from %x\n",
+                       syslog(LOG_WARNING, "malformed host name from %x",
                                from.sin_addr);
                        continue;
                }
                                from.sin_addr);
                        continue;
                }
-               (void) sprintf(path, "/etc/whod.%s", wd.wd_hostname);
-               whod = creat(path, 0666);
+               (void) sprintf(path, "whod.%s", wd.wd_hostname);
+               /*
+                * Rather than truncating and growing the file each time,
+                * use ftruncate if size is less than previous size.
+                */
+               whod = open(path, O_WRONLY | O_CREAT, 0644);
                if (whod < 0) {
                if (whod < 0) {
-                       fprintf(stderr, "rwhod: ");
-                       perror(path);
+                       syslog(LOG_WARNING, "%s: %m", path);
                        continue;
                }
                        continue;
                }
+#if vax || pdp11
+               {
+                       int i, n = (cc - WHDRSIZE)/sizeof(struct whoent);
+                       struct whoent *we;
+
+                       /* undo header byte swapping before writing to file */
+                       wd.wd_sendtime = ntohl(wd.wd_sendtime);
+                       for (i = 0; i < 3; i++)
+                               wd.wd_loadav[i] = ntohl(wd.wd_loadav[i]);
+                       wd.wd_boottime = ntohl(wd.wd_boottime);
+                       we = wd.wd_we;
+                       for (i = 0; i < n; i++) {
+                               we->we_idle = ntohl(we->we_idle);
+                               we->we_utmp.out_time =
+                                   ntohl(we->we_utmp.out_time);
+                               we++;
+                       }
+               }
+#endif
                (void) time(&wd.wd_recvtime);
                (void) write(whod, (char *)&wd, cc);
                (void) time(&wd.wd_recvtime);
                (void) write(whod, (char *)&wd, cc);
+               if (fstat(whod, &st) < 0 || st.st_size > cc)
+                       ftruncate(whod, cc);
                (void) close(whod);
        }
 }
                (void) close(whod);
        }
 }
@@ -160,7 +249,7 @@ verify(name)
        register int size = 0;
 
        while (*name) {
        register int size = 0;
 
        while (*name) {
-               if (!isascii(*name) || !isalnum(*name))
+               if (!isascii(*name) || !(isalnum(*name) || ispunct(*name)))
                        return (0);
                name++, size++;
        }
                        return (0);
                name++, size++;
        }
@@ -169,7 +258,8 @@ verify(name)
 
 int    utmptime;
 int    utmpent;
 
 int    utmptime;
 int    utmpent;
-struct utmp utmp[100];
+int    utmpsize = 0;
+struct utmp *utmp;
 int    alarmcount;
 
 onalrm()
 int    alarmcount;
 
 onalrm()
@@ -180,69 +270,263 @@ onalrm()
        int cc;
        double avenrun[3];
        time_t now = time(0);
        int cc;
        double avenrun[3];
        time_t now = time(0);
+       register struct neighbor *np;
 
        if (alarmcount % 10 == 0)
                getkmem();
        alarmcount++;
        (void) fstat(utmpf, &stb);
 
        if (alarmcount % 10 == 0)
                getkmem();
        alarmcount++;
        (void) fstat(utmpf, &stb);
-       if (stb.st_mtime != utmptime) {
-               (void) lseek(utmpf, (long)0, 0);
-               cc = read(utmpf, (char *)utmp, sizeof (utmp));
+       if ((stb.st_mtime != utmptime) || (stb.st_size > utmpsize)) {
+               utmptime = stb.st_mtime;
+               if (stb.st_size > utmpsize) {
+                       utmpsize = stb.st_size + 10 * sizeof(struct utmp);
+                       if (utmp)
+                               utmp = (struct utmp *)realloc(utmp, utmpsize);
+                       else
+                               utmp = (struct utmp *)malloc(utmpsize);
+                       if (! utmp) {
+                               fprintf(stderr, "rwhod: malloc failed\n");
+                               utmpsize = 0;
+                               goto done;
+                       }
+               }
+               (void) lseek(utmpf, (long)0, L_SET);
+               cc = read(utmpf, (char *)utmp, stb.st_size);
                if (cc < 0) {
                        perror("/etc/utmp");
                if (cc < 0) {
                        perror("/etc/utmp");
-                       return;
+                       goto done;
                }
                }
-               wlast = &mywd.wd_we[(1024 / sizeof (struct whoent)) - 1];
+               wlast = &mywd.wd_we[1024 / sizeof (struct whoent) - 1];
                utmpent = cc / sizeof (struct utmp);
                for (i = 0; i < utmpent; i++)
                        if (utmp[i].ut_name[0]) {
                utmpent = cc / sizeof (struct utmp);
                for (i = 0; i < utmpent; i++)
                        if (utmp[i].ut_name[0]) {
-                               we->we_utmp = utmp[i];
+                               bcopy(utmp[i].ut_line, we->we_utmp.out_line,
+                                  sizeof (utmp[i].ut_line));
+                               bcopy(utmp[i].ut_name, we->we_utmp.out_name,
+                                  sizeof (utmp[i].ut_name));
+                               we->we_utmp.out_time = htonl(utmp[i].ut_time);
                                if (we >= wlast)
                                        break;
                                we++;
                        }
                utmpent = we - mywd.wd_we;
        }
                                if (we >= wlast)
                                        break;
                                we++;
                        }
                utmpent = we - mywd.wd_we;
        }
+
+       /*
+        * The test on utmpent looks silly---after all, if no one is
+        * logged on, why worry about efficiency?---but is useful on
+        * (e.g.) compute servers.
+        */
+       if (utmpent && chdir("/dev")) {
+               syslog(LOG_ERR, "chdir(/dev): %m");
+               exit(1);
+       }
        we = mywd.wd_we;
        for (i = 0; i < utmpent; i++) {
        we = mywd.wd_we;
        for (i = 0; i < utmpent; i++) {
-               if (stat(we->we_utmp.ut_line, &stb) >= 0)
-                       we->we_idle = now - stb.st_atime;
+               if (stat(we->we_utmp.out_line, &stb) >= 0)
+                       we->we_idle = htonl(now - stb.st_atime);
                we++;
        }
                we++;
        }
-       (void) lseek(kmemf, (long)nl[NL_AVENRUN].n_value, 0);
+       (void) lseek(kmemf, (long)nl[NL_AVENRUN].n_value, L_SET);
        (void) read(kmemf, (char *)avenrun, sizeof (avenrun));
        for (i = 0; i < 3; i++)
        (void) read(kmemf, (char *)avenrun, sizeof (avenrun));
        for (i = 0; i < 3; i++)
-               mywd.wd_loadav[i] = avenrun[i] * 100;
+               mywd.wd_loadav[i] = htonl((u_long)(avenrun[i] * 100));
        cc = (char *)we - (char *)&mywd;
        cc = (char *)we - (char *)&mywd;
-       (void) time(&mywd.wd_sendtime);
-       (void) sendto(s, (char *)&mywd, cc, 0, &sin, sizeof (sin));
-       (void) alarm(60);
+       mywd.wd_sendtime = htonl(time(0));
+       mywd.wd_vers = WHODVERSION;
+       mywd.wd_type = WHODTYPE_STATUS;
+       for (np = neighbors; np != NULL; np = np->n_next)
+               (void) sendto(s, (char *)&mywd, cc, 0,
+                       np->n_addr, np->n_addrlen);
+       if (utmpent && chdir(RWHODIR)) {
+               syslog(LOG_ERR, "chdir(%s): %m", RWHODIR);
+               exit(1);
+       }
+done:
+       (void) alarm(AL_INTERVAL);
 }
 
 getkmem()
 {
 }
 
 getkmem()
 {
-       struct nlist *nlp;
+       static ino_t vmunixino;
+       static time_t vmunixctime;
+       struct stat sb;
 
 
-       signal(SIGHUP, getkmem);
+       if (stat("/vmunix", &sb) < 0) {
+               if (vmunixctime)
+                       return;
+       } else {
+               if (sb.st_ctime == vmunixctime && sb.st_ino == vmunixino)
+                       return;
+               vmunixctime = sb.st_ctime;
+               vmunixino= sb.st_ino;
+       }
        if (kmemf >= 0)
                (void) close(kmemf);
 loop:
        if (kmemf >= 0)
                (void) close(kmemf);
 loop:
-       for (nlp = &nl[sizeof (nl) / sizeof (nl[0])]; --nlp >= nl; ) {
-               nlp->n_value = 0;
-               nlp->n_type = 0;
-       }
-       nlist("/vmunix", nl);
-       if (nl[0].n_value == 0) {
-               fprintf(stderr, "/vmunix namelist botch\n");
+       if (nlist("/vmunix", nl)) {
+               syslog(LOG_WARNING, "/vmunix namelist botch");
                sleep(300);
                goto loop;
        }
                sleep(300);
                goto loop;
        }
-       kmemf = open("/dev/kmem", 0);
+       kmemf = open("/dev/kmem", O_RDONLY);
        if (kmemf < 0) {
        if (kmemf < 0) {
-               perror("/dev/kmem");
-               sleep(300);
-               goto loop;
+               syslog(LOG_ERR, "/dev/kmem: %m");
+               exit(1);
+       }
+       (void) lseek(kmemf, (long)nl[NL_BOOTTIME].n_value, L_SET);
+       (void) read(kmemf, (char *)&mywd.wd_boottime,
+           sizeof (mywd.wd_boottime));
+       mywd.wd_boottime = htonl(mywd.wd_boottime);
+}
+
+/*
+ * Figure out device configuration and select
+ * networks which deserve status information.
+ */
+configure(s)
+       int s;
+{
+       char buf[BUFSIZ];
+       struct ifconf ifc;
+       struct ifreq ifreq, *ifr;
+       struct sockaddr_in *sin;
+       register struct neighbor *np;
+       int n;
+
+       ifc.ifc_len = sizeof (buf);
+       ifc.ifc_buf = buf;
+       if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
+               syslog(LOG_ERR, "ioctl (get interface configuration)");
+               return (0);
+       }
+       ifr = ifc.ifc_req;
+       for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++) {
+               for (np = neighbors; np != NULL; np = np->n_next)
+                       if (np->n_name &&
+                           strcmp(ifr->ifr_name, np->n_name) == 0)
+                               break;
+               if (np != NULL)
+                       continue;
+               ifreq = *ifr;
+               np = (struct neighbor *)malloc(sizeof (*np));
+               if (np == NULL)
+                       continue;
+               np->n_name = malloc(strlen(ifr->ifr_name) + 1);
+               if (np->n_name == NULL) {
+                       free((char *)np);
+                       continue;
+               }
+               strcpy(np->n_name, ifr->ifr_name);
+               np->n_addrlen = sizeof (ifr->ifr_addr);
+               np->n_addr = malloc(np->n_addrlen);
+               if (np->n_addr == NULL) {
+                       free(np->n_name);
+                       free((char *)np);
+                       continue;
+               }
+               bcopy((char *)&ifr->ifr_addr, np->n_addr, np->n_addrlen);
+               if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
+                       syslog(LOG_ERR, "ioctl (get interface flags)");
+                       free((char *)np);
+                       continue;
+               }
+               if ((ifreq.ifr_flags & IFF_UP) == 0 ||
+                   (ifreq.ifr_flags & (IFF_BROADCAST|IFF_POINTOPOINT)) == 0) {
+                       free((char *)np);
+                       continue;
+               }
+               np->n_flags = ifreq.ifr_flags;
+               if (np->n_flags & IFF_POINTOPOINT) {
+                       if (ioctl(s, SIOCGIFDSTADDR, (char *)&ifreq) < 0) {
+                               syslog(LOG_ERR, "ioctl (get dstaddr)");
+                               free((char *)np);
+                               continue;
+                       }
+                       /* we assume addresses are all the same size */
+                       bcopy((char *)&ifreq.ifr_dstaddr,
+                         np->n_addr, np->n_addrlen);
+               }
+               if (np->n_flags & IFF_BROADCAST) {
+                       if (ioctl(s, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
+                               syslog(LOG_ERR, "ioctl (get broadaddr)");
+                               free((char *)np);
+                               continue;
+                       }
+                       /* we assume addresses are all the same size */
+                       bcopy((char *)&ifreq.ifr_broadaddr,
+                         np->n_addr, np->n_addrlen);
+               }
+               /* gag, wish we could get rid of Internet dependencies */
+               sin = (struct sockaddr_in *)np->n_addr;
+               sin->sin_port = sp->s_port;
+               np->n_next = neighbors;
+               neighbors = np;
        }
        }
-       (void) lseek(kmemf, (long)nl[NL_BOOTTIME].n_value, 0);
-       (void) read(kmemf, (char *)&mywd.wd_boottime, sizeof (mywd.wd_boottime));
+       return (1);
 }
 }
+
+#ifdef DEBUG
+sendto(s, buf, cc, flags, to, tolen)
+       int s;
+       char *buf;
+       int cc, flags;
+       char *to;
+       int tolen;
+{
+       register struct whod *w = (struct whod *)buf;
+       register struct whoent *we;
+       struct sockaddr_in *sin = (struct sockaddr_in *)to;
+       char *interval();
+
+       printf("sendto %x.%d\n", ntohl(sin->sin_addr), ntohs(sin->sin_port));
+       printf("hostname %s %s\n", w->wd_hostname,
+          interval(ntohl(w->wd_sendtime) - ntohl(w->wd_boottime), "  up"));
+       printf("load %4.2f, %4.2f, %4.2f\n",
+           ntohl(w->wd_loadav[0]) / 100.0, ntohl(w->wd_loadav[1]) / 100.0,
+           ntohl(w->wd_loadav[2]) / 100.0);
+       cc -= WHDRSIZE;
+       for (we = w->wd_we, cc /= sizeof (struct whoent); cc > 0; cc--, we++) {
+               time_t t = ntohl(we->we_utmp.out_time);
+               printf("%-8.8s %s:%s %.12s",
+                       we->we_utmp.out_name,
+                       w->wd_hostname, we->we_utmp.out_line,
+                       ctime(&t)+4);
+               we->we_idle = ntohl(we->we_idle) / 60;
+               if (we->we_idle) {
+                       if (we->we_idle >= 100*60)
+                               we->we_idle = 100*60 - 1;
+                       if (we->we_idle >= 60)
+                               printf(" %2d", we->we_idle / 60);
+                       else
+                               printf("   ");
+                       printf(":%02d", we->we_idle % 60);
+               }
+               printf("\n");
+       }
+}
+
+char *
+interval(time, updown)
+       int time;
+       char *updown;
+{
+       static char resbuf[32];
+       int days, hours, minutes;
+
+       if (time < 0 || time > 3*30*24*60*60) {
+               (void) sprintf(resbuf, "   %s ??:??", updown);
+               return (resbuf);
+       }
+       minutes = (time + 59) / 60;             /* round to minutes */
+       hours = minutes / 60; minutes %= 60;
+       days = hours / 24; hours %= 24;
+       if (days)
+               (void) sprintf(resbuf, "%s %2d+%02d:%02d",
+                   updown, days, hours, minutes);
+       else
+               (void) sprintf(resbuf, "%s    %2d:%02d",
+                   updown, hours, minutes);
+       return (resbuf);
+}
+#endif