1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
--- a/rup.1 2001-01-27 03:37:08.000000000 +1100
+++ b/rup.1 2008-04-06 11:08:46.000000000 +1000
@@ -3,7 +3,7 @@
.SH NAME
rup \- remote uptime display
.SH SYNOPSIS
-\fBrup\fP [ \fIhost\fP | -u | -v ]
+\fBrup\fP { -u | -v | \fIhosts\fP ... }
.SH DESCRIPTION
\fBrup\fP displays a summary of the current status of a particular
host or all hosts on the local network.
@@ -43,7 +43,7 @@ and cannot accomodate any RPC-based serv
.SH SEE ALSO
\fBportmap(8)\fP, \fBrpc.rstatd(8)\fP, \fBinetd(8)\fP
.SH HISTORY
-The \fBrup\fP command appeared in \fBSun-OS\fP.
+The \fBrup\fP command appeared in \fBSunOS\fP.
.SH BUGS
The sorting options are not implemented.
.SH AUTHOR
--- a/rup.c 2005-09-07 17:40:55.000000000 +1000
+++ b/rup.c 2008-04-06 11:08:46.000000000 +1000
@@ -25,6 +25,7 @@
*
**************************************************************************/
+#include <unistd.h>
#include <stdio.h>
#include <rpc/rpc.h>
#include <rpc/clnt.h>
@@ -79,6 +80,42 @@ int find_hostname(struct in_addr the_add
return(0);
}
+static void convuptime(
+ long host_uptime, char *days_buf, size_t days_len, char *hours_buf
+) {
+ int hours, mins;
+ long days;
+
+ *days_buf = 0;
+ *hours_buf = 0;
+
+ if (host_uptime <= 0) {
+ return;
+ }
+
+ host_uptime = (host_uptime + 59) / 60;
+ mins = host_uptime % 60;
+ host_uptime /= 60;
+ hours = host_uptime % 24;
+ days = host_uptime / 24;
+
+ if (days) {
+ snprintf(
+ days_buf, days_len, "%3ld day%s, ",
+ days, (days > 1) ? "s" : ""
+ );
+ }
+
+ if (hours) {
+ sprintf(hours_buf, "%2d:%02d, ", hours, mins);
+ } else if (mins) {
+ sprintf(
+ hours_buf, "%2d min%s, ", mins,
+ (mins > 1) ? "s" : ""
+ );
+ }
+}
+
int rup_answer_v5(struct statsusers *replyp, struct sockaddr_in *raddrp)
{
struct tm *tmp_time;
@@ -86,9 +123,10 @@ int rup_answer_v5(struct statsusers *rep
char *host;
struct statsusers *host_stat;
struct tm host_time;
- struct tm host_uptime;
char days_buf[16];
char hours_buf[16];
+ char users_buf[16];
+ long host_uptime;
if(find_hostname(raddrp->sin_addr)) {
return(0);
@@ -105,36 +143,20 @@ int rup_answer_v5(struct statsusers *rep
else
host = (char *)inet_ntoa(raddrp->sin_addr);
- if (strlen(host) > 12)
- host[12] = '\0';
-
tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec);
host_time = *tmp_time;
- host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
-
- tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
- host_uptime = *tmp_time;
-
-
- if (host_uptime.tm_yday != 0)
- sprintf(days_buf, "%3d day%s, ", host_uptime.tm_yday,
- (host_uptime.tm_yday > 1) ? "s" : "");
- else
- days_buf[0] = '\0';
-
- if (host_uptime.tm_hour != 0)
- sprintf(hours_buf, "%2d:%02d, ",
- host_uptime.tm_hour, host_uptime.tm_min);
- else
- if (host_uptime.tm_min != 0)
- sprintf(hours_buf, "%2d mins, ", host_uptime.tm_min);
- else
- hours_buf[0] = '\0';
-
- printf("%-*s up %9.9s%9.9s%i users, load average: %.2f %.2f %.2f\n",
- 12,host,days_buf,hours_buf,
- host_stat->users,
+ convuptime(
+ host_stat->curtime.tv_sec - host_stat->boottime.tv_sec,
+ days_buf, sizeof(days_buf), hours_buf
+ );
+
+ sprintf(users_buf, "%3d user%s, ", host_stat->users,
+ (host_stat->users > 1) ? "s" : "");
+
+ printf("%-*.*s %2d:%02d up %10.10s%9.9s%11.11sload %.2f %.2f %.2f\n",
+ 21, 21, host, host_time.tm_hour, host_time.tm_min,
+ days_buf, hours_buf, users_buf,
(double)host_stat->avenrun[0]/FSCALE,
(double)host_stat->avenrun[1]/FSCALE,
(double)host_stat->avenrun[2]/FSCALE);
@@ -150,9 +172,9 @@ int rup_answer_v3(struct statstime *repl
char *host;
struct statstime *host_stat;
struct tm host_time;
- struct tm host_uptime;
char days_buf[16];
char hours_buf[16];
+ long host_uptime;
if(find_hostname(raddrp->sin_addr)) {
return(0);
@@ -169,35 +191,17 @@ int rup_answer_v3(struct statstime *repl
else
host = (char *)inet_ntoa(raddrp->sin_addr);
- if (strlen(host) > 12)
- host[12] = '\0';
-
tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec);
host_time = *tmp_time;
- host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
-
- tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
- host_uptime = *tmp_time;
-
-
- if (host_uptime.tm_yday != 0)
- sprintf(days_buf, "%3d day%s, ", host_uptime.tm_yday,
- (host_uptime.tm_yday > 1) ? "s" : "");
- else
- days_buf[0] = '\0';
-
- if (host_uptime.tm_hour != 0)
- sprintf(hours_buf, "%2d:%02d, ",
- host_uptime.tm_hour, host_uptime.tm_min);
- else
- if (host_uptime.tm_min != 0)
- sprintf(hours_buf, "%2d mins, ", host_uptime.tm_min);
- else
- hours_buf[0] = '\0';
-
- printf("%-*s up %9.9s%9.9s load average: %.2f %.2f %.2f\n",
- 12,host,days_buf,hours_buf,
+ convuptime(
+ host_stat->curtime.tv_sec - host_stat->boottime.tv_sec,
+ days_buf, sizeof(days_buf), hours_buf
+ );
+
+ printf("%-*.*s %2d:%02d up %10.10s%9.9sload %.2f %.2f %.2f\n",
+ 21, 21, host, host_time.tm_hour, host_time.tm_min,
+ days_buf, hours_buf,
(double)host_stat->avenrun[0]/FSCALE,
(double)host_stat->avenrun[1]/FSCALE,
(double)host_stat->avenrun[2]/FSCALE);
@@ -306,7 +310,7 @@ int pointopoint_v3(struct sockaddr_in *s
}
void usage()
{
- printf("usage: %s \"host\" -u -v\n"\
+ printf("usage: %s {-u | -v | hosts ...}\n"\
"\t-u\tbroadcast request for info including users.\n"\
"\t-v\tprint version and exit\n", program_name);
}
@@ -341,20 +345,23 @@ int main(int argc, char **argv)
exit(0);
}
- if((hp = gethostbyname(argv[1])) == NULL) {
- fprintf(stderr,"%s: cannot get hostname %s\n",program_name,argv[1]);
- exit(-1);
- }
-
- bcopy(hp->h_addr,(caddr_t)&server_addr.sin_addr, hp->h_length);
- server_addr.sin_family = AF_INET;
- server_addr.sin_port = 0;
-
- if(pointopoint_v5(&server_addr) == 1)
- exit(EXIT_SUCCESS);
- else if(pointopoint_v3(&server_addr) == 1)
- exit(EXIT_SUCCESS);
+ for (; optind < argc; optind++) {
+ if((hp = gethostbyname(argv[optind])) == NULL) {
+ fprintf(stderr,"%s: cannot get hostname %s\n",program_name,argv[optind]);
+ continue;
+ }
+
+ bcopy(hp->h_addr,(caddr_t)&server_addr.sin_addr, hp->h_length);
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = 0;
+
+ if(pointopoint_v5(&server_addr) == 1)
+ continue;
+ else if(pointopoint_v3(&server_addr) == 1)
+ continue;
+ else
+ clnt_pcreateerror(program_name);
+ }
- clnt_pcreateerror(program_name);
- exit(EXIT_FAILURE);
+ return 0;
}
--- a/rsysinfo.c 2005-09-07 18:07:28.000000000 +1000
+++ b/rsysinfo.c 2008-04-06 11:08:46.000000000 +1000
@@ -95,7 +95,7 @@ int rsysinfo_answer_v3(struct statstime
printf("System Information for: %s\n",host);
- printf("uptime: %s%sload averge: %.2f %.2f %.2f\n",
+ printf("uptime: %s%sload average: %.2f %.2f %.2f\n",
days_buf, hours_buf, host_stat->avenrun[0]/256.0,
host_stat->avenrun[1]/256.0, host_stat->avenrun[2]/256.0);
--- a/rstat_main.c 2005-09-07 18:07:28.000000000 +1000
+++ b/rstat_main.c 2008-04-06 11:08:46.000000000 +1000
@@ -83,8 +83,8 @@ char **interfaces;
int main(int argc, char **argv)
{
SVCXPRT *transp;
- int fromlen, sock = 0, proto = 0;
struct sockaddr_in from;
+ int fromlen = sizeof from, sock = 0, proto = 0;
int count = 1;
if (argc > 1) {
--- a/getdata.c 2005-12-07 20:11:04.000000000 +1100
+++ b/getdata.c 2009-06-09 18:40:02.000000000 +1000
@@ -211,7 +211,9 @@ static void get_net(struct statsusers *s
if (*bufp == '\0')
continue; /* skip empty line */
iface = bufp;
+#ifdef LOG_VERBOSITY
syslog(LOG_DEBUG, "interface: %s", iface);
+#endif
/* search for the end of the interface name (':' or \0) */
while (*bufp != ':' && *bufp != '\0') bufp++;
|