[Midnightbsd-cvs] src [11444] trunk/usr.bin/ruptime/ruptime.c: sync ruptime with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jul 7 11:54:44 EDT 2018
Revision: 11444
http://svnweb.midnightbsd.org/src/?rev=11444
Author: laffer1
Date: 2018-07-07 11:54:44 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync ruptime with freebsd
Modified Paths:
--------------
trunk/usr.bin/ruptime/Makefile
trunk/usr.bin/ruptime/ruptime.1
trunk/usr.bin/ruptime/ruptime.c
Property Changed:
----------------
trunk/usr.bin/ruptime/ruptime.1
Modified: trunk/usr.bin/ruptime/Makefile
===================================================================
--- trunk/usr.bin/ruptime/Makefile 2018-07-07 15:54:18 UTC (rev 11443)
+++ trunk/usr.bin/ruptime/Makefile 2018-07-07 15:54:44 UTC (rev 11444)
@@ -1,8 +1,7 @@
+# $MidnightBSD$
# @(#)Makefile 8.1 (Berkeley) 6/6/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/ruptime/Makefile 226419 2011-10-16 07:36:27Z ed $
PROG= ruptime
-WARNS?= 3
-
.include <bsd.prog.mk>
Modified: trunk/usr.bin/ruptime/ruptime.1
===================================================================
--- trunk/usr.bin/ruptime/ruptime.1 2018-07-07 15:54:18 UTC (rev 11443)
+++ trunk/usr.bin/ruptime/ruptime.1 2018-07-07 15:54:44 UTC (rev 11444)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1983, 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -26,9 +27,9 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)ruptime.1 8.2 (Berkeley) 4/5/94
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/ruptime/ruptime.1 320646 2017-07-04 15:53:54Z allanjude $
.\"
-.Dd March 1, 2003
+.Dd July 3, 2017
.Dt RUPTIME 1
.Os
.Sh NAME
@@ -38,6 +39,15 @@
.Nm
.Op Fl alrtu
.Op Ar host ...
+.Sh DEPRECATION NOTICE
+.Nm
+is deprecated and will be removed from future versions of the
+.Fx
+base system.
+If
+.Nm
+is still required, it can be installed from ports or packages
+(net/bsdrcmds).
.Sh DESCRIPTION
The
.Nm
Property changes on: trunk/usr.bin/ruptime/ruptime.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/ruptime/ruptime.c
===================================================================
--- trunk/usr.bin/ruptime/ruptime.c 2018-07-07 15:54:18 UTC (rev 11443)
+++ trunk/usr.bin/ruptime/ruptime.c 2018-07-07 15:54:44 UTC (rev 11444)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 1983, 1993, 1994
* The Regents of the University of California. All rights reserved.
@@ -38,7 +39,7 @@
#endif /* not lint */
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/ruptime/ruptime.c 227178 2011-11-06 08:16:41Z ed $");
#include <sys/param.h>
@@ -54,28 +55,26 @@
#include <time.h>
#include <unistd.h>
-struct hs {
- struct whod *hs_wd;
+static struct hs {
+ struct whod hs_wd;
int hs_nusers;
} *hs;
-struct whod awhod;
-#define LEFTEARTH(h) (now - (h) > 4*24*60*60)
-#define ISDOWN(h) (now - (h)->hs_wd->wd_recvtime > 11 * 60)
-#define WHDRSIZE (sizeof (awhod) - sizeof (awhod.wd_we))
+#define LEFTEARTH(h) (now - (h) > 4*24*60*60)
+#define ISDOWN(h) (now - (h)->hs_wd.wd_recvtime > 11 * 60)
+#define WHDRSIZE __offsetof(struct whod, wd_we)
-size_t nhosts;
-time_t now;
-int rflg = 1;
-DIR *dirp;
+static size_t nhosts;
+static time_t now;
+static int rflg = 1;
+static DIR *dirp;
-int hscmp(const void *, const void *);
-char *interval(time_t, const char *);
-int lcmp(const void *, const void *);
-void morehosts(void);
-void ruptime(const char *, int, int (*)(const void *, const void *));
-int tcmp(const void *, const void *);
-int ucmp(const void *, const void *);
-void usage(void);
+static int hscmp(const void *, const void *);
+static char *interval(time_t, const char *);
+static int lcmp(const void *, const void *);
+static void ruptime(const char *, int, int (*)(const void *, const void *));
+static int tcmp(const void *, const void *);
+static int ucmp(const void *, const void *);
+static void usage(void);
int
main(int argc, char *argv[])
@@ -120,7 +119,7 @@
exit(0);
}
-char *
+static char *
interval(time_t tval, const char *updown)
{
static char resbuf[32];
@@ -127,10 +126,10 @@
int days, hours, minutes;
if (tval < 0) {
- (void)snprintf(resbuf, sizeof(resbuf), " %s ??:??", updown);
+ (void)snprintf(resbuf, sizeof(resbuf), "%s ??:??", updown);
return (resbuf);
}
- /* round to minutes. */
+ /* Round to minutes. */
minutes = (tval + (60 - 1)) / 60;
hours = minutes / 60;
minutes %= 60;
@@ -138,10 +137,10 @@
hours %= 24;
if (days)
(void)snprintf(resbuf, sizeof(resbuf),
- "%s %3d+%02d:%02d", updown, days, hours, minutes);
+ "%s %4d+%02d:%02d", updown, days, hours, minutes);
else
(void)snprintf(resbuf, sizeof(resbuf),
- "%s %2d:%02d", updown, hours, minutes);
+ "%s %2d:%02d", updown, hours, minutes);
return (resbuf);
}
@@ -148,15 +147,15 @@
#define HS(a) ((const struct hs *)(a))
/* Alphabetical comparison. */
-int
+static int
hscmp(const void *a1, const void *a2)
{
return (rflg *
- strcmp(HS(a1)->hs_wd->wd_hostname, HS(a2)->hs_wd->wd_hostname));
+ strcmp(HS(a1)->hs_wd.wd_hostname, HS(a2)->hs_wd.wd_hostname));
}
/* Load average comparison. */
-int
+static int
lcmp(const void *a1, const void *a2)
{
if (ISDOWN(HS(a1)))
@@ -168,10 +167,10 @@
return (-rflg);
else
return (rflg *
- (HS(a2)->hs_wd->wd_loadav[0] - HS(a1)->hs_wd->wd_loadav[0]));
+ (HS(a2)->hs_wd.wd_loadav[0] - HS(a1)->hs_wd.wd_loadav[0]));
}
-void
+static void
ruptime(const char *host, int aflg, int (*cmp)(const void *, const void *))
{
struct hs *hsp;
@@ -179,10 +178,9 @@
struct whoent *we;
struct dirent *dp;
const char *hostname;
- char buf[sizeof(struct whod)];
int fd, i, maxloadav;
size_t hspace;
- u_int cc;
+ ssize_t cc;
rewinddir(dirp);
hsp = NULL;
@@ -195,18 +193,7 @@
warn("%s", dp->d_name);
continue;
}
- cc = read(fd, buf, sizeof(struct whod));
- (void)close(fd);
- if (host != NULL) {
- hostname = ((struct whod *)buf)->wd_hostname;
- if (strcasecmp(hostname, host) != 0)
- continue;
- }
- if (cc < WHDRSIZE)
- continue;
- if (LEFTEARTH(((struct whod *)buf)->wd_recvtime))
- continue;
if (nhosts == hspace) {
if ((hs =
realloc(hs, (hspace += 40) * sizeof(*hs))) == NULL)
@@ -214,16 +201,26 @@
hsp = hs + nhosts;
}
- if ((hsp->hs_wd = malloc((size_t)WHDRSIZE)) == NULL)
- err(1, NULL);
- memmove(hsp->hs_wd, buf, (size_t)WHDRSIZE);
+ wd = &hsp->hs_wd;
+ cc = read(fd, wd, sizeof(*wd));
+ (void)close(fd);
+ if (cc < (ssize_t)WHDRSIZE)
+ continue;
- for (wd = (struct whod *)buf, i = 0; i < 2; ++i)
+ if (host != NULL) {
+ hostname = wd->wd_hostname;
+ if (strcasecmp(hostname, host) != 0)
+ continue;
+ }
+ if (LEFTEARTH(wd->wd_recvtime))
+ continue;
+
+ for (i = 0; i < 2; i++)
if (wd->wd_loadav[i] > maxloadav)
maxloadav = wd->wd_loadav[i];
- for (hsp->hs_nusers = 0,
- we = (struct whoent *)(buf + cc); --we >= wd->wd_we;)
+ for (hsp->hs_nusers = 0, we = &wd->wd_we[0];
+ (char *)(we + 1) <= (char *)wd + cc; we++)
if (aflg || we->we_idle < 3600)
++hsp->hs_nusers;
++hsp;
@@ -239,25 +236,25 @@
qsort(hs, nhosts, sizeof(hs[0]), cmp);
for (i = 0; i < (int)nhosts; i++) {
hsp = &hs[i];
+ wd = &hsp->hs_wd;
if (ISDOWN(hsp)) {
- (void)printf("%-25.25s%s\n", hsp->hs_wd->wd_hostname,
- interval(now - hsp->hs_wd->wd_recvtime, "down"));
+ (void)printf("%-25.25s%s\n", wd->wd_hostname,
+ interval(now - hsp->hs_wd.wd_recvtime, "down"));
continue;
}
(void)printf(
"%-25.25s%s, %4d user%s load %*.2f, %*.2f, %*.2f\n",
- hsp->hs_wd->wd_hostname,
- interval((time_t)hsp->hs_wd->wd_sendtime -
- (time_t)hsp->hs_wd->wd_boottime, " up"),
+ wd->wd_hostname,
+ interval((time_t)wd->wd_sendtime -
+ (time_t)wd->wd_boottime, " up"),
hsp->hs_nusers,
hsp->hs_nusers == 1 ? ", " : "s,",
maxloadav >= 1000 ? 5 : 4,
- hsp->hs_wd->wd_loadav[0] / 100.0,
+ wd->wd_loadav[0] / 100.0,
maxloadav >= 1000 ? 5 : 4,
- hsp->hs_wd->wd_loadav[1] / 100.0,
+ wd->wd_loadav[1] / 100.0,
maxloadav >= 1000 ? 5 : 4,
- hsp->hs_wd->wd_loadav[2] / 100.0);
- free(hsp->hs_wd);
+ wd->wd_loadav[2] / 100.0);
}
free(hs);
hs = NULL;
@@ -264,7 +261,7 @@
}
/* Number of users comparison. */
-int
+static int
ucmp(const void *a1, const void *a2)
{
if (ISDOWN(HS(a1)))
@@ -279,19 +276,19 @@
}
/* Uptime comparison. */
-int
+static int
tcmp(const void *a1, const void *a2)
{
return (rflg * (
- (ISDOWN(HS(a2)) ? HS(a2)->hs_wd->wd_recvtime - now
- : HS(a2)->hs_wd->wd_sendtime - HS(a2)->hs_wd->wd_boottime)
+ (ISDOWN(HS(a2)) ? HS(a2)->hs_wd.wd_recvtime - now
+ : HS(a2)->hs_wd.wd_sendtime - HS(a2)->hs_wd.wd_boottime)
-
- (ISDOWN(HS(a1)) ? HS(a1)->hs_wd->wd_recvtime - now
- : HS(a1)->hs_wd->wd_sendtime - HS(a1)->hs_wd->wd_boottime)
+ (ISDOWN(HS(a1)) ? HS(a1)->hs_wd.wd_recvtime - now
+ : HS(a1)->hs_wd.wd_sendtime - HS(a1)->hs_wd.wd_boottime)
));
}
-void
+static void
usage(void)
{
(void)fprintf(stderr, "usage: ruptime [-alrtu] [host ...]\n");
More information about the Midnightbsd-cvs
mailing list