user/4614: Patch to make "rup -[hlt] host1 host2" work

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

user/4614: Patch to make "rup -[hlt] host1 host2" work

Alexander Farber
>Number:         4614
>Category:       user
>Synopsis:       "rup -[hlt] host1 host2" doesn't work
>Confidential:   yes
>Severity:       non-critical
>Priority:       medium
>Responsible:    bugs
>State:          open
>Quarter:        
>Keywords:      
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 11 21:10:02 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     A. Farber
>Release:        3.8
>Organization:
net
>Environment:
        System      : OpenBSD 3.8
        Architecture: OpenBSD.i386
        Machine     : i386
>Description:
        "rup -[hlt]" only works when broadcasting
        but "rup -[hlt] host1 host2" doesn't work.
>How-To-Repeat:
        rup -h localhost 127.0.0.1 localhost
>Fix:
        Please apply the patch below. Also fixed some spacing.


--- rup.c.OLD Sat Nov  5 10:41:23 2005
+++ rup.c Fri Nov 11 22:41:25 2005
@@ -57,7 +57,7 @@
  struct in_addr addr;
 } *hosts;
 
-void usage(void);
+static __dead void usage(void);
 int print_rup_data(char *, statstime *host_stat);
 
 static int
@@ -80,7 +80,7 @@
 {
  struct host_list *hp;
 
- if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) {
+ if (!(hp = malloc(sizeof(*hp)))) {
  err(1, NULL);
  /* NOTREACHED */
  }
@@ -93,8 +93,8 @@
 struct rup_data {
  char *host;
  struct statstime statstime;
-};
-struct rup_data *rup_data;
+} *rup_data;
+
 int rup_data_idx = 0;
 int rup_data_max = 0;
 
@@ -103,8 +103,7 @@
  SORT_HOST,
  SORT_LDAV,
  SORT_UPTIME
-};
-enum sort_type sort_type;
+} sort_type;
 
 static int
 compare(const void *v1, const void *v2)
@@ -196,12 +195,12 @@
  host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
 
  if (host_stat->curtime.tv_sec > 0)
- ups=host_stat->curtime.tv_sec;
- upd=ups/(3600*24);
- ups-=upd*3600*24;
- uph=ups/3600;
- ups-=uph*3600;
- upm=ups/60;
+ ups = host_stat->curtime.tv_sec;
+ upd = ups / (3600 * 24);
+ ups-= upd * 3600 * 24;
+ uph = ups / 3600;
+ ups-= uph * 3600;
+ upm = ups / 60;
 
  if (upd != 0)
  snprintf(days_buf, sizeof days_buf, "%3u day%s, ", upd,
@@ -227,9 +226,9 @@
 
  printf(" up %9.9s%9.9s load average: %.2f %.2f %.2f\n",
     days_buf, hours_buf,
-    (double)host_stat->avenrun[0]/FSCALE,
-    (double)host_stat->avenrun[1]/FSCALE,
-    (double)host_stat->avenrun[2]/FSCALE);
+    (double)host_stat->avenrun[0] / FSCALE,
+    (double)host_stat->avenrun[1] / FSCALE,
+    (double)host_stat->avenrun[2] / FSCALE);
 
  return(0);
 }
@@ -259,7 +258,11 @@
  return;
  }
 
- print_rup_data(host, &host_stat);
+ if (sort_type != SORT_NONE)
+ remember_rup_data(host, &host_stat);
+ else
+ print_rup_data(host, &host_stat);
+
  clnt_destroy(rstat_clnt);
 }
 
@@ -269,10 +272,9 @@
  statstime host_stat;
  enum clnt_stat clnt_stat;
  extern char *__progname;
- size_t i;
 
  if (sort_type != SORT_NONE) {
- printf("collecting responses...");
+ printf("collecting responses...\n");
  fflush(stdout);
  }
 
@@ -282,23 +284,13 @@
  fprintf(stderr, "%s: %s\n", __progname, clnt_sperrno(clnt_stat));
  exit(1);
  }
-
- if (sort_type != SORT_NONE) {
- putchar('\n');
- qsort(rup_data, rup_data_idx, sizeof(struct rup_data),
-    compare);
-
- for (i = 0; i < rup_data_idx; i++) {
- print_rup_data(rup_data[i].host,
-    &rup_data[i].statstime);
- }
- }
 }
 
 int
 main(int argc, char *argv[])
 {
  int ch;
+ size_t i;
  extern int optind;
 
  sort_type = SORT_NONE;
@@ -330,11 +322,21 @@
  onehost(argv[optind]);
  }
 
+ if (sort_type != SORT_NONE) {
+ qsort(rup_data, rup_data_idx, sizeof(struct rup_data),
+    compare);
+
+ for (i = 0; i < rup_data_idx; i++) {
+ print_rup_data(rup_data[i].host,
+    &rup_data[i].statstime);
+ }
+ }
+
  exit(0);
 }
 
 
-void
+static __dead void
 usage(void)
 {
  fprintf(stderr, "Usage: rup [-dhlt] [hosts ...]\n");


>Release-Note:
>Audit-Trail:
>Unformatted: