[comp.windows.x] setenv DISPLAY automatically

mouse@LARRY.MCRCIM.MCGILL.EDU (11/12/90)

> If one has many accounts on many UNIX machines running X-Windows,
> naturally he doesn't want to do  "setenv DISPLAY ..." every time he
> rlogin to a host.  How do you tell the remote host to know your
> original "DISPLAY" and set it automatically for you when you log in?

> We have figured out the way to do it for a single rlogin.  But once
> you rlogin to still another remote host, the DISPLAY becomes
> incorrect.

What I do is use a front-end to rlogin that packages up $TERM and
$DISPLAY into a single string, which is stuffed into $TERM.  rlogin
then propagates $TERM normally; my .cshrc on the remote machine
contains

	eval `xrlogind`

where xrlogind is a program that checks $TERM and if it is of the
special format it recognizes, unpacks it and spits out setenv and
unsetenv commands to recreate the environment variables.

Works like a charm, and xrlogin is smart enough to ensure that the
DISPLAY it passes to the remote end is usable there, by always
converting machine names to numeric form and handling the bare-":" and
"unix:" abbreviations appropriately.

The programs are not complicated, but they are not in shape to compile
elsewhere; they depend on local include files and library routines (and
also have an unfortunate assumption that the character set in use is
ASCII).  I can't spare the time just now to bash them into
release-ready shape, but if you want them anyway you can ftp them from
132.206.1.1, in X/xrlogin.c and X/xrlogind.c.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

frans@phcisa.UUCP (Francois Staes) (11/14/90)

A simple solution might be to use

rsh <HOST> -n /usr/bin/X11/xterm -display $DISPLAY

This causes the DISPLAY variable to contain the right value, even in the
child process of the xterm. (See man page of xterm)

One problem left: you have to change the initial value of your DISPLAY
variable from unix:0 to <your_hostname>:0. Is there any way that
xinit sets the initial DISPLAY variable to <hostname>:0 instead of unix:0 ?
Or does this cause any performance problems ?

Best greetings,

Francois Staes
Origin/Middleware
Eindhoven, The Netherlands.

moss@brl.mil (Gary S. Moss (VLD/VMB) <moss>) (11/17/90)

In article <1248@phcisa.UUCP>, frans@phcisa.UUCP (Francois Staes) writes:
|> A simple solution might be to use
|> 
|> rsh <HOST> -n /usr/bin/X11/xterm -display $DISPLAY
|> 
|> This causes the DISPLAY variable to contain the right value, even in the
|> child process of the xterm. (See man page of xterm)
|> 
|> One problem left: you have to change the initial value of your DISPLAY
|> variable from unix:0 to <your_hostname>:0. Is there any way that
|> xinit sets the initial DISPLAY variable to <hostname>:0 instead of unix:0 ?
|> Or does this cause any performance problems ?

I have a version of xrsh that I've hacked just a little which is nice to use
for remote execution of X clients.  Not only does it set up the DISPLAY
variable automatically, but it runs xhost, adds X stuff to your path and
sets LD_LIBRARY_PATH in case you are using shared libraries.  Using xrsh,
the above line would turn into the following:

xrsh <HOST> xterm

Below is the xrsh, the comment is not mine, it came with it, and you may
need to change the list of directories that it appends to PATH:

-Gary

#! /bin/sh
#
# start an X11 process on another host
#
# Date: 8 Dec 88 06:29:34 GMT
# From: Chris Torek <chris@mimsy.umd.edu>
# rsh $host -n "setenv DISPLAY $DISPLAY; exec $@ </dev/null >&/dev/null"
#
# An improved version:
# rXcmd (suggested by John Robinson, jr@bbn.com)
#       (generalized for sh,ksh by Keith Boyer, keith@cis.ohio-state.edu)
#
# but they put the rcmd in ()'s which left zombies again.  This
# script combines the best of both.

case $# in
[01])  echo "Usage: $0 host x-cmd [args...]";;
*)
	case $SHELL in
	*csh*)  host="$1"; shift
		xhost "$host" > /dev/null
		rsh "$host" -n \
			"setenv TERM xterm; setenv DISPLAY `hostname`:0; \
			exec $* </dev/null >& /dev/null" &
		;;
	*sh)
		host="$1"; shift
		xhost "$host" > /dev/null
		rsh "$host" -n \
			"TERM=xterm export TERM; \
			DISPLAY=`hostname`:0 export DISPLAY; \
			LD_LIBRARY_PATH=/usr/X11/lib export LD_LIBRARY_PATH; \
			PATH=\$PATH:/usr/X11/bin:/usr/bin/X11:/usr/local/bin; \			export PATH; \
			exec $* < /dev/null > /dev/null 2>&1" &
		;;
	esac
	;;
esac