Path: utzoo!attcan!uunet!ns-mx!iowasp.physics.uiowa.edu!maverick.ksu.ksu.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jato!mr-ed!mwette From: mwette@mr-ed.jpl.nasa.gov (Matt Wette) Newsgroups: comp.windows.x Subject: Message-ID: <1990Oct16.160553.12020@jato.jpl.nasa.gov> Date: 16 Oct 90 21:00:21 GMT References: Sender: news@jato.jpl.nasa.gov Organization: Jet Propulsion Laboratory Lines: 187 Nntp-Posting-Host: mr-ed.jpl.nasa.gov GMT Message-ID: <1990Oct16.090021@mr-ed.jpl.nasa.gov> Reply-To: mwette@mr-ed.jpl.nasa.gov (Matt Wette) Organization: Jet Propulsion Laboratory, Pasadena, CA Subject: Re: rlogin and the DISPLAY variable Keywords: In article , mike%aleytys@UUNET.UU.NET (Michael Kent) writes: |> I appologize if this is a FAQ, but: |> |> I need to rlogin to a remote X Workstation from my local X Workstation, |> and have the DISPLAY environmental variable properly set so that any |> X apps I run on the remote machine will display on my local machine. |> The setting of DISPLAY must happen without operator intervention, and |> must be correct no matter which of several local machines rlogin to the |> remote machine. |> |> Using the remote shell command is out, since the primary app to be run |> on the remote machine is interactive in the manner of 'vi', and is a |> 'tty'-based app which is best run via rlogin. Having the user's profile |> set DISPLAY is out, as the user can be logging in from several different |> local machines. |> |> Any ideas? |> -- |> Michael Kent INTERNET: mike@aleytys.uu.net |> Center for M.C.E. UUCP: ...!{uunet, uflorida}!aleytys!mike |> 2521 N.W. 57th Pl MA BELL: +1-904-335-1573 |> Gainesville, Fl 32606 "...yes, we have no bananas..." You may want to try the included program. It tries to get a reasonable display name by reading /etc/utmp. Basically, you put setenv DISPLAY `echodpy` in your .cshrc file. Matt _______________________________________________________________________ _______ Matthew R. Wette | Jet Propulsion Laboratory, 198-326 mwette@csi.jpl.nasa.gov | 4800 Oak Grove Dr, Pasadena,CA 91109 ----------------------------------------------------------------------- ------- /* echodpy.c - echo reasonable DISPLAY variable, if possible * * Copyright (c) 1990 Matthew R. Wette * Permission for use and distribution granted provided this copyright notice * and source code accompany distribution. * * in your .cshrc file put: * * set dpy=`echodpy` * if ( "$dpy" != "" ) then * setenv DISPLAY $dpy * endif * unset dpy * * history - * 16Oct90 M.Wette: created. * * version - * $Id: echodpy.c,v 1.2 90/10/16 09:07:40 mwette Exp $ * * notes - * 1. probably not the best implementation * */ #include #include #include #include #define UTMP "/etc/utmp" void error(char *fmt, ...) { va_list ap; char *p; fprintf(stderr, "echodpy: "); va_start(ap, fmt); for (p = fmt; *p; p++) { if (*p != '%') { putc(*p, stderr); continue; } switch (*++p) { case 'c': putc(va_arg(ap, char), stderr); break; case 'd': fprintf(stderr, "%d", va_arg(ap, int)); break; case 'f': fprintf(stderr, "%f", va_arg(ap, double)); break; case 's': fprintf(stderr, "%s", va_arg(ap, char *)); break; default: putc(*p, stderr); break; } } putc('\n', stderr); } char * utmphost(char *line) { FILE *fp; struct utmp ut; char *host; # ifdef DEBUG error("in utmphost: match line=%s", line); # endif if (access(UTMP, R_OK) != 0) { error("access denied to \"%s\"", UTMP); return((char *) NULL); } if ((fp = fopen(UTMP, "r")) == NULL) { error("couldn't open \"%s\"", UTMP); return((char *) NULL); } while (fread(&ut, sizeof(struct utmp), 1, fp) > 0) { # ifdef DEBUG if (ut.ut_line[0] != '\0') error("in utmphost: line=%s, host=%s", ut.ut_line, ut.ut_host); # endif if (strcmp(ut.ut_line, line)==0 && ut.ut_name[0]!='\0') { host = (char *) malloc(strlen(ut.ut_host + 1)); strcpy(host, ut.ut_host); return(host); } } return((char *) NULL); } int main(int argc, char *argv[]) { char buf[128], *bufp, *ttyn, *line, *host; if (isatty(0)) { ttyn = ttyname(0); } else if (isatty(1)) { ttyn = ttyname(1); } else if (isatty(2)) { ttyn = ttyname(2); } else { # ifdef DEBUG error("can't establish ttyname\n"); # endif exit(1); } # ifdef DEBUG error("ttyname=\"%s\"", ttyn); # endif strcpy(buf, &ttyn[5]); line = buf; if ((host = utmphost(line)) == (char *) NULL) { # ifdef DEBUG error("couldn't get hostname"); # endif exit(1); } # ifdef DEBUG error("host=\"%s\"", host); # endif bufp = buf; while (*host != ':' && *host != '\0') *bufp++ = *host++; *bufp++ = ':'; *bufp++ = '0'; *bufp++ = '.'; *bufp++ = '0'; *bufp = '\0'; # ifdef DEBUG error("dpy env=\"%s\"", buf); # endif printf(buf); } /* --- last line of echodpy.c --- */