Subject: more rwhod patches
To: None <tech-userlevel@netbsd.org>
From: Liam J. Foy <liamfoy@sepulcrum.org>
List: tech-userlevel
Date: 06/27/2005 17:51:51
Hey Guys,

	I would like feedback/committal of these patches. They allow the
broadcast time of rwhod to be reduced below three minutes. This allows
for more real time information about the host. Another small change just
uses inet_ntoa when printing decimal notation of an IP address. This
makes the debug code much easier to understand, and I think it was meant
this way ;).

	We cannot go above 3 minutes. This is due to a 3 minute
downtime assumption.

Cheers, heres the beef:

Patches:
---------

--- /home/liamfoy/rwhod.8	2005-06-27 17:14:01.000000000 +0100
+++ rwhod.8	2005-06-27 17:34:55.000000000 +0100
@@ -36,6 +36,7 @@
 .Nd system status server
 .Sh SYNOPSIS
 .Nm
+.Op Fl g Ar time
 .Sh DESCRIPTION
 .Nm
 is the server which maintains the database used by the
@@ -46,6 +47,16 @@
 .Em broadcast
 messages on a network.
 .Pp
+.Bl -tag -width flag
+.It Fl g Op Ar time 
+Allows for the broadcast time to be reduced from 3 minutes.
+To reduce the broadcast time, the
+.Ar time
+operand can be given as 30 (30 seconds) or
+1m (1 minute), for example.
+This allows for more real time information about the host.
+.Pp
+.El
 .Nm
 operates as both a producer and consumer of status information.
 As a producer of information it periodically

--- /home/liamfoy/rwhod.c	2005-06-27 16:54:32.000000000 +0100
+++ rwhod.c	2005-06-27 17:34:05.000000000 +0100
@@ -107,6 +107,7 @@
 static void	 handleread(int);
 static void	 quit(const char *);
 static void	 rt_xaddrs(void *, void *, struct rt_addrinfo *);
+static void	 usage(void);
 static int	 verify(const char *);
 #ifdef DEBUG
 static char	*interval(int, const char *);
@@ -118,8 +119,9 @@
 int
 main(int argc, char *argv[])
 {
-	int s;
-	char *cp;
+	int s, ch;
+	int time_interval = 180;	/* Default time (180 seconds) */
+	char *cp, *ep;
 	socklen_t on = 1;
 	struct sockaddr_in sasin;
 	struct pollfd pfd[1];
@@ -127,6 +129,32 @@
 
 	if (getuid())
 		errx(EXIT_FAILURE, "not super user");
+
+	while ((ch = getopt(argc, argv, "g:")) != -1) {
+		switch (ch) {
+		case 'g':
+			time_interval = (int)strtol(optarg, &ep, 10);
+			if (time_interval <= 0)
+				errx(1, "time must be greater than 0");
+
+			if (ep[0] != '\0') {
+				if (ep[1] != '\0')
+					errx(1, "invalid argument: %s", optarg);
+				if (*ep == 'M' || *ep == 'm') {
+					/* Time in minutes. */
+					time_interval *= 60;
+				} else
+					errx(1, "invalid argument: %s", optarg);
+			}
+
+			if (time_interval > 180)
+				errx(1, "cannot be greater than 180 seconds (3 minutes)");
+			break;
+		default:
+			usage();	
+		}
+	}
+
 	sp = getservbyname("who", "udp");
 	if (sp == NULL)
 		errx(EXIT_FAILURE, "udp/who: unknown service");
@@ -169,7 +197,7 @@
 		exit(EXIT_FAILURE);
 
 	send_host_information(s);
-	delta.tv_sec = CHECK_INTERVAL;
+	delta.tv_sec = time_interval;
 	delta.tv_usec = 0;
 	gettimeofday(&now, NULL);
 	timeradd(&now, &delta, &next);
@@ -504,7 +532,7 @@
 	struct whoent *we;
 	struct sockaddr_in *sasin = (struct sockaddr_in *)to;
 
-	printf("sendto %x.%d\n", ntohl(sasin->sin_addr.s_addr),
+	printf("sendto %s.%d\n", inet_ntoa(sasin->sin_addr),
 	    ntohs(sasin->sin_port));
 	printf("hostname %s %s\n", w->wd_hostname,
 	   interval(ntohl(w->wd_sendtime) - ntohl(w->wd_boottime), "  up"));
@@ -553,3 +581,10 @@
 	return resbuf;
 }
 #endif
+
+static void
+usage(void)
+{
+	fprintf(stderr, "usage: rwhod [-g time]");
+	exit(1);
+}
-- 
		- Liam J. Foy
		liamfoy@sepulcrum.org