Subject: bin/30648: [PATCH] rwhod patch to reduce time interval between broadcasts
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Liam J. Foy <liamfoy@sepulcrum.org>
List: netbsd-bugs
Date: 07/01/2005 11:55:00
>Number: 30648
>Category: bin
>Synopsis: [PATCH] rwhod patch to reduce time interval between broadcasts
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Fri Jul 01 11:55:00 +0000 2005
>Originator: Liam J. Foy
>Release: NetBSD 2.0.2 i386
>Organization:
None
>Environment:
System: NetBSD 2.0.2 (ANARION) #1: Thu May 26 16:36:28 BST 2005
liamfoy@anarion:/usr/src/sys/arch/i386/compile/ANARION
>Description:
The following patches allow rwhod to reduce its broadcast time. This allows for
more 'real' time information about the host to be broadcasted. It also contains
a small fix which uses inet_ntoa to print decimal notation of an IP Address. It
makes it much more understandable.
>How-To-Repeat:
rwhod -i 20 /* Broadcast every 20 seconds */
rwhod -i 1m /* Broadcast every minute */
>Fix:
--- rwhod.8.diff begins here ---
--- /home/liamfoy/rwhod.8 2005-06-27 17:14:01.000000000 +0100
+++ rwhod.8 2005-07-01 11:04:25.000000000 +0100
@@ -36,6 +36,7 @@
.Nd system status server
.Sh SYNOPSIS
.Nm
+.Op Fl i Ar time
.Sh DESCRIPTION
.Nm
is the server which maintains the database used by the
@@ -46,6 +47,22 @@
.Em broadcast
messages on a network.
.Pp
+.Bl -tag -width flag
+.It Fl i Op Ar time
+Allows for the broadcast time to be changed from 3 minutes.
+To change the broadcast time, the
+.Ar time
+operand can be given as
+.Dq 30
+(30 seconds) or
+.Dq 1m
+(1 minute), for example.
+This allows for more real time information about the host.
+The
+.Ar time
+operand cannot be greater than 11 minutes.
+.Pp
+.El
.Nm
operates as both a producer and consumer of status information.
As a producer of information it periodically
--- rwhod.8.diff ends here ---
--- rwhod.c.diff begins here ---
--- /home/liamfoy/rwhod.c 2005-07-01 10:43:12.000000000 +0100
+++ rwhod.c 2005-07-01 10:41:33.000000000 +0100
@@ -72,12 +72,12 @@
#include <util.h>
#include "utmpentry.h"
-/*
- * Check interval. Don't forget to change the down time check in ruptime
- * if this is changed.
- */
+
#define CHECK_INTERVAL (3 * 60)
+/* Max interval time_interval can be changed to. */
+#define MAX_INTERVAL (11 * 60)
+
static char myname[MAXHOSTNAMELEN + 1];
/*
@@ -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 = CHECK_INTERVAL;
+ 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, "i:")) != -1) {
+ switch (ch) {
+ case 'i':
+ 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 > MAX_INTERVAL)
+ errx(1, "cannot be greater than %d minutes", MAX_INTERVAL / 60);
+ 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 [-i time]");
+ exit(1);
+}
--- rwhod.c.diff ends here ---