From 8dafeb68269fa6031a4e1f46b9e71985b16ed642 Mon Sep 17 00:00:00 2001 From: John Kohl Date: Sat, 25 Jun 1988 13:24:16 +0000 Subject: cache hostname and terminal in static storage. use windowgram's port number for consistency --- lib/ZLocations.c | 66 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 25 deletions(-) (limited to 'lib/ZLocations.c') diff --git a/lib/ZLocations.c b/lib/ZLocations.c index 40ebcf9..2b4882e 100644 --- a/lib/ZLocations.c +++ b/lib/ZLocations.c @@ -46,6 +46,9 @@ Code_t ZFlushMyLocations() return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, "")); } +static char host[MAXHOSTNAMELEN], mytty[MAXHOSTNAMELEN]; +static int reenter = 0; + Z_SendLocation(class, opcode, auth, format) char *class; char *opcode; @@ -57,12 +60,14 @@ Z_SendLocation(class, opcode, auth, format) int retval; long ourtime; ZNotice_t notice, retnotice; - char *bptr[3], host[MAXHOSTNAMELEN], mytty[MAXHOSTNAMELEN]; - char *display; + char *bptr[3]; + char *display, *ttyp; struct hostent *hent; notice.z_kind = ACKED; - notice.z_port = 0; + notice.z_port = ZGetWGPort(); + if (notice.z_port == -1) + notice.z_port = 0; notice.z_class = class; notice.z_class_inst = ZGetSender(); notice.z_opcode = opcode; @@ -71,33 +76,44 @@ Z_SendLocation(class, opcode, auth, format) notice.z_num_other_fields = 0; notice.z_default_format = format; - if (gethostname(host, MAXHOSTNAMELEN) < 0) - return (errno); - - hent = gethostbyname(host); - if (!hent) - bptr[0] = "unknown"; - else { - (void) strcpy(host, hent->h_name); - bptr[0] = host; - } + /* + keep track of what we said before so that we can be consistent + when changing our minds. + This is done mainly for the sake of the WindowGram client. + */ + + if (!reenter) { + if (gethostname(host, MAXHOSTNAMELEN) < 0) + return (errno); + + hent = gethostbyname(host); + if (!hent) + (void) strcpy(host, "unknown"); + else + (void) strcpy(host, hent->h_name); + bptr[0] = host; + if ((display = getenv("DISPLAY")) && *display) { + (void) strcpy(mytty, display); + bptr[2] = mytty; + } else { + ttyp = ttyname(0); + bptr[2] = rindex(ttyp, '/'); + if (bptr[2]) + bptr[2]++; + else + bptr[2] = ttyp; + (void) strcpy(mytty, bptr[2]); + } + reenter = 1; + } else { + bptr[0] = host; + bptr[2] = mytty; + } ourtime = time((long *)0); bptr[1] = ctime(&ourtime); bptr[1][strlen(bptr[1])-1] = '\0'; - if ((display = getenv("DISPLAY")) && *display) { - (void) strcpy(mytty, display); - bptr[2] = mytty; - } - else { - (void) strcpy(mytty, ttyname(0)); - bptr[2] = rindex(mytty, '/'); - if (bptr[2]) - bptr[2]++; - else - bptr[2] = mytty; - } if ((retval = ZSendList(¬ice, bptr, 3, auth)) != ZERR_NONE) return (retval); -- cgit v1.2.3