home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-28 | 29.5 KB | 1,140 lines |
- Newsgroups: alt.sources
- Path: sparky!uunet!UB.com!pacbell.com!sgiblab!munnari.oz.au!bruce.cs.monash.edu.au!monu6!rjh
- From: rjh@pixel.maths.monash.edu.au (Plagued by Penguins)
- Subject: xrwho - an X version of rwho
- Message-ID: <1993Jan27.050758.9565@monu6.cc.monash.edu.au>
- Keywords: rwho, X11
- Sender: rjh@pixel.maths.monash.edu.au (Mr Robin J Humble)
- Organization: Dept of Maths, Monash Uni, Melbourne, Australia
- Date: Wed, 27 Jan 1993 05:07:58 GMT
- Lines: 1128
-
- xrwho
-
- An X Window based version of rwho.
-
- By Andrew Herbert andrewh@cs.monash.edu.au
- andrew@werple.apana.org.au
- and Robin Humble rjh@pixel.maths.monash.edu.au
-
- xrwho displays the users logged into hosts on the local network. It
- creates a window in which the names of local machines and the users
- that are on these machines are displayed. Each host machine has its
- own box in which the users logged onto this machine are shown.
-
- xrwho uses the X Toolkit and Athena widgets. It requires X11R4 or later.
- Check out the man page for info on all the groovy features in xrwho.
-
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: README xrwho.c xrwho.man Imakefile Makefile.easy
- # Xrwho.apps
- # Wrapped by andrewh@molly.cs.monash.edu.au on Wed Jan 27 15:56:23 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f README -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"README\"
- else
- echo shar: Extracting \"README\" \(1500 characters\)
- sed "s/^X//" >README <<'END_OF_README'
- X
- X xrwho
- X
- X An X Window based version of rwho.
- X
- X By Andrew Herbert andrewh@cs.monash.edu.au
- X andrew@werple.apana.org.au
- X and Robin Humble rjh@pixel.maths.monash.edu.au
- X
- Xxrwho displays the users logged into hosts on the local network. It
- Xcreates a window in which the names of local machines and the users
- Xthat are on these machines are displayed. Each host machine has its
- Xown box in which the users logged onto this machine are shown.
- X
- Xxrwho uses the X Toolkit and Athena widgets. It requires X11R4 or later.
- XCheck out the man page for info on all the groovy features in xrwho.
- X
- XYou can use the Imakefile to build xrwho by:
- X
- X xmkmf
- X make depend
- X make
- X
- Xor a simple
- X
- X gcc -o xrwho xrwho.c -lXaw -lXmu -lXt -lX11
- X
- Xshould suffice. "cc" is okay on most machines too.
- X
- XA sample "Xrwho.apps" file is included which can be customised to your
- Xcolour, font, size and shape preferences and then added to your
- XX resources (~/.Xdefaults) file. xrwho will work fine without having
- Xto do this though.
- X
- Xxrwho can be compiled with "-DDebug" if you really want lots of junk
- Xall over your screen. However, if xrwho crashes and burns on your
- Xmachine then please set the Debug flag, recompile, attempt to
- Xreproduce the error, and then mail us the results.
- X
- XComments and suggestions for improvement are welcome as long as we're
- Xnot too close to some damn conference submission date or something...
- X
- XEnjoy!
- END_OF_README
- if test 1500 -ne `wc -c <README`; then
- echo shar: \"README\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f xrwho.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"xrwho.c\"
- else
- echo shar: Extracting \"xrwho.c\" \(19344 characters\)
- sed "s/^X//" >xrwho.c <<'END_OF_xrwho.c'
- X/*
- X * xrwho 1.0
- X *
- X * By Andrew Herbert and Robin Humble
- X * <andrewh@cs.monash.edu.au> <rjh@pixel.maths.monash.edu.au>
- X * <andrew@werple.apana.org.au>
- X *
- X * Jan '93.
- X *
- X * build with: gcc -O -s -o xrwho xrwho.c -lXaw -lXmu -lXt -lX11
- X *
- X */
- X
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <string.h>
- X#include <stdlib.h>
- X#include <unistd.h>
- X#include <dirent.h>
- X#include <utmp.h>
- X#include <limits.h>
- X#include <errno.h>
- X#include <time.h>
- X#include <protocols/rwhod.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <X11/Intrinsic.h>
- X#include <X11/StringDefs.h>
- X#include <X11/Xaw/Command.h>
- X#include <X11/Xaw/Label.h>
- X#include <X11/Xaw/Box.h>
- X#include <X11/Xaw/Cardinals.h>
- X#include <X11/Xaw/Viewport.h>
- X
- X#ifdef sun
- Xextern char *sys_errlist[];
- X#define strerror(e) (sys_errlist[e])
- X#endif
- X
- X#ifdef __386BSD__
- X#define RWHODIR "/var/rwho"
- X#else
- X#define RWHODIR "/usr/spool/rwho"
- X#endif
- X#define MaxSnoops 32 /* maximum snoop users */
- X#define MaxUtmpEntries 64 /* maximum users for localhost */
- X#define InsensitiveIdleTime 300 /* one minute max idle time*/
- X#define OldUserIdleTime 3600 /* one hour user idle time max unless -a specified */
- X#define HostDeadTime 300 /* time before a host is considered dead */
- X#define RefreshRate 60000 /* refresh every minute (rate in ms) */
- X
- X#define MIN(x, y) ((x)<(y)?(x):(y))
- X
- X#ifdef Debug
- X#define Die abort()
- X#else
- X#define Die exit(1)
- X#endif
- X
- X#ifndef UTMP_FILE
- X#ifdef _PATH_UTMP
- X#define UTMP_FILE _PATH_UTMP
- X#else
- X#define UTMP_FILE "/etc/utmp"
- X#endif /* _PATH_UTMP */
- X#endif /* UTMP_FILE */
- X
- X#ifdef R3_INTRINSICS
- Xtypedef void* XtPointer;
- Xextern Widget XtAppInitialize();
- X#endif
- X
- Xextern int gethostname(char *, int);
- X
- Xtypedef enum { local, rwho } userinfo_source_t;
- X
- X/* per-user information */
- Xtypedef struct user_struct {
- X char name[9]; /* username */
- X int idle; /* minimum of all the idles for this user */
- X int still_here; /* flag to say the user is still logged in */
- X Widget label; /* the label widget for this user */
- X struct user_struct *next; /* next user */
- X} user_t;
- X
- X/* per-host information */
- Xtypedef struct {
- X Widget box; /* box widget to contain the labels for this host */
- X char host_name[32];
- X userinfo_source_t host_file_type;
- X char host_filename[256];
- X Widget title; /* the label widget for this host */
- X user_t *head; /* pointer to userlist on this host */
- X} userinfo_t;
- X
- X/* temp filename info */
- Xtypedef struct host_filestruct {
- X char name[256];
- X struct host_filestruct *next, *prev;
- X} host_t;
- X
- XString fallbacks[] = {
- X "*Label*borderWidth: 0", /* no border around host or usernames */
- X "*vSpace: 2", /* pack usernames fairly tightly */
- X "*host.foreground: blue", /* hostname colour */
- X "*snoop.foreground: red", /* snoop user colour */
- X "*font: -*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*",
- X "*host.font: -*-helvetica-medium-o-*-*-*-120-*-*-*-*-*-*",
- X /* smallish font */
- X "*Viewport*allowVert: True",
- X NULL
- X};
- X
- Xstatic XrmOptionDescRec options[] = {
- X {"-hostfg", "*host.foreground", XrmoptionSepArg, NULL},
- X {"-hostbg", "*host.background", XrmoptionSepArg, NULL},
- X {"-hostfont", "*host.font", XrmoptionSepArg, NULL},
- X {"-font", "*font", XrmoptionSepArg, NULL},
- X {"-highlight", "*snoop.foreground", XrmoptionSepArg, NULL},
- X};
- X
- XWidget toplevel, box;
- Xint no_of_hosts; /* number of remote hosts being monitored */
- Xint list_long, show_all_hosts, empty_boxes, num_snoops, ring_bell;
- Xchar snoop_user[MaxSnoops][9];
- Xuserinfo_t *host_userinfo;
- X
- Xvoid sort(host_t *);
- Xvoid init_rwho(Widget);
- Xvoid process_rwho(void);
- Xvoid refresh_rwho(XtPointer, XtIntervalId *);
- Xint search_for_user(userinfo_t *, char *, user_t **);
- Xint read_utmp(struct utmp [], int);
- Xint read_rwho(char *, struct whod *);
- Xvoid remove_tail(char *string);
- Xvoid syntax(XtAppContext, char *);
- Xvoid main(int, char **);
- X
- Xvoid main(int argc, char **argv)
- X{
- X int i;
- X XtAppContext app_con;
- X Widget viewport;
- X
- X toplevel = XtAppInitialize(&app_con, "Xrwho", options, XtNumber(options),
- X (Cardinal *)&argc, argv, fallbacks, NULL, ZERO);
- X
- X#ifdef Debug
- X/* don't work too well boss:
- XXtAppSetErrorHandler(app_con, abort);
- X*/
- X#endif
- X
- X list_long = 0;
- X show_all_hosts = 0;
- X empty_boxes = 0;
- X num_snoops = 0;
- X ring_bell = 0;
- X
- X /*
- X * parse optional arguments
- X */
- X for (i = 1; i < argc; i++) {
- X if (!strcmp(argv[i], "-a"))
- X list_long = 1;
- X else if (!strcmp(argv[i], "-l"))
- X show_all_hosts = 1;
- X else if (!strcmp(argv[i], "-b"))
- X empty_boxes = 1;
- X else if (!strcmp(argv[i], "-bell"))
- X ring_bell = 1;
- X else if (!strcmp(argv[i], "-snoop")) {
- X char *name;
- X
- X while (i+1 < argc && argv[i+1][0] != '-') {
- X name = strtok(argv[++i], ",");
- X do {
- X strncpy(snoop_user[num_snoops], name, 8);
- X snoop_user[num_snoops][8] = 0; /* 8 chars max for usernames */
- X num_snoops++;
- X } while ((name = strtok(NULL, ",")) && (num_snoops < MaxSnoops));
- X }
- X }
- X else
- X syntax(app_con, argv[0]);
- X }
- X
- X viewport = XtCreateManagedWidget("viewport", viewportWidgetClass, toplevel, NULL, ZERO);
- X box = XtCreateManagedWidget("box", boxWidgetClass, viewport, NULL, ZERO);
- X
- X init_rwho(box); /* initialise the rwho stuff */
- X process_rwho(); /* create label widgets for all current users */
- X
- X XtRealizeWidget(toplevel);
- X XtAppAddTimeOut(XtWidgetToApplicationContext(toplevel), RefreshRate,
- X refresh_rwho, NULL);
- X
- X XtAppMainLoop(app_con);
- X} /* end of main() */
- X
- X
- Xvoid init_rwho(Widget top_box)
- X{
- X DIR *dir;
- X struct dirent *dirent;
- X int i, host_in_whod;
- X char hostname[64], filename[256];
- X Arg args[1];
- X userinfo_t *hui;
- X host_t *head, *file, *tmp;
- X
- X
- X if (gethostname(hostname, 64)) {
- X /* no hostname, downer */
- X perror("xrwho - hostname()");
- X exit(1);
- X }
- X remove_tail(hostname);
- X
- X /* move to rwhod spool area so we can read files in later on */
- X if (chdir(RWHODIR)) {
- X char *msg;
- X
- X if (errno == EACCES)
- X /* the directory exists, but we can't read it */
- X msg = "ho hum";
- X else
- X msg = "check the RWHODIR #define";
- X
- X fprintf(stderr, "xrwho - can't cd to %s (%s) - %s\n",
- X RWHODIR, strerror(errno), msg);
- X
- X if (errno != EACCES)
- X exit(1);
- X }
- X
- X dir = opendir(".");
- X if (!dir) {
- X#ifdef sun
- X fprintf(stderr, "xrwho: can't open %s\n", RWHODIR);
- X#else
- X fprintf(stderr, "xrwho: can't open %s (%s)\n", RWHODIR, strerror(errno));
- X#endif
- X exit(1);
- X }
- X
- X i = 0;
- X host_in_whod = 0;
- X
- X /* init linked list for filenames */
- X head = (host_t *)NULL;
- X
- X while (dirent = readdir(dir))
- X if (!strncmp(dirent->d_name, "whod.", 5)) {
- X struct stat stat_info;
- X int stat_failed;
- X
- X#ifdef Debug
- Xprintf("host rwho file %d: %s\n", i, file->name);
- X#endif
- X strcpy(filename, dirent->d_name + 5);
- X remove_tail(filename);
- X
- X /* check whether we can read it, etc */
- X stat_failed = stat(dirent->d_name, &stat_info);
- X
- X /* search for hostname in whod files, and check whether the file
- X has been updated in the past 12 hours - otherwise indicative
- X of a dead entry for the host we're running on */
- X if (!strcmp(hostname, filename)) {
- X if (stat_failed && stat_info.st_mtime > (time(NULL) - 60*60*12))
- X host_in_whod = 1; /* rwho file is OK */
- X else
- X continue; /* too old to be valid, so ignore */
- X }
- X if (stat_failed)
- X continue;
- X
- X /* malloc space for whod filename */
- X if (head == (host_t *)NULL) {
- X head = (host_t *)malloc(sizeof(host_t));
- X if (head == NULL) {
- X fprintf(stderr, "xrwho: can't malloc\n");
- X Die;
- X }
- X file = head;
- X file->prev = (host_t *)NULL;
- X file->next = (host_t *)NULL;
- X }
- X else {
- X file->next = (host_t *)malloc(sizeof(host_t));
- X if (file->next == NULL) {
- X fprintf(stderr, "xrwho: can't malloc\n");
- X Die;
- X }
- X file->next->prev = file;
- X file->next->next = (host_t *)NULL;
- X file = file->next;
- X }
- X
- X /* read filename */
- X strcpy(file->name, dirent->d_name);
- X
- X i++;
- X }
- X closedir(dir);
- X no_of_hosts = i;
- X
- X /*
- X * sort hostnames into alphabetical order
- X */
- X if (no_of_hosts)
- X sort(head);
- X
- X /*
- X * if host machine not in whod list then use utmp instead
- X */
- X if (!host_in_whod)
- X no_of_hosts++;
- X
- X#ifdef Debug
- Xif (!host_in_whod)
- X printf("No rwho file for localhost - using utmp instead\n");
- X#endif
- X
- X /*
- X * allocate and zero the userinfo array
- X * assume number of hosts isn't going to change that often
- X */
- X host_userinfo = (userinfo_t *)malloc(no_of_hosts*sizeof(userinfo_t));
- X if (host_userinfo == NULL) {
- X fprintf(stderr, "xrwho: can't malloc\n");
- X Die;
- X }
- X
- X /*
- X * create enclosing boxes for each host, and set hostnames as labels
- X */
- X i = 0;
- X for (file = head; file != (host_t *)NULL; file = file->next) {
- X
- X hui = &(host_userinfo[i]);
- X hui->host_file_type = rwho;
- X hui->head = (user_t *)NULL;
- X
- X /* set the host file name */
- X strcpy(hui->host_filename, file->name);
- X
- X /* set the hostname, removing trailing dots */
- X strcpy(hui->host_name, hui->host_filename + 5);
- X remove_tail(hui->host_name);
- X
- X hui->box = XtCreateManagedWidget(hui->host_name,
- X boxWidgetClass, top_box, NULL, ZERO);
- X
- X hui->title = XtCreateManagedWidget("host",
- X labelWidgetClass, hui->box, NULL, ZERO);
- X XtSetArg(args[0], XtNlabel, hui->host_name);
- X XtSetValues(hui->title, args, ONE);
- X
- X i++;
- X }
- X
- X /*
- X * add a widget for localhost if it's not in the whod files
- X */
- X if (!host_in_whod) {
- X hui = &(host_userinfo[no_of_hosts - 1]);
- X hui->host_file_type = local;
- X hui->head = (user_t *)NULL;
- X
- X strcpy(hui->host_name, hostname);
- X
- X hui->box = XtCreateManagedWidget(hui->host_name,
- X boxWidgetClass, top_box, NULL, ZERO);
- X
- X hui->title = XtCreateManagedWidget("host",
- X labelWidgetClass, hui->box, NULL, ZERO);
- X XtSetArg(args[0], XtNlabel, hui->host_name);
- X XtSetValues(hui->title, args, ONE);
- X }
- X
- X /* free tmp filename info */
- X file = head;
- X while (file != (host_t *)NULL) {
- X tmp = file->next;
- X free(file);
- X file = tmp;
- X }
- X} /* end of init_rwho() */
- X
- X
- X/*
- X * Remove trailing part of a string of the form "a.b.c.d", leaving just "a"
- X */
- X
- Xvoid remove_tail(char *string)
- X{
- X if (string = strchr(string, '.'))
- X *string = '\0';
- X}
- X
- X
- X/*
- X * search_for_user
- X * Scans a host's userlist for a particular name, returning the
- X * array index if found, or -1 if not.
- X */
- X
- Xint search_for_user(userinfo_t *hui, char *name, user_t **found)
- X{
- X user_t *i;
- X
- X for (i = hui->head; i != (user_t *)NULL; i = i->next)
- X if (!strcmp(name, i->name)) {
- X *found = i;
- X return 0;
- X }
- X
- X *found = (user_t *)NULL;
- X return -1;
- X}
- X
- X
- X/*
- X * sort
- X * sort filenames into alphabetical order by straight insertion
- X */
- Xvoid sort(host_t *head) {
- X host_t *i, *j;
- X char a[256];
- X
- X for (j = head->next; j != (host_t *)NULL; j = j->next) {
- X
- X strcpy(a, j->name);
- X
- X i = j->prev;
- X while ((i->prev != (host_t *)NULL) && (strcmp(i->name, a) > 0)) {
- X strcpy(i->next->name, i->name);
- X i = i->prev;
- X }
- X
- X if ((i == head) && (strcmp(i->name, a) > 0)) {
- X strcpy(i->next->name, i->name);
- X strcpy(i->name, a);
- X }
- X else
- X strcpy(i->next->name, a);
- X }
- X
- X#ifdef Debug
- Xprintf("\nhosts in order:\n");
- Xfor (j = head; j != (host_t *)NULL; j = j->next)
- X printf(" %s", j->name);
- Xprintf("\n");
- X#endif
- X
- X}
- X
- X
- X/*
- X * read_utmp
- X * Read in a utmp file; returns the number of users in the file.
- X */
- X
- Xint read_utmp(struct utmp utmp[], int max_entries)
- X{
- X int fd, bytes;
- X
- X fd = open(UTMP_FILE, O_RDONLY);
- X if (fd < 0) {
- X#ifdef Debug
- X fprintf(stderr, "xrwho: can't open %s\n", UTMP_FILE);
- X#endif
- X return 0;
- X }
- X bytes = read(fd, utmp, max_entries*sizeof(struct utmp));
- X close(fd);
- X return bytes/sizeof(struct utmp);
- X}
- X
- X
- X/*
- X * read_rwho
- X * Read in a whod file; returns the number of users in the file.
- X */
- X
- Xint read_rwho(char *filename, struct whod *who)
- X{
- X int fd, bytes;
- X
- X fd = open(filename, O_RDONLY);
- X if (fd < 0) {
- X#ifdef Debug
- X fprintf(stderr, "xrwho: can't open %s/%s\n", RWHODIR, filename);
- X#endif
- X return 0;
- X }
- X bytes = read(fd, who, sizeof(struct whod));
- X close(fd);
- X
- X if ((time(NULL) - who->wd_recvtime) > HostDeadTime) {
- X /* we haven't heard from host for too long so ignore it */
- X return 0;
- X }
- X
- X return (bytes - 60)/sizeof(struct whoent); /* number of whoent records */
- X}
- X
- X
- Xvoid process_rwho(void)
- X{
- X int i, n;
- X struct whod who;
- X struct utmp utmp[MaxUtmpEntries];
- X Arg args[1];
- X int j;
- X user_t *k, *prev;
- X time_t time_now = time(NULL);
- X
- X /* add labels to the box, one per remote user */
- X for (i = 0; i < no_of_hosts; i++) {
- X userinfo_t *hui = &(host_userinfo[i]);
- X
- X switch (hui->host_file_type) {
- X case local: n = read_utmp(utmp, MaxUtmpEntries); break;
- X case rwho: n = read_rwho(hui->host_filename, &who); break;
- X }
- X
- X /*
- X * set all idle times to infinity, and still_here to false
- X * so that the following update works correctly
- X */
- X for (k = hui->head; k != (user_t *)NULL; k = k->next) {
- X k->idle = INT_MAX;
- X k->still_here = 0;
- X }
- X
- X /*
- X * scan through the utmp-style array for the host, updating idle times
- X * and checking whether users are still logged on
- X */
- X for (j = 0; j < n; j++) {
- X char *name;
- X int idle;
- X
- X switch (hui->host_file_type) {
- X case local: {
- X char tmp[64];
- X struct stat stat_info;
- X#ifdef USER_PROCESS
- X /* SYSV-style utmp */
- X if (utmp[j].ut_type != USER_PROCESS)
- X continue; /* ignore everything else */
- X name = utmp[j].ut_user;
- X#else
- X if (!utmp[j].ut_name)
- X continue;
- X name = utmp[j].ut_name;
- X#endif
- X /* check how long it's been since the user last accessed
- X their tty */
- X strcpy(tmp, "/dev/");
- X if (!stat(strcat(tmp, utmp[j].ut_line), &stat_info))
- X idle = time_now - stat_info.st_atime;
- X else {
- X#ifdef Debug
- X fprintf(stderr, "can't stat %s\n", tmp);
- X#endif
- X idle = 0; /* ignore */
- X }
- X break;
- X }
- X case rwho:
- X name = who.wd_we[j].we_utmp.out_name;
- X idle = who.wd_we[j].we_idle;
- X break;
- X }
- X
- X /* handle 8-char usernames */
- X name[8] = 0;
- X
- X#ifdef Debug
- Xprintf("checking %s in %s (idle %d seconds)\n", name,
- X hui->host_filename, idle);
- X#endif
- X
- X /* check host_userinfo for this name */
- X if (search_for_user(hui, name, &k) != -1) {
- X /* matched existing user */
- X
- X#ifdef Debug
- Xprintf("user %s matched (idle %d)\n", k->name, k->idle);
- X#endif
- X k->idle = MIN(k->idle, idle);
- X k->still_here++;
- X }
- X else {
- X /* new user */
- X
- X /* check whether idle is too long */
- X if (list_long || idle < OldUserIdleTime) {
- X int m, snoop;
- X
- X if (hui->head == (user_t *)NULL) {
- X /* this is 1st user for this host */
- X hui->head = (user_t *)malloc(sizeof(user_t));
- X if (hui->head == NULL) {
- X fprintf(stderr, "xrwho: can't malloc\n");
- X Die;
- X }
- X k = hui->head;
- X k->next = (user_t *)NULL;
- X }
- X else {
- X k = (user_t *)malloc(sizeof(user_t));
- X if (k == NULL) {
- X fprintf(stderr, "xrwho: can't malloc\n");
- X Die;
- X }
- X k->next = hui->head;
- X hui->head = k;
- X }
- X
- X /*
- X * add user to list
- X */
- X strcpy(k->name, name);
- X k->idle = idle;
- X k->still_here = 1;
- X
- X /*
- X * see if the user is snooped upon
- X */
- X snoop = 0;
- X for (m = 0; m < num_snoops; m++) {
- X if (!strcmp(snoop_user[m], k->name)) {
- X snoop++;
- X#ifdef Debug
- Xprintf("created snoop user %s from %s\n", snoop_user[m], hui->host_filename);
- X#endif
- X k->label = XtCreateManagedWidget("snoop",
- X labelWidgetClass, hui->box, NULL, ZERO);
- X XtSetArg(args[0], XtNlabel, k->name);
- X XtSetValues(k->label, args, ONE);
- X if (ring_bell)
- X XBell(XtDisplay(toplevel), 1);
- X }
- X }
- X
- X if (!snoop) {
- X k->label = XtCreateManagedWidget(k->name,
- X labelWidgetClass, hui->box, NULL, ZERO);
- X#ifdef Debug
- Xprintf("created %s from %s\n", k->name, hui->host_filename);
- X#endif
- X }
- X }
- X }
- X }
- X
- X /* check whether any of the users has logged out, or idle is too long */
- X k = hui->head;
- X prev = (user_t *)NULL;
- X while (k != (user_t *)NULL) {
- X if (!(k->still_here) || (!list_long && (k->idle > OldUserIdleTime))) {
- X#ifdef Debug
- Xprintf("removed %s from %s\n", k->name, hui->host_name);
- X#endif
- X XtDestroyWidget(k->label);
- X
- X /* unlink k from the list */
- X if (prev == (user_t *)NULL) {
- X /* user is head of list */
- X hui->head = k->next;
- X free(k);
- X k = hui->head;
- X }
- X else {
- X prev->next = k->next;
- X free(k);
- X k = prev->next;
- X }
- X }
- X else {
- X prev = k;
- X k = k->next;
- X }
- X }
- X
- X /* set each user as insensitive or sensitive, according to idle time */
- X for (k = hui->head; k != (user_t *)NULL; k = k->next) {
- X
- X#ifdef Debug
- Xprintf("user %s: %s\n", k->name,
- X k->idle < InsensitiveIdleTime ? "active" : "inactive");
- X#endif
- X XtSetArg(args[0], XtNsensitive,
- X k->idle < InsensitiveIdleTime ? True : False);
- X XtSetValues(k->label, args, ONE);
- X }
- X
- X /*
- X * want to hide machine title (and possibly box) if there are no users,
- X * and display it again if there are some.
- X */
- X if (!show_all_hosts) {
- X Widget wid = empty_boxes ? hui->title : hui->box;
- X
- X if (hui->head != (user_t *)NULL) {
- X if (!XtIsManaged(wid)) {
- X XtManageChild(wid);
- X#ifdef Debug
- Xprintf("has users: adding management to %s\n", hui->host_name);
- X#endif
- X }
- X }
- X else {
- X if (XtIsManaged(wid)) {
- X XtUnmanageChild(wid);
- X#ifdef Debug
- Xprintf("no users: removing management from %s\n", hui->host_name);
- X#endif
- X }
- X }
- X }
- X } /* end of host loop */
- X
- X#ifdef Debug
- X{
- X int i;
- X
- X printf("at end of loop -- status:\n");
- X for (i = 0; i < no_of_hosts; i++) {
- X userinfo_t *hui = &(host_userinfo[i]);
- X user_t *k;
- X
- X if (hui->head != (user_t *)NULL)
- X printf("%s (%s) wid: %ld\n", hui->host_name,
- X XtIsManaged(hui->title) ? "managed" : "not managed", hui->title);
- X
- X for (k = hui->head; k != (user_t *)NULL; k = k->next) {
- X printf(" %s - idle %d %s (%d) wid: %ld\n", k->name, k->idle,
- X k->still_here > 0 ? "here" : "not here", k->still_here, k->label);
- X }
- X }
- X}
- X#endif
- X
- X}
- X
- X
- X/*
- X * refresh_rwho
- X * Refresh the rwho display after an interval has expired.
- X */
- X
- Xvoid refresh_rwho(XtPointer client_data, XtIntervalId *id)
- X{
- X /* set it up again */
- X XtAppAddTimeOut(XtWidgetToApplicationContext(toplevel), RefreshRate,
- X refresh_rwho, NULL);
- X
- X /* check what has changed since last time */
- X process_rwho();
- X}
- X
- X
- Xvoid syntax(XtAppContext app_con, char *call)
- X{
- X XtDestroyApplicationContext(app_con);
- X fprintf(stderr, "Usage: %s [-a] [-l | -b] [-snoop <user1>,<user2>,... [-bell] ]\n", call);
- X fprintf(stderr, " [-font <font>] [-hostfont <font>]\n");
- X fprintf(stderr, " [-hostfg <color>] [-hostbg <color>]\n");
- X fprintf(stderr, " [-highlight <color>]\n");
- X fprintf(stderr, " + usual X options.\n");
- X fprintf(stderr, " -a shows users with long idle times also.\n");
- X fprintf(stderr, " -l shows hostnames when no users are logged in.\n");
- X fprintf(stderr, " -b shows empty boxes when no users are logged in.\n");
- X fprintf(stderr, " -snoop <user1>,<user2>,... highlights particular users.\n");
- X fprintf(stderr, " -bell beeps when a snooped user arrives.\n");
- X fprintf(stderr, " -highlight sets the colour of a snooped user (default red).\n");
- X exit(1);
- X}
- X
- END_OF_xrwho.c
- if test 19344 -ne `wc -c <xrwho.c`; then
- echo shar: \"xrwho.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f xrwho.man -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"xrwho.man\"
- else
- echo shar: Extracting \"xrwho.man\" \(3708 characters\)
- sed "s/^X//" >xrwho.man <<'END_OF_xrwho.man'
- X.TH XRWHO 1 "October 1992" "X Version 11"
- X.SH NAME
- Xxrwho - display of who is logged into local machines for X
- X.SH SYNOPSIS
- X.B xrwho
- X[ -toolkitoption ] [-option ...]
- X.SH DESCRIPTION
- X.I xrwho
- Xdisplays the users logged into hosts on the local network.
- X.I xrwho
- Xruns under the
- X.I X
- Xwindow system.
- X.I xrwho
- Xcreates a window in which the names of local machines
- Xand the users that are on these machines are displayed.
- XEach host machine has its own box in which the users
- Xlogged onto this machine are shown.
- X.PP
- X.I xrwho
- Xacts in most respects like
- X.I rwho(1).
- XUsers that have been idle for more than 5 minutes are
- Xdisplayed as shaded, rather than full intensity. Users
- Xwho have been idle for more than one hour, and host machines
- Xthat have no users logged in, are usually not shown.
- XIf nothing has been heard from a machine for 5 minutes
- Xthen the host is assumed to be down and no information
- Xis displayed for that machine.
- X.PP
- X.I xrwho
- Xuses the
- X.I X Toolkit
- Xto display the windows, and so accepts options like
- X.B \-geometry, \-fg
- Xcolour and
- X.B \-display \fIhost:display.\fP
- XIn addition to these standard
- X.I Xt
- Xflags,
- X.I xrwho
- Xunderstands the following options:
- X.PP
- X.TP 8
- X.B \-a
- Xdisplays users with idle times over one hour
- X.TP 8
- X.B \-l
- Xdisplay host names and boxes even when no users are logged in
- X.TP 8
- X.B \-b
- Xshows a tiny box when a host has no users (only one of
- X.B \-b
- Xand
- X.B \-l
- Xmay be used).
- X.TP 8
- X.B \-snoop \fI<user1>,<user2>,...\fP
- Xhighlight particular users using a different colour.
- X.TP 8
- X.B \-bell
- Xring the console bell when a snooped user arrives.
- X.TP 8
- X.B \-font \fIfontname\fP
- Xuser names will be displayed in the specified font (if none
- Xis specified, this defaults to helvetica).
- X.TP 8
- X.B \-hostfont \fIfontname\fP
- Xhost names will be displayed in the specified font (if none
- Xis specified, this defaults to helvetica oblique).
- X.TP 8
- X.B \-hostfg \fIcolour\fP
- Xhost names will be displayed in the specified colour (default blue)
- X.TP 8
- X.B \-hostbg \fIcolour\fP
- Xhost names will be displayed in a box of the specified colour.
- X.TP 8
- X.B \-highlight \fIcolour\fP
- Xsnoop users will be displayed in the specified colour (default red)
- X.PP
- X.SH X DEFAULTS
- XThe widget classes used by
- X.I xrwho
- Xare:
- X.PP
- X.RS
- X.nf
- XBox
- XLabel
- XViewport
- X.fi
- X.PP
- X.RE
- XSome of the X resources used by
- X.I xrwho
- Xare:
- X.PP
- X.TP 20
- X.B font
- Xset the font for user names.
- X.TP 20
- X.B host.font
- Xset the font for the hostname.
- X.TP 20
- X.B foreground
- Xset the window foreground colour
- X.TP 20
- X.B background
- Xset the window background colour
- X.TP 20
- X.B host.foreground
- Xset the host label foreground colour
- X.TP 20
- X.B host.background
- Xset the host box background colour
- X.TP 20
- X.B snoop.foreground
- Xset the colour that snoop users appear in
- X.TP 20
- X.B Label*borderWidth
- Xset the width of the border in pixels around the labels (default 0)
- X.TP 20
- X.B vSpace
- Xset the vertical spacing in pixels between host boxes (default 1)
- X.PP
- XFor example, the following could be put into your ~/.Xdefaults file:
- X.PP
- X.EX
- X.nf
- Xxrwho*foreground: black
- Xxrwho*background: white
- Xxrwho*host.foreground: white
- Xxrwho*host.background: blue
- Xxrwho*snoop.foreground: red
- Xxrwho*Label*borderWidth: 0
- Xxrwho*borderColor: black
- Xxrwho*vSpace: 1
- Xxrwho*font: -*-helvetica-*-r-*-*-*-100-*-*-*-*-*-*
- Xxrwho*host.font: -*-helvetica-*-*-*-*-*-100-*-*-*-*-*-*
- X.fi
- X.EE
- X.PP
- X.SH ENVIRONMENT
- XDISPLAY - to get the default host and display number.
- X.PP
- X.SH SEE ALSO
- XX(1), xrdb(1), rwho(1C), rwhod(1M)
- X.PP
- X.SH FILES
- X/usr/spool/rwho/*
- X.PP
- X.SH DIAGNOSTICS
- XVarious X errors.
- X.PP
- X.SH BUGS
- XThere is currently a maximum of 32 snoop users.
- X.PP
- X.SH AUTHORS
- X.nf
- X.TP 20
- XAndrew Herbert
- Xandrewh@cs.monash.edu.au
- Xandrew@werple.apana.org.au
- X.fi
- X.TP 20
- XRobin Humble
- Xrjh@pixel.maths.monash.edu.au
- END_OF_xrwho.man
- if test 3708 -ne `wc -c <xrwho.man`; then
- echo shar: \"xrwho.man\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f Imakefile -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"Imakefile\"
- else
- echo shar: Extracting \"Imakefile\" \(195 characters\)
- sed "s/^X//" >Imakefile <<'END_OF_Imakefile'
- X# xrwho - an X windows display of users on local machines
- X
- XPROGRAMS = xrwho
- XLOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
- X
- XSRCS = xrwho.c
- X
- XOBJS = xrwho.o
- X
- XComplexProgramTarget(xrwho)
- END_OF_Imakefile
- if test 195 -ne `wc -c <Imakefile`; then
- echo shar: \"Imakefile\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f Makefile.easy -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"Makefile.easy\"
- else
- echo shar: Extracting \"Makefile.easy\" \(218 characters\)
- sed "s/^X//" >Makefile.easy <<'END_OF_Makefile.easy'
- X
- X# gcc is better if you're got it
- XCC = gcc
- XCFLAGS = -O
- X
- X#sgi
- XCLIBS = -lXaw -lXmu -lXt_s -lX11_s -lmalloc -lc_s
- X
- X#dec/386bsd/sun
- XCLIBS = -lXaw -lXmu -lXt -lX11
- X
- Xxrwho: xrwho.o
- X $(CC) $(CFLAGS) xrwho.o $(CLIBS) -o xrwho
- END_OF_Makefile.easy
- if test 218 -ne `wc -c <Makefile.easy`; then
- echo shar: \"Makefile.easy\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f Xrwho.apps -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"Xrwho.apps\"
- else
- echo shar: Extracting \"Xrwho.apps\" \(329 characters\)
- sed "s/^X//" >Xrwho.apps <<'END_OF_Xrwho.apps'
- X
- X! xrwho
- X
- Xxrwho*foreground: black
- Xxrwho*background: white
- Xxrwho*borderColor: black
- Xxrwho*host.foreground: white
- Xxrwho*host.background: blue
- Xxrwho*Label*borderWidth: 0
- Xxrwho*vSpace: 1
- Xxrwho*font: -*-helvetica-*-r-*-*-*-100-*-*-*-*-*-*
- Xxrwho*host.font: -*-helvetica-*-*-*-*-*-100-*-*-*-*-*-*
- Xxrwho*snoop.foreground: red
- END_OF_Xrwho.apps
- if test 329 -ne `wc -c <Xrwho.apps`; then
- echo shar: \"Xrwho.apps\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- echo shar: End of shell archive.
- exit 0
-
-