home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / xwhosup / part01 < prev    next >
Encoding:
Text File  |  1992-12-30  |  45.6 KB  |  1,779 lines

  1. Newsgroups: comp.sources.unix
  2. From: boyd@prl.dec.com (Boyd Roberts)
  3. Subject: v26i083: xwhosup - X11 R5 program to graphically display "rwho" activity, Part01/01
  4. Sender: unix-sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: boyd@prl.dec.com (Boyd Roberts)
  8. Posting-Number: Volume 26, Issue 84
  9. Archive-Name: xwhosup/part01
  10.  
  11. [ i totally blew it on this one the first time out.  "findsrc" doesn't seem
  12.   to like files with names like "s.h" because it left it out of the previous
  13.   kit.  also, i used the wrong name in the title.  sorry, boyd..   --vix ]
  14.  
  15. Originally:
  16.  
  17.     A snapshot performance monitor. Originally written to watch the load
  18.     distribution on the CPU's on an Silicon Graphics Iris4d/240, it can be
  19.     adapted to display a large variety of changing system statistics.
  20.     
  21.         - moraes@cs.toronto.edu (Mark Moraes)
  22.  
  23. Modified to snoop for rwhod(8) packets using Jeff Mogul's packetfilter(4)
  24. and display the 5 minute load average on a log scale, or alternating 
  25. yellow/black diagonal stripes if a host hasn't been heard from.
  26.  
  27. I have some grander plan to turn it into a general purpose resource
  28. monitor, but that'll have to wait.  For the moment I just want have
  29. some rough idea of what our machines are doing.
  30.  
  31. The X knowledgable will realise that the X code in this is pretty naive
  32. because I hate X and _refuse_ to learn about it -- what a disaster.  I just
  33. want the bits on the screen, without having to read through a pile of overly
  34. verbose and tedious documentation.  The (original) X code is Mark Moreas' work.
  35.  
  36.     - Boyd Roberts <boyd@prl.dec.com>
  37.       December '91
  38.       Digital PRL
  39.  
  40. #! /bin/sh
  41. # This is a shell archive.  Remove anything before this line, then unpack
  42. # it by saving it into a file and typing "sh file".  To overwrite existing
  43. # files, type "sh file -c".  You can also feed this as standard input via
  44. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  45. # will see the following message at the end:
  46. #        "End of archive 1 (of 1)."
  47. # Contents:  BUGS Bar.c Bar.h BarP.h COPYRIGHT MANIFEST Makefile README
  48. #   csu.diffs s-pfilt-rwho.c s.h xwhosup.1 xwhosup.c
  49. # Wrapped by vixie@cognition.pa.dec.com on Thu Dec 31 13:11:40 1992
  50. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  51. if test -f 'BUGS' -a "${1}" != "-c" ; then 
  52.   echo shar: Will not clobber existing file \"'BUGS'\"
  53. else
  54. echo shar: Extracting \"'BUGS'\" \(55 characters\)
  55. sed "s/^X//" >'BUGS' <<'END_OF_FILE'
  56. Resizing it vertically causes havoc, I'm not sure why.
  57. END_OF_FILE
  58. if test 55 -ne `wc -c <'BUGS'`; then
  59.     echo shar: \"'BUGS'\" unpacked with wrong size!
  60. fi
  61. # end of 'BUGS'
  62. fi
  63. if test -f 'Bar.c' -a "${1}" != "-c" ; then 
  64.   echo shar: Will not clobber existing file \"'Bar.c'\"
  65. else
  66. echo shar: Extracting \"'Bar.c'\" \(10785 characters\)
  67. sed "s/^X//" >'Bar.c' <<'END_OF_FILE'
  68. X#include <X11/copyright.h>
  69. X
  70. X/* $XConsortium: Bar.c,v 1.2 88/10/25 17:40:25 swick Exp $ */
  71. X/* Copyright    Massachusetts Institute of Technology    1987, 1988 */
  72. X
  73. X#include <X11/IntrinsicP.h>
  74. X#include <X11/StringDefs.h>
  75. X#include "BarP.h"
  76. X
  77. static Dimension def_dimension    = ~0;
  78. static XtOrientation def_orient = XtorientHorizontal;
  79. X#define DEF_LENGTH  ((Dimension) 200)
  80. X#define DEF_THICKNESS    ((Dimension) 15)
  81. X
  82. static XtResource resources[] = {
  83. X#define offset(field) XtOffset(BarWidget, bar.field)
  84. X#define Offset(field) XtOffset(BarWidget, field)
  85. X    /* {name, class, type, size, offset, default_type, default_addr}, */
  86. X    /*
  87. X     * We define these core class values to set defaults, so we can
  88. X     * initialize correctly
  89. X     */
  90. X    {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension),
  91. X    Offset(core.width), XtRDimension, (caddr_t)&def_dimension},
  92. X    {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
  93. X    Offset(core.height), XtRDimension, (caddr_t)&def_dimension},
  94. X    /* Private bar widget resources */
  95. X    {XtNlength, XtCLength, XtRDimension, sizeof(Dimension),
  96. X    offset(length), XtRDimension, (caddr_t) &def_dimension},
  97. X    {XtNthickness, XtCThickness, XtRDimension, sizeof(Dimension),
  98. X    offset(thickness), XtRDimension, (caddr_t) &def_dimension},
  99. X    {XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation),
  100. X    offset(orientation), XtROrientation, (caddr_t) &def_orient},
  101. X#undef offset
  102. X#undef Offset
  103. X};
  104. X
  105. static void ClassInitialize();
  106. static void Initialize();
  107. static void Resize();
  108. static void Redisplay();
  109. X
  110. BarClassRec barClassRec = {
  111. X  { /* core fields */
  112. X    /* superclass        */    (WidgetClass) &widgetClassRec,
  113. X    /* class_name        */    "Bar",
  114. X    /* widget_size        */    sizeof(BarRec),
  115. X    /* class_initialize        */    ClassInitialize,
  116. X    /* class_part_initialize    */    NULL,
  117. X    /* class_inited        */    FALSE,
  118. X    /* initialize        */    Initialize,
  119. X    /* initialize_hook        */    NULL,
  120. X    /* realize            */    XtInheritRealize,
  121. X    /* actions            */    NULL,
  122. X    /* num_actions        */    0,
  123. X    /* resources        */    resources,
  124. X    /* num_resources        */    XtNumber(resources),
  125. X    /* xrm_class        */    NULLQUARK,
  126. X    /* compress_motion        */    TRUE,
  127. X    /* compress_exposure    */    TRUE,
  128. X    /* compress_enterleave    */    TRUE,
  129. X    /* visible_interest        */    FALSE,
  130. X    /* destroy            */    NULL,
  131. X    /* resize            */    Resize,
  132. X    /* expose            */    Redisplay,
  133. X    /* set_values        */    NULL,
  134. X    /* set_values_hook        */    NULL,
  135. X    /* set_values_almost    */    XtInheritSetValuesAlmost,
  136. X    /* get_values_hook        */    NULL,
  137. X    /* accept_focus        */    NULL,
  138. X    /* version            */    XtVersion,
  139. X    /* callback_private        */    NULL,
  140. X    /* tm_table            */    NULL,
  141. X    /* query_geometry        */    XtInheritQueryGeometry,
  142. X    /* display_accelerator    */    XtInheritDisplayAccelerator,
  143. X    /* extension        */    NULL
  144. X  },
  145. X  { /* bar fields */
  146. X    /* gray            */    NULL
  147. X  }
  148. X};
  149. X
  150. WidgetClass barWidgetClass = (WidgetClass)&barClassRec;
  151. X
  152. X#ifdef    UGLY_GRAYS
  153. static char gray0_bits[] = {
  154. X   0x00, 0x00, 0x00};
  155. static char gray1_bits[] = {
  156. X   0x00, 0x02, 0x00};
  157. static char gray2_bits[] = {
  158. X   0x00, 0x03, 0x00};
  159. static char gray3_bits[] = {
  160. X   0x00, 0x03, 0x02};
  161. static char gray4_bits[] = {
  162. X   0x00, 0x07, 0x02};
  163. static char gray5_bits[] = {
  164. X   0x04, 0x07, 0x02};
  165. static char gray6_bits[] = {
  166. X   0x04, 0x07, 0x03};
  167. static char gray7_bits[] = {
  168. X   0x05, 0x07, 0x03};
  169. static char gray8_bits[] = {
  170. X   0x05, 0x07, 0x07};
  171. static char gray9_bits[] = {
  172. X   0xff, 0xff, 0xff};
  173. X
  174. static char *gray_bits[MAXGRAY] = {
  175. X    gray0_bits,
  176. X    gray1_bits,
  177. X    gray2_bits,
  178. X    gray3_bits,
  179. X    gray4_bits,
  180. X    gray5_bits,
  181. X    gray6_bits,
  182. X    gray7_bits,
  183. X    gray8_bits,
  184. X    gray9_bits,
  185. X};
  186. X#else
  187. static char gray0_bits[] = {
  188. X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  189. X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  190. X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  191. static char gray1_bits[] = {
  192. X   0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88,
  193. X   0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88,
  194. X   0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88};
  195. static char gray2_bits[] = {
  196. X   0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
  197. X   0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
  198. X   0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55};
  199. static char gray3_bits[] = {
  200. X   0xdd, 0xdd, 0x77, 0x77, 0xdd, 0xdd, 0x77, 0x77, 0xdd, 0xdd, 0x77, 0x77,
  201. X   0xdd, 0xdd, 0x77, 0x77, 0xdd, 0xdd, 0x77, 0x77, 0xdd, 0xdd, 0x77, 0x77,
  202. X   0xdd, 0xdd, 0x77, 0x77, 0xdd, 0xdd, 0x77, 0x77};
  203. static char gray4_bits[] = {
  204. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  205. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  206. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  207. X
  208. static char *gray_bits[MAXGRAY] = {
  209. X    gray0_bits,
  210. X    gray1_bits,
  211. X    gray2_bits,
  212. X    gray3_bits,
  213. X    gray4_bits,
  214. X};
  215. X#endif
  216. X
  217. X#define stripe_width 14
  218. X#define stripe_height 14
  219. static char stripe_bits[] = {
  220. X   0x0f, 0x3c, 0x07, 0x3e, 0x03, 0x3f, 0x81, 0x3f, 0xc0, 0x3f, 0xe0, 0x1f,
  221. X   0xf0, 0x0f, 0xf8, 0x07, 0xfc, 0x03, 0xfe, 0x01, 0xff, 0x00, 0x7f, 0x20,
  222. X   0x3f, 0x30, 0x1f, 0x38};
  223. X
  224. static void
  225. ClassInitialize()
  226. X{
  227. X    XtAddConverter( XtRString, XtROrientation, XmuCvtStringToOrientation,
  228. X            NULL, (Cardinal)0 );
  229. X}
  230. X
  231. static void
  232. SetDimensions(w)
  233. BarWidget w;
  234. X{
  235. X    if (w->bar.orientation == XtorientVertical) {
  236. X    w->bar.length = w->core.height;
  237. X    w->bar.thickness = w->core.width;
  238. X    }
  239. X    else {
  240. X    w->bar.length = w->core.width;
  241. X    w->bar.thickness = w->core.height;
  242. X    }
  243. X}
  244. X
  245. X/* ARGSUSED */
  246. static void
  247. Initialize(request, new)
  248. Widget request;        /* what the client asked for */
  249. Widget new;        /* what we're going to give him */
  250. X{
  251. X    BarWidget w = (BarWidget) new;
  252. X    XGCValues gcValues;
  253. X    BarClassPart *bcp = &(barClassRec.bar_class);
  254. X    int i;
  255. X    XColor color, exact;
  256. X
  257. X    if (bcp->gray == (Pixmap *) NULL) {
  258. X    /*
  259. X     *  We initialize this here instead of ClassInitialize because
  260. X     *  we need a window to initialize this in. A cleaner way to do
  261. X     *  this would be to use a separate set of Pixmaps for each
  262. X     *  widget, so that widgets can be on different screen/visuals.
  263. X     *  But then we'd have to fix it so this thing understood
  264. X     *  colours, visuals, more resources...  Laziness wins.
  265. X     */
  266. X    bcp->gray = (Pixmap *) XtMalloc(MAXGRAY * sizeof(Pixmap));
  267. X    for(i = 0; i < MAXGRAY; i++) {
  268. X        bcp->gray[i] = XCreatePixmapFromBitmapData(XtDisplay(new),
  269. X         DefaultRootWindow(XtDisplay(new)), gray_bits[i],
  270. X#ifdef    UGLY_GRAYS
  271. X                                  3, 3,
  272. X#else
  273. X                                  16, 16,
  274. X#endif
  275. X         WhitePixelOfScreen(XtScreen(new)),
  276. X         BlackPixelOfScreen(XtScreen(new)), 1);
  277. X    }
  278. X    XAllocNamedColor(XtDisplay(new),
  279. X             DefaultColormap(XtDisplay(new), DefaultScreen(XtDisplay(new))),
  280. X             "Yellow", &color, &exact);
  281. X    bcp->stripe = XCreatePixmapFromBitmapData(XtDisplay(new),
  282. X         DefaultRootWindow(XtDisplay(new)), stripe_bits, stripe_width,
  283. X         stripe_height, color.pixel,
  284. X         BlackPixelOfScreen(XtScreen(new)),
  285. X         DefaultDepth(XtDisplay(new), DefaultScreen(XtDisplay(new))));
  286. X    }
  287. X    gcValues.stipple = bcp->gray[0];
  288. X    gcValues.fill_style = FillOpaqueStippled;
  289. X    w->bar.gc = XCreateGC(XtDisplay(new), DefaultRootWindow(XtDisplay(new)),
  290. X     GCFillStyle | GCStipple, &gcValues);
  291. X    /* Width and height override length and thickness */
  292. X    if (w->bar.length == def_dimension)
  293. X    w->bar.length = DEF_LENGTH;
  294. X    
  295. X    if (w->bar.thickness == def_dimension)
  296. X    w->bar.thickness = DEF_THICKNESS;
  297. X    
  298. X    if (w->core.width == def_dimension)
  299. X    w->core.width = (w->bar.orientation == XtorientVertical)
  300. X        ? w->bar.thickness : w->bar.length;
  301. X
  302. X    if (w->core.height == def_dimension)
  303. X    w->core.height = (w->bar.orientation == XtorientHorizontal)
  304. X        ? w->bar.thickness : w->bar.length;
  305. X    w->bar.striped = 0;
  306. X    w->bar.values = NULL;
  307. X    w->bar.nvalues = 0;
  308. X
  309. X    SetDimensions(w);
  310. X}
  311. X
  312. X/* ARGSUSED */
  313. static void
  314. Resize(gw)
  315. Widget gw;
  316. X{
  317. X    SetDimensions((BarWidget)gw);
  318. X    Redisplay(gw, (XEvent*)NULL, (Region)NULL);
  319. X}
  320. X
  321. X/* ARGSUSED */
  322. static void
  323. Redisplay(gw, event, region)
  324. Widget gw;
  325. XXEvent *event;
  326. Region region;
  327. X{
  328. X    BarWidget w = (BarWidget) gw;
  329. X    int x, y;
  330. X    unsigned int width, height;
  331. X    int maxvalue, i;
  332. X    int inc_gray;
  333. X    int igray; 
  334. X    int vertical = (w->bar.orientation == XtorientVertical);;
  335. X
  336. X    if (! XtIsRealized(gw))
  337. X    return;
  338. X
  339. X    if (w->bar.striped)
  340. X    {
  341. X    if(vertical) {
  342. X        width = w->bar.thickness;
  343. X        height = w->core.height;
  344. X    }
  345. X    else {
  346. X        height = w->bar.thickness;
  347. X        width = w->core.width;
  348. X    }
  349. X    XSetTile(XtDisplay(gw), w->bar.gc, barClassRec.bar_class.stripe);
  350. X    XSetFillStyle(XtDisplay(gw), w->bar.gc, FillTiled);
  351. X    XFillRectangle(XtDisplay(gw), XtWindow(gw), w->bar.gc,
  352. X           0, 0, width, height);
  353. X    XSetFillStyle(XtDisplay(gw), w->bar.gc, FillOpaqueStippled);
  354. X    return;
  355. X    }
  356. X
  357. X    for(maxvalue = 0, i = 0; i < w->bar.nvalues; i++)
  358. X    maxvalue += w->bar.values[i];
  359. X    if(maxvalue <= 0)
  360. X    return;
  361. X    x = y = 0;
  362. X    if(vertical)
  363. X    width = w->bar.thickness;
  364. X    else
  365. X    height = w->bar.thickness;
  366. X    inc_gray = (w->bar.nvalues > 1) ? (MAXGRAY - 1) / (w->bar.nvalues - 1) :
  367. X    MAXGRAY - 1;
  368. X    for(igray = 0, i = 0; i < w->bar.nvalues; i++, igray += inc_gray) {
  369. X    unsigned int rectlen = (w->bar.length * w->bar.values[i] +
  370. X                maxvalue / 2) / maxvalue;
  371. X    if (rectlen == 0)
  372. X        continue;
  373. X    if (i == w->bar.nvalues - 1) {
  374. X        if (vertical)
  375. X        rectlen = w->core.height - y;
  376. X        else
  377. X        rectlen = w->core.width - x;
  378. X#ifndef    UGLY_GRAYS
  379. X        igray = MAXGRAY - 1;
  380. X#endif
  381. X    }
  382. X    XSetStipple(XtDisplay(gw), w->bar.gc, barClassRec.bar_class.gray[igray]);
  383. X    if(vertical) {
  384. X        XFillRectangle(XtDisplay(gw), XtWindow(gw), w->bar.gc,
  385. X         x, y, width, rectlen);
  386. X        y += rectlen;
  387. X    } else {
  388. X        XFillRectangle(XtDisplay(gw), XtWindow(gw), w->bar.gc,
  389. X         x, y, rectlen, height);
  390. X        x += rectlen;
  391. X    }
  392. X    }
  393. X}
  394. X
  395. X/* Public routines. */
  396. void
  397. SetBarValues(gw, values, nvalues)
  398. Widget gw;
  399. int *values;
  400. int nvalues;
  401. X{
  402. X    BarWidget w = (BarWidget) gw;
  403. X    int i;
  404. X
  405. X    if (nvalues > MAXGRAY) {
  406. X#define ERRFMT "Tried to set %d values for bar - maximum is %d\n"
  407. X    char errbuf[sizeof(ERRFMT) + 32];
  408. X    (void) sprintf(errbuf, ERRFMT, nvalues, MAXGRAY);
  409. X#undef ERRFMT
  410. X    XtWarning(errbuf);
  411. X    nvalues = MAXGRAY;
  412. X    }
  413. X    if (nvalues < 0) {
  414. X#define ERRFMT "Tried to set %d values for bar - it must be > 0\n"
  415. X    char errbuf[sizeof(ERRFMT) + 32];
  416. X    (void) sprintf(errbuf, ERRFMT, nvalues);
  417. X    XtWarning(errbuf);
  418. X#undef ERRFMT
  419. X    return;
  420. X    }
  421. X    w->bar.nvalues = nvalues;
  422. X    if (w->bar.values != NULL)
  423. X    XtFree((char *) w->bar.values);
  424. X    if (nvalues != 0)
  425. X    w->bar.values = (int *) XtMalloc(nvalues * sizeof(int));
  426. X    for(i = 0; i < nvalues; i++)
  427. X    w->bar.values[i] = values[i];
  428. X    w->bar.striped = 0;
  429. X    Redisplay( gw, (XEvent*)NULL, (Region)NULL );
  430. X}
  431. X
  432. void
  433. SetBarStripe(gw)
  434. Widget gw;
  435. X{
  436. X    BarWidget w = (BarWidget) gw;
  437. X    int i;
  438. X
  439. X    w->bar.striped = 1;
  440. X    Redisplay( gw, (XEvent*)NULL, (Region)NULL );
  441. X}
  442. END_OF_FILE
  443. if test 10785 -ne `wc -c <'Bar.c'`; then
  444.     echo shar: \"'Bar.c'\" unpacked with wrong size!
  445. fi
  446. # end of 'Bar.c'
  447. fi
  448. if test -f 'Bar.h' -a "${1}" != "-c" ; then 
  449.   echo shar: Will not clobber existing file \"'Bar.h'\"
  450. else
  451. echo shar: Extracting \"'Bar.h'\" \(1187 characters\)
  452. sed "s/^X//" >'Bar.h' <<'END_OF_FILE'
  453. X#include <X11/copyright.h>
  454. X
  455. X/* $XConsortium: Bar.h,v 1.2 88/10/25 17:22:09 swick Exp $ */
  456. X/* Copyright    Massachusetts Institute of Technology    1987, 1988 */
  457. X
  458. X#ifndef _Bar_h
  459. X#define _Bar_h
  460. X
  461. X/****************************************************************
  462. X *
  463. X * Bar widget
  464. X *
  465. X ****************************************************************/
  466. X
  467. X/* Resources:
  468. X
  469. X Name             Class        RepType        Default Value
  470. X ----             -----        -------        -------------
  471. X background         Background        Pixel        XtDefaultBackground
  472. X border             BorderColor    Pixel        XtDefaultForeground
  473. X borderWidth         BorderWidth    Dimension    1
  474. X destroyCallback     Callback        Pointer        NULL
  475. X height             Height        Dimension    0
  476. X mappedWhenManaged   MappedWhenManaged    Boolean        True
  477. X sensitive         Sensitive        Boolean        True
  478. X width             Width        Dimension    0
  479. X x             Position        Position    0
  480. X y             Position        Position    0
  481. X
  482. X*/
  483. X
  484. X/* declare specific BarWidget class and instance datatypes */
  485. X
  486. typedef struct _BarClassRec*    BarWidgetClass;
  487. typedef struct _BarRec*        BarWidget;
  488. X
  489. X/* declare the class constant */
  490. X
  491. extern WidgetClass barWidgetClass;
  492. X
  493. X/* Public procedures */
  494. extern void SetBarValues(/* BarWidget w, int *values, int nvalues */);
  495. X
  496. X#endif  _Bar_h
  497. END_OF_FILE
  498. if test 1187 -ne `wc -c <'Bar.h'`; then
  499.     echo shar: \"'Bar.h'\" unpacked with wrong size!
  500. fi
  501. # end of 'Bar.h'
  502. fi
  503. if test -f 'BarP.h' -a "${1}" != "-c" ; then 
  504.   echo shar: Will not clobber existing file \"'BarP.h'\"
  505. else
  506. echo shar: Extracting \"'BarP.h'\" \(1160 characters\)
  507. sed "s/^X//" >'BarP.h' <<'END_OF_FILE'
  508. X#include <X11/copyright.h>
  509. X
  510. X/* $XConsortium: BarP.h,v 1.2 88/10/25 17:37:59 swick Exp $ */
  511. X/* Copyright    Massachusetts Institute of Technology    1987, 1988 */
  512. X
  513. X#ifndef _BarP_h
  514. X#define _BarP_h
  515. X
  516. X#include <X11/Xmu/Xmu.h>
  517. X#include "Bar.h"
  518. X/* include superclass private header file */
  519. X#include <X11/CoreP.h>
  520. X
  521. X/* define unique representation types not found in <X11/StringDefs.h> */
  522. X
  523. X#ifdef UGLY_GRAYS
  524. X#define MAXGRAY 10
  525. X#else
  526. X#define MAXGRAY 5
  527. X#endif
  528. X
  529. typedef struct {
  530. X    Pixmap *gray;
  531. X    Pixmap stripe;
  532. X} BarClassPart;
  533. X
  534. typedef struct _BarClassRec {
  535. X    CoreClassPart    core_class;
  536. X    BarClassPart    bar_class;
  537. X} BarClassRec;
  538. X
  539. extern BarClassRec barClassRec;
  540. X
  541. typedef struct {
  542. X    /* private state */
  543. X    int striped;        /* In the striped state? */
  544. X    int *values;        /* Array of values displayed in bar */
  545. X    int nvalues;        /* Number of elements in values */
  546. X    XtOrientation orientation;    /* XtorientHorizontal or XtorientVertical */
  547. X    Dimension      length;    /* either height or width */
  548. X    Dimension      thickness;    /* either width or height */
  549. X    GC          gc;        /* a gc */
  550. X} BarPart;
  551. X
  552. typedef struct _BarRec {
  553. X    CorePart    core;
  554. X    BarPart    bar;
  555. X} BarRec;
  556. X
  557. X#endif  _BarP_h
  558. END_OF_FILE
  559. if test 1160 -ne `wc -c <'BarP.h'`; then
  560.     echo shar: \"'BarP.h'\" unpacked with wrong size!
  561. fi
  562. # end of 'BarP.h'
  563. fi
  564. if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then 
  565.   echo shar: Will not clobber existing file \"'COPYRIGHT'\"
  566. else
  567. echo shar: Extracting \"'COPYRIGHT'\" \(915 characters\)
  568. sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE'
  569. X/*
  570. X * Copyright University of Toronto 1988, 1989.
  571. X * Written by Mark Moraes
  572. X *
  573. X * Permission is granted to anyone to use this software for any purpose on
  574. X * any computer system, and to alter it and redistribute it freely, subject
  575. X * to the following restrictions:
  576. X *
  577. X * 1. The author and the University of Toronto are not responsible 
  578. X *    for the consequences of use of this software, no matter how awful, 
  579. X *    even if they arise from flaws in it.
  580. X *
  581. X * 2. The origin of this software must not be misrepresented, either by
  582. X *    explicit claim or by omission.  Since few users ever read sources,
  583. X *    credits must appear in the documentation.
  584. X *
  585. X * 3. Altered versions must be plainly marked as such, and must not be
  586. X *    misrepresented as being the original software.  Since few users
  587. X *    ever read sources, credits must appear in the documentation.
  588. X *
  589. X * 4. This notice may not be removed or altered.
  590. X */
  591. END_OF_FILE
  592. if test 915 -ne `wc -c <'COPYRIGHT'`; then
  593.     echo shar: \"'COPYRIGHT'\" unpacked with wrong size!
  594. fi
  595. # end of 'COPYRIGHT'
  596. fi
  597. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  598.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  599. else
  600. echo shar: Extracting \"'MANIFEST'\" \(499 characters\)
  601. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  602. X   File Name        Archive #    Description
  603. X-----------------------------------------------------------
  604. X BUGS                       1    
  605. X Bar.c                      1    
  606. X Bar.h                      1    
  607. X BarP.h                     1    
  608. X COPYRIGHT                  1    
  609. X MANIFEST                   1    
  610. X Makefile                   1    
  611. X README                     1    
  612. X csu.diffs                  1    
  613. X s-pfilt-rwho.c             1    
  614. X s.h                        1    
  615. X xwhosup.1                  1    
  616. X xwhosup.c                  1    
  617. END_OF_FILE
  618. if test 499 -ne `wc -c <'MANIFEST'`; then
  619.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  620. fi
  621. # end of 'MANIFEST'
  622. fi
  623. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  624.   echo shar: Will not clobber existing file \"'Makefile'\"
  625. else
  626. echo shar: Extracting \"'Makefile'\" \(1165 characters\)
  627. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  628. DESTROOT =
  629. DESTPATH = $(DESTROOT)/contrib
  630. DESTSHR = $(DESTPATH)/share
  631. DESTSYS = $(DESTPATH)/system
  632. MAND = $(DESTSHR)/man
  633. BIND = $(DESTSYS)/bin
  634. X
  635. SRCROOT =
  636. SRCPATH = $(SRCROOT)/contrib
  637. SRCSHR = $(SRCPATH)/share
  638. SRCSYS = $(SRCPATH)/system
  639. INCD = $(SRCSHR)/include
  640. LIBD = $(SRCSYS)/lib
  641. X
  642. X#(decnet needed by xlib?)
  643. XXLIB = -lX11 -ldnet
  644. X#(nope)
  645. X#XLIB = -lX11
  646. X
  647. PROGRAM        = xwhosup
  648. MANPAGE        = xwhosup.1
  649. X
  650. H        = \
  651. X        Bar.h \
  652. X        BarP.h \
  653. X        s.h
  654. X
  655. SRC        = \
  656. X        BUGS \
  657. X        COPYRIGHT \
  658. X        Makefile \
  659. X        README \
  660. X        $(MANPAGE) \
  661. X        $(H) \
  662. X        Bar.c \
  663. X        s-pfilt-rwho.c \
  664. X        xwhosup.c
  665. X
  666. OBJS         = \
  667. X        Bar.o \
  668. X        s-pfilt-rwho.o \
  669. X        xwhosup.o
  670. X
  671. X#(gcc)
  672. CC        = gcc
  673. CDEBUG        = -O -g
  674. X#(other)
  675. CC        = cc
  676. CDEBUG        = -O
  677. X
  678. INC        = -I$(INCD)
  679. CFLAGS        = $(INC) $(CDEBUG)
  680. LIBS        = -L$(LIBD) -lXaw -lXmu -lXt -lXext $(XLIB) -lm
  681. X
  682. all        : $(PROGRAM)
  683. X
  684. X$(PROGRAM)    : $(OBJS)
  685. X        $(CC) -o $(PROGRAM) $(OBJS) $(LIBS)
  686. X
  687. install        : $(PROGRAM) $(MANPAGE)
  688. X        install -c -s $(PROGRAM) $(BIND)/$(PROGRAM)
  689. X        install -c    $(MANPAGE) $(MAND)/man1/$(MANPAGE)
  690. X
  691. shar        :
  692. X        shar $(SRC) > $(PROGRAM).shar
  693. X
  694. clean        :
  695. X        -rm -f $(OBJS) $(PROGRAM).shar $(PROGRAM)
  696. X
  697. Bar.o        : Bar.c BarP.h Bar.h
  698. xwhosup.o    : xwhosup.c Bar.h s.h
  699. s-pfilt-rwho.o    : s-pfilt-rwho.c 
  700. END_OF_FILE
  701. if test 1165 -ne `wc -c <'Makefile'`; then
  702.     echo shar: \"'Makefile'\" unpacked with wrong size!
  703. fi
  704. # end of 'Makefile'
  705. fi
  706. if test -f 'README' -a "${1}" != "-c" ; then 
  707.   echo shar: Will not clobber existing file \"'README'\"
  708. else
  709. echo shar: Extracting \"'README'\" \(1056 characters\)
  710. sed "s/^X//" >'README' <<'END_OF_FILE'
  711. Originally:
  712. X
  713. X    A snapshot performance monitor. Originally written to watch the load
  714. X    distribution on the CPU's on an Silicon Graphics Iris4d/240, it can be
  715. X    adapted to display a large variety of changing system statistics.
  716. X    
  717. X        - moraes@cs.toronto.edu (Mark Moraes)
  718. X
  719. Modified to snoop for rwhod(8) packets using Jeff Mogul's packetfilter(4)
  720. and display the 5 minute load average on a log scale, or alternating 
  721. yellow/black diagonal stripes if a host hasn't been heard from.
  722. X
  723. I have some grander plan to turn it into a general purpose resource
  724. monitor, but that'll have to wait.  For the moment I just want have
  725. some rough idea of what our machines are doing.
  726. X
  727. The X knowledgable will realise that the X code in this is pretty naive
  728. because I hate X and _refuse_ to learn about it -- what a disaster.  I just
  729. want the bits on the screen, without having to read through a pile of overly
  730. verbose and tedious documentation.  The (original) X code is Mark Moreas' work.
  731. X
  732. X
  733. X    - Boyd Roberts <boyd@prl.dec.com>
  734. X      December '91
  735. X      Digital PRL
  736. END_OF_FILE
  737. if test 1056 -ne `wc -c <'README'`; then
  738.     echo shar: \"'README'\" unpacked with wrong size!
  739. fi
  740. # end of 'README'
  741. fi
  742. if test -f 'csu.diffs' -a "${1}" != "-c" ; then 
  743.   echo shar: Will not clobber existing file \"'csu.diffs'\"
  744. else
  745. echo shar: Extracting \"'csu.diffs'\" \(1465 characters\)
  746. sed "s/^X//" >'csu.diffs' <<'END_OF_FILE'
  747. X*** Makefile.orig    Wed Dec 30 10:19:09 1992
  748. X--- Makefile    Wed Dec 30 11:01:00 1992
  749. X***************
  750. X*** 1,2 ****
  751. X--- 1,21 ----
  752. X+ DESTROOT =
  753. X+ DESTPATH = $(DESTROOT)/contrib
  754. X+ DESTSHR = $(DESTPATH)/share
  755. X+ DESTSYS = $(DESTPATH)/system
  756. X+ MAND = $(DESTSHR)/man
  757. X+ BIND = $(DESTSYS)/bin
  758. X+ 
  759. X+ SRCROOT =
  760. X+ SRCPATH = $(SRCROOT)/contrib
  761. X+ SRCSHR = $(SRCPATH)/share
  762. X+ SRCSYS = $(SRCPATH)/system
  763. X+ INCD = $(SRCSHR)/include
  764. X+ LIBD = $(SRCSYS)/lib
  765. X+ 
  766. X+ #(decnet needed by xlib?)
  767. X+ XLIB = -lX11 -ldnet
  768. X+ #(nope)
  769. X+ #XLIB = -lX11
  770. X+ 
  771. X  PROGRAM        = xwhosup
  772. X  MANPAGE        = xwhosup.1
  773. X***************
  774. X*** 23,30 ****
  775. X          xwhosup.o
  776. X  
  777. X! INC        = -I/usr/local/include
  778. X! CFLAGS        = $(INC) -O -g
  779. X! LIBS        = -lXaw -lXmu -lXt -lXext -lX11 -lm
  780. X  
  781. X  all        : $(PROGRAM)
  782. X  
  783. X--- 42,56 ----
  784. X          xwhosup.o
  785. X  
  786. X! #(gcc)
  787. X! CC        = gcc
  788. X! CDEBUG        = -O -g
  789. X! #(other)
  790. X! CC        = cc
  791. X! CDEBUG        = -O
  792. X  
  793. X+ INC        = -I$(INCD)
  794. X+ CFLAGS        = $(INC) $(CDEBUG)
  795. X+ LIBS        = -L$(LIBD) -lXaw -lXmu -lXt -lXext $(XLIB) -lm
  796. X+ 
  797. X  all        : $(PROGRAM)
  798. X  
  799. X***************
  800. X*** 32,35 ****
  801. X--- 58,65 ----
  802. X          $(CC) -o $(PROGRAM) $(OBJS) $(LIBS)
  803. X  
  804. X+ install        : $(PROGRAM) $(MANPAGE)
  805. X+         install -c -s $(PROGRAM) $(BIND)/$(PROGRAM)
  806. X+         install -c    $(MANPAGE) $(MAND)/man1/$(MANPAGE)
  807. X+ 
  808. X  shar        :
  809. X          shar $(SRC) > $(PROGRAM).shar
  810. X***************
  811. X*** 36,40 ****
  812. X  
  813. X  clean        :
  814. X!         -rm -f $(OBJS) $(PROGRAM).shar
  815. X  
  816. X  Bar.o        : Bar.c BarP.h Bar.h
  817. X--- 66,70 ----
  818. X  
  819. X  clean        :
  820. X!         -rm -f $(OBJS) $(PROGRAM).shar $(PROGRAM)
  821. X  
  822. X  Bar.o        : Bar.c BarP.h Bar.h
  823. END_OF_FILE
  824. if test 1465 -ne `wc -c <'csu.diffs'`; then
  825.     echo shar: \"'csu.diffs'\" unpacked with wrong size!
  826. fi
  827. # end of 'csu.diffs'
  828. fi
  829. if test -f 's-pfilt-rwho.c' -a "${1}" != "-c" ; then 
  830.   echo shar: Will not clobber existing file \"'s-pfilt-rwho.c'\"
  831. else
  832. echo shar: Extracting \"'s-pfilt-rwho.c'\" \(11679 characters\)
  833. sed "s/^X//" >'s-pfilt-rwho.c' <<'END_OF_FILE'
  834. X/*
  835. X *    packetfilter(4) support for rwhod(8) packets in the style of
  836. X *    the original `system dependant' s.c file.
  837. X *
  838. X *    Boyd Roberts <boyd@prl.dec.com>
  839. X *    December '91
  840. X *    Digital PRL
  841. X */
  842. X
  843. X#include        <stdio.h>
  844. X#include        <sys/types.h>
  845. X#include        <sys/socket.h>
  846. X#include        <fcntl.h>
  847. X#include    <netdb.h>
  848. X#include    <time.h>
  849. X#include        <net/pfilt.h>
  850. X#include        <net/if.h>
  851. X#include        <netinet/in_systm.h>
  852. X#include        <netinet/in.h>
  853. X#include        <netinet/if_ether.h>
  854. X#include        <netinet/ip.h>
  855. X#include        <netinet/udp.h>
  856. X#include    <protocols/rwhod.h>
  857. X#include    <ctype.h>
  858. X#include    <math.h>
  859. X
  860. X#include    <X11/Xos.h>
  861. X#include    <X11/StringDefs.h>
  862. X#include    <X11/Intrinsic.h>
  863. X#include    <X11/Xaw/Form.h>
  864. X#include    <X11/Xaw/Label.h>
  865. X#include    <X11/Xmu/Xmu.h>
  866. X
  867. X/*
  868. X *    rwho strings for getservbyname(3).
  869. X */
  870. X#define     RWHO_SERVICE    "who"
  871. X#define     RWHO_PROTOCOL    "udp"
  872. X
  873. X/*
  874. X *    Number of load average ints.
  875. X */
  876. X#define        NLOADAV        3
  877. X
  878. X/*
  879. X *    Timeout (in seconds) for marking a host dead.
  880. X */
  881. X#define        HOSTTIMEUP    (2 * 60)
  882. X
  883. X/*
  884. X *    Simple host data structure.
  885. X */
  886. struct host
  887. X{
  888. X    char        *h_name;
  889. X    time_t        h_when;
  890. X    int        h_loadav[NLOADAV];
  891. X    int        h_state;
  892. X};
  893. X
  894. X/*
  895. X *    Host states.
  896. X */
  897. X#define HS_INIT        0        /* not heard from yet */
  898. X#define HS_UP        1        /* heard from */
  899. X#define HS_DOWN        2        /* not heard from for HOSTIMEUP */
  900. X
  901. X/*
  902. X *    Host array and number.
  903. X *
  904. X *    I could add a hashtable here to point into the host array,
  905. X *    but the search of the table (on receipt of a packet) will
  906. X *    probably be quick because there will only be a small
  907. X *    number of hosts; how much screen real estate have you got?
  908. X */
  909. static struct host    *hosts;
  910. static int        nhosts;
  911. X
  912. X/*
  913. X *    packetfilter(4) file descriptor.
  914. X */
  915. int            Clnt_multi_sock;
  916. X
  917. X/*
  918. X *    Highest bar value and the value of one point on the bar.
  919. X */
  920. X#define BAREND        1000
  921. X#define BARPOINT    250
  922. X
  923. extern char        *progname;
  924. X
  925. X/*
  926. X *    System error message.
  927. X */
  928. char    *
  929. sysmess()
  930. X{
  931. X    extern int    errno;
  932. X    extern int    sys_nerr;
  933. X    extern char    *sys_errlist[];
  934. X
  935. X    return errno <= 0 || errno > sys_nerr ? "Unknown error" : sys_errlist[errno];
  936. X}
  937. X
  938. X/*
  939. X *    Add a packetfilter(4) expression.
  940. X */
  941. X#define add(x)    f.enf_Filter[i++] = (x)
  942. X
  943. X
  944. X/*
  945. X *    Set up a packetfilter(4) filter for rwhod(8) packets.
  946. X */
  947. int
  948. rwho_filter()
  949. X{
  950. X    int        fd;
  951. X    u_short        bits;
  952. X    int        i;
  953. X    struct servent    *rwho;
  954. X    struct enfilter    f;
  955. X
  956. X    if ((fd = pfopen((char *)0, O_RDONLY)) == -1)
  957. X    {
  958. X        fprintf(stderr, "%s: Could not open packetfilter.", progname, sysmess());
  959. X        exit(1);
  960. X        /* NOTREACHED */
  961. X    }
  962. X
  963. X    /*
  964. X     *    Match promiscuoslsy received packets non-exclusively
  965. X     *    and return them prepended by a `struct enstamp'.
  966. X     */
  967. X    bits = ENPROMISC | ENNONEXCL | ENTSTAMP;
  968. X
  969. X    if (ioctl(fd, EIOCMBIS, (char *)&bits) == -1)
  970. X    {
  971. X        fprintf(stderr, "%s: Could not ioctl packetfilter. %s", progname, sysmess());
  972. X        exit(1);
  973. X        /* NOTREACHED */
  974. X    }
  975. X
  976. X    /*
  977. X     *    Grab the rwhod(8) service info.
  978. X     */
  979. X    if ((rwho = getservbyname(RWHO_SERVICE, RWHO_PROTOCOL)) == (struct servent *)0)
  980. X    {
  981. X        fprintf(stderr, "%s: No rwho UDP service. %s", progname, sysmess());
  982. X        exit(1);
  983. X        /* NOTREACHED */
  984. X    }
  985. X
  986. X    /*
  987. X     *    Build and ioctl(2) the filter.
  988. X     */
  989. X    f.enf_Priority = 0;
  990. X    i = 0;
  991. X
  992. X    add(ENF_PUSHWORD + 6);        /* packet type */
  993. X    add(ENF_PUSHLIT);
  994. X    add(htons((u_short)ETHERTYPE_IP));
  995. X    add(ENF_EQ);            /* IP? */
  996. X
  997. X    add(ENF_PUSHWORD + 11);        /* protocol type */
  998. X    add(ENF_PUSHLIT);
  999. X    add(htons((u_short)0x00FF));
  1000. X    add(ENF_AND);            /* in low byte */
  1001. X    add(ENF_PUSHLIT);
  1002. X    add(htons((u_short)IPPROTO_UDP));
  1003. X    add(ENF_EQ);            /* UDP? */
  1004. X
  1005. X    add(ENF_CAND);            /* IP && UDP ? */
  1006. X
  1007. X    add(ENF_PUSHWORD + 17);        /* src port */
  1008. X    add(ENF_PUSHLIT);
  1009. X    add((u_short)rwho->s_port);
  1010. X
  1011. X    add(ENF_EQ);            /* rwho? */
  1012. X
  1013. X    f.enf_FilterLen = i;
  1014. X
  1015. X    if (ioctl(fd, EIOCSETF, &f) == -1)
  1016. X    {
  1017. X        fprintf(stderr, "%s: Could not ioctl packetfilter. %s", progname, sysmess());
  1018. X        exit(1);
  1019. X        /* NOTREACHED */
  1020. X    }
  1021. X
  1022. X    return fd;
  1023. X}
  1024. X
  1025. X/*
  1026. X *    Return the ASCII representation of an Ethernet address.
  1027. X */
  1028. char    *
  1029. ether_addr(a)
  1030. u_char    *a;
  1031. X{
  1032. X    static char    buf[18];
  1033. X
  1034. X    sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", a[0], a[1], a[2], a[3], a[4], a[5]);
  1035. X
  1036. X    return buf;
  1037. X}
  1038. X
  1039. X/*
  1040. X *    Process a rwhod(8) packet.  Do _a lot_ of sanity checking, trashing
  1041. X *    any packets that look weird.  Various extraneous IP structs are
  1042. X *    initialised here for debugging.
  1043. X */
  1044. static struct whod    *
  1045. rwho(fd)
  1046. X{
  1047. X    unsigned char        *p;
  1048. X    int            n;
  1049. X    int            i;
  1050. X    struct ether_header    *ether;
  1051. X    struct ip        *ip;
  1052. X    struct udphdr        *udp;
  1053. X    static struct whod    whop;
  1054. X    struct enstamp        stamp;
  1055. X    unsigned char        buf[4096];
  1056. X    extern Bool        noisy;
  1057. X    int            true_length;
  1058. X    extern char        *progname;
  1059. X
  1060. X    switch (n = read(fd, (char *)buf, sizeof buf))
  1061. X    {
  1062. X    case 0:
  1063. X        if (noisy)
  1064. X            fprintf(stderr, "%s: End of file on packetfilter.\n", progname);
  1065. X
  1066. X        return (struct whod *)0;
  1067. X
  1068. X    case -1:
  1069. X        if (noisy)
  1070. X            fprintf(stderr, "%s: Could not read packetfilter. %s\n", progname, sysmess());
  1071. X
  1072. X        return (struct whod *)0;
  1073. X    
  1074. X    default:
  1075. X        break;
  1076. X    }
  1077. X
  1078. X    p = buf;
  1079. X
  1080. X    /* peek at the stamp and copy it */
  1081. X
  1082. X    if (n <= sizeof(stamp.ens_stamplen) || n <= ((struct enstamp *)p)->ens_stamplen)
  1083. X    {
  1084. X        if (noisy)
  1085. X            fprintf(stderr, "%s: Short packetfilter read of %d bytes.\n", progname, n);
  1086. X
  1087. X        return (struct whod *)0;
  1088. X    }
  1089. X
  1090. X    bcopy((char *)p, (char *)&stamp, (int)((struct enstamp *)p)->ens_stamplen);
  1091. X
  1092. X    n -= stamp.ens_stamplen;
  1093. X    true_length = n;
  1094. X
  1095. X    if (n < 0)
  1096. X    {
  1097. X        if (noisy)
  1098. X            fprintf(stderr, "%s: %d byte packet missing enstamp.\n", progname, true_length);
  1099. X
  1100. X        return (struct whod *)0;
  1101. X    }
  1102. X
  1103. X    p += stamp.ens_stamplen;
  1104. X    n -= sizeof (struct ether_header);
  1105. X
  1106. X    if (n < 0)
  1107. X    {
  1108. X        if (noisy)
  1109. X            fprintf(stderr, "%s: %d byte packet missing Ethernet header.\n", progname, true_length);
  1110. X
  1111. X        return (struct whod *)0;
  1112. X    }
  1113. X
  1114. X    /* now we have an ethernet packet */
  1115. X
  1116. X    ether = (struct ether_header *)p;
  1117. X    p += sizeof (struct ether_header);
  1118. X
  1119. X    n -= sizeof (struct ip);
  1120. X
  1121. X    if (n < 0)
  1122. X    {
  1123. X        if (noisy)
  1124. X            fprintf(stderr, "%s: %d byte packet from %s missing IP header.\n", progname, true_length, ether_addr(ether->ether_shost));
  1125. X
  1126. X        return (struct whod *)0;
  1127. X    }
  1128. X
  1129. X    /* now we have an IP packet */
  1130. X
  1131. X    ip = (struct ip *)p;
  1132. X    p += sizeof (struct ip);
  1133. X
  1134. X    if (n <= sizeof (struct udphdr))
  1135. X    {
  1136. X        if (noisy)
  1137. X            fprintf(stderr, "%s: %d byte packet from %s missing UDP header.\n", progname, true_length, inet_ntoa(ip->ip_src));
  1138. X
  1139. X        return (struct whod *)0;
  1140. X    }
  1141. X
  1142. X    /* now we have a UDP packet */
  1143. X
  1144. X    udp = (struct udphdr *)p;
  1145. X
  1146. X    /* check the UDP datalength with the length returned by read(2) */
  1147. X
  1148. X    if (n != ntohs(udp->uh_ulen))
  1149. X    {
  1150. X        if (noisy)
  1151. X            fprintf(stderr, "%s: %d byte packet from %s UDP length %d, should be %d.\n", progname, true_length, inet_ntoa(ip->ip_src), ntohs(udp->uh_ulen), n);
  1152. X
  1153. X        return (struct whod *)0;
  1154. X    }
  1155. X
  1156. X    p += sizeof (struct udphdr);        /* rwho packet */
  1157. X    n -= sizeof (struct udphdr);        /* rwho packet length */
  1158. X
  1159. X        /* make _sure_ that we have the bits of the rwho we want */
  1160. X
  1161. X    if ((unsigned char *)&((struct whod *)p)->wd_we[0] - p > n)
  1162. X    {
  1163. X        if (noisy)
  1164. X            fprintf(stderr, "%s: %d byte rwho packet from %s truncated.\n", progname, true_length, inet_ntoa(ip->ip_src));
  1165. X
  1166. X        return (struct whod *)0;
  1167. X    }
  1168. X
  1169. X    bcopy((char *)p, (char *)&whop, n);        /* rwho packet */
  1170. X
  1171. X    /*
  1172. X     *    Verify and turn into host byte order.
  1173. X     */
  1174. X    if (whop.wd_vers != WHODVERSION)
  1175. X    {
  1176. X        if (noisy)
  1177. X            fprintf(stderr, "%s: %d byte rwho packet version %d from %s should be version %d.\n", progname, true_length, whop.wd_vers, inet_ntoa(ip->ip_src), WHODVERSION);
  1178. X
  1179. X        return (struct whod *)0;
  1180. X    }
  1181. X
  1182. X    whop.wd_sendtime = (int)ntohl(whop.wd_sendtime);
  1183. X
  1184. X    /* use the receive time in the packet stamp */
  1185. X    whop.wd_recvtime = stamp.ens_tstamp.tv_sec;
  1186. X
  1187. X    for (i = 0; i < sizeof(whop.wd_hostname); i++)
  1188. X    {
  1189. X        unsigned char    c;
  1190. X
  1191. X        if ((c = whop.wd_hostname[i]) == '\0')
  1192. X            break;
  1193. X
  1194. X        if (!isprint(c))
  1195. X        {
  1196. X            if (noisy)
  1197. X                fprintf(stderr, "%s: Unprintable hostname character 0%03o in rwho packet from %s.\n", progname, c, inet_ntoa(ip->ip_src));
  1198. X
  1199. X            return (struct whod *)0;
  1200. X        }
  1201. X    }
  1202. X
  1203. X    if (noisy)
  1204. X    {
  1205. X        for (i = 0; i < sizeof(whop.wd_hostname); i++)
  1206. X        {
  1207. X            unsigned char    c;
  1208. X
  1209. X            if ((c = whop.wd_hostname[i]) == '\0')
  1210. X                break;
  1211. X
  1212. X            putchar(c);
  1213. X        }
  1214. X    }
  1215. X
  1216. X    for (i = 0; i < NLOADAV; i++)
  1217. X    {
  1218. X        whop.wd_loadav[i] = (int)ntohl(whop.wd_loadav[i]);
  1219. X
  1220. X        if (noisy)
  1221. X            printf(" %.3f", (double)whop.wd_loadav[i] / 100.0);
  1222. X    }
  1223. X
  1224. X    whop.wd_boottime = (int)ntohl(whop.wd_boottime);
  1225. X
  1226. X    if (noisy)
  1227. X        printf("\n");
  1228. X
  1229. X    /* forget about the utmp data -- it's too ugly */
  1230. X
  1231. X    return &whop;
  1232. X}
  1233. X
  1234. X/*
  1235. X *    Called when XtMainLoop gets seltrue on the packetfilter descriptor.
  1236. X */
  1237. X
  1238. X/* ARGSUSED */
  1239. XXtInputCallbackProc
  1240. get_socket_msg(client_data, source, id)
  1241. caddr_t client_data;
  1242. int *source;
  1243. XXtInputId *id;
  1244. X{
  1245. X    int        i;
  1246. X    struct whod    *whop;
  1247. X
  1248. X    /*
  1249. X     *    Grab packet in host byte order.
  1250. X     */
  1251. X    if ((whop = rwho(Clnt_multi_sock)) == (struct whod *)0)
  1252. X        return;
  1253. X
  1254. X    /*
  1255. X     *    Find host slot in table and update it.  A linear search,
  1256. X     *    but I could add a hashtable.
  1257. X     */
  1258. X    for (i = 0; i < nhosts; i++)
  1259. X    {
  1260. X        int        j;
  1261. X        struct host    *hp;
  1262. X        double        d;
  1263. X        int        bars[4];
  1264. X
  1265. X        hp = &hosts[i];
  1266. X
  1267. X        if (strncmp(whop->wd_hostname, hp->h_name, sizeof (whop->wd_hostname)) != 0)
  1268. X            continue;
  1269. X
  1270. X        /* copy load averages and mark up */
  1271. X        for (j = 0; j < NLOADAV; j++)
  1272. X            hp->h_loadav[j] = whop->wd_loadav[j];
  1273. X
  1274. X        hp->h_when = whop->wd_recvtime;
  1275. X        hp->h_state = HS_UP;
  1276. X
  1277. X        /*
  1278. X         *    Logarithmic bar display from 1..BAREND but linear from 0..1
  1279. X         */
  1280. X        bars[0] = 0;
  1281. X
  1282. X        if ((d = (double)hp->h_loadav[0] / 100.0) > 1.0)
  1283. X            bars[1] = log10(d) * BARPOINT + BARPOINT;
  1284. X        else
  1285. X            bars[1] = d * BARPOINT;
  1286. X
  1287. X        if (bars[1] > BAREND)
  1288. X            bars[1] = BAREND;
  1289. X
  1290. X        bars[2] = BAREND - bars[1];
  1291. X        bars[3] = 0;
  1292. X
  1293. X        draw_bar(i, &bars[0], sizeof bars / sizeof bars[0]);
  1294. X        break;
  1295. X    }
  1296. X}
  1297. X
  1298. X/*
  1299. X *    Called every HOSTTIMEUP seconds to scan for dead hosts.
  1300. X */
  1301. X/* ARGSUSED */
  1302. XXtTimerCallbackProc
  1303. host_down(closure, id)
  1304. caddr_t closure;
  1305. XXtIntervalId *id;
  1306. X{
  1307. X    int        i;
  1308. X    struct timeval    t;
  1309. X    struct timezone    tz;
  1310. X
  1311. X    if (gettimeofday(&t, &tz) == -1)
  1312. X        t.tv_sec = 0x7FFFFFFF;        /* cannot happen */
  1313. X
  1314. X    for (i = 0; i < nhosts; i++)
  1315. X    {
  1316. X        struct host    *hp;
  1317. X
  1318. X        hp = &hosts[i];
  1319. X
  1320. X        switch (hp->h_state)
  1321. X        {
  1322. X        case HS_INIT:
  1323. X        case HS_UP:
  1324. X            if (t.tv_sec > hp->h_when + HOSTTIMEUP)
  1325. X            {
  1326. X                extern Widget *bar;
  1327. X
  1328. X                hp->h_state = HS_DOWN;
  1329. X
  1330. X#if    DEBUG
  1331. X                printf("%s DOWN\n", hp->h_name);
  1332. X#endif
  1333. X
  1334. X                SetBarStripe(bar[i]);
  1335. X            }
  1336. X            break;
  1337. X
  1338. X        case HS_DOWN:
  1339. X            break;
  1340. X        }
  1341. X    }
  1342. X
  1343. X    /* set up next call */
  1344. X    XtAddTimeOut((unsigned long)(HOSTTIMEUP * 1000), host_down, (caddr_t)0);
  1345. X}
  1346. X
  1347. X/*
  1348. X *    Look at argv for the number of hosts (bars).
  1349. X */
  1350. X/* ARGSUSED */
  1351. int
  1352. num_bars(argc, argv)
  1353. int    argc;
  1354. char    *argv[];
  1355. X{
  1356. X    if (argc < 2)
  1357. X    {
  1358. X        extern void    usage();
  1359. X
  1360. X        usage();
  1361. X        /* NOTREACHED */
  1362. X    }
  1363. X
  1364. X    return argc - 1;
  1365. X}
  1366. X
  1367. X/*
  1368. X *    Initialise (in some sense).
  1369. X */
  1370. X/* ARGSUSED */
  1371. void
  1372. init_bars(n)
  1373. int    n;
  1374. X{
  1375. X    Clnt_multi_sock = rwho_filter();
  1376. X
  1377. X    XtAddTimeOut((unsigned long)(HOSTTIMEUP * 1000), host_down, (caddr_t)0);
  1378. X}
  1379. X
  1380. X/*
  1381. X *    Called after num_bars to ask for the bar names.
  1382. X *
  1383. X *    I use a naive algorithm to match hostnames without the domain part.
  1384. X *    If the domain is present, it's stripped.  Use of /etc/hosts or any
  1385. X *    form of nameserver is explicitly avoided; it's simpler and more
  1386. X *    robust just to use strcmp(3) to match/verify hostnames.
  1387. X */
  1388. X/* ARGSUSED */
  1389. char **
  1390. label_bars(nbars, argc, argv)
  1391. int nbars;
  1392. int argc;
  1393. char **argv;
  1394. X{
  1395. X    int        i;
  1396. X    char        **hostv;
  1397. X    char        **n;
  1398. X    extern char    *xmalloc();
  1399. X
  1400. X    nhosts = nbars;
  1401. X    hosts = (struct host *)xmalloc(nhosts * sizeof (struct host));
  1402. X    argv++;
  1403. X
  1404. X    n = hostv = (char **)xmalloc(nhosts * sizeof (char *));
  1405. X
  1406. X    for (i = 0; i < nhosts; i++)
  1407. X    {
  1408. X        char        *p;
  1409. X        int        j;
  1410. X        struct host    *hp;
  1411. X        extern char    *strchr();
  1412. X        extern char    *strncpy();
  1413. X
  1414. X        hp = &hosts[i];
  1415. X
  1416. X        /* hack off domain part */
  1417. X        if ((p = strchr(argv[i], '.')) != (char *)0)
  1418. X            j = p - argv[i];
  1419. X        else
  1420. X            j = strlen(argv[i]);
  1421. X
  1422. X        hp->h_name = *n++ = strncpy(xmalloc(j + 1), argv[i], j);
  1423. X        hp->h_name[j] = '\0';
  1424. X        hp->h_when = 0;
  1425. X
  1426. X        for (j = 0; j < NLOADAV; j++)
  1427. X            hp->h_loadav[j] = 0;
  1428. X    
  1429. X        hp->h_state = HS_INIT;    
  1430. X    }
  1431. X
  1432. X    return hostv;
  1433. X}
  1434. END_OF_FILE
  1435. if test 11679 -ne `wc -c <'s-pfilt-rwho.c'`; then
  1436.     echo shar: \"'s-pfilt-rwho.c'\" unpacked with wrong size!
  1437. fi
  1438. # end of 's-pfilt-rwho.c'
  1439. fi
  1440. if test -f 's.h' -a "${1}" != "-c" ; then 
  1441.   echo shar: Will not clobber existing file \"'s.h'\"
  1442. else
  1443. echo shar: Extracting \"'s.h'\" \(262 characters\)
  1444. sed "s/^X//" >'s.h' <<'END_OF_FILE'
  1445. X/*
  1446. X *  Any system dependent file must implement these routines. See s-bsd.c
  1447. X *  and s-iris4d.c for examples.
  1448. X */
  1449. extern int num_bars();
  1450. extern char **label_bars(/* int nbars */);
  1451. extern void init_bars(/* int nbars */);
  1452. extern void display_bars(/* int nbars */);
  1453. END_OF_FILE
  1454. if test 262 -ne `wc -c <'s.h'`; then
  1455.     echo shar: \"'s.h'\" unpacked with wrong size!
  1456. fi
  1457. # end of 's.h'
  1458. fi
  1459. if test -f 'xwhosup.1' -a "${1}" != "-c" ; then 
  1460.   echo shar: Will not clobber existing file \"'xwhosup.1'\"
  1461. else
  1462. echo shar: Extracting \"'xwhosup.1'\" \(2136 characters\)
  1463. sed "s/^X//" >'xwhosup.1' <<'END_OF_FILE'
  1464. X.TH XWHOSUP 1
  1465. X.SH NAME
  1466. xwhosup - display rwho based host up/down status
  1467. X.SH SYNTAX
  1468. X\fBxwhosup\fP [\fI\-toolkitoption\fP ...] [\fI-noisy\fP] host ...
  1469. X.SH DESCRIPTION
  1470. X.I Xwhosup
  1471. displays a logarithmic bar graph showing
  1472. X.I host
  1473. load average.  This data is gathered from network
  1474. X.IR rwhod (8)
  1475. broadcasts collected via
  1476. X.IR packetfilter (4).
  1477. Hosts can be specified by either their hostname, or by their fully qualified
  1478. domain name.  If the domain is supplied it is stripped and ignored.
  1479. X.PP
  1480. Initially no bar graph is displayed until either a packet is received or the
  1481. host alive timer expires.  The bar graph displays the 5 minute load average
  1482. for a host.  The scale is logarithmic with a maximum value of 1000.  For values
  1483. between 0 to 1 the scale is linear.
  1484. X.PP
  1485. If a host has not been heard from after some interval it is as marked down.
  1486. This is indicated by a bar consisting of alternating yellow/black diagonal
  1487. stripes.
  1488. X.PP
  1489. If the
  1490. X.I -noisy
  1491. option is specified
  1492. X.I xwhosup
  1493. prints a one line summary (hostname and load averages) for each
  1494. X.IR rwho (8)
  1495. broadcast received.  If a corrupted packet is received this option
  1496. causes debugging information to be written to standard error.
  1497. X.SH SEE ALSO
  1498. X.IR ruptime (1),
  1499. X.IR rwho (1),
  1500. X.IR xcpustate (1),
  1501. X.IR packetfilter (4),
  1502. X.IR rwhod (8).
  1503. X.SH BUGS
  1504. Vertical re-sizing doesn't work well and horizontal re-sizing is
  1505. X.IR interesting .
  1506. X.PP
  1507. More concern has been placed on network snooping than X programming, as the
  1508. later does not interest the author.
  1509. X.PP
  1510. The linear 0 to 1 scale is provided so that the graph is more interesting
  1511. because most of our hosts are basically idle.
  1512. X.SH AUTHOR
  1513. Boyd Roberts <boyd@prl.dec.com>
  1514. X.PP
  1515. X.I Xwhosup
  1516. is based on the code from Mark Moraes' 
  1517. X.IR xcpustate (1)
  1518. X.SM CPU
  1519. user/system/idle time monitor.  This 
  1520. X.IR packetfilter (4)
  1521. interface was written to provide a simple indication of the
  1522. status of network host(s).
  1523. X.PP
  1524. Originally authored by Mark Moraes, University of Toronto.
  1525. Thanks to Chris Siebenmann for the code for BSD systems.
  1526. Thanks to Walter D. Poxon from Cray Research for the code for Cray X/MP and
  1527. Y/MPs.
  1528. X.SH "LOCAL PROPRIETOR"
  1529. Boyd Roberts <boyd@prl.dec.com>
  1530. END_OF_FILE
  1531. if test 2136 -ne `wc -c <'xwhosup.1'`; then
  1532.     echo shar: \"'xwhosup.1'\" unpacked with wrong size!
  1533. fi
  1534. # end of 'xwhosup.1'
  1535. fi
  1536. if test -f 'xwhosup.c' -a "${1}" != "-c" ; then 
  1537.   echo shar: Will not clobber existing file \"'xwhosup.c'\"
  1538. else
  1539. echo shar: Extracting \"'xwhosup.c'\" \(5923 characters\)
  1540. sed "s/^X//" >'xwhosup.c' <<'END_OF_FILE'
  1541. X/*
  1542. X*  Displays CPU state distribution
  1543. X*/
  1544. X#ifndef lint
  1545. static char rcsid[] = "$Header: /ai/lambda/X.V11R4/contrib/clients/xcpustate/RCS/xcpustate.c,v 1.2 90/02/20 00:33:36 xwindows Exp $";
  1546. X#endif /*lint*/
  1547. X
  1548. X#include <stdio.h>
  1549. X
  1550. X#include <X11/Xos.h>
  1551. X#include <X11/StringDefs.h>
  1552. X#include <X11/Intrinsic.h>
  1553. X#include <X11/Xaw/Form.h>
  1554. X#include <X11/Xaw/Label.h>
  1555. X#include <X11/Xmu/Xmu.h>
  1556. X#include "Bar.h"
  1557. X#include "s.h"
  1558. X
  1559. X#define MAXSTR 512
  1560. X#define DEF_INTERVAL    1
  1561. X#define DEF_COUNT        -1
  1562. X
  1563. char *progname;
  1564. static int defaultInterval = DEF_INTERVAL;
  1565. static int defaultCount = DEF_COUNT;
  1566. static Bool defaultNoisy = False;
  1567. int count, interval;
  1568. Bool noisy;
  1569. X
  1570. X/* Application Resources - no particular widget */
  1571. static XtResource application_resources[] = {
  1572. X    {"interval", "Interval", XtRInt, sizeof(int),
  1573. X        (Cardinal)&interval, XtRInt, (caddr_t) &defaultInterval},
  1574. X    {"count", "Count", XtRInt, sizeof(int),
  1575. X        (Cardinal)&count, XtRInt, (caddr_t) &defaultCount},
  1576. X    {"noisy", "Noisy", XtRBoolean, sizeof(Bool),
  1577. X        (Cardinal)&noisy, XtRBoolean, (caddr_t) &defaultNoisy},
  1578. X};
  1579. X
  1580. X/*
  1581. X*  Command line options table. The command line is parsed for these,
  1582. X*  and it sets/overrides the appropriate values in the resource
  1583. X*  database
  1584. X*/
  1585. static XrmOptionDescRec optionDescList[] = {
  1586. X    {"-interval",   ".interval",    XrmoptionSepArg,    (caddr_t) NULL},
  1587. X    {"-count",        ".count",        XrmoptionSepArg,    (caddr_t) NULL},
  1588. X    {"-noisy",        ".noisy",        XrmoptionNoArg,     (caddr_t) "True"},
  1589. X};
  1590. X
  1591. X/*
  1592. X*  DON'T CHANGE THE ORDER OF THE ARGS IN THE VARIOUS ARG STRUCTS. IF
  1593. X*  YOU WANT TO ADD STUFF, ADD IT AT THE END OF THE STRUCT, BECAUSE WE
  1594. X*  REFER TO SOME OF THE ELEMENTS BY POSITION IN THE CODE.
  1595. X*/
  1596. X/* No spacing between the widgets on the Form */
  1597. static Arg form_args[] = {
  1598. X    {XtNdefaultDistance, (XtArgVal) 0},
  1599. X};
  1600. X
  1601. static Arg subform_args[] = {
  1602. X    {XtNfromVert, (XtArgVal) 0},
  1603. X    {XtNdefaultDistance, (XtArgVal) 2},
  1604. X    {XtNborderWidth, (XtArgVal) 0},
  1605. X    {XtNtop, (XtArgVal) XtChainTop},
  1606. X    {XtNbottom, (XtArgVal) XtChainTop}, /* ChainBottom causes strange resize */
  1607. X    {XtNright, (XtArgVal) XtChainRight},
  1608. X    {XtNleft, (XtArgVal) XtChainLeft},
  1609. X};
  1610. X
  1611. static Arg bar_args[] = {
  1612. X/*    {XtNfromHoriz, (XtArgVal) 0}, */
  1613. X    {XtNorientation, (XtArgVal) XtorientHorizontal},
  1614. X    {XtNborderWidth, (XtArgVal) 1},
  1615. X    {XtNlength, (XtArgVal) ((Dimension) 200)},
  1616. X    {XtNthickness, (XtArgVal) ((Dimension) 20)},
  1617. X    {XtNtop, (XtArgVal) XtChainTop},
  1618. X    {XtNbottom, (XtArgVal) XtChainTop},
  1619. X    {XtNright, (XtArgVal) XtChainRight},
  1620. X    {XtNleft, (XtArgVal) XtChainRight},
  1621. X    {XtNvertDistance, (XtArgVal) 0},
  1622. X/*    {XtNhorizDistance, (XtArgVal) 0}, */
  1623. X    {XtNresizable, (XtArgVal) FALSE},
  1624. X};
  1625. X
  1626. static Arg label_args[] = {
  1627. X    {XtNlabel, (XtArgVal) 0},
  1628. X    {XtNjustify, (XtArgVal) XtJustifyLeft},
  1629. X    {XtNborderWidth, (XtArgVal) 0},
  1630. X    {XtNtop, (XtArgVal) XtChainTop},
  1631. X    {XtNbottom, (XtArgVal) XtChainTop},
  1632. X    {XtNright, (XtArgVal) XtChainLeft},
  1633. X    {XtNleft, (XtArgVal) XtChainLeft},
  1634. X    {XtNvertDistance, (XtArgVal) 0},
  1635. X    {XtNhorizDistance, (XtArgVal) 0},
  1636. X    {XtNresizable, (XtArgVal) FALSE},
  1637. X};
  1638. X
  1639. static Arg gwid_args[] = {
  1640. X    {XtNwidth, (XtArgVal)0},
  1641. X};
  1642. X
  1643. static Arg sx_args[] = {
  1644. X    {XtNhorizDistance, (XtArgVal)0},
  1645. X};
  1646. X
  1647. void
  1648. usage()
  1649. X{
  1650. X    (void) fprintf(stderr,
  1651. X"usage: %s [Xt options] [-count iterations] [-interval delay_seconds] [-noisy] host ...\n",
  1652. X     progname);
  1653. X    exit(-1);
  1654. X}
  1655. X
  1656. char *
  1657. xmalloc(n)
  1658. int n;
  1659. X{
  1660. X    extern char *malloc();
  1661. X    char *cp = malloc((unsigned) n);
  1662. X    if (cp == NULL) {
  1663. X        (void) fprintf(stderr, "%s: Ran out of memory.\n", progname);
  1664. X        exit(-1);
  1665. X    }
  1666. X    return cp;
  1667. X}
  1668. X
  1669. extern XtInputCallbackProc    get_socket_msg();
  1670. X
  1671. static int nbars;
  1672. Widget *bar;
  1673. static char **barnames;
  1674. X    
  1675. main(argc, argv)
  1676. int argc;
  1677. char **argv;
  1678. X{
  1679. X    int i;
  1680. X    Widget topLevel;
  1681. X    Widget form, label;
  1682. X    Widget subform = NULL;
  1683. X    extern char *strchr(/* const char *, char */);
  1684. X    int maxwid;
  1685. X    extern int Clnt_multi_sock;
  1686. X
  1687. X    if ((progname = strchr(argv[0], '/')) == NULL)
  1688. X    progname = argv[0];
  1689. X    else
  1690. X    progname++;
  1691. X
  1692. X
  1693. X    topLevel = XtInitialize(progname, "RWHOHostMonitor",
  1694. X                optionDescList, XtNumber(optionDescList),
  1695. X                &argc, argv);
  1696. X
  1697. X    nbars = num_bars(argc, argv);
  1698. X    if (nbars == 0) {
  1699. X    (void) fprintf(stderr, "num_bars returned 0 - something is wrong\n");
  1700. X    exit(-1);
  1701. X    }
  1702. X    bar = (Widget *) xmalloc(nbars * sizeof(Widget));
  1703. X    barnames = label_bars(nbars, argc, argv);
  1704. X    
  1705. X    XtGetApplicationResources(topLevel, 0, application_resources,
  1706. X                  XtNumber(application_resources), NULL, 0 );
  1707. X
  1708. X    form = XtCreateManagedWidget("form", formWidgetClass, topLevel,
  1709. X                 form_args, XtNumber(form_args));
  1710. X    
  1711. X    maxwid = 0;
  1712. X    for(i = 0; i < nbars; i++) {
  1713. X#define FORMNAMEFMT    "form%d"
  1714. X    char formname[sizeof(FORMNAMEFMT) + 32];
  1715. X#define BARNAMEFMT    "bar%d"
  1716. X    char barname[sizeof(BARNAMEFMT) + 32];
  1717. X
  1718. X    if (i > 0)
  1719. X        subform_args[0].value = (XtArgVal) subform;
  1720. X    (void) sprintf(formname, FORMNAMEFMT, i);
  1721. X    subform = XtCreateManagedWidget(formname, formWidgetClass, form,
  1722. X                 subform_args, XtNumber(subform_args));
  1723. X    label_args[0].value = (XtArgVal) barnames[i];
  1724. X    label = XtCreateManagedWidget(barnames[i], labelWidgetClass, subform,
  1725. X                      label_args, XtNumber(label_args));
  1726. X    XtSetArg(gwid_args[0], XtNwidth, 0);
  1727. X    XtGetValues(label, gwid_args, 1);
  1728. X    if (gwid_args[0].value > maxwid)
  1729. X        maxwid = gwid_args[0].value;
  1730. X    (void) sprintf(barname, BARNAMEFMT, i);
  1731. X/*    bar_args[0].value = (XtArgVal) label; */
  1732. X    bar[i] = XtCreateManagedWidget(barname, barWidgetClass, subform,
  1733. X                    bar_args, XtNumber(bar_args));
  1734. X    }
  1735. X    sx_args[0].value = (XtArgVal)(maxwid + 2);
  1736. X    for(i = 0; i < nbars; i++)
  1737. X    XtSetValues(bar[i], sx_args, 1);
  1738. X
  1739. X    XtRealizeWidget(topLevel);
  1740. X
  1741. X    init_bars(nbars);
  1742. X
  1743. X    XtAddInput(Clnt_multi_sock, XtInputReadMask, get_socket_msg, (caddr_t)0);
  1744. X
  1745. X    XtMainLoop();
  1746. X}
  1747. X
  1748. void
  1749. draw_bar(i, states, nstates)
  1750. int i;
  1751. int states[];
  1752. int nstates;
  1753. X{
  1754. X    SetBarValues((Widget) bar[i], states, nstates);
  1755. X}
  1756. END_OF_FILE
  1757. if test 5923 -ne `wc -c <'xwhosup.c'`; then
  1758.     echo shar: \"'xwhosup.c'\" unpacked with wrong size!
  1759. fi
  1760. # end of 'xwhosup.c'
  1761. fi
  1762. echo shar: End of archive 1 \(of 1\).
  1763. cp /dev/null ark1isdone
  1764. MISSING=""
  1765. for I in 1 ; do
  1766.     if test ! -f ark${I}isdone ; then
  1767.     MISSING="${MISSING} ${I}"
  1768.     fi
  1769. done
  1770. if test "${MISSING}" = "" ; then
  1771.     echo You have the archive.
  1772.     rm -f ark[1-9]isdone
  1773. else
  1774.     echo You still need to unpack the following archives:
  1775.     echo "        " ${MISSING}
  1776. fi
  1777. ##  End of shell archive.
  1778. exit 0
  1779.