1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1994-05-09 07:35:55 +04:00
|
|
|
* Copyright (c) 1980, 1991, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1994-05-09 07:35:55 +04:00
|
|
|
static char copyright[] =
|
|
|
|
"@(#) Copyright (c) 1980, 1991, 1993, 1994\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1994-05-09 07:35:55 +04:00
|
|
|
static char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94";
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* w - print system status (who and what)
|
|
|
|
*
|
|
|
|
* This program is similar to the systat command on Tenex/Tops 10/20
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/stat.h>
|
1994-05-09 07:35:55 +04:00
|
|
|
#include <sys/sysctl.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-05-09 07:35:55 +04:00
|
|
|
#include <sys/socket.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <sys/tty.h>
|
1994-05-09 07:35:55 +04:00
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <ctype.h>
|
1994-05-09 07:35:55 +04:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <nlist.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <paths.h>
|
|
|
|
#include <stdio.h>
|
1994-05-09 07:35:55 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <tzfile.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <utmp.h>
|
1993-07-15 21:55:48 +04:00
|
|
|
#include <vis.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
struct timeval boottime;
|
|
|
|
struct utmp utmp;
|
|
|
|
struct winsize ws;
|
|
|
|
kvm_t *kd;
|
|
|
|
time_t now; /* the current time of day */
|
|
|
|
time_t uptime; /* time of last reboot & elapsed time since */
|
|
|
|
int ttywidth; /* width of tty */
|
|
|
|
int argwidth; /* width of tty */
|
|
|
|
int header = 1; /* true if -h flag: don't print heading */
|
|
|
|
int nflag; /* true if -n flag: don't convert addrs */
|
|
|
|
int sortidle; /* sort bu idle time */
|
|
|
|
char *sel_user; /* login of particular user selected */
|
|
|
|
char domain[MAXHOSTNAMELEN];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1994-05-09 07:35:55 +04:00
|
|
|
* One of these per active utmp entry.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
struct entry {
|
|
|
|
struct entry *next;
|
|
|
|
struct utmp utmp;
|
|
|
|
dev_t tdev; /* dev_t of terminal */
|
1994-05-09 07:35:55 +04:00
|
|
|
time_t idle; /* idle time of terminal in seconds */
|
|
|
|
struct kinfo_proc *kp; /* `most interesting' proc */
|
1993-03-21 12:45:37 +03:00
|
|
|
char *args; /* arg list of interesting process */
|
|
|
|
} *ep, *ehead = NULL, **nextp = &ehead;
|
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
static void pr_header __P((time_t *, int));
|
|
|
|
static struct stat
|
|
|
|
*ttystat __P((char *));
|
|
|
|
static void usage __P((int));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
char *fmt_argv __P((char **, char *, int)); /* ../../bin/ps/fmt.c */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
1994-05-09 07:35:55 +04:00
|
|
|
extern char *__progname;
|
|
|
|
struct kinfo_proc *kp;
|
|
|
|
struct hostent *hp;
|
|
|
|
struct stat *stp;
|
1993-03-21 12:45:37 +03:00
|
|
|
FILE *ut;
|
1994-05-09 07:35:55 +04:00
|
|
|
u_long l;
|
|
|
|
size_t arglen;
|
|
|
|
int ch, i, nentries, nusers, wcmd;
|
|
|
|
char *memf, *nlistf, *p, *vis_args, *x;
|
|
|
|
char buf[MAXHOSTNAMELEN], errbuf[256];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
/* Are we w(1) or uptime(1)? */
|
|
|
|
p = __progname;
|
|
|
|
if (*p == '-')
|
|
|
|
p++;
|
|
|
|
if (*p == 'u') {
|
1993-03-21 12:45:37 +03:00
|
|
|
wcmd = 0;
|
1994-05-09 07:35:55 +04:00
|
|
|
p = "";
|
|
|
|
} else {
|
|
|
|
wcmd = 1;
|
|
|
|
p = "hiflM:N:nsuw";
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
memf = nlistf = NULL;
|
|
|
|
while ((ch = getopt(argc, argv, p)) != EOF)
|
|
|
|
switch (ch) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'h':
|
|
|
|
header = 0;
|
|
|
|
break;
|
|
|
|
case 'i':
|
1994-05-09 07:35:55 +04:00
|
|
|
sortidle = 1;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
header = 0;
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
nflag = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case 'f': case 'l': case 's': case 'u': case 'w':
|
1994-05-09 07:35:55 +04:00
|
|
|
warnx("[-flsuw] no longer supported");
|
|
|
|
/* FALLTHROUGH */
|
1993-03-21 12:45:37 +03:00
|
|
|
case '?':
|
|
|
|
default:
|
1994-05-09 07:35:55 +04:00
|
|
|
usage(wcmd);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == NULL)
|
|
|
|
errx(1, "%s", errbuf);
|
|
|
|
|
|
|
|
(void)time(&now);
|
|
|
|
if ((ut = fopen(_PATH_UTMP, "r")) == NULL)
|
|
|
|
err(1, "%s", _PATH_UTMP);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (*argv)
|
|
|
|
sel_user = *argv;
|
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
for (nusers = 0; fread(&utmp, sizeof(utmp), 1, ut);) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (utmp.ut_name[0] == '\0')
|
|
|
|
continue;
|
1994-05-09 07:35:55 +04:00
|
|
|
++nusers;
|
|
|
|
if (wcmd == 0 || (sel_user &&
|
1993-03-21 12:45:37 +03:00
|
|
|
strncmp(utmp.ut_name, sel_user, UT_NAMESIZE) != 0))
|
|
|
|
continue;
|
1994-05-09 07:35:55 +04:00
|
|
|
if ((ep = calloc(1, sizeof(struct entry))) == NULL)
|
|
|
|
err(1, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
*nextp = ep;
|
|
|
|
nextp = &(ep->next);
|
1994-05-09 07:35:55 +04:00
|
|
|
memmove(&(ep->utmp), &utmp, sizeof(struct utmp));
|
1994-06-30 12:08:08 +04:00
|
|
|
if (!(stp = ttystat(ep->utmp.ut_line)))
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
ep->tdev = stp->st_rdev;
|
1994-05-09 07:35:55 +04:00
|
|
|
#ifdef CPU_CONSDEV
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-05-09 07:35:55 +04:00
|
|
|
* If this is the console device, attempt to ascertain
|
|
|
|
* the true console device dev_t.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-05-09 07:35:55 +04:00
|
|
|
if (ep->tdev == 0) {
|
|
|
|
int mib[2];
|
|
|
|
size_t size;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
mib[0] = CTL_MACHDEP;
|
|
|
|
mib[1] = CPU_CONSDEV;
|
|
|
|
size = sizeof(dev_t);
|
|
|
|
(void) sysctl(mib, 2, &ep->tdev, &size, NULL, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-05-09 07:35:55 +04:00
|
|
|
#endif
|
|
|
|
if ((ep->idle = now - stp->st_atime) < 0)
|
|
|
|
ep->idle = 0;
|
|
|
|
}
|
|
|
|
(void)fclose(ut);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
if (header || wcmd == 0) {
|
|
|
|
pr_header(&now, nusers);
|
|
|
|
if (wcmd == 0)
|
|
|
|
exit (0);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define HEADER "USER TTY FROM LOGIN@ IDLE WHAT\n"
|
|
|
|
#define WUSED (sizeof (HEADER) - sizeof ("WHAT\n"))
|
1994-05-09 07:35:55 +04:00
|
|
|
(void)printf(HEADER);
|
|
|
|
|
|
|
|
if ((kp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nentries)) == NULL)
|
|
|
|
err(1, "%s", kvm_geterr(kd));
|
|
|
|
for (i = 0; i < nentries; i++, kp++) {
|
|
|
|
struct proc *p = &kp->kp_proc;
|
|
|
|
struct eproc *e;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
if (p->p_stat == SIDL || p->p_stat == SZOMB)
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
1994-05-09 07:35:55 +04:00
|
|
|
e = &kp->kp_eproc;
|
1993-03-21 12:45:37 +03:00
|
|
|
for (ep = ehead; ep != NULL; ep = ep->next) {
|
|
|
|
if (ep->tdev == e->e_tdev && e->e_pgid == e->e_tpgid) {
|
|
|
|
/*
|
|
|
|
* Proc is in foreground of this terminal
|
|
|
|
*/
|
1994-05-09 07:35:55 +04:00
|
|
|
if (proc_compare(&ep->kp->kp_proc, p))
|
|
|
|
ep->kp = kp;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-05-09 07:35:55 +04:00
|
|
|
if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
|
|
|
|
ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
|
|
|
|
ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
ttywidth = 79;
|
|
|
|
else
|
|
|
|
ttywidth = ws.ws_col - 1;
|
|
|
|
argwidth = ttywidth - WUSED;
|
|
|
|
if (argwidth < 4)
|
|
|
|
argwidth = 8;
|
|
|
|
for (ep = ehead; ep != NULL; ep = ep->next) {
|
1994-05-09 07:35:55 +04:00
|
|
|
if (ep->kp == NULL) {
|
|
|
|
ep->args = "-";
|
1993-04-26 19:50:34 +04:00
|
|
|
continue;
|
|
|
|
}
|
1994-05-09 07:35:55 +04:00
|
|
|
ep->args = fmt_argv(kvm_getargv(kd, ep->kp, argwidth),
|
|
|
|
ep->kp->kp_proc.p_comm, MAXCOMLEN);
|
|
|
|
if (ep->args == NULL)
|
|
|
|
err(1, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/* sort by idle time */
|
|
|
|
if (sortidle && ehead != NULL) {
|
|
|
|
struct entry *from = ehead, *save;
|
|
|
|
|
|
|
|
ehead = NULL;
|
|
|
|
while (from != NULL) {
|
1994-05-09 07:35:55 +04:00
|
|
|
for (nextp = &ehead;
|
1993-03-21 12:45:37 +03:00
|
|
|
(*nextp) && from->idle >= (*nextp)->idle;
|
|
|
|
nextp = &(*nextp)->next)
|
1994-05-09 07:35:55 +04:00
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
save = from;
|
|
|
|
from = from->next;
|
|
|
|
save->next = *nextp;
|
|
|
|
*nextp = save;
|
|
|
|
}
|
|
|
|
}
|
1994-05-09 07:35:55 +04:00
|
|
|
|
|
|
|
if (!nflag)
|
|
|
|
if (gethostname(domain, sizeof(domain) - 1) < 0 ||
|
|
|
|
(p = strchr(domain, '.')) == 0)
|
|
|
|
domain[0] = '\0';
|
|
|
|
else {
|
|
|
|
domain[sizeof(domain) - 1] = '\0';
|
|
|
|
memmove(domain, p, strlen(p) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vis_args = malloc(argwidth * 4 + 1)) == NULL)
|
|
|
|
err(1, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (ep = ehead; ep != NULL; ep = ep->next) {
|
1994-05-09 07:35:55 +04:00
|
|
|
p = *ep->utmp.ut_host ? ep->utmp.ut_host : "-";
|
|
|
|
if ((x = strchr(p, ':')) != NULL)
|
|
|
|
*x++ = '\0';
|
|
|
|
if (!nflag && isdigit(*p) &&
|
|
|
|
(long)(l = inet_addr(p)) != -1 &&
|
|
|
|
(hp = gethostbyaddr((char *)&l, sizeof(l), AF_INET))) {
|
|
|
|
if (domain[0] != '\0') {
|
|
|
|
p = hp->h_name;
|
|
|
|
p += strlen(hp->h_name);
|
|
|
|
p -= strlen(domain);
|
|
|
|
if (p > hp->h_name && strcmp(p, domain) == 0)
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
p = hp->h_name;
|
|
|
|
}
|
|
|
|
if (x) {
|
1994-06-30 11:18:44 +04:00
|
|
|
(void)snprintf(buf, sizeof(buf), "%s:%.*s", p,
|
|
|
|
ep->utmp.ut_host + UT_HOSTSIZE - x, x);
|
1994-05-09 07:35:55 +04:00
|
|
|
p = buf;
|
|
|
|
}
|
|
|
|
(void)printf("%-*.*s %-2.2s %-*.*s ",
|
|
|
|
UT_NAMESIZE, UT_NAMESIZE, ep->utmp.ut_name,
|
|
|
|
strncmp(ep->utmp.ut_line, "tty", 3) ?
|
|
|
|
ep->utmp.ut_line : ep->utmp.ut_line + 3,
|
|
|
|
UT_HOSTSIZE, UT_HOSTSIZE, *p ? p : "-");
|
|
|
|
pr_attime(&ep->utmp.ut_time, &now);
|
|
|
|
pr_idle(ep->idle);
|
|
|
|
if (ep->args != NULL) {
|
|
|
|
arglen = strlen(ep->args);
|
|
|
|
strvisx(vis_args, ep->args,
|
|
|
|
arglen > argwidth ? argwidth : arglen,
|
|
|
|
VIS_TAB | VIS_NL | VIS_NOSLASH);
|
|
|
|
}
|
|
|
|
(void)printf("%.*s\n", argwidth, ep->args);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
static void
|
|
|
|
pr_header(nowp, nusers)
|
|
|
|
time_t *nowp;
|
|
|
|
int nusers;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:35:55 +04:00
|
|
|
double avenrun[3];
|
|
|
|
time_t uptime;
|
|
|
|
int days, hrs, i, mins;
|
|
|
|
int mib[2];
|
|
|
|
size_t size;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print time of day.
|
|
|
|
*
|
|
|
|
* SCCS forces the string manipulation below, as it replaces
|
|
|
|
* %, M, and % in a character string with the file name.
|
|
|
|
*/
|
|
|
|
(void)strftime(buf, sizeof(buf),
|
|
|
|
__CONCAT("%l:%","M%p"), localtime(nowp));
|
|
|
|
(void)printf("%s ", buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
/*
|
|
|
|
* Print how long system has been up.
|
|
|
|
* (Found by looking getting "boottime" from the kernel)
|
|
|
|
*/
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_BOOTTIME;
|
|
|
|
size = sizeof(boottime);
|
|
|
|
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
|
|
|
|
boottime.tv_sec != 0) {
|
|
|
|
uptime = now - boottime.tv_sec;
|
|
|
|
uptime += 30;
|
|
|
|
days = uptime / SECSPERDAY;
|
|
|
|
uptime %= SECSPERDAY;
|
|
|
|
hrs = uptime / SECSPERHOUR;
|
|
|
|
uptime %= SECSPERHOUR;
|
|
|
|
mins = uptime / SECSPERMIN;
|
|
|
|
(void)printf(" up");
|
|
|
|
if (days > 0)
|
|
|
|
(void)printf(" %d day%s,", days, days > 1 ? "s" : "");
|
|
|
|
if (hrs > 0 && mins > 0)
|
|
|
|
(void)printf(" %2d:%02d,", hrs, mins);
|
|
|
|
else {
|
|
|
|
if (hrs > 0)
|
|
|
|
(void)printf(" %d hr%s,",
|
|
|
|
hrs, hrs > 1 ? "s" : "");
|
|
|
|
if (mins > 0)
|
|
|
|
(void)printf(" %d min%s,",
|
|
|
|
mins, mins > 1 ? "s" : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print number of users logged in to system */
|
|
|
|
(void)printf(" %d user%s", nusers, nusers > 1 ? "s" : "");
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
/*
|
|
|
|
* Print 1, 5, and 15 minute load averages.
|
|
|
|
*/
|
|
|
|
if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) == -1)
|
|
|
|
(void)printf(", no load average information available\n");
|
|
|
|
else {
|
|
|
|
(void)printf(", load averages:");
|
|
|
|
for (i = 0; i < (sizeof(avenrun) / sizeof(avenrun[0])); i++) {
|
|
|
|
if (i > 0)
|
|
|
|
(void)printf(",");
|
|
|
|
(void)printf(" %.2f", avenrun[i]);
|
|
|
|
}
|
|
|
|
(void)printf("\n");
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
static struct stat *
|
|
|
|
ttystat(line)
|
|
|
|
char *line;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:35:55 +04:00
|
|
|
static struct stat sb;
|
|
|
|
char ttybuf[MAXPATHLEN];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
(void)snprintf(ttybuf, sizeof(ttybuf), "%s/%s", _PATH_DEV, line);
|
|
|
|
if (stat(ttybuf, &sb))
|
1994-06-30 12:08:08 +04:00
|
|
|
return (NULL);
|
1994-05-09 07:35:55 +04:00
|
|
|
return (&sb);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:35:55 +04:00
|
|
|
static void
|
|
|
|
usage(wcmd)
|
|
|
|
int wcmd;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:35:55 +04:00
|
|
|
if (wcmd)
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"usage: w: [-hin] [-M core] [-N system] [user]\n");
|
|
|
|
else
|
|
|
|
(void)fprintf(stderr, "uptime\n");
|
|
|
|
exit (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|