3 /*#include <signal.h>*/
7 * lab: print out status of some labs.
8 * possibly with heading, possibly only down or outofservice machines
11 char *periodname[] = { "<null>", "FREE", "FULL", "CLOSED" };
12 char *nstatus[] = { "<null>", "Up", "Down"};
13 char *bstatus[] = { "<null>", "OutOfService", "Broken", "NotBookable",
14 "UnAllocated", "Allocated", "Tentative" };
16 enum { N_UP, N_DOWN, N_OUT, N_ALL } class; /* which workstations to show */
20 void print_lab(labinfo li)
26 int xdrname = 1, xdrhost = 1;
27 name = get_mappingchar(li->labid, M_ATTRIBUTE);
32 host = get_mappingchar(alloc_host(li->alloc), M_HOST);
37 if (li->alloc->data.data_len <3)
38 printf("\nLab %s is %s: no allocations\n\n",
39 name, periodname[alloc_status(li->alloc)]);
42 time_t period = cluster_modtime(li->alloc);
44 char doys[10], pods[10];
45 get_doypod(&period, &doy, &pod);
46 printf("\nLab %s is %s, last allocation by %s for %s %s (at %s)\n\n",
47 name, periodname[alloc_status(li->alloc)],
49 doy2str(doys, doy), pod2str(pods, pod),
50 myctime(alloc_when(li->alloc))
59 for (i=0 ; i < li->wscnt ; i++)
61 workstation w = &li->wslist[i];
63 ((class==N_UP) && ws_status(w->status) == NODEUP)
64 || ((class==N_DOWN) && ws_status(w->status) == NODEDOWN)
65 || ((class==N_OUT) && res_status(w->alloc) == NODEOUTOFSERVICE)
72 char c1 = ' ' , c2= ' ' ;
74 wsname = get_mappingchar(w->wsid, M_WORKSTATION);
75 if (wsname == NULL) wsname = strdup("<unknown>");
76 if (ws_user(w->status) >= 0)
78 useron = find_username(ws_user(w->status));
79 if (useron == NULL) useron = strdup("<who?>");
81 if (res_user(w->alloc) >= 0)
83 userres = find_username(res_user(w->alloc));
84 if (userres == NULL) userres = strdup("<who?>");
86 if (in_class(ws_user(w->status), res_user(w->alloc))==1)
90 printf("%-12s:%-8s%12s: %-10s %c %-9s%c",
91 wsname, nstatus[ws_status(w->status)],
92 bstatus[res_status(w->alloc)],
94 c1, userres?userres:"", c2);
98 int h = ws_whereon(w->status);
101 char *hn = get_mappingchar(h, M_HOST);
103 printf(" on %s", hn);
105 printf("on host-%d", h);
110 /* print login time */
111 if (ws_whenon(w->status))
113 myctime(ws_whenon(w->status)));
118 workstation_state ws;
120 memset(&ws, 0, sizeof(ws));
121 if (db_read(key_int(k, C_WORKSTATIONS, w->wsid), &ws,
122 (xdrproc_t)xdr_workstation_state, CONFIG) == R_RESOK)
125 printf(" %s (%s)\n", ws.why,
127 xdr_free((xdrproc_t)xdr_workstation_state, (char*) &ws);
130 if (useron) free(useron);
131 if (userres) free(userres);
138 "Usage: lab [-udosASht] labname ...",
139 " -u : only list UP workstations",
140 " -d : only list DOWN workstations",
141 " -o : only list out of service workstations, and give reason",
142 " -s : don't print header on lab listing",
143 " -t : show time of login (default)",
144 " -h : show host that ws is logged on to instead of time",
145 " -A : list all labs",
146 " -S : list all bookable labs",
147 " -R : repeat listing ever 30 seconds",
148 " labname: the name of any lab of group of labs",
152 int main(int argc, char *argv[])
158 void *lablist = lablist_make();
162 /* quit on receipt of sigusr1 - to help with memory debugging in loops */
166 sa.sa_handler = exit;
169 sigaddset(&ss, SIGUSR1);
171 sigaction(SIGUSR1, &sa, NULL);
176 while ((opt = getopt(argc, argv, "udosASRht"))!= EOF)
179 case 'h': phost = TRUE; break;
180 case 't': phost = FALSE; break;
181 case 'u': class = N_UP ; break ;
182 case 'd': class = N_DOWN ; break ;
183 case 'o': class = N_OUT ; break ;
184 case 's': show_header = FALSE ; break ;
185 case 'R': repeat = TRUE; break;
187 msg = add_lab(lablist, NULL);
190 fprintf(stderr, "lab: could not find all labs: %s\n", msg);
195 msg = add_lab(lablist, "bookable");
198 fprintf(stderr, "lab: could not find bookable labs: %s\n", msg);
206 for (; optind < argc ; optind++)
208 msg = add_lab(lablist, argv[optind]);
211 fprintf(stderr, "lab: could not add lab %s: %s\n", argv[optind], msg);
215 if (lablist_empty(lablist))
217 fprintf(stderr, "lab: no labs given\n");
225 for (li = lablist_next(lablist) ; li != lablist ; li = lablist_next(li))
229 printf("Cannot get table for %s\n", li->labname);
231 printf("---------------------\n");