home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2319 < prev    next >
Encoding:
Text File  |  1990-12-28  |  23.8 KB  |  916 lines

  1. Newsgroups: alt.sources
  2. From: christos@theory.tn.cornell.edu (Christos S. Zoulas)
  3. Subject: tcsh 5.20.02 available [and ywho source]
  4. Message-ID: <1990Dec15.180804.12756@batcomputer.tn.cornell.edu>
  5. Date: Sat, 15 Dec 90 18:08:04 GMT
  6.  
  7.  
  8. Hello,
  9.  
  10. Tcsh-5.20.02 is now available from tesla.ee.cornell.edu (128.84.253.11),
  11. in /pub/tcsh-5.20.
  12.  
  13. Tcsh is a set of patches to the 4.3BSD csh that add amongst other
  14. things command line editing and completion.
  15.  
  16. In order to compile tcsh, you will need a copy of the 4.3BSD csh, or
  17. a copy of the 4.3BSD-tahoe, or a copy of the 4.3BSD-reno csh.
  18.  
  19. I would like to thank everybody for their bug reports.
  20. I would also like to thank the following people for fixing bugs, testing,
  21. and re-writing parts of the code.
  22.  
  23. Mark Davies        mark@comp.vuw.ac.nz
  24. Matt Day         mday@iconsys.icon.com
  25. Per Hedeland        per@erix.ericsson.se
  26. Borje Josefsson        bj@dc.luth.se
  27. Dan Karron        karron@karron.med.nyu.edu
  28. Dan Oscarsson        dan@dna.lth.se 
  29. Eric Schnoebelen    schonebe@convex.com
  30. Jaap Vermeulen        jaap@sequent.com
  31. Johan Widen         jw@sics.se
  32.  
  33. The following binaries are available for 5.20.02:
  34.  
  35. -rwxr-xr-x  1 christos   144832 Dec 14 18:34 tcsh.Dynix_3.Z
  36. -rwxr-xr-x  1 christos   181250 Dec 14 18:30 tcsh.Dynix_ptx.Z
  37. -rwxr-xr-x  1 christos   153730 Dec 14 17:01 tcsh.hp9000s300-hpux7.0.Z
  38. -rwxr-xr-x  1 christos   198911 Dec 14 17:01 tcsh.ibm370-aixG9.9.Z
  39. -rwxr-xr-x  1 christos   180207 Dec 14 17:01 tcsh.iris4d-irix3.3.1.Z
  40. -rwxr-xr-x  1 christos   155830 Dec 14 17:01 tcsh.rs6000-aix3.1.Z
  41. -rwxr-xr-x  1 christos   131933 Dec 14 17:01 tcsh.sun3-sunos4.1.Z
  42. -rwxr-xr-x  1 christos   155562 Dec 14 17:01 tcsh.sun4-sunos4.1.Z
  43.  
  44. Also I would like to mention that this is the last tcsh announcement
  45. in alt.sources. From now on, tcsh announcements will be posted in
  46. comp.unix.shell.
  47.  
  48. Also I am adding the source for ywho/yusers/yuptime to redeem myself!
  49.  
  50. Have a Merry Christmas!
  51.  
  52. christos
  53.  
  54. PS: I will be out of the country for the next two weeks, so don't expect
  55.     immediate answers to your mail messages...
  56.  
  57. #! /bin/sh
  58. # This is a shell archive.  Remove anything before this line, then unpack
  59. # it by saving it into a file and typing "sh file".  To overwrite existing
  60. # files, type "sh file -c".  You can also feed this as standard input via
  61. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  62. # will see the following message at the end:
  63. #        "End of shell archive."
  64. # Contents:  ywho ywho/Makefile ywho/ywho.1v ywho/ywho.c ywho/yhosts
  65. # Wrapped by christos@guillemin on Sat Dec 15 12:51:35 1990
  66. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  67. if test ! -d 'ywho' ; then
  68.     echo shar: Creating directory \"'ywho'\"
  69.     mkdir 'ywho'
  70. fi
  71. if test -f 'ywho/Makefile' -a "${1}" != "-c" ; then 
  72.   echo shar: Will not clobber existing file \"'ywho/Makefile'\"
  73. else
  74. echo shar: Extracting \"'ywho/Makefile'\" \(650 characters\)
  75. sed "s/^X//" >'ywho/Makefile' <<'END_OF_FILE'
  76. X#
  77. X# Makefile for ywho
  78. X#
  79. XSHELL         = /bin/sh
  80. XCFLAGS        = -O
  81. X#CFLAGS        = -g -DDEBUG
  82. XDEST          = /usr/local/bin
  83. XOBJS          = ywho.o
  84. XPROGRAM          = ywho
  85. XSRCS          = ywho.c
  86. XCC          = cc
  87. X
  88. Xall:        $(PROGRAM)
  89. X
  90. X$(PROGRAM):     $(OBJS) 
  91. X        cc $(CFLAGS) $(OBJS) -o $(PROGRAM) -lrpcsvc
  92. X
  93. Xclean:;        rm -f $(OBJS) ywho yusers yuptime
  94. X
  95. Xinstall:    $(PROGRAM)
  96. X        rm -f ${DEST}/ywho ${DEST}/yusers ${DEST}/yuptime
  97. X        install -s $(PROGRAM) $(DEST)
  98. X        ln $(DEST)/$(PROGRAM) $(DEST)/yusers
  99. X        ln $(DEST)/$(PROGRAM) $(DEST)/yuptime
  100. X
  101. Xtags:           $(HDRS) $(SRCS)
  102. X        ctags $(HDRS) $(SRCS)
  103. X
  104. Xdepend:        
  105. X        gendep -m Makefile $(CFLAGS) $(SRCS)
  106. X
  107. X# DO NOT DELETE THIS LINE
  108. END_OF_FILE
  109. if test 650 -ne `wc -c <'ywho/Makefile'`; then
  110.     echo shar: \"'ywho/Makefile'\" unpacked with wrong size!
  111. fi
  112. # end of 'ywho/Makefile'
  113. fi
  114. if test -f 'ywho/ywho.1v' -a "${1}" != "-c" ; then 
  115.   echo shar: Will not clobber existing file \"'ywho/ywho.1v'\"
  116. else
  117. echo shar: Extracting \"'ywho/ywho.1v'\" \(2440 characters\)
  118. sed "s/^X//" >'ywho/ywho.1v' <<'END_OF_FILE'
  119. X.TH YWHO 1V "28 February 1988"
  120. X.SH NAME
  121. Xywho/yusers/yuptime \- who, users, uptime on clients in a sun-RPC network.
  122. X.SH SYNOPSIS
  123. X.B ywho/yusers/yuptime 
  124. X[<host>]|[-g <netgroup>]
  125. X.SH DESCRIPTION
  126. X.I ywho
  127. Xis another version of rwho, but it is faster than rwho and requires
  128. Xno /usr/spool/rwho/rwhod.*. Note that rwho wastes system resources, but
  129. Xywho doesn't. It utilizes SUN RPC and XDR protocol.
  130. X.br
  131. X.sp
  132. X.nf
  133. XHost           User     tty      login at       idle  from host     
  134. Xphaeton        Nobody logged on.
  135. Xwhite          danb     console  Feb 27 16:06      3 
  136. Xkafka          dave     console  Feb 24 09:39     49 
  137. Xcamus          ananth   console  Feb 24 20:22        
  138. Xhyperion       luk      ttyp0    Feb 27 12:01   1:19  jacobi        
  139. X.fi
  140. X.br
  141. X.sp
  142. XWhen invoked with a hostname or netgroup argument, 
  143. X.I ywho 
  144. Xwill only perform a who on
  145. Xthat host or all the hosts in that netgroup, 
  146. Xotherwise it will look for a list of hosts in $HOME/.yhosts.
  147. XIf that file is not found, ywho will try to find the system default
  148. Xyhosts file.
  149. X.br
  150. X.sp
  151. XThe system ywho file is a list of hosts separated by white-space or 
  152. Xcommas. A `#' character signifies the beginning of a comment.
  153. XA line of the form
  154. X.I timeout=<number>
  155. Xspecifies the number of seconds to timeout when waiting for a host 
  156. Xto respond.
  157. X.br
  158. X.sp
  159. XIf
  160. X.I ywho 
  161. Xis invoked as
  162. X.I yusers,
  163. Xthen a more compact form of the information is presented in the form
  164. Xof 
  165. X.I rusers(1).
  166. X.br
  167. X.sp
  168. X.nf
  169. Xkafka         : dave
  170. Xcamus         : ananth
  171. Xsibelius      : tlfine
  172. Xjacobi        : luk
  173. Xlove          : phw phw phw
  174. Xtcgould       : schinder metzger swb xputer cohen dsingh fielding
  175. X                fielding metzger mary chiang berggren leary danae
  176. X                beers scann beers
  177. X.fi
  178. X.br
  179. X.sp
  180. XIf
  181. X.I ywho 
  182. Xis invoked as
  183. X.I yuptime,
  184. Xthe uptime information for the hosts is presented, like
  185. X.I ruptime(1).
  186. X.br
  187. X.sp
  188. X.nf
  189. Xphaeton         up   41+00:08,   1  user, load 0.19, 0.27, 0.04
  190. Xhyperion        up   11+02:31,  12 users, load 0.43, 0.41, 0.30
  191. Xeos             up   40+23:56,   1  user, load 0.00, 0.00, 0.00
  192. Xtesla           up       8:29,   6 users, load 0.07, 0.25, 0.33
  193. Xsvax            up    1+06:20,  26 users, load 0.52, 1.38, 1.65
  194. X.fi
  195. X.br
  196. X.sp
  197. X.br
  198. X.sp
  199. X.SH AUTHORS 
  200. XJames P. Lewis, York University, 1988
  201. X.br
  202. XChristos S. Zoulas, Cornell University, 1989
  203. X.SH SEE ALSO
  204. Xnetgroup(5), yp(5)
  205. X.SH NOTE
  206. XWhen a host is down, it retries until timeout. It only works if your
  207. Xserver and clients are configured with SUN RPC.
  208. END_OF_FILE
  209. if test 2440 -ne `wc -c <'ywho/ywho.1v'`; then
  210.     echo shar: \"'ywho/ywho.1v'\" unpacked with wrong size!
  211. fi
  212. # end of 'ywho/ywho.1v'
  213. fi
  214. if test -f 'ywho/ywho.c' -a "${1}" != "-c" ; then 
  215.   echo shar: Will not clobber existing file \"'ywho/ywho.c'\"
  216. else
  217. echo shar: Extracting \"'ywho/ywho.c'\" \(14519 characters\)
  218. sed "s/^X//" >'ywho/ywho.c' <<'END_OF_FILE'
  219. X/* $Header: /usr/share/src/local/common/bin/ywho/RCS/ywho.c,v 1.10 90/10/04 19:28:14 christos Exp $ */
  220. X/* 
  221. X * ywho.c: Use rpc to obtain information about remote users
  222. X *       if it is invoked as yusers, present info in short format
  223. X *
  224. X *
  225. X * Original Author:
  226. X *    James P. Lewis        | FREE TO DISTRIBUTE WITH THIS HEADER
  227. X *    York University        | REMAINS INTACT.
  228. X *    4700 Keele Street    |
  229. X *    Downsview, Ontario    |
  230. X *    Canada            |
  231. X *    M3J-1P3            |
  232. X *
  233. X *    ...yunexus!james
  234. X *
  235. X * yuptime, yusers, and .yhosts added by Christos Zoulas
  236. X * christos@ee.cornell.edu
  237. X *
  238. X *
  239. X * $Log:    ywho.c,v $
  240. X * Revision 1.10  90/10/04  19:28:14  christos
  241. X * Eliminated duplicate hosts from the list.
  242. X * Fixed printing for remote host.
  243. X * Added error message when no hosts are found.
  244. X * 
  245. X * Revision 1.9  90/08/27  14:29:32  root
  246. X * Fixed some non terminated host names.
  247. X * 
  248. X * Revision 1.8  90/08/27  14:20:41  root
  249. X * Fixed bug with day-hours, and increased
  250. X * hosts field widths.
  251. X * 
  252. X * Revision 1.7  90/03/03  15:41:36  christos
  253. X * Fixed > to >= for the check to divide
  254. X * for times. What a stupid mistake!
  255. X * Also fixed 'user ,' to ' user,' in
  256. X * yuptime.
  257. X * 
  258. X * Revision 1.6  90/02/12  18:55:50  christos
  259. X * Fixed missing longjmp in yuptime
  260. X * and dont cut X11 DISPLAYS.
  261. X * 
  262. X * Revision 1.5  89/11/27  02:18:34  christos
  263. X * Fixed interrupted/exiting
  264. X * 
  265. X * Revision 1.4  89/11/27  02:11:02  christos
  266. X * Added netgroups
  267. X * 
  268. X * Revision 1.3  89/11/15  18:41:32  christos
  269. X * *** empty log message ***
  270. X * 
  271. X * Revision 1.2  89/09/16  07:22:18  christos
  272. X * Fixed to exit on 2 consecutive
  273. X * interrupts.
  274. X * 
  275. X * Revision 1.1  89/09/16  07:03:00  christos
  276. X * Initial revision
  277. X *  
  278. X *
  279. X */
  280. X#ifndef lint
  281. Xstatic char rcsid[] = "$Id: ywho.c,v 1.10 90/10/04 19:28:14 christos Exp $";
  282. X#endif /* lint */
  283. X
  284. X#include <sys/types.h>
  285. X#include <sys/param.h>
  286. X#include <stdio.h>
  287. X#include <signal.h>
  288. X#include <string.h>
  289. X#include <utmp.h>
  290. X#include <ctype.h>
  291. X#include <setjmp.h>
  292. X#include <rpc/rpc.h>
  293. X#include <rpcsvc/rstat.h>
  294. X#include <rpcsvc/rusers.h>
  295. X#include <sys/socket.h>
  296. X#include <sys/time.h>
  297. X#include <netdb.h>
  298. X
  299. X#ifdef MAXHOSTNAMELEN
  300. X# define HST_LEN MAXHOSTNAMELEN
  301. X#else
  302. X# define HST_LEN 64
  303. X#endif
  304. X
  305. X#define NIL(a) ((a *) 0)
  306. X#define NEW(a) ((a *) Malloc(sizeof(a)))
  307. X#define NEWN(a, n) ((a *) Malloc(sizeof(a) * (n)))
  308. X#define strdup(a) ((char *) strcpy(Malloc(strlen(a) + 1), a))
  309. X#define SEP "\t \n,="
  310. X#ifndef FSCALE
  311. X#define FSCALE (1 << 8)
  312. X#endif
  313. X
  314. X#define RWHO     0
  315. X#define RUSERS     1
  316. X#define RUPTIME 2
  317. X
  318. X#ifdef hpux
  319. X#define bcopy(a, b, c) memcpy(b, a, c)
  320. X#endif
  321. X#ifndef SYSHOSTS
  322. X#define SYSHOSTS "/usr/local/etc/yhosts"
  323. X#endif
  324. Xtypedef struct hosts_t {
  325. X    struct hostent hp;
  326. X    struct hosts_t *next;
  327. X} hosts_t;
  328. X
  329. Xextern char *ctime();
  330. Xextern char *strchr();
  331. Xextern char *getenv();
  332. Xextern char *sys_errlist[];
  333. Xextern int  errno;
  334. Xstatic char *Malloc();
  335. Xstatic void do_host();
  336. Xstatic void do_timeout();
  337. Xstatic char *pname;
  338. Xstatic int  timeout;
  339. Xstatic int  what;
  340. Xstatic jmp_buf goback;
  341. Xstatic int interrupted;
  342. Xstatic hosts_t *hosts = NIL(hosts_t), *hptr = NIL(hosts_t);
  343. X
  344. X
  345. Xvoid
  346. Xaddhost(h)
  347. Xchar *h;
  348. X{
  349. X    struct hostent *hp;
  350. X    struct hosts_t *hh;
  351. X    int i;
  352. X
  353. X    if (h == NIL(char))
  354. X    return;
  355. X
  356. X    if ((hp = gethostbyname(h)) == NIL(struct hostent)) {
  357. X    (void) fprintf(stderr, 
  358. X        "gethostbyname: can't get addr for %s\n", h);
  359. X    return;
  360. X    }
  361. X    if ( hosts == NIL(hosts_t) ) 
  362. X    hosts = hptr = NEW(hosts_t);
  363. X    else {
  364. X    for (hh = hosts; hh != NIL(hosts_t); hh = hh->next) 
  365. X        if (strcmp(hp->h_name, hh->hp.h_name) == 0)
  366. X        return;
  367. X    hptr->next = NEW(hosts_t);
  368. X    hptr = hptr->next;
  369. X    }
  370. X    hptr->hp = *hp;
  371. X    hptr->hp.h_name = strdup(hp->h_name);
  372. X#ifndef h_addr
  373. X    hptr->hp.h_addr = NEWN(char, hp->h_length);
  374. X    bcopy(hp->h_addr, hptr->hp.h_addr, hp->h_length);
  375. X#else
  376. X    for (i = 0; hp->h_addr_list[i] != NIL(char); i++);
  377. X    hptr->hp.h_addr_list = NEWN(char *, i + 1);
  378. X    hptr->hp.h_addr_list[i] = NIL(char);
  379. X    for (i--;i >= 0; i--) {
  380. X    hptr->hp.h_addr_list[i] = NEWN(char, hp->h_length);
  381. X    bcopy(hp->h_addr_list[i], hptr->hp.h_addr_list[i], hp->h_length);
  382. X    }
  383. X#endif
  384. X
  385. X    for (h = hptr->hp.h_name; *h; h++)
  386. X    *h = isupper(*h) ? tolower(*h) : *h;
  387. X    hptr->next = NIL(hosts_t);    
  388. X} /* end addhost */
  389. X
  390. X
  391. Xmain(argc, argv)
  392. Xint     argc;
  393. Xchar    *argv[];
  394. X{
  395. X    FILE *fp;
  396. X    char *ptr;
  397. X    char *home;
  398. X    int err1, err2;
  399. X    char buffer[BUFSIZ];
  400. X
  401. X
  402. X    pname = strdup(*argv);
  403. X    if ( (ptr = strrchr(pname, '/')) != NIL(char) )
  404. X    pname = ptr + 1;
  405. X    
  406. X    what = RWHO;
  407. X    what += (pname[1] == 'u'); /* y(u)sers */
  408. X    what += (pname[2] == 'p'); /* yu(p)time */
  409. X    timeout = 2;
  410. X
  411. X
  412. X    if ( argc == 1 ) {
  413. X    home = getenv("HOME");
  414. X    sprintf(buffer, "%s%s.yhosts", home ? home : "", home ? "/" : "");
  415. X    fp = fopen(buffer, "r");
  416. X
  417. X    if ( fp == NIL(FILE) ) {
  418. X        err1 = errno;
  419. X        fp = fopen(SYSHOSTS, "r");
  420. X    }
  421. X    
  422. X    if ( fp == NIL(FILE) ) {
  423. X        err2 = errno;
  424. X        (void) fprintf(stderr, 
  425. X        "%s: Could not open \n\t`%s' (%s) or \n\t`%s' (%s).\n",
  426. X        pname, buffer, sys_errlist[err1], SYSHOSTS, sys_errlist[err2]);
  427. X        exit(1);
  428. X    }
  429. X    while ( fgets(buffer, BUFSIZ, fp) != 0 ) {
  430. X        ptr = strtok(buffer, SEP);
  431. X        if ( ptr == NIL(char) )
  432. X        continue;
  433. X        if ( ptr[0] == '#' )
  434. X        continue;
  435. X        if ( strcmp(ptr, "timeout") == 0 ) {
  436. X        if ((ptr = strtok(NIL(char), "= \t\n")) == NIL(char)) {
  437. X            (void) fprintf(stderr, 
  438. X            "%s: Missing timeout value.\n", pname);
  439. X            exit(1);
  440. X        }
  441. X        if ( sscanf(ptr, "%d", &timeout) != 1 ) {
  442. X            (void) fprintf(stderr, 
  443. X            "%s: Bad timeout value (%s).\n", pname,
  444. X            ptr);
  445. X            exit(1);
  446. X        }
  447. X        if ( timeout <= 0 ) {
  448. X            (void) fprintf(stderr, 
  449. X            "%s: Negative or zero timeout value (%d).\n", pname, 
  450. X            timeout);
  451. X            exit(1);
  452. X        }
  453. X        continue;
  454. X        }
  455. X        addhost(ptr);
  456. X    }
  457. X    (void) fclose(fp);
  458. X    } 
  459. X    else {
  460. X    int i;
  461. X    char *s;
  462. X
  463. X    for ( i = 1; i < argc; i++ ) 
  464. X        if (argv[i][0] == '-') 
  465. X        for (s = &argv[i][1]; *s; s++)
  466. X        switch (*s) {
  467. X        case 'g':
  468. X            setnetgrent(argv[++i]);
  469. X            do {
  470. X            char *hp = NIL(char), *gp = NIL(char), *dp = NIL(char);
  471. X            if (getnetgrent(&hp, &gp, &dp) == 0)
  472. X                break;
  473. X            addhost(hp);
  474. X            } while (1);
  475. X            endnetgrent();
  476. X            break;
  477. X        default:
  478. X            (void) fprintf(stderr, 
  479. X            "Usage: %s [<host>]|[-g <netgroup>]\n",
  480. X            pname);
  481. X            exit(1);
  482. X        }
  483. X        else
  484. X        addhost(argv[i]);
  485. X    }
  486. X    if (hosts == NIL(hosts_t)) {
  487. X    (void) fprintf(stderr, "%s: No hosts.\n", pname);
  488. X    exit(1);
  489. X    }
  490. X
  491. X            
  492. X    switch ( what ) {
  493. X    case RWHO :
  494. X#if !defined(hpux) || defined(__hpux)
  495. X    (void) fprintf(stdout,
  496. X        "%-16.16s %-8.8s %-8.8s %-12.12s %6.6s  %-16.16s\n", 
  497. X        "Host",  "User", "tty", "login at ", "idle", "from host");
  498. X#else
  499. X    (void) fprintf(stdout,
  500. X        "%-16.16s %-8.8s %-8.8s %-12.12s %6.6s\n", 
  501. X        "Host",  "User", "tty", "login at ", "idle");
  502. X#endif
  503. X    break;
  504. X    case RUSERS :
  505. X    break;
  506. X    case RUPTIME :
  507. X    break;
  508. X    }
  509. X
  510. X    (void) signal(SIGALRM, do_timeout);
  511. X    (void) signal(SIGINT, do_timeout);
  512. X    (void) fflush(stdout);
  513. X    interrupted = 0;
  514. X    for ( hptr = hosts; hptr != NIL(hosts_t); hptr = hptr->next ) {
  515. X    if ( !setjmp(goback) ) { 
  516. X        alarm(timeout+1);
  517. X        interrupted = 0;
  518. X        do_host(hptr); 
  519. X    }
  520. X    alarm(0);
  521. X    }
  522. X    exit(0);
  523. X}
  524. X
  525. Xstatic struct utmpidlearr      cutmpidlearr;
  526. Xstatic struct statstime        sttime;
  527. X
  528. X/* do_host():
  529. X *    Somehow I am corrupting memory. If I don't declare utmpidlearray
  530. X *    and sttime as globals, I core dump *sometimes*. Allocation for
  531. X *    these might be wrong. Anyway it is working now. Till it breaks 
  532. X *    again.
  533. X */
  534. Xstatic void
  535. Xdo_host(hst)
  536. Xhosts_t *hst;
  537. X{
  538. X    char                nick_name[HST_LEN], tmp[BUFSIZ];
  539. X    int                 ss, dd, hh, mm, printed;
  540. X    int                 addrlen, i, j, sock;
  541. X    register CLIENT     *client, *client_st;
  542. X    struct hostent      *hp;
  543. X    struct timeval      pertry_timeout, total_timeout;
  544. X    struct sockaddr_in  server_addr;
  545. X    enum clnt_stat      clnt_stat, clnt_stat_st;
  546. X    char                *ptr, *host;
  547. X    
  548. X
  549. X    (void) strncpy(nick_name, hst->hp.h_name, HST_LEN);
  550. X
  551. X    hp = &hst->hp;
  552. X
  553. X    if ( ! isdigit(nick_name[0]) )
  554. X    if ( ptr = strchr(nick_name, '.'))
  555. X        *ptr = '\0';
  556. X    
  557. X    
  558. X    if ( what == RWHO || what == RUPTIME ) {
  559. X    (void) fprintf(stdout, "%-16.16s ", nick_name);
  560. X    (void) fflush(stdout);
  561. X    }
  562. X    if ( what == RUPTIME ) {
  563. X    sock = RPC_ANYSOCK;
  564. X    pertry_timeout.tv_sec = timeout;
  565. X    pertry_timeout.tv_usec = 0;
  566. X    total_timeout.tv_sec = timeout;
  567. X    total_timeout.tv_usec = 0;
  568. X    addrlen = sizeof(struct sockaddr_in);
  569. X    bcopy(hp->h_addr, (caddr_t) &server_addr.sin_addr, hp->h_length);
  570. X    server_addr.sin_family = AF_INET;
  571. X    server_addr.sin_port = 0;
  572. X    if ((client_st = clntudp_create(&server_addr, RSTATPROG,
  573. X        RSTATVERS_TIME, pertry_timeout, &sock)) == NULL) {
  574. X        (void) fprintf(stdout, "down\n");
  575. X        return;
  576. X    }
  577. X    clnt_stat_st = clnt_call(client_st, RSTATPROC_STATS, xdr_void, 
  578. X        0, xdr_statstime, &sttime, total_timeout);
  579. X    if ( clnt_stat_st != RPC_SUCCESS ) {
  580. X        switch ( what ) {
  581. X        case RWHO :
  582. X        case RUPTIME :
  583. X        case RUSERS :
  584. X        clnt_perror(client_st, "RSTAT");
  585. X        break;
  586. X        }
  587. X        return;
  588. X    }
  589. X    clnt_freeres(client_st, xdr_statstime, &sttime);
  590. X    clnt_destroy(client_st);
  591. X    }
  592. X
  593. X    sock = RPC_ANYSOCK;
  594. X    pertry_timeout.tv_sec = timeout;
  595. X    pertry_timeout.tv_usec = 0;
  596. X    total_timeout.tv_sec = timeout;
  597. X    total_timeout.tv_usec = 0;
  598. X    addrlen = sizeof(struct sockaddr_in);
  599. X    bcopy(hp->h_addr, (caddr_t) &server_addr.sin_addr, hp->h_length);
  600. X    server_addr.sin_family = AF_INET;
  601. X    server_addr.sin_port = 0;
  602. X    if ((client = clntudp_create(&server_addr, RUSERSPROG,
  603. X    RUSERSVERS_IDLE, pertry_timeout, &sock)) == NULL) {
  604. X    switch (what) {
  605. X        case RWHO :
  606. X        clnt_pcreateerror("clntudp_create");
  607. X        break;
  608. X        case RUSERS :
  609. X        break;
  610. X        case RUPTIME :    
  611. X        break;
  612. X    }
  613. X    return;
  614. X    }
  615. X
  616. X    clnt_stat = clnt_call(client, RUSERSPROC_NAMES, xdr_void, 
  617. X    0, xdr_utmpidlearr, &cutmpidlearr, total_timeout);
  618. X    if ( clnt_stat != RPC_SUCCESS ) {
  619. X    switch ( what ) {
  620. X    case RWHO :
  621. X    case RUPTIME :
  622. X    case RUSERS :
  623. X        clnt_perror(client, "RUSERS");
  624. X        break;
  625. X    }
  626. X    return;
  627. X    }
  628. X
  629. X    if ( what == RWHO ) 
  630. X    if ( cutmpidlearr.uia_cnt == 0 ) 
  631. X        (void) fprintf(stdout, "Nobody logged on.\n");
  632. X
  633. X    switch ( what ) {
  634. X    case RWHO :
  635. X    for (i = 0; i < cutmpidlearr.uia_cnt; i++) {
  636. X        j = cutmpidlearr.uia_arr[i]->ui_utmp.ut_time;
  637. X
  638. X        dd = hh = 0;
  639. X        mm = cutmpidlearr.uia_arr[i]->ui_idle;
  640. X
  641. X        if (mm >= 60) {
  642. X        hh = mm / 60;
  643. X        mm = mm % 60;
  644. X        }
  645. X        if (hh >= 24) {
  646. X        dd = hh / 24;
  647. X        hh = hh % 24;
  648. X        }
  649. X
  650. X        if ( dd == 0 )
  651. X        if ( hh == 0 )
  652. X            if ( mm == 0 ) 
  653. X                *tmp = 0;
  654. X            else
  655. X            (void) sprintf(tmp, "    %2d", mm);
  656. X        else
  657. X            (void) sprintf(tmp, " %2d:%-2.2d", hh, mm);
  658. X        else
  659. X        (void) sprintf(tmp, "%2dd%-2.2dh", dd, hh);
  660. X
  661. X        (void) fprintf(stdout, "%-8.8s %-8.8s %-12.12s %-6.6s ", 
  662. X           cutmpidlearr.uia_arr[i]->ui_utmp.ut_name,
  663. X           cutmpidlearr.uia_arr[i]->ui_utmp.ut_line,
  664. X           ctime(&j)+4, tmp);
  665. X
  666. X#if !defined(hpux) || defined(__hpux) 
  667. X        if (*(host = cutmpidlearr.uia_arr[i]->ui_utmp.ut_host)) {
  668. X        char *ptr, flg;
  669. X        for (ptr = tmp, flg = isdigit(*host) ? '\0' : '.'; 
  670. X             *host != '\0' && ptr < 
  671. X             &tmp[sizeof(cutmpidlearr.uia_arr[i]->ui_utmp.ut_host)] &&
  672. X             (*host != flg || ((host = strchr(host, ':')) != 0));
  673. X             host++) {
  674. X            if (*host == ':') flg = '\0';
  675. X            *ptr++ = isupper(*host) ? tolower(*host) : *host;
  676. X            *ptr = '\0';
  677. X        }
  678. X        (void) fprintf(stdout, " %-16.16s\n", tmp);
  679. X        }
  680. X        else 
  681. X#endif
  682. X        (void) fprintf(stdout, "\n");
  683. X        if ( i < cutmpidlearr.uia_cnt - 1 ) 
  684. X        (void) fprintf(stdout, "%-16.16s ", nick_name);
  685. X    }
  686. X    break;
  687. X    case RUSERS :
  688. X    /* print in rusers format */
  689. X    for (i = 0; i < cutmpidlearr.uia_cnt; i++) {
  690. X        printed = FALSE;
  691. X        if ( i == 0 )
  692. X        (void) sprintf(tmp, "%-16.16s:", nick_name);
  693. X        (void) strcat(tmp, " ");
  694. X        (void) strncat(tmp, cutmpidlearr.uia_arr[i]->ui_utmp.ut_name, 8);
  695. X        
  696. X        if ( strlen(tmp) > 60 ) {
  697. X        (void) fprintf(stdout, "%s\n", tmp);
  698. X        (void) strcpy(tmp, "               ");
  699. X        printed = TRUE;
  700. X        }
  701. X    }
  702. X    if ( i > 0 && ! printed )
  703. X        (void) fprintf(stdout, "%s\n", tmp);
  704. X    (void) fflush(stdout);
  705. X    break;
  706. X    case RUPTIME :
  707. X    ss = sttime.curtime.tv_sec - sttime.boottime.tv_sec;
  708. X    mm = hh = dd = 0;
  709. X    if ( ss >= 60 ) {
  710. X        mm = ss / 60;
  711. X        ss = ss % 60;
  712. X    }
  713. X    if ( mm >= 60 ) {
  714. X        hh = mm / 60;
  715. X        mm = mm % 60;
  716. X    }
  717. X    if ( hh >= 24 ) {
  718. X        dd = hh / 24;
  719. X        hh = hh % 24;
  720. X    }
  721. X    if ( dd > 0 ) 
  722. X        (void) sprintf(tmp, "%3d+%.2d:%.2d", dd, hh, mm);
  723. X    else if ( hh > 0 )
  724. X        (void) sprintf(tmp, "    %2d:%.2d", hh, mm);
  725. X    else 
  726. X        (void) sprintf(tmp, "       %2d", mm);
  727. X
  728. X    (void) fprintf(stdout, " up  %s, %3d %5s, load %3.2f, %3.2f, %3.2f\n",
  729. X        tmp, 
  730. X        cutmpidlearr.uia_cnt,
  731. X        cutmpidlearr.uia_cnt == 1 ? " user" : "users",
  732. X        (double) sttime.avenrun[0] / FSCALE, 
  733. X        (double) sttime.avenrun[1] / FSCALE, 
  734. X        (double) sttime.avenrun[2] / FSCALE);
  735. X    break;
  736. X    }
  737. X
  738. X    clnt_freeres(client, xdr_utmpidlearr, &cutmpidlearr);
  739. X    clnt_destroy(client);
  740. X
  741. X    return; 
  742. X} /* end do_host */
  743. X
  744. X/* Malloc(): 
  745. X *    Memory checked malloc
  746. X */
  747. Xstatic char *
  748. XMalloc(nth)
  749. Xunsigned nth;
  750. X{
  751. X    char *ptr;
  752. X    extern char *malloc();
  753. X
  754. X    if ((ptr = malloc(nth)) == NIL(char)) {
  755. X    (void) fprintf(stderr, "%s: Out of memory.\n", pname);
  756. X    exit(1);
  757. X    }
  758. X    return(ptr);
  759. X} /* end Malloc */
  760. X
  761. X/* do_timeout():
  762. X *    Since the select timeout does not work right, we use our's
  763. X */
  764. Xstatic void
  765. Xdo_timeout(signum)
  766. Xint signum;
  767. X{
  768. X    switch ( what ) {
  769. X    case RWHO :
  770. X    if ( signum == SIGALRM ) 
  771. X        (void) fprintf(stdout, "No answer.\n");
  772. X    else if ( signum == SIGINT ) 
  773. X        if ( ! interrupted ) {
  774. X        interrupted = 1;
  775. X        (void) fprintf(stdout, "Interrupted.\n");
  776. X        sleep(1);
  777. X        }
  778. X        else {
  779. X        (void) fprintf(stdout, "Exiting.\n");
  780. X        exit(0);
  781. X        }
  782. X    (void) fflush(stdout);
  783. X    longjmp(goback, 1);
  784. X    break;
  785. X    case RUPTIME :
  786. X    if ( signum == SIGALRM ) 
  787. X        (void) fprintf(stdout, "down\n");
  788. X    else if ( signum == SIGINT ) 
  789. X        if ( ! interrupted ) {
  790. X        interrupted = 1;
  791. X        (void) fprintf(stdout, "Interrupted.\n");
  792. X        sleep(1);
  793. X        }
  794. X        else {
  795. X        (void) fprintf(stdout, "Exiting.\n");
  796. X        exit(0);
  797. X        }
  798. X    longjmp(goback, 1);
  799. X    break;
  800. X    case RUSERS :
  801. X    if ( signum == SIGALRM ) ;
  802. X    else if ( signum == SIGINT ) 
  803. X        if ( ! interrupted ) {
  804. X        interrupted = 1;
  805. X        (void) fprintf(stdout, "Interrupted.\n");
  806. X        sleep(1);
  807. X        }
  808. X        else {
  809. X        (void) fprintf(stdout, "Exiting.\n");
  810. X        exit(0);
  811. X        }
  812. X    (void) fflush(stdout);
  813. X    longjmp(goback, 1);
  814. X    break;
  815. X    }
  816. X} /* end do_timeout */
  817. X
  818. X#ifdef hpux
  819. Xvoid (*
  820. Xsignal(s, a))()
  821. X    int s;
  822. Xvoid (*a)();
  823. X{
  824. X    struct sigvec osv, sv;
  825. X
  826. X    sigvector(s, 0, &osv);
  827. X    sv = osv;
  828. X    sv.sv_handler = a;
  829. X    sv.sv_flags = SV_BSDSIG;
  830. X    if (sigvector(s, &sv, 0) < 0)
  831. X        return (BADSIG);
  832. X    return (osv.sv_handler);
  833. X}
  834. X#endif
  835. END_OF_FILE
  836. if test 14519 -ne `wc -c <'ywho/ywho.c'`; then
  837.     echo shar: \"'ywho/ywho.c'\" unpacked with wrong size!
  838. fi
  839. # end of 'ywho/ywho.c'
  840. fi
  841. if test -f 'ywho/yhosts' -a "${1}" != "-c" ; then 
  842.   echo shar: Will not clobber existing file \"'ywho/yhosts'\"
  843. else
  844. echo shar: Extracting \"'ywho/yhosts'\" \(1532 characters\)
  845. sed "s/^X//" >'ywho/yhosts' <<'END_OF_FILE'
  846. X#
  847. X# yhosts - list of hosts monitored by ywho/yuptime/yusers
  848. X#
  849. X
  850. X  timeout=10
  851. X
  852. X  tesla.ee.cornell.edu
  853. X# paxvax.ee.cornell.edu        (RPC is not yet set up)
  854. X# popov.ee.cornell.edu        (RPC is not yet set up)
  855. X# elvis.ee.cornell.edu        (no RPC support on VMS)
  856. X# mosvax.ee.cornell.edu        (RPC is not yet set up)
  857. X
  858. X  phaeton.ee.cornell.edu
  859. X  white.ee.cornell.edu
  860. X  kafka.ee.cornell.edu
  861. X  camus.ee.cornell.edu
  862. X  sibelius.ee.cornell.edu
  863. X  gonzo.ee.cornell.edu
  864. X  vonnegut.ee.cornell.edu
  865. X  jacobi.ee.cornell.edu
  866. X  seidel.ee.cornell.edu
  867. X  lewis.ee.cornell.edu
  868. X  london.ee.cornell.edu
  869. X  bigwood.ee.cornell.edu
  870. X# frost.ee.cornell.edu        (Prof. Berger is on sabbatical leave)
  871. X  twain.ee.cornell.edu
  872. X
  873. X  hyperion.ee.cornell.edu
  874. X  zombie.ee.cornell.edu
  875. X  bakul.ee.cornell.edu
  876. X  guillemin.ee.cornell.edu
  877. X  macdlab.ee.cornell.edu
  878. X
  879. X  ambrose.ee.cornell.edu
  880. X  whamo.ee.cornell.edu
  881. X  cardinal.ee.cornell.edu
  882. X  archy.ee.cornell.edu
  883. X  abarth.ee.cornell.edu
  884. X# nano.ee.cornell.edu        (not yet upgraded to HP/UX 6.5)
  885. X# pico.ee.cornell.edu        (not yet upgraded to HP/UX 6.5)
  886. X  femto.ee.cornell.edu
  887. X  pixel.ee.cornell.edu
  888. X  alto.ee.cornell.edu
  889. X  ragmanns.ee.cornell.edu
  890. X  dugout.ee.cornell.edu
  891. X  dunbars.ee.cornell.edu
  892. X
  893. X# pplab1.ee.cornell.edu        (no RPC support on System V)
  894. X# pplab2.ee.cornell.edu        (no RPC support on System V)
  895. X  pplab3.ee.cornell.edu
  896. X# pplab4.ee.cornell.edu        (no RPC support on System V)
  897. X  pplab5.ee.cornell.edu
  898. X
  899. X# nyquist.ee.cornell.edu    (no RPC support on System V)
  900. X# comp-sim.ee.cornell.edu    (no RPC support on System V)
  901. X
  902. X# ee-demo.ee.cornell.edu    (demo machine)
  903. END_OF_FILE
  904. if test 1532 -ne `wc -c <'ywho/yhosts'`; then
  905.     echo shar: \"'ywho/yhosts'\" unpacked with wrong size!
  906. fi
  907. # end of 'ywho/yhosts'
  908. fi
  909. echo shar: End of shell archive.
  910. exit 0
  911. -- 
  912. +------------------------------------------------------------------------+
  913. | Christos Zoulas         | 389 Theory Center, Electrical Engineering,   |
  914. | christos@ee.cornell.edu | Cornell University, Ithaca NY 14853.         |
  915. | christos@crnlee.bitnet  | Phone: Disconnected  |   Fax: (607) 254 4565 |
  916.