4a38b47e76d53e1802b19359791ba7f99778c54c
[openafs.git] / src / scout / scout.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Scout: A quick and (semi-)dirty attempt at the old CMU vopcon.
12  *------------------------------------------------------------------------*/
13
14 #include <afsconfig.h>
15 #include <afs/param.h>
16
17 #include <roken.h>
18
19 #undef  IN
20 #include <afs/gtxwindows.h>             /*Generic window package */
21 #include <afs/gtxobjects.h>             /*Object definitions */
22 #include <afs/gtxtextobj.h>             /*Text object interface */
23 #include <afs/gtxlightobj.h>    /*Light object interface */
24 #include <afs/gtxcurseswin.h>   /*Curses window package */
25 #include <afs/gtxdumbwin.h>             /*Dumb terminal window package */
26 #include <afs/gtxX11win.h>              /*X11 window package */
27 #include <afs/gtxframe.h>               /*Frame package */
28 #include <afs/gtxinput.h>
29 #include <afs/cmd.h>            /*Command interpretation library */
30 #include <afs/fsprobe.h>                /*Interface for fsprobe module */
31 #include <afs/afsutil.h>
32
33 /*
34  * Command line parameter indicies.
35  */
36 #define P_SERVER    0
37 #define P_BASE      1
38 #if 0
39 #define P_PACKAGE   2
40 #endif /* 0 */
41 #define P_FREQ      2
42 #define P_HOST      3
43 #define P_ATTENTION 4
44 #define P_DEBUG     5
45 #define P_WIDTHS    6
46
47 /*
48   * Define the default width in chars for each light object on the mini-line.
49   */
50 #define LIGHTOBJ_CONN_WIDTH      5
51 #define LIGHTOBJ_FETCH_WIDTH    10
52 #define LIGHTOBJ_STORE_WIDTH    10
53 #define LIGHTOBJ_WK_WIDTH        5
54 #define LIGHTOBJ_SRVNAME_WIDTH  13
55 #define LIGHTOBJ_DISK_WIDTH     12
56
57 /*
58  * Define column width indices.
59  */
60 #define COL_CONN        0
61 #define COL_FETCH       1
62 #define COL_STORE       2
63 #define COL_WK          3
64 #define COL_SRVNAME     4
65 #define COL_DISK        5
66
67 /*
68  * Define the types of justification we can perform.
69  */
70 #define SCOUT_RIGHT_JUSTIFY     0
71 #define SCOUT_LEFT_JUSTIFY      1
72 #define SCOUT_CENTER            2
73
74 /*
75  * Define the types of truncation we can perform.
76  */
77 #define SCOUT_LEFT_TRUNC        0
78 #define SCOUT_RIGHT_TRUNC       1
79
80 /*
81  * Define whether the value passed is a labeled disk quantity.
82  */
83 #define SCOUT_ISNT_LDISK        0
84 #define SCOUT_IS_LDISK          1
85
86 /*
87   * We sometimes use index-base pointers, so we need a distinguished
88   * NIL value.
89   */
90 #define SCOUT_NIL  (-1)
91
92 /*
93   * Structure describing everything you want to know about a FileServer
94   * disk.
95   */
96 struct scout_disk {
97     int prev;                   /*Index of previous list entry */
98     int next;                   /*Index of next list entry */
99     int active;                 /*Is this disk known to exist? */
100     char *name;                 /*Single-letter disk name */
101     struct onode *disk_lp;      /*Ptr to disk light object */
102 };
103
104 /*
105   * Structure defining all the objects in the Scout line (or lines)
106   * for each server being watched.  Note that scout_disk linked list
107   * for used disks is ordered alphabetically.
108   */
109 struct mini_line {
110     /*
111      * Information on server location & configuration.
112      */
113     struct sockaddr_in skt;     /*Server's socket info */
114     int numDisks;               /*Number of disks used */
115     /*
116      * Screen location info.
117      */
118     int base_line;              /*Line number on the screen */
119     int num_lines;              /*Number of lines of info */
120     /*
121      * Associated light objects.
122      */
123     struct onode *currConns_lp; /*Number of current connections */
124     struct onode *fetches_lp;   /*Number of data fetches */
125     struct onode *stores_lp;    /*Number of data stores */
126     struct onode *workstations_lp;      /*Workstation info */
127     struct onode *srvName_lp;   /*Server name */
128     struct scout_disk disks[VOLMAXPARTS];       /*Info on all the disks */
129     int used_head;              /*Index of first used disk struct */
130     int used_tail;              /*Index of last used disk struct */
131     int free_head;              /*Index of first free disk struct */
132     int free_tail;              /*Index of last free disk struct */
133 };
134
135 /*
136   * Structure defining the contents of the Scout screen.
137   */
138 struct mini_screen {
139     int numServers;             /*Number of servers being watched */
140     int base_line_num;          /*Base mini-line number */
141     struct mini_line *line;     /*Array of screen lines */
142 };
143
144 static char pn[] = "scout";     /*Program name */
145 static int scout_debug = 0;     /*Is debugging turned on? */
146 static FILE *scout_debugfd;     /*Debugging file descriptor */
147 static int scout_gtx_initialized = 0;   /*Has gtx been initialized? */
148 static struct mini_screen scout_screen; /*Mini-screen itself */
149 static int scout_probefreq;     /*Probe frequency in seconds */
150 static char scout_basename[64]; /*Base server name */
151 static char scout_hostname[128];        /*Name of machine we're running on */
152 static int scout_showhostname = 0;      /*Show name of machine we're on? */
153 static char scout_blankline[256];       /*Blank line */
154 static struct gwin *scout_gwin; /*Window to use */
155 static struct gtx_frame *scout_frame;   /*Frame to use */
156 static struct onode *scout_banner0_lp;  /*Banner light, line 0 */
157 static struct onode *scout_banner1_lp;  /*Banner light, line 1 */
158 static struct onode *scout_banner2_lp;  /*Banner light, line 2 */
159 static int scout_DiskLightLeftCol = 0;  /*Column for leftmost disk light */
160 static struct gwin_sizeparams scout_frameDims;  /*Frame dimensions */
161
162 static int scout_col_width[] = { LIGHTOBJ_CONN_WIDTH,
163     LIGHTOBJ_FETCH_WIDTH,
164     LIGHTOBJ_STORE_WIDTH,
165     LIGHTOBJ_WK_WIDTH,
166     LIGHTOBJ_SRVNAME_WIDTH,
167     LIGHTOBJ_DISK_WIDTH
168 };
169
170 /*
171   * Attention thresholds & modes.
172   */
173 #define SCOUT_ATTN_NOTUSED  (-1)
174 #define SCOUT_DISKM_PCUSED    0
175 #define SCOUT_DISKM_MINFREE   1
176
177 static int scout_attn_conn = SCOUT_ATTN_NOTUSED;
178 static int scout_attn_fetch = SCOUT_ATTN_NOTUSED;
179 static int scout_attn_store = SCOUT_ATTN_NOTUSED;
180 static int scout_attn_workstations = SCOUT_ATTN_NOTUSED;
181 static int scout_attn_disk_mode = SCOUT_DISKM_PCUSED;
182 static int scout_attn_disk_minfree = 1000;
183 static float scout_attn_disk_pcused = 0.95;
184 static char scout_attn_disk_pcusedstr[8] = "95";
185
186 /*
187   * Some strings we'll be using over and over again.
188   */
189 static char scout_Banner[256];
190 static const char *scout_label[] =
191     { "Conn", "Fetch", "Store", "Ws", "", "Disk attn" };
192 static const char *scout_underline[] =
193     { "----", "--------", "--------", "-----", "", "----------" };
194
195
196 /*------------------------------------------------------------------------
197  * scout_CleanExit
198  *
199  * Description:
200  *      Exits cleanly from the Scout.  If gtx has not yet been initialized,
201  *      then we simply call exit() with the value provided.  Otherwise,
202  *      we call the appropriate gtx routine to exit cleanly from gtx, which
203  *      must reset the terminal or window.  We also close the debugging
204  *      file descriptor, if one has been opened.
205  *
206  * Arguments:
207  *      int a_exitval : Value with which to exit the program.
208  *
209  * Returns:
210  *      Void.
211  *
212  * Environment:
213  *      Actions depend on scout_gtx_initialized.
214  *
215  * Side Effects:
216  *      This routine will always exit Scout.
217  *------------------------------------------------------------------------*/
218
219 static void
220 scout_CleanExit(int a_exitval)
221 {                               /*scout_CleanExit */
222
223     static char rn[] = "scout_CleanExit";       /*Routine name */
224
225     if (scout_debugfd != (FILE *) 0) {
226         fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
227         fclose(scout_debugfd);
228     }
229
230     if (scout_gtx_initialized) {
231         gtxframe_exitValue = a_exitval;
232         gtxframe_ExitCmd((void *)(&gtxframe_exitValue), NULL);
233     } else
234         exit(a_exitval);
235
236 }                               /*scout_CleanExit */
237
238 /*------------------------------------------------------------------------
239  * mini_initLightObject
240  *
241  * Description:
242  *      Create and initialize a light onode according to the given
243  *      parameters.
244  *
245  * Arguments:
246  *      char *a_name       : Ptr to the light's string name.
247  *      int a_x            : X offset.
248  *      int a_y            : Y offset.
249  *      int a_width        : Width in chars.
250  *      struct gwin *a_win : Ptr to window structure.
251  *
252  * Returns:
253  *      Ptr to new light onode on success,
254  *      A null pointer otherwise.
255  *
256  * Environment:
257  *      See above.
258  *
259  * Side Effects:
260  *      As advertised.
261  *------------------------------------------------------------------------*/
262
263 static struct onode *
264 mini_initLightObject(char *a_name, int a_x, int a_y, int a_width, struct gwin *a_win)
265 {                               /*mini_initLightObject */
266
267     static char rn[] = "mini_initLightObject";  /*Routine name */
268     struct onode *newlightp;    /*Ptr to new light onode */
269     /*We only support curses right now */
270     struct gator_light_crparams light_crparams; /*Light creation params */
271     char *truncname;            /*Truncated name, if needed */
272     int name_len;               /*True length of name */
273
274     if (scout_debug) {
275         fprintf(scout_debugfd,
276                 "[%s] Called for name '%s', [%d, %d], %d-char field\n", rn,
277                 a_name, a_x, a_y, a_width);
278         fflush(scout_debugfd);
279     }
280     newlightp = NULL;
281
282     /*
283      * Set up the creation parameters according to the information we've
284      * received.
285      */
286     light_crparams.onode_params.cr_type = GATOR_OBJ_LIGHT;
287     name_len = strlen(a_name);
288     if (scout_debug)
289         fprintf(scout_debugfd, "[%s] Name '%s' has %d chars\n", rn, a_name,
290                 name_len);
291     if (name_len <= a_width)
292         sprintf(light_crparams.onode_params.cr_name, "%s", a_name);
293     else {
294         /*
295          * We need to truncate the given name, leaving a `*' at the end to
296          * show us it's been truncated.
297          */
298         truncname = light_crparams.onode_params.cr_name;
299         strncpy(truncname, a_name, a_width - 1);
300         truncname[a_width - 1] = '*';
301         truncname[a_width] = 0;
302     }
303     light_crparams.onode_params.cr_x = a_x;
304     light_crparams.onode_params.cr_y = a_y;
305     light_crparams.onode_params.cr_width = a_width;
306     light_crparams.onode_params.cr_height = 1;
307     light_crparams.onode_params.cr_window = a_win;
308     light_crparams.onode_params.cr_home_obj = NULL;
309     light_crparams.onode_params.cr_prev_obj = NULL;
310     light_crparams.onode_params.cr_parent_obj = NULL;
311     light_crparams.onode_params.cr_helpstring = NULL;
312
313     light_crparams.appearance = 0;
314     light_crparams.flashfreq = 0;
315     sprintf(light_crparams.label, "%s", a_name);
316     light_crparams.label_x = 0;
317     light_crparams.label_y = 0;
318
319     newlightp =
320         gator_objects_create((struct onode_createparams *)(&light_crparams));
321
322     /*
323      * Return the news, happy or not.
324      */
325     return (newlightp);
326
327 }                               /*mini_initLightObject */
328
329 /*------------------------------------------------------------------------
330  * scout_initDiskLightObjects
331  *
332  * Description:
333  *      Create and initialize all Scout light objects for a server's
334  *      disks.
335  *
336  * Arguments:
337  *      struct scout_disk *a_line : Ptr to the server object line.
338  *      struct gwin *a_win        : Ptr to window structure.
339  *
340  * Returns:
341  *      0 on success,
342  *      -1 otherwise.
343  *
344  * Environment:
345  *      See above.
346  *
347  * Side Effects:
348  *      As advertised.
349  *------------------------------------------------------------------------*/
350
351 static int
352 scout_initDiskLightObjects(struct mini_line *a_line, struct gwin *a_win)
353 {                               /*scout_initDiskLightObjects */
354
355     static char rn[] = "scout_initDiskLightObjects";    /*Routine name */
356     struct scout_disk *curr_disk;       /*Ptr to current disk being set up */
357     int i;                      /*Loop variable */
358
359     if (scout_debug) {
360         fprintf(scout_debugfd, "[%s] Called\n", rn);
361         fflush(scout_debugfd);
362     }
363
364     /*
365      * Set up the base linked list fields.
366      */
367     a_line->used_head = SCOUT_NIL;
368     a_line->used_tail = SCOUT_NIL;
369     a_line->free_head = 0;
370     a_line->free_tail = VOLMAXPARTS - 1;
371
372     /*
373      * Sweep through the disk structures, creating the light objects and
374      * marking them all as free.
375      */
376     curr_disk = a_line->disks;
377     for (i = 0; i < VOLMAXPARTS; i++) {
378         /*
379          * Create the disk light object.
380          */
381         if ((curr_disk->disk_lp = mini_initLightObject("Disk",  /*Object name */
382                                                        0,       /*X value */
383                                                        0,       /*Y value */
384                                                        scout_col_width[COL_DISK],       /*Width */
385                                                        a_win))  /*Window */
386             == NULL) {
387             fprintf(stderr, "[%s:%s] Can't create disk %d light object\n", pn,
388                     rn, i);
389             return (-1);
390         }
391
392         /*
393          * Set the other fields in the disk records; Note that in the
394          * fencepost cases, the prev and next pointers will have to be
395          * fixed.
396          */
397         curr_disk->prev = i - 1;
398         curr_disk->next = i + 1;
399         curr_disk->active = 0;
400         curr_disk->name = "";
401
402         /*
403          * Bump up to the next disk structure.
404          */
405         curr_disk++;
406
407     }                           /*for each disk structure */
408
409     /*
410      * We made it all the way through.  Fix the fencepost pointers, set
411      * the overall pointers, then return success.
412      */
413     a_line->disks[0].prev = SCOUT_NIL;
414     a_line->disks[VOLMAXPARTS - 1].next = SCOUT_NIL;
415
416     return (0);
417
418 }                               /*scout_initDiskLightObjects */
419
420
421 /*------------------------------------------------------------------------
422  * mini_justify
423  *
424  * Description:
425  *      Place the chars in the source buffer into the target buffer
426  *      with the desired justification, either centered, left-justified
427  *      or right-justified.  Also, support inidication of truncation
428  *      with a star (*), either on the left or right of the string,
429  *      and whether we're justifying a labeled disk quantity.
430  *
431  * Arguments:
432  *      char *a_srcbuff     : Ptr to source char buffer.
433  *      char *a_dstbuff     : Ptr to dest char buffer.
434  *      int a_dstwidth      : Width of dest buffer in chars.
435  *      int a_justification : Kind of justification.
436  *      int a_rightTrunc    : If non-zero, place the truncation char
437  *                            on the right of the string.  Otherwise,
438  *                            place it on the left.
439  *      int a_isLabeledDisk : Is this a labeled disk quantity?
440  *
441  * Returns:
442  *      0 on success,
443  *      -1 otherwise.
444  *
445  * Environment:
446  *      All it needs to know is exported by the fsprobe module, namely
447  *      the data structure where the probe results are stored.
448  *
449  * Side Effects:
450  *      As advertised.
451  *------------------------------------------------------------------------*/
452
453 int
454 mini_justify(char *a_srcbuff, char *a_dstbuff, int a_dstwidth,
455              int a_justification, int a_rightTrunc,
456              int a_isLabeledDisk)
457 {                               /*mini_justify */
458
459     static char rn[] = "mini_justify";  /*Routine name */
460     int leftpad_chars;          /*# of chars for left-padding */
461     int num_src_chars;          /*# of chars in source */
462     int true_num_src_chars;     /*# src chars before truncation */
463     int trunc_needed;           /*Is truncation needed? */
464     char diskChar = 0;          /*Disk name prefix */
465
466     if (scout_debug) {
467         fprintf(scout_debugfd, "[%s] Called with '%s', dest width=%d\n", rn,
468                 a_srcbuff, a_dstwidth);
469         fflush(scout_debugfd);
470     }
471
472     /*
473      * Remember the disk label, if we've been passed such a thing.
474      */
475     if (a_isLabeledDisk)
476         diskChar = *a_srcbuff;
477
478     /*
479      * If the destination width will overrun the gtx string storage,
480      * we automatically shorten up.
481      */
482     if (a_dstwidth > GATOR_LABEL_CHARS) {
483         if (scout_debug) {
484             fprintf(scout_debugfd,
485                     "[%s] Dest width (%d) > gtx buflen (%d), shrinking dest width\n",
486                     rn, a_dstwidth, GATOR_LABEL_CHARS);
487             fflush(scout_debugfd);
488         }
489         a_dstwidth = GATOR_LABEL_CHARS;
490     }
491
492     /*
493      * If our source string is too long, prepare for truncation.
494      */
495     true_num_src_chars = strlen(a_srcbuff);
496     if (true_num_src_chars >= a_dstwidth) {
497         trunc_needed = 1;
498         num_src_chars = a_dstwidth - 1;
499         leftpad_chars = 0;
500         if (!a_rightTrunc)
501             a_srcbuff += (true_num_src_chars - num_src_chars);
502     } else {
503         trunc_needed = 0;
504         num_src_chars = true_num_src_chars;
505
506         /*
507          * Compute the necessary left-padding.
508          */
509         switch (a_justification) {
510
511         case SCOUT_RIGHT_JUSTIFY:
512             leftpad_chars = (a_dstwidth - 1) - num_src_chars;
513             break;
514
515         case SCOUT_LEFT_JUSTIFY:
516             /*
517              * This is the really easy one.
518              */
519             leftpad_chars = 0;
520             break;
521
522         case SCOUT_CENTER:
523             leftpad_chars = ((a_dstwidth - 1) - num_src_chars) / 2;
524             break;
525
526         default:
527             fprintf(stderr, "[%s] Illegal justification command: %d", rn,
528                     a_justification);
529             return (-1);
530         }                       /*Switch on justification type */
531     }
532
533     /*
534      * Clear out the dest buffer, then place the source string at the
535      * appropriate padding location.  Remember to place a string
536      * terminator at the end of the dest buffer, plus whatever truncation
537      * may be needed.  If we're left-truncating, we've already shifted
538      * the src buffer appropriately.
539      */
540     strncpy(a_dstbuff, scout_blankline, a_dstwidth);
541     strncpy(a_dstbuff + leftpad_chars, a_srcbuff, num_src_chars);
542     *(a_dstbuff + a_dstwidth - 1) = '\0';
543     if (trunc_needed) {
544         if (a_rightTrunc)
545             *(a_dstbuff + a_dstwidth - 2) = '*';        /*Truncate on the right */
546         else {
547             if (a_isLabeledDisk) {
548                 *a_dstbuff = diskChar;
549                 *(a_dstbuff + 1) = ':';
550                 *(a_dstbuff + 2) = '*'; /*Truncate on the left, disk */
551             } else
552                 *a_dstbuff = '*';       /*Truncate on the left, non-disk */
553         }
554     }
555
556     /*Handle truncations */
557     /*
558      * Return the good news.
559      */
560     return (0);
561
562 }                               /*mini_justify */
563
564 /*------------------------------------------------------------------------
565  * scout_SetNonDiskLightLine
566  *
567  * Description:
568  *      Given a mini-line and a line number, place all non-disk lights
569  *      on that line.
570  *
571  * Arguments:
572  *      struct mini_line *a_srvline : Ptr to server descriptor.
573  *      int a_linenum               : Line number to move to.
574  *
575  * Returns:
576  *      Nothing.
577  *
578  * Environment:
579  *      The light's location is stored not only in the onode, but in
580  *      the light's rock, so we have to change both sets of value.
581  *
582  * Side Effects:
583  *      As described.
584  *------------------------------------------------------------------------*/
585
586 static void
587 scout_SetNonDiskLightLine(struct mini_line *a_srvline, int a_linenum)
588 {                               /*scout_SetNonDiskLightLine */
589
590     struct gator_lightobj *nondisk_lightdata;   /*Non-disk light data field */
591     struct gwin_strparams *nondisk_strparams;   /*Associated string params */
592
593     /*
594      * Do the exact same operation for each non-disk light in the record.
595      */
596     a_srvline->currConns_lp->o_y = a_linenum;
597     nondisk_lightdata =
598         (struct gator_lightobj *)(a_srvline->currConns_lp->o_data);
599     nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
600     nondisk_strparams->y = a_linenum;
601
602     a_srvline->fetches_lp->o_y = a_linenum;
603     nondisk_lightdata =
604         (struct gator_lightobj *)(a_srvline->fetches_lp->o_data);
605     nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
606     nondisk_strparams->y = a_linenum;
607
608     a_srvline->stores_lp->o_y = a_linenum;
609     nondisk_lightdata =
610         (struct gator_lightobj *)(a_srvline->stores_lp->o_data);
611     nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
612     nondisk_strparams->y = a_linenum;
613
614     a_srvline->workstations_lp->o_y = a_linenum;
615     nondisk_lightdata =
616         (struct gator_lightobj *)(a_srvline->workstations_lp->o_data);
617     nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
618     nondisk_strparams->y = a_linenum;
619
620     a_srvline->srvName_lp->o_y = a_linenum;
621     nondisk_lightdata =
622         (struct gator_lightobj *)(a_srvline->srvName_lp->o_data);
623     nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
624     nondisk_strparams->y = a_linenum;
625
626 }                               /*scout_SetNonDiskLightLine */
627
628 /*------------------------------------------------------------------------
629  * scout_RecomputeLightLocs
630  *
631  * Description:
632  *      Given a pointer to a server record, recompute its disk light
633  *      locations (and keep proper track of the number of screen lines
634  *      required for the server record).
635  *
636  * Arguments:
637  *      struct mini_line *a_srvline : Ptr to server descriptor.
638  *
639  * Returns:
640  *      0 if anything went wrong,
641  *      else the number of lines used by this server record.
642  *
643  * Environment:
644  *      One or more records have joined or left the used light list
645  *      for this server.  We're not sure which ones, so we recompute
646  *      them all.  We may also have had a width change in the gtx
647  *      frame.  The base_line field in the server record is guaranteed
648  *      to be correct at this point.
649  *
650  * Side Effects:
651  *      As described.
652  *------------------------------------------------------------------------*/
653
654 static int
655 scout_RecomputeLightLocs(struct mini_line *a_srvline)
656 {                               /*scout_RecomputeLightLocs */
657
658     static char rn[] = "scout_RecomputeLightLocs";      /*Routine name */
659     int lights_per_line;        /*# lights/line */
660     int lights_this_line;       /*# lights on cur line */
661     int curr_idx;               /*Current disk light idx */
662     struct scout_disk *sc_disk; /*Ptr to disk record array */
663     int lines_for_server;       /*Num lines in server record */
664     int curr_line;              /*Current line being filled */
665     int curr_x;                 /*Current x value for light */
666     struct gator_lightobj *disk_lightdata;      /*Disk light data field */
667     struct gwin_strparams *disk_strparams;      /*String params for disk light */
668
669     if (scout_debug) {
670         fprintf(scout_debugfd, "[%s] Called\n", rn);
671         fflush(scout_debugfd);
672     }
673
674     /*
675      * If we haven't yet computed the column for the leftmost disk light,
676      * do it now.
677      */
678     if (scout_DiskLightLeftCol == 0) {
679         int i;
680         int num_cols = sizeof(scout_col_width) / sizeof(*scout_col_width);
681         scout_DiskLightLeftCol = 0;
682         for (i = 0; i < (num_cols - 1); i++) {
683             scout_DiskLightLeftCol += scout_col_width[i] + 1;
684         }
685     }
686
687     /*
688      * Calculate how many disk light objects can fit in one line.
689      */
690     lights_per_line =
691         (scout_frameDims.maxx -
692          scout_DiskLightLeftCol) / (scout_col_width[COL_DISK] + 1);
693     if (scout_debug) {
694         fprintf(scout_debugfd, "[%s] %d lights per line\n", rn,
695                 lights_per_line);
696         fflush(scout_debugfd);
697     }
698
699     /*
700      * Sweep through the used disk light list, computing the location
701      * for each.
702      */
703     lights_this_line = 0;
704     curr_idx = a_srvline->used_head;
705     lines_for_server = 1;
706     curr_line = a_srvline->base_line;
707     curr_x = scout_DiskLightLeftCol;
708
709     while (curr_idx != SCOUT_NIL) {
710         /*
711          * Bump the number of lines for the server if we've already
712          * filled up the current line.
713          */
714         if (lights_this_line >= lights_per_line) {
715             lights_this_line = 0;
716             lines_for_server++;
717             curr_line++;
718             curr_x = scout_DiskLightLeftCol;
719         }
720
721         /*Current line filled up */
722         /*
723          * Set the current disk light's location.
724          */
725         sc_disk = a_srvline->disks;
726         sc_disk[curr_idx].disk_lp->o_x = curr_x;
727         sc_disk[curr_idx].disk_lp->o_y = curr_line;
728         disk_lightdata =
729             (struct gator_lightobj *)(sc_disk[curr_idx].disk_lp->o_data);
730         disk_strparams = (struct gwin_strparams *)(disk_lightdata->llrock);
731         disk_strparams->x = curr_x;
732         disk_strparams->y = curr_line;
733         if (scout_debug) {
734             fprintf(scout_debugfd,
735                     "[%s] Disk light at index %d located at [%d, %d]\n", rn,
736                     curr_idx, curr_x, curr_line);
737             fflush(scout_debugfd);
738         }
739
740         /*
741          * Record the inclusion of the light and move on to the next
742          * light, if any.
743          */
744         lights_this_line++;
745         curr_x += scout_col_width[COL_DISK] + 1;
746         curr_idx = sc_disk[curr_idx].next;
747
748     }                           /*Update each used disk light */
749
750     /*
751      * Remember to record the (possibly new) number of lines in the
752      * server record before returning the value of that field.
753      */
754     if (a_srvline->num_lines != lines_for_server) {
755         if (scout_debug) {
756             fprintf(scout_debugfd,
757                     "[%s] Server previously had %d screen lines; now changed\n",
758                     rn, a_srvline->num_lines);
759             fflush(scout_debugfd);
760         }
761         a_srvline->num_lines = lines_for_server;
762     }
763
764     if (scout_debug) {
765         fprintf(scout_debugfd, "[%s] Server has %d screen lines\n", rn,
766                 a_srvline->num_lines);
767         fflush(scout_debugfd);
768     }
769     return (a_srvline->num_lines);
770
771 }                               /*scout_RecomputeLightLocs */
772
773 /*------------------------------------------------------------------------
774  * scout_FindUsedDisk
775  *
776  * Description:
777  *      Given a single-letter disk name and a pointer to the current server
778  *      record, look for a used disk record with that name within the server.
779  *      If we can't find one, we create and incorporate one, and return that
780  *      fact to our caller.
781  *
782  * Arguments:
783  *      char a_diskname             : Single-char disk name.
784  *      struct mini_line *a_srvline : Ptr to server descriptor.
785  *      int *a_record_added         : Was a new record added?
786  *
787  * Returns:
788  *      Index of matching used disk record,
789  *      SCOUT_NIL otherwise.
790  *
791  * Return via parameter:
792  *      a_record_added set to 1 iff record was added to the used disk list.
793  *
794  * Environment:
795  *      Used disk records are kept in alphabetical order by the single-char
796  *      disk name.  Should a matching used disk record not be found, one is
797  *      pulled from the free pool.
798  *
799  * Side Effects:
800  *      An entry may be pulled off the free list and inserted into the
801  *      used list.  This entry is placed in the update list for the
802  *      current gtx frame (at least not by this routine).
803  *------------------------------------------------------------------------*/
804
805 static int
806 scout_FindUsedDisk(char *a_diskname, struct mini_line *a_srvline, int *a_record_added)
807 {                               /*scout_FindUsedDisk */
808
809     static char rn[] = "scout_FindUsedDisk";    /*Routine name */
810     int curr_idx;               /*Disk record index */
811     int append_idx;             /*Index to append after */
812     int new_idx;                /*Index of new used record */
813     struct scout_disk *sc_disk; /*Ptr to disk record */
814     int code;                   /*Function return value */
815
816     if (scout_debug) {
817         fprintf(scout_debugfd, "[%s] Called\n", rn);
818         fflush(scout_debugfd);
819     }
820
821     /*
822      * Sweep through the used disk records, looking for a match.
823      */
824     curr_idx = a_srvline->used_head;
825     append_idx = SCOUT_NIL;
826     sc_disk = a_srvline->disks;
827     if (scout_debug) {
828         fprintf(scout_debugfd,
829                 "[%s] Scanning existing used disk entries for disk '%s'\n",
830                 rn, a_diskname);
831         fflush(scout_debugfd);
832     }
833     while (curr_idx != SCOUT_NIL) {
834         if (scout_debug) {
835             fprintf(scout_debugfd, "[%s] Disk %d is named '%s'\n", rn,
836                     curr_idx, sc_disk[curr_idx].name);
837             fflush(scout_debugfd);
838         }
839         if (strcmp(sc_disk[curr_idx].name, a_diskname) == 0) {
840             /*
841              * We found it!  Bug out.
842              */
843             if (scout_debug) {
844                 fprintf(scout_debugfd, "[%s] Match found\n", rn);
845                 fflush(scout_debugfd);
846             }
847             return (curr_idx);
848         }
849
850         /*
851          * If we are alphabetically past the given disk name, we
852          * know that we won't find it in the used disk list; we
853          * also have the append index set correctly.
854          */
855         if (strcmp(a_diskname, sc_disk[curr_idx].name) < 0) {
856             if (scout_debug) {
857                 fprintf(scout_debugfd, "[%s] Disk '%s' can't be here\n", rn,
858                         a_diskname);
859                 fflush(scout_debugfd);
860             }
861             break;
862         }
863
864         /*
865          * There's still hope we'll find it.  Move on to the next used
866          * disk record, keeping this index as the best candidate so far
867          * for appending a missing entry.
868          */
869         append_idx = curr_idx;
870         curr_idx = sc_disk[curr_idx].next;
871     }                           /*Look for match */
872
873     /*
874      * We didn't find the record we wanted, which means we'll pull a
875      * record out of the free pool for it.  If we didn't find a place
876      * to append it, we then insert it at the beginning of the queue.
877      */
878     if (a_srvline->free_head == SCOUT_NIL)
879         return (SCOUT_NIL);
880     *a_record_added = 1;
881     new_idx = a_srvline->free_head;
882     if (scout_debug) {
883         fprintf(scout_debugfd, "[%s] Choosing free index %d for new entry\n",
884                 rn, new_idx);
885         fflush(scout_debugfd);
886     }
887     a_srvline->free_head = sc_disk[new_idx].next;
888     if (a_srvline->free_head == SCOUT_NIL)
889         a_srvline->free_tail = SCOUT_NIL;
890
891     /*
892      * Fill in the new record.
893      */
894     sc_disk[new_idx].active = 0;
895     sc_disk[new_idx].name = a_diskname;
896
897     /*
898      * Insert the new record where it belongs on the used disk list.
899      */
900     if (append_idx == SCOUT_NIL) {
901         /*
902          * It belongs at the beginning of the list.
903          */
904         if (scout_debug) {
905             fprintf(scout_debugfd, "[%s] Inserted at used disk head\n", rn);
906             fflush(scout_debugfd);
907         }
908         sc_disk[new_idx].next = a_srvline->used_head;
909         sc_disk[new_idx].prev = SCOUT_NIL;
910         a_srvline->used_head = new_idx;
911         if (a_srvline->used_tail == SCOUT_NIL)
912             a_srvline->used_tail = new_idx;
913     } else {
914         if (scout_debug) {
915             fprintf(scout_debugfd, "[%s] Entry appended after index %d\n", rn,
916                     append_idx);
917             fflush(scout_debugfd);
918         }
919         sc_disk[new_idx].prev = append_idx;
920         sc_disk[new_idx].next = sc_disk[append_idx].next;
921         sc_disk[append_idx].next = new_idx;
922         if (sc_disk[new_idx].next == SCOUT_NIL)
923             a_srvline->used_tail = new_idx;
924         else
925             sc_disk[sc_disk[new_idx].next].prev = new_idx;
926     };
927
928     /*
929      * Add the new used disk light object to the display list for
930      * the scout frame.
931      */
932     if (scout_debug) {
933         fprintf(scout_debugfd,
934                 "[%s] Adding disk light at index %d to display list\n", rn,
935                 new_idx);
936         fflush(scout_debugfd);
937     }
938     code = gtxframe_AddToList(scout_frame, sc_disk[new_idx].disk_lp);
939     if (code) {
940         if (scout_debug) {
941             fprintf(scout_debugfd,
942                     "[%s] Can't add to display list, code is %d\n", rn, code);
943             fflush(scout_debugfd);
944         }
945     }
946     return (new_idx);
947
948 }                               /*scout_FindUsedDisk */
949
950 /*------------------------------------------------------------------------
951  * scout_RemoveInactiveDisk
952  *
953  * Description:
954  *      Given a server record and a used disk index, remove the disk
955  *      record from the used list, put it on the free list, and remove
956  *      it from the gtx frame update list.
957  *
958  * Arguments:
959  *      struct mini_line *a_srvline     : Ptr to server descriptor.
960  *      int a_used_idx                  : Index of used disk record.
961  *
962  * Returns:
963  *      Nothing.
964  *
965  * Environment:
966  *      Formerly-used disk records are returned to the free pool.
967  *
968  * Side Effects:
969  *      Free and used disk record lists are modified for this server.
970  *      The disk record in question is pulled off the gtx update list
971  *      for the frame.
972  *------------------------------------------------------------------------*/
973
974 static void
975 scout_RemoveInactiveDisk(struct mini_line *a_srvline, int a_used_idx)
976 {                               /*scout_RemoveInactiveDisk */
977
978     static char rn[] = "scout_RemoveInactiveDisk";      /*Routine name */
979
980     if (scout_debug) {
981         fprintf(scout_debugfd, "[%s] Called\n", rn);
982         fflush(scout_debugfd);
983     }
984
985     /*code = gtxframe_RemoveFromList(scout_frame->window, lightobj); */
986
987 }                               /*scout_RemoveInactiveDisk */
988
989 /*------------------------------------------------------------------------
990  * mini_PrintDiskStats
991  *
992  * Description:
993  *      Given server indexing and light object information, a pointer
994  *      to a set of statistics, and whether the probe that produced these
995  *      stats succeeded or not, print out the stats in a nice way.
996  *
997  * Arguments:
998  *      struct mini_line *a_srvline     : Ptr to server descriptor.
999  *      struct ProbeViceStatistics *a_stats     : Ptr to current stats.
1000  *      int a_probeOK                   : Was the probe OK?
1001  *      int a_width_changed             : Has the frame width changed?
1002  *      int a_fix_line_num              : Is the line number wrong?
1003  *      int a_delta_line_num            : Change in line number.
1004  *
1005  * Returns:
1006  *      0 if something went wrong,
1007  *      else the number of lines taken up by this server record.
1008  *
1009  * Environment:
1010  *      Nothing interesting.
1011  *
1012  * Side Effects:
1013  *      As advertised.
1014  *------------------------------------------------------------------------*/
1015
1016 static int
1017 mini_PrintDiskStats(struct mini_line *a_srvline,
1018                     struct ProbeViceStatistics *a_stats,
1019                     int a_probeOK, int a_width_changed,
1020                     int a_fix_line_num, int a_delta_line_num)
1021 {                               /*mini_PrintDiskStats */
1022
1023     static char rn[] = "mini_PrintDiskStats";   /*Routine name */
1024     char s[128];                /*String buffer */
1025     struct onode *curr_disklight;       /*Ptr to current disk light */
1026     struct onode *srvname_light;        /*Ptr to server name light */
1027     ViceDisk *curr_diskstat;    /*Ptr to current disk stat */
1028     int curr_disk;              /*Current disk stat number */
1029     int used_disk_idx;          /*Used disk index */
1030     int next_used_idx;          /*Ditto */
1031     int pastthreshold;          /*Was disk past threshold? */
1032     struct gator_lightobj *diskdata;    /*Private light data */
1033     struct gwin_strparams *disk_strparams;      /*String params for disk light */
1034     char *diskname = 0;         /*Name of disk */
1035     int found_idx;              /*Idx of matching disk */
1036     char *srv_name;             /*Server name */
1037     struct scout_disk *sc_disk; /*Ptr to scout disk desc */
1038     int fix_light_locs;         /*Recompute disk light locs? */
1039
1040     if (scout_debug) {
1041         fprintf(scout_debugfd, "[%s] Called\n", rn);
1042         fflush(scout_debugfd);
1043     }
1044
1045     /*
1046      * Remember the current server's print name, don't recompute light
1047      * locations yet.
1048      */
1049     srvname_light = a_srvline->srvName_lp;
1050     srv_name = ((struct gator_lightobj *)(srvname_light->o_data))->label;
1051     fix_light_locs = 0;
1052     if (scout_debug) {
1053         fprintf(scout_debugfd, "[%s] Value of a_delta_line_num is %d\n", rn,
1054                 a_delta_line_num);
1055         fflush(scout_debugfd);
1056     }
1057
1058     /*
1059      * If the probe failed, we simply blank out all the used disk
1060      * objects.  Note: a NON-ZERO value of a_probeOK implies failure.
1061      */
1062     if (a_probeOK) {
1063         used_disk_idx = a_srvline->used_head;
1064         while (used_disk_idx != SCOUT_NIL) {
1065             /*
1066              * Point to the current used disk's light, blank out its
1067              * contents, and make sure highlighting is turned off.  We
1068              * also take this opportunity to fix the line numbers if
1069              * needed.
1070              */
1071             curr_disklight = a_srvline->disks[used_disk_idx].disk_lp;
1072             diskdata = (struct gator_lightobj *)(curr_disklight->o_data);
1073             if (scout_debug) {
1074                 fprintf(scout_debugfd,
1075                         "[%s] Prev value of disk light %d: '%s'\n", rn,
1076                         used_disk_idx, diskdata->label);
1077                 fflush(scout_debugfd);
1078             }
1079             mini_justify(" ",   /*Src buffer */
1080                          diskdata->label,       /*Dest buffer */
1081                          scout_col_width[COL_DISK],     /*Dest's width */
1082                          SCOUT_RIGHT_JUSTIFY,   /*Right-justify */
1083                          SCOUT_LEFT_TRUNC,      /*Left-truncate */
1084                          SCOUT_ISNT_LDISK);     /*Not a labeled disk */
1085             gator_light_set(curr_disklight, 0);
1086             if (a_fix_line_num) {
1087                 curr_disklight->o_y += a_delta_line_num;
1088                 disk_strparams = (struct gwin_strparams *)(diskdata->llrock);
1089                 disk_strparams->y += a_delta_line_num;
1090             }
1091
1092             /*
1093              * Advance to next used disk, if any.
1094              */
1095             used_disk_idx = a_srvline->disks[used_disk_idx].next;
1096
1097         }                       /*Blank out disk name field */
1098
1099         /*
1100          * If the frame width has changed, we have to recompute all disk
1101          * light locations.  After that, the number of lines in the server
1102          * record will be accurate, and we return them.
1103          */
1104         if (a_width_changed)
1105             scout_RecomputeLightLocs(a_srvline);
1106
1107         return (a_srvline->num_lines);
1108
1109     }
1110
1111     /*Probe failed for the server */
1112     /*
1113      * Probe was successful.  Sweep through the statistics records,
1114      * and put up all values having to do with AFS partitions.  First,
1115      * mark all used disk objects for this server as inactive and fix
1116      * their line numbers if needed.
1117      */
1118     used_disk_idx = a_srvline->used_head;
1119     while (used_disk_idx != SCOUT_NIL) {
1120         if (scout_debug) {
1121             fprintf(scout_debugfd, "[%s] Marking used disk %d inactive\n", rn,
1122                     used_disk_idx);
1123             fflush(scout_debugfd);
1124         }
1125         sc_disk = (a_srvline->disks) + used_disk_idx;
1126         sc_disk->active = 0;
1127         used_disk_idx = sc_disk->next;
1128         if (a_fix_line_num) {
1129             sc_disk->disk_lp->o_y += a_delta_line_num;
1130             diskdata = (struct gator_lightobj *)(sc_disk->disk_lp->o_data);
1131             disk_strparams = (struct gwin_strparams *)(diskdata->llrock);
1132             disk_strparams->y += a_delta_line_num;
1133         }
1134     }                           /*Mark used disks inactive */
1135
1136     curr_diskstat = (ViceDisk *) a_stats->Disk;
1137     for (curr_disk = 0; curr_disk < VOLMAXPARTS; curr_disk++) {
1138         /*
1139          * An AFS partition name must be prefixed by `/vicep`.
1140          */
1141         if (scout_debug) {
1142             fprintf(scout_debugfd, "[%s] Disk stats at %p for disk '%s'\n",
1143                     rn, curr_diskstat, curr_diskstat->Name);
1144             fflush(scout_debugfd);
1145         }
1146         if (strncmp("/vice", curr_diskstat->Name, 5) == 0) {
1147             /*
1148              * Pull out the single-letter name (actually, abbreviation)
1149              * of the disk and look for such an entry in the used disks.
1150              */
1151             diskname = &curr_diskstat->Name[6];
1152             found_idx = scout_FindUsedDisk(diskname,    /*1-char name */
1153                                            a_srvline,   /*Server record */
1154                                            &fix_light_locs);    /*Recompute? */
1155             if (found_idx == SCOUT_NIL) {
1156                 fprintf(stderr,
1157                         "[%s] Can't display /vicep%s on server '%s'\n", rn,
1158                         diskname, srv_name);
1159             } else {
1160                 /*
1161                  * Found (or created) record for this disk.  Fill in the single-
1162                  * letter name of the disk followed by the number of free blocks.
1163                  * Turn the disk light on if the number of free blocks exceeds
1164                  * the threshold the user set, either % used or min free blocks.
1165                  */
1166                 sprintf(s, "%s:%d", diskname, curr_diskstat->BlocksAvailable);
1167                 if (scout_attn_disk_mode == SCOUT_DISKM_PCUSED) {
1168                     if ((float)
1169                         (curr_diskstat->TotalBlocks -
1170                          curr_diskstat->BlocksAvailable) /
1171                         (float)(curr_diskstat->TotalBlocks) >
1172                         scout_attn_disk_pcused)
1173                         pastthreshold = 1;
1174                     else
1175                         pastthreshold = 0;
1176                 } else
1177                     pastthreshold =
1178                         (curr_diskstat->BlocksAvailable <
1179                          scout_attn_disk_minfree) ? 1 : 0;
1180                 sc_disk = (a_srvline->disks) + found_idx;
1181                 sc_disk->active = 1;
1182                 diskdata =
1183                     (struct gator_lightobj *)(sc_disk->disk_lp->o_data);
1184                 if (scout_debug) {
1185                     fprintf(scout_debugfd,
1186                             "[%s] Justifying %s for disk idx %d (prev value: '%s')\n",
1187                             rn, s, found_idx, diskdata->label);
1188                     fflush(scout_debugfd);
1189                 }
1190                 mini_justify(s, /*Src buffer */
1191                              diskdata->label,   /*Dest buffer */
1192                              scout_col_width[COL_DISK], /*Dest's width */
1193                              SCOUT_LEFT_JUSTIFY,        /*Left-justify */
1194                              SCOUT_LEFT_TRUNC,  /*Left-truncate */
1195                              SCOUT_IS_LDISK);   /*Labeled disk */
1196
1197                 gator_light_set(sc_disk->disk_lp, pastthreshold);
1198
1199             }                   /*Found disk record */
1200         }
1201
1202         /*Found AFS disk name */
1203         /*
1204          * Advance to the next disk statistics record.
1205          */
1206         curr_diskstat++;
1207     }                           /*For each statistics record */
1208
1209     /*
1210      * We've now pulled out all the disk statistics from the probe.
1211      * See if any used disks that were there from the last time are
1212      * now gone.  If so, we remove them.
1213      */
1214     if (scout_debug) {
1215         fprintf(scout_debugfd,
1216                 "[%s] Scanning used disk records for inactive entries\n", rn);
1217         fflush(scout_debugfd);
1218     }
1219     used_disk_idx = a_srvline->used_head;
1220     while (used_disk_idx != SCOUT_NIL) {
1221         if (scout_debug) {
1222             fprintf(scout_debugfd, "[%s] Examining entry at index %d\n", rn,
1223                     used_disk_idx);
1224             fflush(scout_debugfd);
1225         }
1226         sc_disk = (a_srvline->disks) + used_disk_idx;
1227         next_used_idx = sc_disk->next;
1228         if (!(sc_disk->active)) {
1229             scout_RemoveInactiveDisk(a_srvline, /*Server record */
1230                                      used_disk_idx);    /*Disk index to nuke */
1231             fix_light_locs = 1;
1232         }
1233         used_disk_idx = next_used_idx;
1234
1235     }                           /*Remove inactive used disks */
1236
1237     /*
1238      * If we've had to add or remove disks to/from the used list,
1239      * or if the frame width has changed, we recompute the light
1240      * locations before returning.
1241      */
1242     if (fix_light_locs || a_width_changed)
1243         scout_RecomputeLightLocs(a_srvline);
1244
1245     /*
1246      * Return the (possibly new) size of the current server record.
1247      */
1248     return (a_srvline->num_lines);
1249
1250 }                               /*mini_PrintDiskStats */
1251
1252 /*------------------------------------------------------------------------
1253  * FS_Handler
1254  *
1255  * Description:
1256  *      Handler routine passed to the fsprobe module.  This handler is
1257  *      called immediately after a poll of all the FileServers has taken
1258  *      place.  Its job is to write out selected data to the scout
1259  *      screen.
1260  *
1261  * Arguments:
1262  *      None.
1263  *
1264  * Returns:
1265  *      0 on success,
1266  *      -1 otherwise.
1267  *
1268  * Environment:
1269  *      All it needs to know is exported by the fsprobe module, namely
1270  *      the data structure where the probe results are stored.
1271  *
1272  * Side Effects:
1273  *      Recomputes disk light locations in response to reshaping the
1274  *      scout window or from adding/deleting disk lights to/from
1275  *      individual servers.
1276  *------------------------------------------------------------------------*/
1277
1278 int
1279 FS_Handler(void)
1280 {                               /*FS_Handler */
1281
1282     static char rn[] = "FS_Handler";    /*Routine name */
1283     int code;                   /*Return code */
1284     struct ProbeViceStatistics *curr_stats;     /*Ptr to current stats */
1285     int *curr_probeOK;          /*Ptr to current probeOK field */
1286     int curr_srvidx;            /*Current server index */
1287     char s[128];                /*String buffer */
1288     static char sblank[] = " "; /*Blank string buffer */
1289     char *sp;                   /*Ptr to string buffer */
1290     struct mini_line *curr_line;        /*Current mini-line */
1291     int curr_line_num;          /*Current line number */
1292     struct gator_lightobj *lightdata;   /*Private light data */
1293     int setting;                /*Light setting (on or off) */
1294     int old_width;              /*Keep the old width value */
1295     int width_changed;          /*Has the frame width changed? */
1296     int fix_line_num;           /*Line number needs fixing */
1297     int delta_line_num;         /*Change in line number */
1298
1299     /*
1300      * See if the size of the scout frame has changed since the last
1301      * time.
1302      */
1303     old_width = scout_frameDims.maxx;
1304     if (scout_debug) {
1305         fprintf(scout_debugfd, "[%s] Calling wop_getdimensions\n", rn);
1306         fflush(scout_debugfd);
1307     }
1308     WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1309     width_changed = (old_width == scout_frameDims.maxx) ? 0 : 1;
1310     if (scout_debug) {
1311         fprintf(scout_debugfd,
1312                 "[%s] Frame dimensions are %d rows, %d columns\n", rn,
1313                 scout_frameDims.maxy, scout_frameDims.maxx);
1314         if (width_changed)
1315             fprintf(scout_debugfd, "[%s] Width has changed from %d columns\n",
1316                     rn, old_width);
1317         fflush(scout_debugfd);
1318     }
1319
1320     /*
1321      * Print out the selected fields for each server.  We actually change
1322      * the light's label to the new data.
1323      */
1324     curr_line = scout_screen.line;
1325     curr_stats = fsprobe_Results.stats;
1326     curr_probeOK = fsprobe_Results.probeOK;
1327     curr_line_num = curr_line->base_line;
1328
1329     for (curr_srvidx = 0; curr_srvidx < scout_screen.numServers;
1330          curr_srvidx++) {
1331         /*
1332          * If the current server record is set up on the wrong line, fix
1333          * the non-disk light objects directly, and remember to fix the
1334          * disk light objects later on.
1335          */
1336         if (curr_line->base_line != curr_line_num) {
1337             fix_line_num = 1;
1338             delta_line_num = curr_line_num - curr_line->base_line;
1339             curr_line->base_line = curr_line_num;
1340             scout_SetNonDiskLightLine(curr_line, curr_line_num);
1341         } else {
1342             fix_line_num = 0;
1343             delta_line_num = 0;
1344         }
1345
1346         lightdata =
1347             (struct gator_lightobj *)(curr_line->currConns_lp->o_data);
1348         if (*curr_probeOK == 0) {
1349             sp = s;
1350             sprintf(sp, "%d", curr_stats->CurrentConnections);
1351         } else
1352             sp = sblank;
1353         mini_justify(sp,        /*Src buffer */
1354                      lightdata->label,  /*Dest buffer */
1355                      scout_col_width[COL_CONN], /*Dest's width */
1356                      SCOUT_RIGHT_JUSTIFY,       /*Right-justify */
1357                      SCOUT_LEFT_TRUNC,  /*Left-truncate */
1358                      SCOUT_ISNT_LDISK); /*Not a labeled disk */
1359         if (scout_attn_conn != SCOUT_ATTN_NOTUSED
1360             && curr_stats->CurrentConnections >= scout_attn_conn)
1361             setting = 1;
1362         else
1363             setting = 0;
1364         gator_light_set(curr_line->currConns_lp, setting);
1365
1366         lightdata = (struct gator_lightobj *)(curr_line->fetches_lp->o_data);
1367         if (*curr_probeOK == 0) {
1368             sp = s;
1369             sprintf(sp, "%u", curr_stats->TotalFetchs);
1370         } else
1371             sp = sblank;
1372         mini_justify(sp,        /*Src buffer */
1373                      lightdata->label,  /*Dest buffer */
1374                      scout_col_width[COL_FETCH],        /*Dest's width */
1375                      SCOUT_RIGHT_JUSTIFY,       /*Right-justify */
1376                      SCOUT_LEFT_TRUNC,  /*Left-truncate */
1377                      SCOUT_ISNT_LDISK); /*Not a labeled disk */
1378         if (scout_attn_fetch != SCOUT_ATTN_NOTUSED
1379             && curr_stats->TotalFetchs >= scout_attn_fetch)
1380             setting = 1;
1381         else
1382             setting = 0;
1383         gator_light_set(curr_line->fetches_lp, setting);
1384
1385         lightdata = (struct gator_lightobj *)(curr_line->stores_lp->o_data);
1386         if (*curr_probeOK == 0) {
1387             sp = s;
1388             sprintf(sp, "%u", curr_stats->TotalStores);
1389         } else
1390             sp = sblank;
1391         mini_justify(sp,        /*Src buffer */
1392                      lightdata->label,  /*Dest buffer */
1393                      scout_col_width[COL_STORE],        /*Dest's width */
1394                      SCOUT_RIGHT_JUSTIFY,       /*Right-justify */
1395                      SCOUT_LEFT_TRUNC,  /*Left-truncate */
1396                      SCOUT_ISNT_LDISK); /*Not a labeled disk */
1397         if (scout_attn_store != SCOUT_ATTN_NOTUSED
1398             && curr_stats->TotalStores >= scout_attn_store)
1399             setting = 1;
1400         else
1401             setting = 0;
1402         gator_light_set(curr_line->stores_lp, setting);
1403
1404         lightdata =
1405             (struct gator_lightobj *)(curr_line->workstations_lp->o_data);
1406         if (*curr_probeOK == 0) {
1407             sp = s;
1408             sprintf(sp, "%d", curr_stats->WorkStations);
1409         } else
1410             sp = sblank;
1411         mini_justify(sp,        /*Src buffer */
1412                      lightdata->label,  /*Dest buffer */
1413                      scout_col_width[COL_WK],   /*Dest's width */
1414                      SCOUT_RIGHT_JUSTIFY,       /*Right-justify */
1415                      SCOUT_LEFT_TRUNC,  /*Left-truncate */
1416                      SCOUT_ISNT_LDISK); /*Not a labeled disk */
1417         if (scout_attn_workstations != SCOUT_ATTN_NOTUSED
1418             && curr_stats->WorkStations >= scout_attn_workstations)
1419             setting = 1;
1420         else
1421             setting = 0;
1422         gator_light_set(curr_line->workstations_lp, setting);
1423
1424         /*
1425          * We turn the server light on if there was an error in the
1426          * current probe (e.g., if the curr_probeOK field is non-zero.
1427          * (Don't forget to fix the light's line if it needs it).
1428          */
1429         setting = (*curr_probeOK) ? 1 : 0;
1430         gator_light_set(curr_line->srvName_lp, setting);
1431
1432         /*
1433          * Print out the disk statistics.  The value returned is the
1434          * number of lines taken up by the server record (or 0 if
1435          * something went wrong).
1436          */
1437         code = mini_PrintDiskStats(curr_line,   /*Ptr to server line */
1438                                    curr_stats,  /*Fresh disk stats */
1439                                    *curr_probeOK,       /*Was probe OK? */
1440                                    width_changed,       /*Has the width changed? */
1441                                    fix_line_num,        /*Fix the line number? */
1442                                    delta_line_num);     /*Change in line number */
1443         if (code == 0) {
1444             fprintf(stderr, "[%s] Error in printing out disk statistics\n",
1445                     rn);
1446             return (-1);
1447         } else
1448             curr_line_num += code;
1449
1450         /*
1451          * Advance the current mini_line, stats source, and probe success
1452          * indication.
1453          */
1454         curr_line++;
1455         curr_stats++;
1456         curr_probeOK++;
1457
1458     }                           /*for each server probed */
1459
1460     /*
1461      * Display the scout frame.
1462      */
1463     sprintf(s, "Probe %d results", fsprobe_Results.probeNum);
1464     gtxframe_DisplayString(scout_frame, s);
1465     WOP_DISPLAY(scout_gwin);
1466
1467     /*
1468      * Return the happy news.
1469      */
1470     return (0);
1471
1472 }                               /*FS_Handler */
1473
1474 /*------------------------------------------------------------------------
1475  * init_mini_line
1476  *
1477  * Description:
1478  *      Initialize each line in the mini_screen.
1479  *
1480  * Arguments:
1481  *      struct sockaddr_in *a_skt : Ptr to server socket info.
1482  *      int a_lineNum;            : Line number being created.
1483  *      struct mini_line *a_line  : Ptr to mini_line to set up.
1484  *      char *a_srvname           : Printable server name.
1485  *
1486  * Returns:
1487  *      0 on success,
1488  *      Error value otherwise.
1489  *
1490  * Environment:
1491  *      Nothing interesting.
1492  *
1493  * Side Effects:
1494  *      As advertised.
1495  *------------------------------------------------------------------------*/
1496
1497 static int
1498 init_mini_line(struct sockaddr_in *a_skt, int a_lineNum,
1499                struct mini_line *a_line, char *a_srvname)
1500 {                               /*init_mini_line */
1501
1502     static char rn[] = "init_mini_line";        /*Routine name */
1503     int curr_x;                 /*Current X position */
1504     int curr_y;                 /*Current Y position */
1505     char s[128];                /*Scratch buffer */
1506     int code;                   /*Return code */
1507     struct gator_lightobj *lightdata;   /*Private light data */
1508
1509     if (scout_debug) {
1510         fprintf(scout_debugfd, "[%s] Called for base line %d\n", rn,
1511                 a_lineNum);
1512         fflush(scout_debugfd);
1513     }
1514
1515     /*
1516      * Fill in the top fields (except the disk fields, which will be
1517      * done elsewhere), then create the light onodes.
1518      */
1519     memcpy((char *)&(a_line->skt), (char *)a_skt, sizeof(struct sockaddr_in));
1520     a_line->numDisks = 0;
1521     a_line->base_line = a_lineNum + scout_screen.base_line_num;
1522     a_line->num_lines = 1;
1523
1524     curr_x = 1;
1525     curr_y = a_line->base_line;
1526     if ((a_line->currConns_lp =
1527          mini_initLightObject("Conns", curr_x, curr_y, scout_col_width[COL_CONN],
1528                               scout_gwin))
1529         == NULL) {
1530         fprintf(stderr, "[%s:%s] Can't create currConns light object\n", pn,
1531                 rn);
1532         return (-1);
1533     }
1534     curr_x += scout_col_width[COL_CONN] + 1;
1535
1536     if ((a_line->fetches_lp =
1537          mini_initLightObject("Fetches", curr_x, curr_y, scout_col_width[COL_FETCH],
1538                               scout_frame->window))
1539         == NULL) {
1540         fprintf(stderr, "[%s:%s] Can't create fetches light object\n", pn,
1541                 rn);
1542         return (-1);
1543     }
1544     curr_x += scout_col_width[COL_FETCH] + 1;
1545
1546     if ((a_line->stores_lp =
1547          mini_initLightObject("Stores", curr_x, curr_y, scout_col_width[COL_STORE],
1548                               scout_frame->window))
1549         == NULL) {
1550         fprintf(stderr, "[%s:%s] Can't create stores light object\n", pn, rn);
1551         return (-1);
1552     }
1553     curr_x += scout_col_width[COL_STORE] + 1;
1554
1555     if ((a_line->workstations_lp =
1556          mini_initLightObject("WrkStn", curr_x, curr_y, scout_col_width[COL_WK],
1557                               scout_frame->window))
1558         == NULL) {
1559         fprintf(stderr, "[%s:%s] Can't create workstations light object\n",
1560                 pn, rn);
1561         return (-1);
1562     }
1563     curr_x += scout_col_width[COL_WK] + 1;
1564
1565     if ((a_line->srvName_lp =
1566          mini_initLightObject(a_srvname, curr_x, curr_y,
1567                               scout_col_width[COL_SRVNAME], scout_frame->window))
1568         == NULL) {
1569         fprintf(stderr, "[%s:%s] Can't create server name light object\n", pn,
1570                 rn);
1571         return (-1);
1572     }
1573     sprintf(s, "%s", a_srvname);
1574     lightdata = (struct gator_lightobj *)(a_line->srvName_lp->o_data);
1575     code = mini_justify(s,      /*Src buffer */
1576                         lightdata->label,       /*Dest buffer */
1577                         scout_col_width[COL_SRVNAME],   /*Dest's width */
1578                         SCOUT_CENTER,   /*Centered */
1579                         SCOUT_RIGHT_TRUNC,      /*Right-truncate */
1580                         SCOUT_ISNT_LDISK);      /*Not a labeled disk */
1581     if (code) {
1582         fprintf(stderr,
1583                 "[%s] Can't center server name inside of light object\n", rn);
1584         return (code);
1585     }
1586
1587     if (scout_initDiskLightObjects(a_line, scout_frame->window)) {
1588         fprintf(stderr, "[%s:%s] Can't create disk light objects\n", pn, rn);
1589         return (-1);
1590     }
1591
1592     /*
1593      * Finally, return the happy news.
1594      */
1595     return (0);
1596
1597 }                               /*init_mini_line */
1598
1599 /*------------------------------------------------------------------------
1600  * execute_scout
1601  *
1602  * Description:
1603  *      Workhorse routine that starts up the FileServer probe.
1604  *
1605  * Arguments:
1606  *      int a_numservers                : Length of above list.
1607  *      struct cmd_item *a_srvname      : List of FileServer machines to
1608  *                                        monitor.
1609  *      int a_pkg                       : Window package to use.
1610  *
1611  * Returns:
1612  *      0 on success,
1613  *      Error value otherwise.
1614  *
1615  * Environment:
1616  *      Nothing interesting.
1617  *
1618  * Side Effects:
1619  *      As advertised.
1620  *------------------------------------------------------------------------*/
1621
1622 static int
1623 execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg)
1624 {                               /*execute_scout */
1625
1626     static char rn[] = "execute_scout"; /*Routine name */
1627     static char fullsrvname[128];       /*Full server name */
1628     int code;           /*Return code */
1629     struct sockaddr_in *FSSktArray;     /*Server socket array */
1630     int sktbytes;               /*Num bytes in above */
1631     struct sockaddr_in *curr_skt;       /*Ptr to current socket */
1632     struct cmd_item *curr_item; /*Ptr to current cmd item */
1633     struct hostent *he;         /*Host entry */
1634     struct mini_line *mini_lines;       /*Ptr to all mini-lines */
1635     struct mini_line *curr_line;        /*Ptr to current line */
1636     int i;                      /*Generic loop variable */
1637     int mini_line_bytes;        /*Num bytes in mini_lines */
1638     int linenum;                /*Current mini-line number */
1639 #if 0
1640     PROCESS pid;                /*Main LWP process ID */
1641     PROCESS gxlistener_ID;      /*Input Server LWP process ID */
1642 #endif /* 0 */
1643     struct gator_lightobj *lightdata;   /*Private light data */
1644
1645     if (scout_debug) {
1646         fprintf(scout_debugfd, "[%s] Called\n", rn);
1647         fflush(scout_debugfd);
1648     }
1649
1650     /*
1651      * We have to initialize LWP support before we start up any of
1652      * our packages.
1653      */
1654 #if 0
1655     code = LWP_InitializeProcessSupport(LWP_NORMAL_PRIORITY, &pid);
1656     if (code) {
1657         fprintf(stderr, "[%s:%s] Can't initialize LWP\n", pn, rn);
1658         scout_CleanExit(code);
1659     }
1660 #endif /* 0 */
1661
1662     /*
1663      * Initialize the gtx package.
1664      */
1665 #if 0
1666     fprintf(stderr, "[%s:%s] Starting up gtx package\n", pn, rn);
1667 #endif /* 0 */
1668     scout_gwin = gtx_Init(0,    /*Don't start up InputServer yet */
1669                           -1);  /*Type of window package */
1670     if (scout_gwin == NULL) {
1671         fprintf(stderr, "[%s:%s] Call to gtx_Init() failed!\n", pn, rn);
1672         return (-1);
1673     }
1674
1675     /*
1676      * Remember we've set up gtx so we can exit cleanly from now on.
1677      */
1678     scout_gtx_initialized = 1;
1679
1680     /*
1681      * Create the frame everything will go into, set it up as our only
1682      * frame for this window.
1683      */
1684     scout_frame = gtxframe_Create();
1685     if (scout_frame == (struct gtx_frame *)0) {
1686         fprintf(stderr, "[%s:%s] Call to gtxframe_Create() failed!\n", pn,
1687                 rn);
1688         return (-1);
1689     }
1690     gtxframe_SetFrame(scout_gwin, scout_frame);
1691     WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1692
1693     /*
1694      * Allocate an array of sockets to describe each FileServer we'll be
1695      * watching.
1696      */
1697     sktbytes = a_numservers * sizeof(struct sockaddr_in);
1698     FSSktArray = calloc(1, sktbytes);
1699     if (FSSktArray == (struct sockaddr_in *)0) {
1700         fprintf(stderr,
1701                 "[%s] Can't malloc() %d sockaddrs (%d bytes) for the given servers\n",
1702                 rn, a_numservers, sktbytes);
1703         scout_CleanExit(-1);
1704     }
1705
1706     /*
1707      * Sweep through the server names provided, filling in the socket
1708      * info for each.  Take into account the fact that we may have a
1709      * base name associated for each.
1710      */
1711     curr_item = a_srvname;
1712     curr_skt = FSSktArray;
1713     while (curr_item) {
1714         if (*scout_basename == '\0')
1715             sprintf(fullsrvname, "%s", curr_item->data);
1716         else
1717             sprintf(fullsrvname, "%s.%s", curr_item->data, scout_basename);
1718         he = hostutil_GetHostByName(fullsrvname);
1719         if (he == NULL) {
1720             fprintf(stderr, "[%s] Can't get host info for '%s'\n", rn,
1721                     fullsrvname);
1722             return (-1);
1723         }
1724         memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
1725         curr_skt->sin_family = AF_INET;
1726         curr_skt->sin_port = htons(7000);       /* FileServer port */
1727
1728         /*
1729          * Bump our pointers.
1730          */
1731         curr_item = curr_item->next;
1732         curr_skt++;
1733
1734     }                           /*Build socket entry for each server */
1735
1736     /*
1737      * Create the set of mini-lines, one per server.
1738      */
1739     mini_line_bytes = a_numservers * sizeof(struct mini_line);
1740     mini_lines = calloc(1, mini_line_bytes);
1741     if (mini_lines == (struct mini_line *)0) {
1742         fprintf(stderr, "[%s] Can't malloc() %d bytes for %d screen lines\n",
1743                 rn, mini_line_bytes, a_numservers);
1744         return (-1);
1745     }
1746
1747     /*
1748      * Set up each line in the mini_lines, creating and initializing
1749      * its light objects.
1750      */
1751     scout_screen.base_line_num = 4;
1752     curr_line = mini_lines;
1753     curr_skt = FSSktArray;
1754     linenum = 0;
1755     curr_item = a_srvname;
1756     gtxframe_ClearList(scout_frame);
1757
1758     /*
1759      * Create the light objects that server as banner lines.  Remember
1760      * to take into account the server basename, if any, and the name
1761      * of the host that scout if running on, if that's wanted.
1762      */
1763     if (scout_showhostname) {
1764         if (*scout_basename == '\0')
1765             sprintf(scout_Banner, "[%s] %s", scout_hostname, "Scout");
1766         else
1767             sprintf(scout_Banner, "[%s] Scout for %s", scout_hostname,
1768                     scout_basename);
1769     } else {
1770         if (*scout_basename == '\0')
1771             sprintf(scout_Banner, "%s", " Scout");
1772         else
1773             sprintf(scout_Banner, " Scout for %s", scout_basename);
1774     }
1775     scout_banner0_lp = mini_initLightObject("Banner 0", /*Light name */
1776                                             0, /*X*/ 0, /*Y*/ scout_frameDims.maxx,     /*Width */
1777                                             scout_gwin);        /*Window */
1778     if (scout_banner0_lp != NULL) {
1779         lightdata = (struct gator_lightobj *)(scout_banner0_lp->o_data);
1780         mini_justify(scout_Banner, lightdata->label, scout_frameDims.maxx,
1781                      SCOUT_CENTER, SCOUT_RIGHT_TRUNC, SCOUT_ISNT_LDISK);
1782         gator_light_set(scout_banner0_lp, 1);
1783         gtxframe_AddToList(scout_frame, scout_banner0_lp);
1784
1785         /*Debugging */
1786         if (scout_debug)
1787             fprintf(scout_debugfd, "[%s] Scout label is '%s', %" AFS_SIZET_FMT " chars\n", rn,
1788                     lightdata->label, strlen(lightdata->label));
1789     }
1790
1791     scout_banner1_lp = mini_initLightObject("Banner 1", /*Light name */
1792                                             0, /*X*/ 2, /*Y*/ scout_frameDims.maxx,     /*Width */
1793                                             scout_gwin);        /*Window */
1794     if (scout_banner1_lp != NULL) {
1795         char attn_label[256];
1796         if (scout_attn_disk_mode == SCOUT_DISKM_PCUSED) {
1797             snprintf(attn_label, sizeof(attn_label), "%s: > %s%% used",
1798                      scout_label[5], scout_attn_disk_pcusedstr);
1799         } else {
1800             snprintf(attn_label, sizeof(attn_label), "%s: < %d blocks free",
1801                      scout_label[5], scout_attn_disk_minfree);
1802         }
1803         snprintf(scout_Banner, sizeof(scout_Banner),
1804                  "%*s %*s %*s %*s %*s %s",
1805                  scout_col_width[0], scout_label[0],
1806                  scout_col_width[1], scout_label[1],
1807                  scout_col_width[2], scout_label[2],
1808                  scout_col_width[3], scout_label[3],
1809                  scout_col_width[4], scout_label[4],
1810                  attn_label);
1811
1812         lightdata = (struct gator_lightobj *)(scout_banner1_lp->o_data);
1813         mini_justify(scout_Banner, lightdata->label, scout_frameDims.maxx,
1814                      SCOUT_LEFT_JUSTIFY, SCOUT_RIGHT_TRUNC,
1815                      SCOUT_ISNT_LDISK);
1816
1817         gtxframe_AddToList(scout_frame, scout_banner1_lp);
1818     }
1819
1820     scout_banner2_lp = mini_initLightObject("Banner 2", /*Light name */
1821                                             0, /*X*/ 3, /*Y*/ scout_frameDims.maxx,     /*Width */
1822                                             scout_gwin);        /*Window */
1823     if (scout_banner2_lp != NULL) {
1824         snprintf(scout_Banner, sizeof(scout_Banner),
1825                  "%*s %*s %*s %*s %*s %s",
1826                  scout_col_width[0], scout_underline[0],
1827                  scout_col_width[1], scout_underline[1],
1828                  scout_col_width[2], scout_underline[2],
1829                  scout_col_width[3], scout_underline[3],
1830                  scout_col_width[4], scout_underline[4],
1831                  scout_underline[5]);
1832
1833         lightdata = (struct gator_lightobj *)(scout_banner2_lp->o_data);
1834         mini_justify(scout_Banner, lightdata->label,
1835                      scout_frameDims.maxx, SCOUT_LEFT_JUSTIFY,
1836                      SCOUT_RIGHT_TRUNC, SCOUT_ISNT_LDISK);
1837         gtxframe_AddToList(scout_frame, scout_banner2_lp);
1838     }
1839
1840     for (i = 0; i < a_numservers; i++) {
1841         code = init_mini_line(curr_skt, linenum, curr_line, curr_item->data);
1842         if (code) {
1843             fprintf(stderr, "[%s] Can't initialize line for server %d\n", rn,
1844                     i);
1845             return (-1);
1846         }
1847         curr_skt++;
1848         curr_line++;
1849         linenum++;
1850         curr_item = curr_item->next;
1851     }
1852
1853     /*
1854      * Now that all lines have been set up, we feed in the light items
1855      * created.  Note: the disk lights are entered at a later time,
1856      * as they enter the used disk list for each server.
1857      */
1858     curr_line = mini_lines;
1859     for (i = 0; i < a_numservers; i++) {
1860         code = gtxframe_AddToList(scout_frame, curr_line->currConns_lp);
1861         if (code) {
1862             fprintf(stderr,
1863                     "[%s] Can't add client connections light to display list\n",
1864                     rn);
1865             return (code);
1866         }
1867
1868         code = gtxframe_AddToList(scout_frame, curr_line->fetches_lp);
1869         if (code) {
1870             fprintf(stderr,
1871                     "[%s] Can't add fetches light to frame display list\n",
1872                     rn);
1873             return (code);
1874         }
1875
1876         code = gtxframe_AddToList(scout_frame, curr_line->stores_lp);
1877         if (code) {
1878             fprintf(stderr,
1879                     "[%s] Can't add stores light to frame display list\n",
1880                     rn);
1881             return (code);
1882         }
1883
1884         code = gtxframe_AddToList(scout_frame, curr_line->workstations_lp);
1885         if (code) {
1886             fprintf(stderr,
1887                     "[%s] Can't add workstation light to display list\n", rn);
1888             return (code);
1889         }
1890
1891         code = gtxframe_AddToList(scout_frame, curr_line->srvName_lp);
1892         if (code) {
1893             fprintf(stderr,
1894                     "[%s] Can't add server name light to display list\n", rn);
1895             return (code);
1896         }
1897
1898         /*
1899          * Move down to the next server record.
1900          */
1901         curr_line++;
1902
1903     }                           /*Add lights in server records to display list */
1904
1905 #if 0
1906     /*
1907      * Set up the minimal keymap.
1908      */
1909     code = keymap_BindToString(scout_frame->keymap,     /*Ptr to keymap */
1910                                "e",     /*Key to bind */
1911                                ExitCmd, /*Cmd to execute */
1912                                NULL,    /*Name */
1913                                NULL);   /*Ptr to rock */
1914     if (code) {
1915         fprintf(stderr, "[%s] Can't bind key `e', code is %d\n", rn, code);
1916         return (code);
1917     }
1918 #endif /* 0 */
1919
1920     /*
1921      * Finish setting up the overall mini_screen structure.
1922      */
1923     scout_screen.numServers = a_numservers;
1924     scout_screen.line = mini_lines;
1925     WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1926
1927     /*
1928      * Start up the fsprobe package, which will gather FileServer
1929      * statistics for us on a regular basis.
1930      */
1931     gtxframe_DisplayString(scout_frame,
1932                            "Establishing File Server connection(s)...");
1933     code = fsprobe_Init(a_numservers,   /*Num FileServers to probe */
1934                         FSSktArray,     /*FileServer socket array */
1935                         scout_probefreq,        /*Probe frequency */
1936                         FS_Handler,     /*Handler routine */
1937                         0);     /*Turn debugging output off */
1938 #if 0
1939     scout_debug);               /*Turn debugging output off */
1940 #endif /* 0 */
1941     if (code) {
1942         fprintf(stderr, "[%s] Error returned by fsprobe_Init: %d\n", rn,
1943                 code);
1944         return (-1);
1945     }
1946
1947
1948     /*
1949      * Start up the input server LWP for our window.
1950      */
1951 #if 0
1952     code = LWP_CreateProcess(gtx_InputServer,   /*Fcn to start up */
1953                              8192,      /*Stack size in bytes */
1954                              LWP_NORMAL_PRIORITY,       /*Priority */
1955                              (void *)scout_gwin,        /*Params: Ptr to window */
1956                              "gx-listener",     /*Name to use */
1957                              &gxlistener_ID);   /*Returned LWP process ID */
1958 #endif /* 0 */
1959
1960     code = (int)(intptr_t)gtx_InputServer(scout_gwin);
1961     if (code) {
1962         fprintf(stderr,
1963                 "[%s] Error exit from gtx_InputServer(), error is %d\n", rn,
1964                 code);
1965         scout_CleanExit(code);
1966     }
1967
1968     fsprobe_Wait(0); /* sleep forever */
1969
1970 #if 0
1971     /*
1972      * How did we get here?  Oh, well, clean up our windows and
1973      * return sweetness and light anyway.
1974      */
1975     WOP_CLEANUP(&scout_gwin);
1976     return (0);
1977 #endif /* 0 */
1978
1979     return 0;
1980 }                               /*execute_scout */
1981
1982 /*------------------------------------------------------------------------
1983  * countServers
1984  *
1985  * Description:
1986  *      Given a pointer to the list of servers we'll be polling,
1987  *      compute the length of the list.
1988  *
1989  * Arguments:
1990  *      struct cmd_item *a_firstItem : Ptr to first item in list.
1991  *
1992  * Returns:
1993  *      Length of the above list.
1994  *
1995  * Environment:
1996  *      Nothing interesting.
1997  *
1998  * Side Effects:
1999  *      As advertised.
2000  *------------------------------------------------------------------------*/
2001
2002 static int countServers(struct cmd_item *a_firstItem)
2003 {                               /*countServers */
2004
2005     int list_len;               /*List length */
2006     struct cmd_item *curr_item; /*Ptr to current item */
2007
2008     list_len = 0;
2009     curr_item = a_firstItem;
2010
2011     /*
2012      * Count 'em up.
2013      */
2014     while (curr_item) {
2015         list_len++;
2016         curr_item = curr_item->next;
2017     }
2018
2019     /*
2020      * Return our tally.
2021      */
2022     return (list_len);
2023
2024 }                               /*countServers */
2025
2026 /*------------------------------------------------------------------------
2027  * scout_AdoptThresholds
2028  *
2029  * Description:
2030  *      Parse and adopt one or more threshold values, as read off the
2031  *      command line.
2032  *
2033  * Arguments:
2034  *      struct cmd_item *a_thresh_item : Ptr to item on command-line
2035  *                                       threshold list.
2036  *
2037  * Returns:
2038  *      Nothing (but may exit the entire program on error!)
2039  *
2040  * Environment:
2041  *      Valid keywords are:
2042  *          conn, disk, fetch, store, ws
2043  *      The disk value, if it has a % sign, signifies that attention
2044  *      will be triggered when the disk is more than that percentage
2045  *      full; otherwise, it will specify the minimum number of free
2046  *      blocks.
2047  *
2048  * Side Effects:
2049  *      As specified.
2050  *------------------------------------------------------------------------*/
2051
2052 static void scout_AdoptThresholds(struct cmd_item *a_thresh_item)
2053 {                               /*scout_AdoptThresholds */
2054
2055     static char rn[] = "scout_AdoptThresholds"; /*Routine name */
2056     struct cmd_item *curr_item; /*Current item */
2057     char *curr_name;            /*Current name half of pair */
2058     char *curr_value;           /*Current value half of pair */
2059     int diskval_len;            /*Length of disk attn value */
2060
2061     curr_item = a_thresh_item;
2062     while (curr_item) {
2063         /*
2064          * If there isn't a corresponding value for the current
2065          * attention field, bitch & die.
2066          */
2067         if (curr_item->next == (struct cmd_item *)0) {
2068             printf("[%s] No threshold value given for '%s'\n", rn,
2069                    curr_item->data);
2070             scout_CleanExit(-1);
2071         }
2072
2073         curr_name = curr_item->data;
2074         curr_value = curr_item->next->data;
2075
2076         if (strcmp(curr_name, "conn") == 0) {
2077             if (scout_debug) {
2078                 fprintf(scout_debugfd,
2079                         "[%s] Setting conn attn value to %d (default %d)\n",
2080                         rn, atoi(curr_value), scout_attn_conn);
2081                 fflush(scout_debugfd);
2082             }
2083             scout_attn_conn = atoi(curr_value);
2084         } else if (strcmp(curr_name, "disk") == 0) {
2085             /*
2086              * If there's a '%' as the last character in the value,
2087              * we use percentage mode.
2088              */
2089             diskval_len = strlen(curr_value);
2090             if (curr_value[diskval_len - 1] == '%') {
2091                 curr_value[diskval_len - 1] = '\0';
2092                 if (scout_debug) {
2093                     fprintf(scout_debugfd,
2094                             "[%s] New disk attn value: 0.%s used (default %f)\n",
2095                             rn, curr_value, scout_attn_disk_pcused);
2096                     fflush(scout_debugfd);
2097                 }
2098                 sprintf(scout_attn_disk_pcusedstr, "%s", curr_value);
2099                 scout_attn_disk_pcused =
2100                     ((float)(atoi(curr_value))) / ((float)(100));
2101             } /*Percentage mode */
2102             else {
2103                 if (scout_debug) {
2104                     fprintf(scout_debugfd,
2105                             "[%s] New disk attn value: %s min free (default %f)\n",
2106                             rn, curr_value, scout_attn_disk_pcused);
2107                     fflush(scout_debugfd);
2108                 }
2109                 scout_attn_disk_mode = SCOUT_DISKM_MINFREE;
2110                 scout_attn_disk_minfree = atoi(curr_value);
2111             }                   /*Min free blocks mode */
2112         } else if (strcmp(curr_name, "fetch") == 0) {
2113             if (scout_debug) {
2114                 fprintf(scout_debugfd,
2115                         "[%s] Setting fetch attn value to %d (default %d)\n",
2116                         rn, atoi(curr_value), scout_attn_fetch);
2117                 fflush(scout_debugfd);
2118             }
2119             scout_attn_fetch = atoi(curr_value);
2120         } else if (strcmp(curr_name, "store") == 0) {
2121             if (scout_debug) {
2122                 fprintf(scout_debugfd,
2123                         "[%s] Setting store attn value to %d (default %d)\n",
2124                         rn, atoi(curr_value), scout_attn_store);
2125                 fflush(scout_debugfd);
2126             }
2127             scout_attn_store = atoi(curr_value);
2128         } else if (strcmp(curr_name, "ws") == 0) {
2129             if (scout_debug) {
2130                 fprintf(scout_debugfd,
2131                         "[%s] Setting workstation attn value to %d (default %d)\n",
2132                         rn, atoi(curr_value), scout_attn_workstations);
2133                 fflush(scout_debugfd);
2134             }
2135             scout_attn_workstations = atoi(curr_value);
2136         } else {
2137             printf("[%s] Unknown attention item: '%s'\n", rn,
2138                    curr_item->data);
2139             scout_CleanExit(-1);
2140         }
2141
2142         /*
2143          * Advance past the just-processed pair.
2144          */
2145         curr_item = curr_item->next->next;
2146
2147     }                           /*Interpret each name-value pair */
2148
2149 }                               /*scout_AdoptThresholds */
2150
2151 /**
2152  * Setup the user specified column widths.
2153  *
2154  * The column widths specifies the number of digits which
2155  * will be displayed without truncation.  The column widths
2156  * are given in the same order in which they are displayed,
2157  * from left to right. Not all columns need to be specified
2158  * on the command line. The default column widths for those
2159  * columns not specified. Column widths can not be set smaller
2160  * than the heading underline.
2161  *
2162  * @param[in] a_width_item      command line width item list
2163  */
2164 void
2165 scout_SetColumnWidths(struct cmd_item *a_width_item)
2166 {
2167     int i;
2168     int width;
2169     int num_cols = sizeof(scout_col_width) / sizeof(*scout_col_width);
2170
2171     for (i = 0; a_width_item && i < num_cols; i++) {
2172         width = atoi(a_width_item->data);
2173         if (width > 0) {
2174             int min_width = strlen(scout_underline[i]);
2175             if (min_width) {
2176                width = max(width, min_width);
2177             }
2178             scout_col_width[i] = width + 1;
2179         }
2180         a_width_item = a_width_item->next;
2181     }
2182     if (a_width_item) {
2183         fprintf(stderr, "Too many values given for -columnwidths\n");
2184         scout_CleanExit(1);
2185     }
2186 }
2187
2188 /*------------------------------------------------------------------------
2189  * scoutInit
2190  *
2191  * Description:
2192  *      Routine called when Scout is invoked, responsible for basic
2193  *      initialization, command line parsing, and calling the
2194  *      routine that does all the work.
2195  *
2196  * Arguments:
2197  *      as      : Command syntax descriptor.
2198  *      arock   : Associated rock (not used here).
2199  *
2200  * Returns:
2201  *      Zero (but may exit the entire program on error!)
2202  *
2203  * Environment:
2204  *      Nothing interesting.
2205  *
2206  * Side Effects:
2207  *      Initializes this program.
2208  *------------------------------------------------------------------------*/
2209
2210 static int scoutInit(struct cmd_syndesc *as, void *arock)
2211 {                               /*scoutInit */
2212
2213     static char rn[] = "scoutInit";     /*Routine name */
2214     int code;                   /*Return code */
2215     int wpkg_to_use;            /*Window package to use */
2216     int server_count;           /*Number of servers to watch */
2217     char *debug_filename;       /*Name of debugging output file */
2218
2219     if (scout_debug) {
2220         fprintf(scout_debugfd, "[%s] Called\n", rn);
2221         fflush(scout_debugfd);
2222     }
2223
2224     if (as->parms[P_DEBUG].items != 0) {
2225         scout_debug = 1;
2226         debug_filename = as->parms[P_DEBUG].items->data;
2227         scout_debugfd = fopen(debug_filename, "w");
2228         if (scout_debugfd == (FILE *) 0) {
2229             printf("[%s] Can't open debugging file '%s'!\n", rn,
2230                    debug_filename);
2231             scout_CleanExit(-1);
2232         }
2233         fprintf(scout_debugfd, "[%s] Writing to Scout debugging file '%s'\n",
2234                 rn, debug_filename);
2235     }
2236 #if 0
2237     wpkg_to_use = atoi(as->parms[P_PACKAGE].items->data);
2238 #endif /* 0 */
2239     wpkg_to_use = 2;            /*Always use curses for now */
2240 #if 0
2241     fprintf(stderr, "[%s:%s] Using graphics package %d: ", pn, rn,
2242             wpkg_to_use);
2243     switch (wpkg_to_use) {
2244     case GATOR_WIN_CURSES:
2245         fprintf(stderr, "curses\n");
2246         break;
2247     case GATOR_WIN_DUMB:
2248         fprintf(stderr, "dumb terminal\n");
2249         break;
2250     case GATOR_WIN_X11:
2251         fprintf(stderr, "X11\n");
2252         break;
2253     default:
2254         fprintf(stderr, "Illegal graphics package: %d\n", wpkg_to_use);
2255         scout_CleanExit(-1);
2256     }                           /*end switch (wpkg_to_use) */
2257 #endif /* 0 */
2258
2259     if (as->parms[P_FREQ].items != 0)
2260         scout_probefreq = atoi(as->parms[P_FREQ].items->data);
2261     else
2262         scout_probefreq = 60;
2263
2264     /*
2265      * See if we've been fed a base server name.
2266      */
2267     if (as->parms[P_BASE].items != 0)
2268         sprintf(scout_basename, "%s", as->parms[P_BASE].items->data);
2269     else
2270         *scout_basename = '\0';
2271
2272     /*
2273      * Count the number of servers we've been asked to monitor.
2274      */
2275     server_count = countServers(as->parms[P_SERVER].items);
2276
2277     /*
2278      * Create a line of blanks, a generally-useful thing.
2279      */
2280     sprintf(scout_blankline, "%255s", " ");
2281
2282     /*
2283      * Pull in the name of the host we're executing on if we've been
2284      * asked to.  If we can't get the name, we provide a default.
2285      */
2286     if (as->parms[P_HOST].items != 0) {
2287         scout_showhostname = 1;
2288         *scout_hostname = '\0';
2289         code = gethostname(scout_hostname, 128);
2290         if (code)
2291             sprintf(scout_hostname, "%s", "*No Hostname*");
2292     }
2293
2294     /*
2295      * Pull in any and all attention/highlighting thresholds.
2296      */
2297     if (as->parms[P_ATTENTION].items != 0)
2298         scout_AdoptThresholds(as->parms[P_ATTENTION].items);
2299
2300     if (as->parms[P_WIDTHS].items != 0) {
2301         scout_SetColumnWidths(as->parms[P_WIDTHS].items);
2302     }
2303
2304     /*
2305      * Now, drive the sucker.
2306      */
2307     code = execute_scout(server_count,  /*Num servers */
2308                          as->parms[P_SERVER].items,     /*Ptr to srv names */
2309                          wpkg_to_use);  /*Graphics pkg */
2310     if (code) {
2311         fprintf(stderr, "[%s] Error executing scout: %d\n", rn, code);
2312         scout_CleanExit(-1);
2313     }
2314
2315     /*
2316      * We initialized (and ran) correctly, so return the good news.
2317      */
2318     return (0);
2319
2320 }                               /*scoutInit */
2321
2322 #include "AFS_component_version_number.c"
2323
2324 int
2325 main(int argc, char **argv)
2326 {                               /*main */
2327
2328     afs_int32 code;     /*Return code */
2329     struct cmd_syndesc *ts;     /*Ptr to cmd line syntax descriptor */
2330
2331 #ifdef  AFS_AIX32_ENV
2332     /*
2333      * The following signal action for AIX is necessary so that in case of a
2334      * crash (i.e. core is generated) we can include the user's data section
2335      * in the core dump. Unfortunately, by default, only a partial core is
2336      * generated which, in many cases, isn't too useful.
2337      */
2338     struct sigaction nsa;
2339
2340     sigemptyset(&nsa.sa_mask);
2341     nsa.sa_handler = SIG_DFL;
2342     nsa.sa_flags = SA_FULLDUMP;
2343     sigaction(SIGSEGV, &nsa, NULL);
2344 #endif
2345     /*
2346      * Set up the commands we understand.
2347      */
2348     ts = cmd_CreateSyntax("initcmd", scoutInit, NULL, 0, "initialize the program");
2349     cmd_AddParm(ts, "-server", CMD_LIST, CMD_REQUIRED,
2350                 "FileServer name(s) to monitor");
2351     cmd_AddParm(ts, "-basename", CMD_SINGLE, CMD_OPTIONAL,
2352                 "base server name");
2353 #if 0
2354     cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED,
2355                 "Graphics package to use");
2356 #endif /* 0 */
2357     cmd_AddParm(ts, "-frequency", CMD_SINGLE, CMD_OPTIONAL,
2358                 "poll frequency, in seconds");
2359     cmd_AddParm(ts, "-host", CMD_FLAG, CMD_OPTIONAL,
2360                 "show name of host you're running on");
2361     cmd_AddParm(ts, "-attention", CMD_LIST, CMD_OPTIONAL,
2362                 "specify attention (highlighting) level");
2363     cmd_AddParm(ts, "-debug", CMD_SINGLE, CMD_OPTIONAL,
2364                 "turn debugging output on to the named file");
2365     cmd_AddParm(ts, "-columnwidths", CMD_LIST, CMD_OPTIONAL,
2366                 "specify column widths");
2367
2368     /*
2369      * Parse command-line switches & execute the test, then get the heck
2370      * out of here.
2371      */
2372     code = cmd_Dispatch(argc, argv);
2373     if (code) {
2374 #if 0
2375         fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n",
2376                 pn, rn, code);
2377 #endif /* 0 */
2378         scout_CleanExit(1);
2379     } else
2380         scout_CleanExit(0);
2381
2382     return 0; /* not reachable */
2383 }                               /*main */