home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-25 | 32.9 KB | 1,541 lines |
- Newsgroups: comp.sources.misc
- subject: v11i086: statline - BSD sysline clone for System V/Xenix
- From: staceyc@sco.UUCP
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 11, Issue 86
- Submitted-by: staceyc@sco.UUCP
- Archive-name: statline/part01
-
- This is a System V/Xenix clone of a BSD PD program called sysline.
- Statline displays system and user information on the hardware
- status line of a terminal.
-
- It has been compiled and runs under Xenix 2.3 on a 386 box,
- System 5.3.2 on a AT&T 3b2, and SCO Unix 5.3.2. It should be
- readily portable to any System 5.3 based operating system.
-
- Statline has the following flags;
-
- -d date [default]
- -l machine load [default]
- -c user count [default]
- -u current logins
- -g logins/logouts [default]
- -t machine uptime [default]
- -b mail arrival
-
- #!/bin/sh
- # Created by mshar - shell archiver
- #
- # This archive contains:
- # README
- # statline.1
- # Makefile
- # biff.c
- # date.c
- # statline.c
- # users.c
- # kmem.sysv.c
- # kmem.xenix.c
- # editwarn.c
- # funcs.h
- # types.h
- #
- PATH=/bin:$PATH
- echo 'mshar: extracting README (size: 2736)'
- sed 's/^X//' << 'GURK' > README &&
- X Statline 1.0
- X ------------
- X
- XThis is a System V/Xenix clone of a BSD PD program called sysline.
- XStatline displays system and user information on the hardware
- Xstatus line of a terminal.
- X
- XIt has been compiled and runs under Xenix 2.3 on a 386 box,
- XSystem 5.3.2 on a AT&T 3b2, and SCO Unix 5.3.2. It should be
- Xreadily portable to any System 5.3 based operating system.
- X
- XStatline has the following flags;
- X
- X -d date [default]
- X -l machine load [default]
- X -c user count [default]
- X -u current logins
- X -g logins/logouts [default]
- X -t machine uptime [default]
- X -b mail arrival
- X
- XSpecifying an upper case flag switches that option off.
- X
- XStatline takes one parameter which is the number of seconds to
- Xsleep between updates.
- X
- XThe machine load and uptime are calculated from values in
- X/dev/kmem. This means statline expects to read /unix (or
- X/xenix) using nlist(2) (xlist(3)) to obtain the offset of
- Xcertain symbols in the kernel.
- X
- XOn systems where security is not an issue this is as simple
- Xas making /unix and /dev/kmem readable by all. The alternative
- Xis to make use of /etc/group and either establish or use an
- Xexisting group privilege to access the files.
- X
- XFor example under Xenix 2.3 /xenix and /dev/kmem typically
- Xallow access to group 'sysinfo'. To enable statline to read these
- Xfiles do the following;
- X
- X$ su root
- X# chgrp sysinfo /usr/local/bin/statline
- X# chmod g+s /usr/local/bin/statline
- X# chmod g+r /dev/kmem /xenix
- X
- XUser information is read from /etc/utmp. This is usually
- Xreadable by all, so privileges should not be an issue.
- X
- XThe cpu load information is slightly different between Unix
- Xand Xenix; there is a corresponding difference in the display.
- XThe mail notification routine is fairly simple minded and
- Xmay need tweaking.
- X
- XStatline will attempt to show as much information as possible,
- Xso if it cannot read /dev/kmem it will still show other
- Xnon-kernel displays.
- X
- XStatline uses the following terminal capablities;
- X
- X hs - termial has status line
- X tsl - to status line
- X fsl - from status line
- X wsl - width of status line
- X
- XThese capabilities are extracted from terminfo(4) files under
- XUnix 5.3, or terminfo(4) or termcap(M) under Xenix 2.3. Thanks
- Xto Jon Luini for adding termcap support for SCO Unix/Xenix.
- X
- XStatline forks a process that runs in the background. The process
- Xshould be killed with SIGTERM (15) or SIGHUP (1).
- X
- XEdit the Makefile to reflect your compiling and running environment.
- X
- XGood luck!
- X
- XStacey Campbell _--_|\
- X{uunet,ucscc,decwrl,att,microsoft,wyse}!sco!staceyc / \
- Xstaceyc@sco.com \_.--._/
- X v
- GURK
- chmod 0644 README || echo 'restore of README fails'
- echo 'mshar: extracting statline.1 (size: 847)'
- sed 's/^X//' << 'GURK' > statline.1 &&
- X.TH Statline 1l
- X.SH NAME
- Xstatline \- display user/system information on terminal status line
- X.SH SYNOPSIS
- X.B statline
- X.B [\-dlcugtb] [N]
- X.SH DESCRIPTION
- X.I Statline
- Xdisplays information about the system and the system's users on
- Xthe hardware status line of a terminal. N is the number
- Xof seconds to sleep between display updates.
- XOptions are:
- X.TP
- X.B \-d
- Xdisplay the current time
- X.TP
- X.B \-l
- Xmachine load
- X.TP
- X.B \-c
- Xuser count
- X.TP
- X.B \-u
- Xcurrent logins
- X.TP
- X.B \-g
- Xdisplay users logging on or off the system
- X.TP
- X.B \-t
- Xmachine uptime
- X.TP
- X.B \-b
- Xmail arrival
- X.TP
- X.B \-h
- X.I statline
- Xoptions and the defaults
- X.PP
- XUsing an upper case flag disables the given option.
- X.SH BUGS
- XUnknown, but please send bug problems to {uunet,ucscc,decwrl,sun}!sco!staceyc
- Xor staceyc@sco.com.
- X.SH AUTHOR
- XStacey Campbell \- Santa Cruz, California, USA \- March 1990
- GURK
- chmod 0640 statline.1 || echo 'restore of statline.1 fails'
- echo 'mshar: extracting Makefile (size: 983)'
- sed 's/^X//' << 'GURK' > Makefile &&
- X# statline makefile
- X
- XOBJS= statline.o biff.o date.o kmem.o users.o
- XSRC= biff.c date.c statline.c users.c kmem.sysv.c kmem.xenix.c editwarn.c
- XINCLUDES= funcs.h types.h
- XDOC= README $(EXE).1
- XARCFILES= $(DOC) Makefile $(SRC) $(INCLUDES)
- X
- X# Xenix - terminfo
- X#PFLAGS= -DM_TERMINFO
- X#LDLIBS= -ltinfo
- X
- X# Xenix - termcap
- X#PFLAGS= -DM_TERMCAP
- X#LDLIBS= -ltermlib
- X
- X# System V
- XPFLAGS=
- XLDLIBS= -lcurses
- X
- XCFLAGS= -O $(PFLAGS)
- XEXE= statline
- X
- X$(EXE): $(OBJS)
- X cc $(CFLAGS) $(OBJS) -o $(EXE) $(LDLIBS)
- X
- Xclean:
- X rm -f core $(OBJS) $(EXE) kmem.c
- X
- Xtar:
- X tar cvf $(EXE).tar $(ARCFILES)
- X
- Xshar:
- X mshar $(ARCFILES) > $(EXE).shar
- X
- Xkmem.o: kmem.c
- X
- Xkmem.c: kmem.sysv.c kmem.xenix.c
- X @if test -f /unix ; then \
- X echo "Using System V kmem routines." ; \
- X cat editwarn.c kmem.sysv.c > kmem.c ; \
- X else \
- X if test -f /xenix ; then \
- X echo "Using Xenix kmem routines." ; \
- X cat editwarn.c kmem.xenix.c > kmem.c ; \
- X else \
- X echo "Where is /unix?? Warm up the editor." ; \
- X fi \
- X fi
- GURK
- chmod 0644 Makefile || echo 'restore of Makefile fails'
- echo 'mshar: extracting biff.c (size: 3252)'
- sed 's/^X//' << 'GURK' > biff.c &&
- X#include <stdio.h>
- X#include <string.h>
- X#include <time.h>
- X#include <sys/types.h>
- X#include "types.h"
- X#include "funcs.h"
- X
- X#define MESSAGE "mail has arrived from "
- X
- Xextern char *getenv();
- Xextern char *malloc();
- Xextern void free();
- X
- Xstatic void DoWarning();
- X
- Xextern char *TermBell;
- Xextern time_t Now;
- X
- Xstatic char *MonthCmp[] = {
- X "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
- X "Nov", "Dec"};
- X
- Xstatic char *MailFile;
- Xstatic struct tm StartTm;
- Xstatic long StartDaySecond;
- Xstatic long Check;
- X
- Xstatic int MonthVal(str)
- X
- Xchar *str;
- X
- X {
- X int i;
- X
- X for (i = 0; i < sizeof(MonthCmp) / sizeof(MonthCmp[0]); ++i)
- X if (strcmp(MonthCmp[i], str) == 0)
- X return i;
- X return -1;
- X }
- X
- Xint BiffFnInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X char *home;
- X long start;
- X char *check_str;
- X static char spool[256];
- X
- X if (! (MailFile = getenv("MAIL")))
- X if ((home = getenv("HOME")) && (home = strrchr(home, '/')))
- X {
- X sprintf(spool, "/usr/spool/mail%s", home);
- X MailFile = spool;
- X }
- X else
- X {
- X DisplayAdd(display, "unknown mail spool file ");
- X return 0;
- X }
- X else
- X {
- X strcpy(spool, MailFile);
- X MailFile = spool;
- X }
- X if (! (check_str = getenv("MAILCHECK")))
- X Check = 30;
- X else
- X {
- X Check = atol(check_str);
- X if (Check <= 0)
- X Check = 30;
- X }
- X start = Now;
- X StartTm = *localtime(&start);
- X StartDaySecond = StartTm.tm_hour * 60 * 60 + StartTm.tm_min * 60 +
- X StartTm.tm_sec;
- X StartDaySecond = StartTm.tm_mday * 24 * 60 * 60 + StartTm.tm_hour
- X * 60 * 60 + StartTm.tm_min * 60 + StartTm.tm_sec;
- X
- X return 1;
- X }
- X
- Xint BiffFn(display)
- X
- Xdisplay_t *display;
- X
- X {
- X long start, current;
- X FILE *fp;
- X char buf[256];
- X int count;
- X char from[6], user[129], wday[6], month[6];
- X int day, hour, minute, second, year, monthval;
- X int warn = 0;
- X long day_second;
- X static long last_check = 0;
- X
- X current = Now;
- X if (last_check + Check > current)
- X return 1;
- X
- X last_check = current;
- X
- X if ((fp = fopen(MailFile, "r")) == NULL)
- X {
- X DisplayAdd(display, "biff: cannot read spool file ");
- X return 0;
- X }
- X
- X while (fgets(buf, sizeof(buf), fp) != NULL)
- X {
- X if (buf[0] != 'F')
- X continue;
- X count = sscanf(buf,
- X "%5s %128s %4s %4s %d %d:%d:%d %d",
- X from, user, wday, month, &day, &hour,
- X &minute, &second, &year);
- X if (count == 9 && strcmp(from, "From") == 0 &&
- X ((monthval = MonthVal(month)) != -1))
- X {
- X year -= 1900;
- X day_second = day * 24 * 60 * 60 + hour
- X * 60 * 60 + minute * 60 + second;
- X if ((year > StartTm.tm_year)
- X ||
- X (year == StartTm.tm_year &&
- X monthval > StartTm.tm_mon)
- X ||
- X (year == StartTm.tm_year &&
- X monthval == StartTm.tm_mon &&
- X day_second >= StartDaySecond))
- X {
- X DoWarning(display, user);
- X warn = 1;
- X }
- X }
- X }
- X
- X if (warn)
- X {
- X start = time((time_t *)0);
- X StartTm = *localtime(&start);
- X StartDaySecond = StartTm.tm_mday * 24 * 60
- X * 60 + StartTm.tm_hour * 60 * 60 +
- X StartTm.tm_min * 60 + StartTm.tm_sec;
- X }
- X
- X (void)fclose(fp);
- X
- X return 1;
- X }
- X
- Xstatic void DoWarning(display, user)
- X
- Xdisplay_t *display;
- Xchar *user;
- X
- X {
- X char *buffer;
- X
- X buffer = malloc(strlen(user) + sizeof(MESSAGE) + 5);
- X sprintf(buffer, "%s%s ", MESSAGE, user);
- X DisplayAdd(display, buffer);
- X free(buffer);
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X }
- GURK
- chmod 0644 biff.c || echo 'restore of biff.c fails'
- echo 'mshar: extracting date.c (size: 467)'
- sed 's/^X//' << 'GURK' > date.c &&
- X#include <time.h>
- X#include <sys/types.h>
- X#include <string.h>
- X#include "types.h"
- X#include "funcs.h"
- X
- Xextern char *malloc();
- Xextern void free();
- X
- Xextern time_t Now;
- X
- Xint DateFnInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X return 1;
- X }
- X
- Xint DateFn(display)
- X
- Xdisplay_t *display;
- X
- X {
- X long clock;
- X struct tm tm;
- X char buf[32];
- X
- X clock = Now;
- X tm = *localtime(&clock);
- X sprintf(buf, "%.2d:%.2d:%.2d ", tm.tm_hour, tm.tm_min, tm.tm_sec);
- X DisplayAdd(display, buf);
- X
- X return 1;
- X }
- GURK
- chmod 0644 date.c || echo 'restore of date.c fails'
- echo 'mshar: extracting statline.c (size: 9371)'
- sed 's/^X//' << 'GURK' > statline.c &&
- X#include <signal.h>
- X#include <time.h>
- X#include <string.h>
- X#include <sys/types.h>
- X
- X#if (defined(M_XENIX) && defined(M_TERMINFO)) || ! defined(M_XENIX)
- X#define USE_TERMINFO
- X#endif
- X
- X#ifdef USE_TERMINFO
- X#include <curses.h>
- X#include <term.h>
- X#define TERMMODE "terminfo"
- X#define GETFLAG(flag) tigetflag(flag)
- X#define GETNUM(flag) tigetnum(flag)
- X#define GETPARM(flag) tparm(flag, 0)
- X#else
- X#include <stdio.h>
- X#include <sgtty.h>
- X#define TERMMODE "termcap"
- X#define reset_shell_mode() ;
- X#define GETFLAG(flag) tgetflag(flag, &area)
- X#define GETNUM(flag) tgetnum(flag, &area)
- X#define GETPARM(flag) tgetstr(flag, &area)
- X#endif
- X
- X#include <ctype.h>
- X#include "types.h"
- X#include "funcs.h"
- X
- X#define SLEEP_DEFAULT 10
- X#define DIS_BUF_BLOCK 128
- X#define CONT "..."
- X
- Xextern char *malloc(), *realloc();
- Xextern void free();
- X#ifndef USE_TERMINFO
- Xextern char *getenv();
- Xextern char *tgetstr();
- X#endif
- X
- Xchar *TermBell;
- Xtime_t Now;
- X
- Xstatic char *DefaultBell = "\007";
- Xstatic display_t *CleanDisplay;
- X
- Xstatic int InitStatusLine();
- Xstatic void ProcessOptions();
- Xstatic void Usage();
- Xstatic void ShowDisplay();
- Xstatic void PutStatLine();
- Xstatic int FormChunk();
- Xstatic void CleanUp();
- Xstatic void TermInit();
- X
- Xint main(argc, argv)
- X
- Xint argc;
- Xchar **argv;
- X
- X {
- X int errret, i;
- X long sleeptime;
- X int fn_list_size;
- X static display_t display;
- X static fn_list_t fn_list[] = {
- X {DateFn, DateFnInit, 1, 'd', "date"},
- X {LoadFn, LoadFnInit, 1, 'l', "machine load"},
- X {UsersCountFn, UsersCountFnInit, 1, 'c', "user count"},
- X {UsersFn, UsersFnInit, 0, 'u', "current logins"},
- X {UsersDelta, UsersDeltaInit, 1, 'g', "logins/logouts"},
- X {UptimeFn, UptimeFnInit, 1, 't', "machine uptime"},
- X {BiffFn, BiffFnInit, 0, 'b', "mail arrival"}};
- X
- X fn_list_size = sizeof(fn_list) / sizeof(fn_list[0]);
- X ProcessOptions(argc, argv, fn_list, fn_list_size, &sleeptime);
- X TermInit(argv[0]);
- X if (InitStatusLine(argv[0], &display.stat_line_info))
- X {
- X reset_shell_mode();
- X exit(1);
- X }
- X errret = fork();
- X if (errret == -1)
- X {
- X reset_shell_mode();
- X perror(argv[0]);
- X exit(1);
- X }
- X if (errret)
- X {
- X reset_shell_mode();
- X exit(0);
- X }
- X CleanDisplay = &display;
- X (void)signal(SIGTERM, CleanUp);
- X (void)signal(SIGHUP, CleanUp);
- X (void)signal(SIGINT, SIG_IGN);
- X (void)signal(SIGQUIT, SIG_IGN);
- X Now = time((time_t *)0);
- X for (i = 0; i < fn_list_size; ++i)
- X if (fn_list[i].call)
- X fn_list[i].call = (*fn_list[i].init_fn_name)(&display);
- X ShowDisplay(&display, sleeptime);
- X for (;;)
- X {
- X Now = time((time_t *)0);
- X for (i = 0; i < fn_list_size; ++i)
- X if (fn_list[i].call)
- X fn_list[i].call =
- X (*fn_list[i].fn_name)(&display);
- X ShowDisplay(&display, sleeptime);
- X }
- X }
- X
- Xstatic void ShowDisplay(display, sleeptime)
- X
- Xdisplay_t *display;
- Xlong sleeptime;
- X
- X {
- X int index;
- X long sub_sleep;
- X stat_line_info_t *info;
- X static char *buf = 0;
- X static int sub_width;
- X
- X info = &display->stat_line_info;
- X if (! display->display_len)
- X {
- X DisplayAdd(display, " ");
- X ShowDisplay(display, sleeptime);
- X return;
- X }
- X if (! buf)
- X {
- X buf = malloc(info->width + 2);
- X sub_width = info->width - sizeof(CONT) - 1;
- X }
- X sub_sleep = sleeptime / (display->display_len / sub_width + 1);
- X if (sub_sleep < 2)
- X sub_sleep = 2;
- X index = 0;
- X while (index + sub_width < display->display_len)
- X {
- X index += FormChunk(buf, &display->buffer[index], sub_width);
- X PutStatLine(buf, CONT, &display->stat_line_info, sub_sleep);
- X }
- X PutStatLine(&display->buffer[index], "", &display->stat_line_info,
- X sub_sleep);
- X display->buffer[0] = '\0';
- X display->display_len = 0;
- X }
- X
- Xstatic int FormChunk(buf, str, max_width)
- X
- Xchar *buf;
- Xchar *str;
- Xint max_width;
- X
- X {
- X int i;
- X
- X i = max_width - 1;
- X while (i >= 0 && str[i] != ' ')
- X --i;
- X if (i > 0)
- X {
- X memcpy(buf, str, i);
- X buf[i] = '\0';
- X return i;
- X }
- X memcpy(buf, str, max_width);
- X buf[max_width] = '\0';
- X
- X return max_width;
- X }
- X
- Xstatic void PutStatLine(str, sup, info, sleeptime)
- X
- Xchar *str;
- Xchar *sup;
- Xstat_line_info_t *info;
- Xlong sleeptime;
- X
- X {
- X int total;
- X static char *out_buf = 0;
- X static char *buf = 0;
- X
- X if (! buf)
- X {
- X buf = malloc(info->width + info->tsl_len + info->fsl_len + 2);
- X out_buf = malloc(info->width + 2);
- X }
- X (void)sprintf(out_buf, "%s%s", str, sup);
- X total = strlen(out_buf);
- X while (total < info->width)
- X {
- X out_buf[total] = ' ';
- X ++total;
- X }
- X out_buf[total] = '\0';
- X sprintf(buf, "%s%s%s", info->tsl, out_buf, info->fsl);
- X total = strlen(buf);
- X (void)write(fileno(stdout), buf, total);
- X (void)sleep(sleeptime);
- X }
- X
- Xstatic void ProcessOptions(argc, argv, fn_list, fn_list_size, sleeptime)
- X
- Xint argc;
- Xchar **argv;
- Xfn_list_t *fn_list;
- Xint fn_list_size;
- Xlong *sleeptime;
- X
- X {
- X int i, opt, index;
- X char *optstring;
- X fn_list_t *init_list;
- X extern int optind;
- X
- X optstring = malloc(fn_list_size * 2 + 1);
- X init_list = (fn_list_t *)malloc(sizeof(fn_list_t) * fn_list_size);
- X for (i = 0; i < fn_list_size; ++i)
- X {
- X index = i * 2;
- X optstring[index] = fn_list[i].flag;
- X optstring[index + 1] = toupper(fn_list[i].flag);
- X init_list[i] = fn_list[i];
- X }
- X optstring[fn_list_size * 2] = '\0';
- X while ((opt = getopt(argc, argv, optstring)) != EOF)
- X {
- X i = 0;
- X while (i < fn_list_size && opt != fn_list[i].flag &&
- X opt != toupper(fn_list[i].flag))
- X ++i;
- X if (i < fn_list_size)
- X fn_list[i].call = fn_list[i].flag == opt;
- X else
- X Usage(argv[0], init_list, fn_list_size);
- X }
- X if (optind == argc)
- X *sleeptime = SLEEP_DEFAULT;
- X else
- X if (optind + 1 == argc)
- X {
- X *sleeptime = atol(argv[optind]);
- X if (sleeptime <= 0)
- X Usage(argv[0], init_list, fn_list_size);
- X }
- X else
- X Usage(argv[0], init_list, fn_list_size);
- X free(optstring);
- X free(init_list);
- X }
- X
- Xstatic void Usage(prog, fn_list, fn_list_size)
- X
- Xchar *prog;
- Xfn_list_t *fn_list;
- Xint fn_list_size;
- X
- X {
- X int i;
- X
- X fprintf(stderr, "usage: %s [-", prog);
- X for (i = 0; i < fn_list_size; ++i)
- X fprintf(stderr, "%c", fn_list[i].flag);
- X fprintf(stderr, "] [N]\n\n");
- X fprintf(stderr, "Descriptions:\n");
- X for (i = 0; i < fn_list_size; ++i)
- X {
- X fprintf(stderr, "\t-%c\t %s", fn_list[i].flag, fn_list[i].desc);
- X if (fn_list[i].call)
- X fprintf(stderr, " [default]");
- X fprintf(stderr, "\n");
- X }
- X fprintf(stderr, "\tN = seconds to sleep between iterations ");
- X fprintf(stderr, "[default %d]\n", SLEEP_DEFAULT);
- X fprintf(stderr, "Upper case flag switches display off.\n");
- X exit(1);
- X }
- X
- Xstatic int InitStatusLine(prog, stat_line_info)
- X
- Xchar *prog;
- Xstat_line_info_t *stat_line_info;
- X
- X {
- X int errret;
- X char *buf;
- X int len;
- X int width;
- X char *tsl, *fsl;
- X#ifndef USE_TERMINFO
- X static char buffer[200], *area = buffer;
- X#endif
- X
- X if ((errret = GETFLAG("hs")) <= 0)
- X {
- X fprintf(stderr, "%s: ", prog);
- X if (errret == 0)
- X {
- X fprintf(stderr, "status line not supported ");
- X fprintf(stderr, "by terminal\n");
- X }
- X else
- X fprintf(stderr, "bogus 'hs' %s entry\n", TERMMODE);
- X return 1;
- X }
- X width = GETNUM("wsl");
- X if (width == -2)
- X {
- X fprintf(stderr, "%s: bogus 'wsl' %s entry\n", prog, TERMMODE);
- X return 1;
- X }
- X if (width <= 0)
- X {
- X width = GETNUM("cols");
- X if (width <= 0)
- X width = 40; /* hope this is reasonable */
- X }
- X stat_line_info->width = width - 1;
- X#ifdef USE_TERMINFO
- X tsl = GETPARM(to_status_line);
- X#else
- X tsl = GETPARM("ts");
- X#endif
- X if (!tsl)
- X {
- X fprintf(stderr, "%s: no to status line %s entry\n", prog,
- X TERMMODE);
- X return 1;
- X }
- X len = strlen(tsl);
- X buf = malloc(len + 1);
- X strcpy(buf, tsl);
- X stat_line_info->tsl = buf;
- X stat_line_info->tsl_len = len;
- X#ifdef USE_TERMINFO
- X fsl = GETPARM(from_status_line);
- X#else
- X fsl = GETPARM("fs");
- X#endif
- X
- X if (!fsl)
- X {
- X fprintf(stderr, "%s: no from status line %s entry\n", prog,
- X TERMMODE);
- X return 1;
- X }
- X len = strlen(fsl);
- X buf = malloc(len + 1);
- X strcpy(buf, fsl);
- X stat_line_info->fsl = buf;
- X stat_line_info->fsl_len = len;
- X#ifdef USE_TERMINFO
- X if (TermBell = GETPARM(bell))
- X#else
- X if (TermBell = GETPARM("vb"))
- X#endif
- X {
- X buf = malloc(strlen(TermBell) + 1);
- X strcpy(buf, TermBell);
- X TermBell = buf;
- X }
- X else
- X TermBell = DefaultBell;
- X
- X return 0;
- X }
- X
- Xvoid DisplayAdd(display, str)
- X
- Xdisplay_t *display;
- Xchar *str;
- X
- X {
- X int len, new_dis_len;
- X
- X len = strlen(str);
- X new_dis_len = display->display_len + len;
- X while (new_dis_len + 1 >= display->buf_len)
- X {
- X if (display->buffer)
- X display->buffer = realloc(display->buffer,
- X display->buf_len += DIS_BUF_BLOCK);
- X else
- X display->buffer = malloc(
- X display->buf_len = DIS_BUF_BLOCK);
- X new_dis_len = display->display_len + len;
- X }
- X strcpy(&display->buffer[display->display_len], str);
- X display->display_len = new_dis_len;
- X }
- X
- Xstatic void CleanUp(sig_no)
- X
- Xint sig_no;
- X
- X {
- X (void)signal(SIGHUP, SIG_IGN);
- X (void)signal(SIGTERM, SIG_IGN);
- X CleanDisplay->display_len = 0;
- X ShowDisplay(CleanDisplay, 1);
- X reset_shell_mode();
- X
- X exit(0);
- X }
- X
- X#ifdef USE_TERMINFO
- X
- Xstatic void TermInit(prog)
- X
- Xchar *prog;
- X
- X {
- X int errret;
- X
- X if (setupterm((char *)0, 1, &errret) == ERR)
- X {
- X fprintf(stderr, "%s: setupterm failed - %d\n", prog, errret);
- X exit(1);
- X }
- X }
- X
- X#else
- X
- Xstatic void TermInit(prog)
- X
- Xchar *prog;
- X
- X {
- X static char bp[1024];
- X char *term;
- X
- X term = getenv("TERM");
- X if (! term)
- X {
- X fprintf(stderr, "%s: bad TERM variable\n", prog);
- X exit(1);
- X }
- X switch (tgetent(bp, term))
- X {
- X case -1 :
- X fprintf(stderr, "%s: can't open termcap file.\n", prog);
- X exit(1);
- X break;
- X case 0:
- X fprintf(stderr, "%s: no termcap entry for %s.\n", term);
- X exit(1);
- X }
- X }
- X
- X#endif
- GURK
- chmod 0644 statline.c || echo 'restore of statline.c fails'
- echo 'mshar: extracting users.c (size: 3938)'
- sed 's/^X//' << 'GURK' > users.c &&
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <utmp.h>
- X#include <string.h>
- X#include "types.h"
- X#include "funcs.h"
- X
- X#define USER_SIZE (sizeof(sizeutmp.ut_user) / sizeof(sizeutmp.ut_user[0]))
- X
- Xextern char *malloc(), *realloc();
- Xextern void qsort();
- X
- Xextern time_t Now;
- X
- Xstatic int Users();
- Xstatic int AddUser();
- Xstatic int UserCmp();
- Xstatic int InUserList();
- X
- Xstatic char **UserList = 0;
- Xstatic int UserListSize = 0;
- Xstatic struct utmp sizeutmp;
- X
- Xint UsersCountFnInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X return 1;
- X }
- X
- Xint UsersCountFn(display)
- X
- Xdisplay_t *display;
- X
- X {
- X int user_count;
- X char buf[128];
- X
- X user_count = Users();
- X if (user_count < 0)
- X {
- X DisplayAdd(display, "cannot read /etc/utmp ");
- X return 0;
- X }
- X sprintf(buf, "uc: %d ", user_count);
- X DisplayAdd(display, buf);
- X
- X return 1;
- X }
- X
- Xint UsersFnInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X return 1;
- X }
- X
- Xint UsersFn(display)
- X
- Xdisplay_t *display;
- X
- X {
- X int i;
- X int user_count;
- X
- X user_count = Users();
- X if (user_count < 0)
- X {
- X DisplayAdd(display, "cannot read /etc/utmp");
- X return 0;
- X }
- X if (user_count == 0)
- X {
- X DisplayAdd(display, "no users ");
- X return 1;
- X }
- X DisplayAdd(display, "users: ");
- X for (i = 0; i < user_count; ++i)
- X {
- X DisplayAdd(display, UserList[i]);
- X DisplayAdd(display, " ");
- X }
- X
- X return 1;
- X }
- X
- Xint UsersDeltaInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X return 1;
- X }
- X
- Xint UsersDelta(display)
- X
- Xdisplay_t *display;
- X
- X {
- X int i;
- X int user_count;
- X static char **old_list = 0;
- X static int old_list_count = 0;
- X static int old_list_size = 0;
- X
- X user_count = Users();
- X if (user_count < 0)
- X {
- X DisplayAdd(display, "delta cannot read /etc/utmp");
- X return 0;
- X }
- X for (i = 0; i < old_list_count; ++i)
- X if (! InUserList(old_list[i], UserList, user_count))
- X {
- X DisplayAdd(display, old_list[i]);
- X DisplayAdd(display, "(off) ");
- X }
- X for (i = 0; i < user_count; ++i)
- X if (! InUserList(UserList[i], old_list, old_list_count))
- X {
- X DisplayAdd(display, UserList[i]);
- X DisplayAdd(display, "(on) ");
- X }
- X if (user_count == 0 && old_list_count == 0)
- X return 1;
- X if (user_count > old_list_size)
- X {
- X if (! old_list)
- X old_list = (char **)malloc(sizeof(char **) *
- X user_count);
- X else
- X old_list = (char **)realloc(old_list,
- X sizeof(char **) * user_count);
- X for (i = old_list_size; i < user_count; ++i)
- X old_list[i] = malloc(USER_SIZE + 1);
- X old_list_size = user_count;
- X }
- X for (i = 0; i < user_count; ++i)
- X strcpy(old_list[i], UserList[i]);
- X old_list_count = user_count;
- X
- X return 1;
- X }
- X
- Xstatic int InUserList(name, list, list_count)
- X
- Xchar *name;
- Xchar **list;
- Xint list_count;
- X
- X {
- X int i;
- X
- X i = 0;
- X while (i < list_count && strcmp(name, list[i]))
- X ++i;
- X
- X return i < list_count;
- X }
- X
- Xstatic int Users()
- X
- X {
- X FILE *fp;
- X struct utmp utmp;
- X static time_t last_check = 0;
- X static int user_count = 0;
- X
- X if (last_check == Now) /* go easy on file system */
- X return user_count;
- X if ((fp = fopen("/etc/utmp", "r")) == NULL)
- X return -1;
- X user_count = 0;
- X while (fread((char *)&utmp, sizeof(utmp), 1, fp) == 1)
- X if (utmp.ut_user[0] != '\0' && utmp.ut_type == USER_PROCESS)
- X if (AddUser(&utmp, user_count))
- X ++user_count;
- X (void)fclose(fp);
- X
- X if (user_count)
- X qsort((char *)UserList, user_count, sizeof(char *), UserCmp);
- X
- X last_check = Now;
- X
- X return user_count;
- X }
- X
- Xstatic int UserCmp(s1, s2)
- X
- Xchar **s1;
- Xchar **s2;
- X
- X {
- X return strcmp(*s1, *s2);
- X }
- X
- Xstatic int AddUser(utmp, count)
- X
- Xstruct utmp *utmp;
- Xint count;
- X
- X {
- X char new_user[USER_SIZE + 1];
- X int i;
- X
- X memcpy(new_user, utmp->ut_user, USER_SIZE);
- X new_user[USER_SIZE] = '\0';
- X i = 0;
- X while (i < count && strcmp(UserList[i], new_user) != 0)
- X ++i;
- X if (i < count)
- X return 0;
- X if (count >= UserListSize)
- X {
- X UserListSize = count + 1;
- X if (! UserList)
- X UserList = (char **)malloc(sizeof(char *));
- X else
- X UserList = (char **)realloc(UserList,
- X sizeof(char *) * UserListSize);
- X UserList[count] = malloc(USER_SIZE + 1);
- X }
- X strcpy(UserList[count], new_user);
- X
- X return 1;
- X }
- GURK
- chmod 0644 users.c || echo 'restore of users.c fails'
- echo 'mshar: extracting kmem.sysv.c (size: 4390)'
- sed 's/^X//' << 'GURK' > kmem.sysv.c &&
- X
- X/* kmem.sysv.c - kmem routines for System V.3.2 */
- X
- X#include <fcntl.h>
- X#include <stdio.h>
- X#include <a.out.h>
- X#include <sys/types.h>
- X#include <sys/sysinfo.h>
- X#include <errno.h>
- X#include "types.h"
- X#include "funcs.h"
- X
- X#define NL_SYSINFO 0
- X#define NL_LBOLT 1
- X#define CPU_INFO_SZ (sizeof(sysinfo.cpu) / sizeof(sysinfo.cpu[0]))
- X#define DEFAULT_HZ "60"
- X
- Xextern long lseek();
- Xextern char *getenv();
- X
- Xextern char *TermBell;
- Xextern time_t Now;
- X
- Xstruct sysinfo sysinfo; /* need to declare these to deal with sys/sysinfo.h */
- Xtime_t lbolt; /* extern declarations */
- Xstatic struct nlist NlistInfo[] = {
- X {"sysinfo"},
- X {"lbolt"},
- X {0}};
- X
- Xstatic int NlistLoaded = 0;
- Xstatic int KmemFd;
- Xstatic time_t SavedCpu[CPU_INFO_SZ];
- Xstatic time_t BootTime;
- Xstatic int Hertz;
- X
- Xint LoadFnInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X int i;
- X char *hz_str;
- X struct sysinfo sysinfo;
- X static int kmem_status = 0;
- X
- X if (! NlistLoaded)
- X {
- X NlistLoaded = 1;
- X if (nlist("/unix", NlistInfo) < 0)
- X {
- X DisplayAdd(display, "nlist error ");
- X return 0;
- X }
- X if (NlistInfo[NL_SYSINFO].n_value == 0)
- X {
- X DisplayAdd(display, "bad sysinfo offset ");
- X write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if (NlistInfo[NL_LBOLT].n_value == 0)
- X {
- X DisplayAdd(display, "bad lbolt offset ");
- X write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if (! (hz_str = getenv("HZ")))
- X hz_str = DEFAULT_HZ;
- X Hertz = atoi(hz_str);
- X if ((KmemFd = open("/dev/kmem", O_RDONLY)) < 0)
- X {
- X DisplayAdd(display, "cannot open kmem ");
- X return 0;
- X }
- X if (lseek(KmemFd, NlistInfo[NL_SYSINFO].n_value, 0) == -1L)
- X {
- X char buf[128];
- X extern char *sys_errlist[];
- X
- X sprintf(buf, "kmem lseek error %d %s %u ", errno,
- X sys_errlist[errno], NlistInfo[NL_SYSINFO].n_value);
- X DisplayAdd(display, buf);
- X write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if (read(KmemFd, (char *)&sysinfo, sizeof(sysinfo)) < 0)
- X {
- X DisplayAdd(display, "kmem read error ");
- X write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X for (i = 0; i < CPU_INFO_SZ; ++i)
- X SavedCpu[i] = sysinfo.cpu[i];
- X
- X kmem_status = 1;
- X }
- X
- X return kmem_status;
- X }
- X
- Xint LoadFn(display)
- X
- Xdisplay_t *display;
- X
- X {
- X int i;
- X time_t all_krn;
- X struct sysinfo sysinfo;
- X time_t new_cpu[CPU_INFO_SZ];
- X double total_cpu;
- X char buf[128];
- X
- X if (lseek(KmemFd, NlistInfo[NL_SYSINFO].n_value, 0) == -1L)
- X {
- X DisplayAdd(display, "kmem lseek error ");
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if (read(KmemFd, (char *)&sysinfo, sizeof(sysinfo)) < 0)
- X {
- X DisplayAdd(display, "kmem read error ");
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X
- X total_cpu = 0.0;
- X for (i = 0; i < CPU_INFO_SZ; ++i)
- X {
- X total_cpu += new_cpu[i] = sysinfo.cpu[i] - SavedCpu[i];
- X SavedCpu[i] = sysinfo.cpu[i];
- X }
- X
- X DisplayAdd(display, "cpu: ");
- X sprintf(buf, "usr %.0f%%, ", new_cpu[CPU_USER] / total_cpu * 100.0);
- X DisplayAdd(display, buf);
- X all_krn = new_cpu[CPU_KERNEL] + new_cpu[CPU_WAIT] + new_cpu[CPU_SXBRK];
- X sprintf(buf, "krn %.0f%%, ", all_krn / total_cpu * 100.0);
- X DisplayAdd(display, buf);
- X sprintf(buf, "idl %.0f%% ", new_cpu[CPU_IDLE] / total_cpu * 100.0);
- X DisplayAdd(display, buf);
- X
- X return 1;
- X }
- X
- Xint UptimeFnInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X time_t lbolt; /* a contraction of lightning bolt */
- X
- X if (LoadFnInit(display) == 0)
- X return 0;
- X
- X if (lseek(KmemFd, NlistInfo[NL_LBOLT].n_value, 0) == -1L)
- X {
- X DisplayAdd(display, "kmem lbolt lseek error ");
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if (read(KmemFd, (char *)&lbolt , sizeof(lbolt)) < 0)
- X {
- X DisplayAdd(display, "kmem lbolt read error ");
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X
- X BootTime = Now - lbolt / Hertz;
- X if (BootTime < 0)
- X DisplayAdd(display, "very strange boottime ");
- X
- X return 1;
- X }
- X
- Xint UptimeFn(display)
- X
- Xdisplay_t *display;
- X
- X {
- X time_t lbolt;
- X time_t uptime;
- X int days, hours, minutes, seconds;
- X char buf[64];
- X
- X uptime = Now - BootTime;
- X days = uptime / (60 * 60 * 24);
- X uptime -= days * (60 * 60 * 24);
- X hours = uptime / (60 * 60);
- X uptime -= hours * (60 * 60);
- X minutes = uptime / 60;
- X uptime -= minutes * 60;
- X seconds = uptime;
- X sprintf(buf, "ut: %d+%.2d:%.2d:%.2d ", days, hours, minutes, seconds);
- X DisplayAdd(display, buf);
- X
- X return 1;
- X }
- GURK
- chmod 0644 kmem.sysv.c || echo 'restore of kmem.sysv.c fails'
- echo 'mshar: extracting kmem.xenix.c (size: 2701)'
- sed 's/^X//' << 'GURK' > kmem.xenix.c &&
- X
- X/* kmem.xenix.c - kmem routines for Xenix 2.3 */
- X
- X#include <fcntl.h>
- X#include <stdio.h>
- X#include <a.out.h>
- X#include <sys/types.h>
- X#include "types.h"
- X#include "funcs.h"
- X
- X#define XL_AVENRUN 0
- X#define XL_BOOTIME 1
- X
- Xextern long lseek();
- Xextern char *getenv();
- X
- Xextern char *TermBell;
- Xextern time_t Now;
- X
- Xstatic struct xlist XlistInfo[] = {
- X {0, 0, 0, "_avenrun"},
- X {0, 0, 0, "_bootime"},
- X {0}};
- X
- Xstatic int KmemFd;
- Xstatic time_t BootTime;
- X
- Xint LoadFnInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X static int xlist_loaded = 0;
- X static int kmem_status = 0;
- X
- X if (! xlist_loaded)
- X {
- X xlist_loaded = 1;
- X if (xlist("/xenix", XlistInfo) < 0)
- X {
- X DisplayAdd(display, "xlist error ");
- X return 0;
- X }
- X if (XlistInfo[XL_AVENRUN].xl_value == 0)
- X {
- X DisplayAdd(display, "bad avenrun offset ");
- X write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if (XlistInfo[XL_BOOTIME].xl_value == 0)
- X {
- X DisplayAdd(display, "bad bootime offset ");
- X write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if ((KmemFd = open("/dev/kmem", O_RDONLY)) < 0)
- X {
- X DisplayAdd(display, "cannot open kmem ");
- X return 0;
- X }
- X kmem_status = 1;
- X }
- X
- X return kmem_status;
- X }
- X
- Xint LoadFn(display)
- X
- Xdisplay_t *display;
- X
- X {
- X short total_cpu;
- X char buf[32];
- X
- X if (lseek(KmemFd, XlistInfo[XL_AVENRUN].xl_value, 0) == -1L)
- X {
- X DisplayAdd(display, "kmem lseek error ");
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if (read(KmemFd, (char *)&total_cpu, sizeof(total_cpu)) < 0)
- X {
- X DisplayAdd(display, "kmem read error ");
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X
- X DisplayAdd(display, "load: ");
- X sprintf(buf, "%.2f ", total_cpu / 256.0);
- X DisplayAdd(display, buf);
- X
- X return 1;
- X }
- X
- Xint UptimeFnInit(display)
- X
- Xdisplay_t *display;
- X
- X {
- X if (LoadFnInit(display) == 0)
- X return 0;
- X
- X if (lseek(KmemFd, XlistInfo[XL_BOOTIME].xl_value, 0) == -1L)
- X {
- X DisplayAdd(display, "kmem lbolt lseek error ");
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X if (read(KmemFd, (char *)&BootTime, sizeof(BootTime)) < 0)
- X {
- X DisplayAdd(display, "kmem bootime read error ");
- X (void)write(fileno(stdout), TermBell, strlen(TermBell));
- X return 0;
- X }
- X
- X return 1;
- X }
- X
- Xint UptimeFn(display)
- X
- Xdisplay_t *display;
- X
- X {
- X time_t uptime;
- X int days, hours, minutes, seconds;
- X char buf[64];
- X
- X uptime = Now - BootTime;
- X days = uptime / (60 * 60 * 24);
- X uptime -= days * (60 * 60 * 24);
- X hours = uptime / (60 * 60);
- X uptime -= hours * (60 * 60);
- X minutes = uptime / 60;
- X uptime -= minutes * 60;
- X seconds = uptime;
- X sprintf(buf, "ut: %d+%.2d:%.2d:%.2d ", days, hours, minutes, seconds);
- X DisplayAdd(display, buf);
- X
- X return 1;
- X }
- GURK
- chmod 0644 kmem.xenix.c || echo 'restore of kmem.xenix.c fails'
- echo 'mshar: extracting editwarn.c (size: 140)'
- sed 's/^X//' << 'GURK' > editwarn.c &&
- X
- X /* WARNING - this is a generated file, any changes will
- X * be lost in the next make. Edit either kmem.sysv.c or
- X * kmem.xenix.c.
- X */
- X
- GURK
- chmod 0644 editwarn.c || echo 'restore of editwarn.c fails'
- echo 'mshar: extracting funcs.h (size: 271)'
- sed 's/^X//' << 'GURK' > funcs.h &&
- Xint LoadFn();
- Xint UsersCountFn();
- Xint UsersFn();
- Xint UptimeFn();
- Xint DateFn();
- Xint BiffFn();
- Xint UsersDelta();
- X
- Xint LoadFnInit();
- Xint UsersCountFnInit();
- Xint UsersFnInit();
- Xint UptimeFnInit();
- Xint DateFnInit();
- Xint BiffFnInit();
- Xint UsersDeltaInit();
- X
- Xvoid DisplayAdd();
- GURK
- chmod 0644 funcs.h || echo 'restore of funcs.h fails'
- echo 'mshar: extracting types.h (size: 363)'
- sed 's/^X//' << 'GURK' > types.h &&
- Xtypedef struct stat_line_info_t {
- X char *tsl;
- X int tsl_len;
- X char *fsl;
- X int fsl_len;
- X int width;
- X } stat_line_info_t;
- X
- Xtypedef struct display_t {
- X char *buffer;
- X int display_len;
- X int buf_len;
- X stat_line_info_t stat_line_info;
- X } display_t;
- X
- Xtypedef struct fn_list_t {
- X int (*fn_name)();
- X int (*init_fn_name)();
- X int call;
- X char flag;
- X char *desc;
- X } fn_list_t;
- GURK
- chmod 0644 types.h || echo 'restore of types.h fails'
- exit 0
-
-
-