[comp.windows.x] DISPLAY environment variable from login

bph@buengc.BU.EDU (Blair P. Houghton) (09/05/89)

When opening a new login window (pseudo-terminal in an X window running
a shell enabled to run the login(1) program), as in

	xterm -ls -e login &

(xterm(1X) from X11R2) the new window comes up and immediately
does the login(1).

Only, login(1) creates an entirely new set of environment variables,
effectively ignoring the imported environment, and DISPLAY in particular.
One can also no longer determine the DISPLAY variable by using tty(1)
to look at whether one is at ttyv0 or ttyv1 (the display-consoles),
because the terminal is a pty with the name of whichever was the next
available pseudo-terminal, and any pty can get set to either of the two
displays on these two-head GPX workstations.

The question is, although I know the window is on this screen, and the
X server knows the window is on this screen, how can I get the shell
(csh(1)) to know which screen this window is on, in order to set
DISPLAY (in $HOME/.login, for the benefit of this process' children),
other than by prompting for that information from the user?

/etc/gettytab(5) has this information in it so that getty(8) knows
where to send the display-consoles, but it's tied again to knowing that
you're using either ttyv0 or ttyv1, so that route is moot.

Any assistance will be appreciated.

Flame if you must:  you know I would. :-)

				--Blair
				  "Shell Script 101 has been cancelled
				   for the fall semester due to the
				   fact that the instructor is stumped
				   on this one."

dce@Solbourne.COM (David Elliott) (09/06/89)

In article <4045@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>Only, login(1) creates an entirely new set of environment variables,
>effectively ignoring the imported environment, and DISPLAY in particular.

Yep, this is a real pain.  I've seen a lot of solutions, but most
end up asking the user or assuming no more than one rlogin.  The only
one I really like is one in which you can query xterm for the
value of DISPLAY, but there are problems in doing this, so I use
the following solution:

1. Instead of using the normal rlogin, I have in my path ~/.rlogin,
   which contains the same type of links as /usr/hosts (that is,
   links for each hostname and nickname to an rlogin program) and a
   command called rlogin, which is the following shell script:

	#!/bin/sh

	case "$DISPLAY" in
	"")
		;;
	*)
		rm -f $HOME/.xdisplay
		echo "$DISPLAY" > $HOME/.xdisplay
		;;
	esac

	case "$0" in
	*rlogin)
		;;
	*)
		set "`basename $0`" ${1+"$@"}
		;;
	esac

	exec /usr/ucb/rlogin ${1+"$@"}

   This results in creating a file called ~/.xdisplay which contains the
   value of DISPLAY.

2. In my .login, I have the following block of code:

	if ("$TERM" == "xterm") then
		if ($?DISPLAY) then
			:
		else
			setenv DISPLAY `getdisplay`
		endif
		switch ("$DISPLAY")

		case selene\:*:
			alias bitmap bitmap -nodashed -geometry '1024x850+20+20'
			breaksw
		...

   That is, if my terminal type is xterm, then I want to get the DISPLAY
   variable if it isn't set already (i.e., I rlogin'ed instead of
   creating a new xterm directly on the client machine).  The last bit
   is where I set up aliases and variables for specific servers.

3. In my personal bin directory, I have getdisplay:

	#!/bin/sh

	PATH=/bin:/usr/bin

	if [ -f "$HOME/.xdisplay"  ]
	then
		DISPLAY=`cat $HOME/.xdisplay`
		rm -f $HOME/.xdisplay
	else
		DISPLAY="unknown:0"
	fi

	echo "$DISPLAY"

   In other words, if there's a .xdisplay file, use it to set DISPLAY.
   Note that .xdisplay is removed after it is used to avoid the possibility
   of rlogins clashing (it's better to have no DISPLAY than to have it
   be wrong).

This solution has stood me well over the last few months.  It's not
perfect, especially since the way we have our network setup, half the
machines I can login to can't find my home directory, but until there
exists an rlogin-type function that can send across required variables,
this should do fine.
-- 
David Elliott		dce@Solbourne.COM
			...!{uunet,boulder,nbires,sun}!stan!dce

"We don't do this because we love you or like you...we don't even know you!"

rlk@THINK.COM (Robert L. Krawitz) (09/07/89)

Passing DISPLAY across an rlogin isn't very hard; it simply requires
overloading TERM.  I use this script (which I call xdsp) to pass it
across:

#!/bin/sh
TERM=xtu.$XDISPLAY
export TERM
exec rsh $*

The following code in my .login picks it up:

if (($TERM =~ xt?.*) || ($TERM =~ xt.*)) then
  setenv DISPLAY `echo $TERM | sed 's/xt[^.]*\.//'`
  set term = xterm
  setenv TERM xterm
endif

Under X10 I didn't need the sed; I could do everything with the shell.
Under X11 I need the sed to handle the foo:0.0 syntax.

ames >>>>>>>>>  |	Robert Krawitz <rlk@think.com>	245 First St.
bloom-beacon >  |think!rlk				Cambridge, MA  02142
harvard >>>>>>  .	Thinking Machines Corp.		(617)876-1111