budd@bu-cs.BU.EDU (Philip Budne) (01/21/87)
Here is a shar file with changes to rwho and rwhod to implement a new facility called hungry. Just see the README file below! #!/bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #!/bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # README # hungry.c # hungry.h # hungry.1c # rwho-changes # rwhod-changes # rwho.1c # This archive created: Mon Oct 6 11:22:33 1986 export PATH; PATH=/bin:$PATH if test -f 'README' then echo shar: over-writing existing file "'README'" fi cat << \SHAR_EOF > 'README' Scenario: You are at your terminal and feeling a bit hungry. Perhaps someone else is hungry too! So why eat alone. Now you can tell the world about your needs and set you "hunger bit". Instructions: To tell the world incant "hungry y", to stop type "hungry n", to waffle (twiddle) type "hungry ^", to figure out if you are hungry type "hungry". To find out about other needy people type "rwho -h". Disclaimer: This was written largely as a joke. However it adds little system overhead (no additional system calls if you run rwhod) and adds a lovely "ambiance" to your system. Credits: The original idea of the HUNGRYP bit comes from Mel Pleasants Twenex ultra-cusp TOPPLE. However setting hunger was a noop since noone could see it. I would also like to thank Sally Shepherd for convincing me that this was a "good" thing to do. (Sally has "hungry y" in her .login file!!) Phil Budne Boston University / Distributed Systems Groupies budd@bu-cs.bu.edu ....!harvard!bu-cs!budd SHAR_EOF if test -f 'hungry.c' then echo shar: over-writing existing file "'hungry.c'" fi cat << \SHAR_EOF > 'hungry.c' /* * hungry.c -- set/display hunger status * Phil Budne @ Boston University / Distributed Systems */ # include <stdio.h> # include <sys/types.h> # include <sys/stat.h> # include "hungry.h" main( argc, argv ) int argc; char *argv[]; { struct stat stb; int f; f = fileno( stderr ); if( !isatty( f ) ) { fprintf(stderr, "?no tty\n"); exit( 2 ); } /* not a tty */ if( fstat( f, &stb ) < 0 ) { perror( "fstat" ); exit( 2 ); } /* fstat failed */ if( argc < 2 ) { if( (stb.st_mode & HUNGRY) != 0 ) puts("is y"); else puts("is n"); } /* argc < 2 */ else { int newmode; newmode = stb.st_mode & ~S_IFMT; /* clear file format bits */ switch( argv[1][0] ) { case 'y': newmode |= HUNGRY; break; case 'n': newmode &= ~HUNGRY; break; case '^': /* toggle! */ newmode ^= HUNGRY; break; default: fprintf(stderr, "%s [y n ^]\n", argv[0] ); exit( 2 ); } /* switch */ # ifdef sun /* avoid sun bug */ { char *name; extern char *ttyname(); if( (name = ttyname( f )) == NULL ) { perror( "ttyname" ); exit( 2 ); } /* ttyname failed */ if( chmod(name, newmode) < 0 ) perror( "chmod" ); } /* sun */ # else if( fchmod(f, newmode) < 0 ) perror( "fchmod" ); # endif not sun } /* argv >= 2 */ if( (stb.st_mode & HUNGRY) == 0 ) exit( 1 ); /* false */ else exit( 0 ); /* true */ } /* main */ SHAR_EOF if test -f 'hungry.h' then echo shar: over-writing existing file "'hungry.h'" fi cat << \SHAR_EOF > 'hungry.h' # define HUNGRY 001 SHAR_EOF if test -f 'hungry.1c' then echo shar: over-writing existing file "'hungry.1c'" fi cat << \SHAR_EOF > 'hungry.1c' .TH HUNGRY 1C "30 May 1986" .SH NAME hungry \- set hunger status .SH SYNOPSIS .B hungry [ .B y | n | \^ ] .SH DESCRIPTION .I hungry is a new and innovative way to find someone to lunch with, it is used to inform the system as to whether you are .I hungry or not. The command: .RS .nf .B hungry y .RE .fi sets user status to .I hungry. The command: .RS .nf .B hungry n .RE .fi disables it, while: .RS .nf .B hungry \^ .RE .fi toggles the hungry status. Finally, the command: .RS .nf .B hungry .RE .fi on its own tells you whether your .I hungry state is .B y or .BR n . The command .B rwho -h lists all .I hungry users on participating systems. .LP .I hungry operates asynchronously. It may take a minute or more for a change in .I hungry status to take effect. .LP All commands return the .I previous status, true (0) for hungry, false satisfied. .LP .I hungry works by setting world execute permission on your tty. .SH SEE ALSO rwho(1C) SHAR_EOF if test -f 'rwho-changes' then echo shar: over-writing existing file "'rwho-changes'" fi cat << \SHAR_EOF > 'rwho-changes' in rwho.c: **************************************************************** int aflg; int hflg; /* budd */ main(argc, argv) int argc; char **argv; { struct direct *dp; int cc, width; register struct whod *w = &wd; register struct whoent *we; register struct myutmp *mp; int f, n, i; argc--; argv++; while( argc > 0 && argv[0][0] == '-' ) { /* reworked - budd */ switch( argv[0][1] ) { case 'a': aflg++; break; case 'h': /* budd */ hflg++; break; } argc--; argv++; } **************************************************************** for (n = cc / sizeof (struct whoent); n > 0; n--) { if (aflg == 0 && we->we_idle >= 60*60) { we++; continue; } # define HC sizeof( we->we_utmp.out_line ) /* budd... */ if(hflg != 0 && (we->we_utmp.out_line[HC] & 0200) == 0 ) { we++; continue; } we->we_utmp.out_line[HC] &= ~0200; /* ...budd */ if (nusers >= NUSERS) { printf("too many users\n"); exit(1); } mp->myutmp = we->we_utmp; mp->myidle = we->we_idle; (void) strcpy(mp->myhost, w->wd_hostname); nusers++; we++; mp++; } /* for */ **************************************************************** SHAR_EOF if test -f 'rwhod-changes' then echo shar: over-writing existing file "'rwhod-changes'" fi cat << \SHAR_EOF > 'rwhod-changes' in rwhod.c: **************************************************************** # include "......rwhod.h" # define HUNGER 1 /* non-zero to broadcast hunger */ # if HUNGER # include "hungry.h" # endif **************************************************************** for (i = 0; i < utmpent; i++) { if (stat(we->we_utmp.out_line, &stb) >= 0) { we->we_idle = htonl(now - stb.st_atime); # if HUNGER if( (stb.st_mode & HUNGRY) != 0 ) /* BUDD */ we->we_utmp.out_line[ sizeof( we->we_utmp.out_line ) ] |= 0200; /* BUDD */ # endif } we++; } /* for i */ **************************************************************** SHAR_EOF if test -f 'rwho.1c' then echo shar: over-writing existing file "'rwho.1c'" fi cat << \SHAR_EOF > 'rwho.1c' .\" @(#)rwho.1c 1.4 85/04/05 SMI; from UCB 4.1 .TH RWHO 1C "30 May 1986" .SH NAME rwho \- who's logged in on local machines .SH SYNOPSIS .B rwho [ .B \-a ] [ .B \-h ] .SH DESCRIPTION .IX "rwho command" "" "\fLrwho\fP \(em who is logged in on local network" .IX "who is logged in on local network" "" "who is logged in on local network \(em \fLrwho\fP" .IX network rwho "" "\fLrwho\fP \(em who is logged in on local network" .IX login rwho "" "\fLrwho\fP \(em who is on local network" The .I rwho command produces output similar to .IR who (1), but for all machines on your network. If no report has been received from a machine for 5 minutes, .I rwho assumes the machine is down, and does not report users last known to be logged into that machine. .LP If a user hasn't typed to the system for a minute or more, .I rwho reports this idle time. If a user hasn't typed to the system for an hour or more, the user is omitted from the output of .I rwho unless the .B \-a flag is given. .SH OPTIONS .TP .B \-a report all users whether or not they have typed to the system in the past hour. .TP .B \-h report all users who are .I hungry. .SH FILES /usr/spool/rwho/whod.* information about other machines .SH SEE ALSO hungry(1C), ruptime(1C), rwhod(8C) .SH BUGS .LP Does not work through gateways. .LP This is unwieldy when the number of machines on the local net is large. SHAR_EOF # End of shell archive exit 0