DISPLAY environment variable from login(1)

David Elliott dce at Solbourne.COM
Wed Sep 6 23:44:50 AEST 1989


In article <4045 at buengc.BU.EDU> bph at 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 at 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!"



More information about the Comp.unix.questions mailing list