summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorGravatar John F. Carr <jfc@mit.edu>1991-06-29 20:11:46 +0000
committerGravatar John F. Carr <jfc@mit.edu>1991-06-29 20:11:46 +0000
commit2162bc03f980411cfb0c8c2e1a7d9bbecba41f5d (patch)
tree60fcbac08beda16c4eed9e10fb61511c5a111570 /clients
parentb30e1810f81725211b93f2fd587baaeff0eaeaf6 (diff)
Rewritten to use async locate.
Diffstat (limited to 'clients')
-rw-r--r--clients/zlocate/zlocate.c249
1 files changed, 154 insertions, 95 deletions
diff --git a/clients/zlocate/zlocate.c b/clients/zlocate/zlocate.c
index a0e514f..7b7655c 100644
--- a/clients/zlocate/zlocate.c
+++ b/clients/zlocate/zlocate.c
@@ -11,113 +11,172 @@
* "mit-copyright.h".
*/
-#include <zephyr/mit-copyright.h>
+#include <zephyr/zephyr_internal.h>
+#include <signal.h>
+#include <sys/socket.h>
-#include <zephyr/zephyr.h>
-#include <string.h>
-
-#ifndef lint
-static char rcsid_zlocate_c[] = "$Header$";
-#endif lint
+#if !defined(lint) && !defined(SABER)
+static char rcsid_zlocate_c[] = "$Id$";
+#endif
+int numusers=0, numleft=0, parallel=0, oneline=0;
char *whoami;
+#ifdef _POSIX_SOURCE
+void
+#endif
+timeout(sig)
+{
+ fprintf (stderr, "%s: no response from server\n", whoami);
+ exit(1);
+}
+
void usage()
{
- printf("Usage: %s [ -a | -d ] user ... \n",whoami);
+ printf("Usage: %s [ -a | -d ] [ -p ] [ -1 ] user ... \n",whoami);
exit(1);
}
+void print_locs(user,nlocs)
+ char *user;
+ int nlocs;
+{
+ int one = 1, retval;
+ ZLocations_t locations;
+
+ if ((!oneline) && (numusers>1))
+ printf("\t%s:\n",user);
+
+ if ((!oneline) && (nlocs == 0))
+ printf("Hidden or not logged-in\n");
+
+ for (;nlocs;nlocs--) {
+ if ((retval = ZGetLocations(&locations,&one)) != ZERR_NONE) {
+ com_err(whoami,retval,"while getting location");
+ exit(1);
+ }
+
+ if (oneline) {
+ printf("%s:\t%s\t%s\t%s\n",user,locations.host,locations.tty,
+ locations.time);
+ } else {
+ printf("%-42s %-7s %s\n",locations.host, locations.tty, locations.time);
+ }
+ }
+
+ if ((!oneline) && (numusers > 1) && (numleft > 0))
+ printf("\n");
+}
+
+/*ARGSUSED*/
main(argc,argv)
int argc;
char *argv[];
{
- int retval,numlocs,i,one,ourargc,found,auth;
- char bfr[BUFSIZ],user[BUFSIZ];
- ZLocations_t locations;
-
- whoami = argv[0];
- auth = -1;
-
- if (argc < 2) usage();
-
- if ((retval = ZInitialize()) != ZERR_NONE) {
- com_err(whoami,retval,"while initializing");
- exit(1);
- }
-
- argv++;
- argc--;
-
- for (i=0; argv[i]; i++)
- if (argv[i][0] == '-')
- switch (argv[i][1]) {
- case 'a':
- if (auth != -1) usage();
- auth = 1;
- break;
- case 'd':
- if (auth != -1) usage();
- auth = 0;
- break;
- default:
- usage();
- break;
- }
-
- one = 1;
- found = 0;
- ourargc = argc - ((auth == -1)?0:1);
-
- if (auth == -1) auth = 1;
-
- for (;argc--;argv++) {
- if ((*argv)[0] == '-') continue;
- (void) strcpy(user,*argv);
- if (!index(user,'@')) {
- (void) strcat(user,"@");
- (void) strcat(user,ZGetRealm());
- }
- if ((retval = ZNewLocateUser(user,&numlocs,
- (auth?ZAUTH:ZNOAUTH)))
- != ZERR_NONE) {
- (void) sprintf(bfr,"while locating user %s",user);
- com_err(whoami,retval,bfr);
- continue;
- }
- if (ourargc > 1)
- printf("\t%s:\n",user);
- if (!numlocs) {
- printf("Hidden or not logged-in\n");
- if (argc)
- printf("\n");
- continue;
- }
- for (i=0;i<numlocs;i++) {
- if ((retval = ZGetLocations(&locations,&one))
- != ZERR_NONE) {
- com_err(whoami,retval,
- "while getting location");
- continue;
- }
- if (one != 1) {
- printf("%s: internal failure while getting location\n",whoami);
- exit(1);
- }
- /* just use printf; make the field widths one
- * smaller to deal with the extra separation space.
- */
- printf("%-*s %-*s %s\n",
- 42, locations.host,
- 7, locations.tty,
- locations.time);
- found++;
- }
- if (argc)
- printf("\n");
- (void) ZFlushLocations();
- }
- if (!found)
+ char user[BUFSIZ],*whichuser;
+ ZAsyncLocateData_t ald;
+ int retval,i,numlocs,loc,auth;
+ ZNotice_t notice;
+
+ whoami = argv[0];
+ auth = -1;
+
+ argv++;
+ argc--;
+
+ for (i=0; i < argc; i++)
+ if (argv[i][0] == '-')
+ switch (argv[i][1]) {
+ case 'a':
+ if (auth != -1) usage();
+ auth = 1;
+ break;
+ case 'd':
+ if (auth != -1) usage();
+ auth = 0;
+ break;
+ case 'p':
+ parallel = 1;
+ break;
+ case '1':
+ oneline = 1;
+ break;
+ default:
+ usage();
+ break;
+ }
+ else
+ numusers++;
+
+ if (numusers == 0)
+ usage();
+
+ if (auth == -1) auth = 1;
+
+ if ((retval = ZInitialize()) != ZERR_NONE) {
+ com_err(whoami,retval,"while initializing");
+ exit(1);
+ }
+
+#if 0
+ {
+ int len,len2;
+ ZOpenPort((u_short*)0);
+ if(getsockopt(ZGetFD(), SOL_SOCKET, SO_RCVBUF, (char *)&len, &len2) == -1)
+ perror("getsockopt");
+ fprintf(stderr, "socket RCVBUF is %x\n", len);
+ len = 56 * 1024;
+ if(setsockopt(ZGetFD(), SOL_SOCKET, SO_RCVBUF, (char *)&len, sizeof(int)) == -1)
+ perror("setsockopt");
+ }
+#endif
+
+ numleft = numusers;
+
+ i = 0;
+ for (loc = 0; loc < argc; loc++) {
+ if (argv[loc][0] == '-') continue;
+
+ (void) strcpy(user,argv[loc]);
+ if (!index(user,'@')) {
+ (void) strcat(user,"@");
+ (void) strcat(user,ZGetRealm());
+ }
+ if (parallel) {
+ if ((retval = ZRequestLocations(user, &ald, i ? UNSAFE : UNACKED,
+ auth?ZAUTH:ZNOAUTH)) != ZERR_NONE) {
+ com_err(whoami,retval,"requesting location of %s",user);
exit(1);
- exit(0);
+ }
+ i = 1;
+ } else {
+ if ((retval = ZLocateUser(user,&numlocs,auth?ZAUTH:ZNOAUTH)) != ZERR_NONE) {
+ com_err(whoami,retval,"while locating user %s",user);
+ exit(1);
+ }
+ print_locs(user,numlocs);
+ }
+ }
+
+ if (parallel) {
+ signal (SIGALRM, timeout);
+ while (numleft-- > 0) {
+ alarm(SRV_TIMEOUT);
+ if ((retval = ZReceiveNotice(&notice, NULL)) != ZERR_NONE) {
+ com_err(whoami,retval,"while searching notice queue");
+ continue;
+ }
+ if ((retval = ZParseLocations(&notice, (ZAsyncLocateData_t *)NULL,
+ &numlocs, &whichuser)) != ZERR_NONE) {
+ com_err(whoami,retval,"while parsing locations");
+ continue;
+ }
+ if (numlocs >= 0) {
+ print_locs(whichuser,numlocs);
+ free(whichuser);
+ }
+ ZFreeNotice(&notice);
+ }
+ }
+ return(0);
}