Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Jul 2001 20:26:22 -0700
From:      "Chad R. Larson" <chad@DCFinc.com>
To:        David Wolfskill <david@catwhisker.org>
Cc:        Stable@FreeBSD.org
Subject:   Re: running on X server?
Message-ID:  <20010726202622.A9940@freeway.dcfinc.com>
In-Reply-To: <200107262222.f6QMMXO00601@bunrab.catwhisker.org>; from david@catwhisker.org on Thu, Jul 26, 2001 at 03:22:33PM -0700
References:  <20010726150701.C9091@freeway.dcfinc.com> <200107262222.f6QMMXO00601@bunrab.catwhisker.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jul 26, 2001 at 03:22:33PM -0700, David Wolfskill wrote:
>>Date: Thu, 26 Jul 2001 15:07:01 -0700
>>From: "Chad R. Larson" <chad@DCFinc.com>
>>
>>Is there a simple, reliable way to determine if a script is running
>>in an X environment?
>>
>>I've seen too many scripts (such as the one shipped with urlview)
>>that test for the presence of the environmental variable DISPLAY,
>>but that's hardly foolproof.

> I suspect that the answer to the question "Is this process (script)
> running in an X environment?" is equivalent to answering the question
> "Does the currently-running process have access to X services?"

Yes, you've got the crux of it.  On my own desktop, I have a

  setenv DISPLAY unix:0

in my .login file.

And on remote machines I regularly use there's a

  setenv DISPLAY chad:0

in the .login.  But if I've telnet'd, or rsh'd, or ssh'd to the remote
machine then things like the mutt "urlview" program, or lynx or any
number of other programs that try to exist on both ttys and on xterms in
an X environment DNDTRT (do not do the right thing).

So, I'm thinking of some kind of test in the .login that will
conditionally set (or unset) the DISPLAY variable to TRT.

> I further suspect that this is best determined empirically -- by
> trying to invoke some (innocuous?) X service (if there is such a
> thing), and checking for an indicative result.

Yes, I goofed around with xdpyinfo in that regard, since its output
is text rather than trying to pop up a window.  You could grep its
stream.  But you still have to start with an assumed DISPLAY value,
and if you're wrong you might have your login delayed quite a while
as the xdpyinfo times out.

So, still looking for a clean, quick way to come up with what should
be set in the DISPLAY environmental variable (if anything) from
inside a login script.

In the old days (and I'm dating myself) we used to have

  setenv TERM `qterm`

in our .logins.  You youngsters might want to look up qterm on
google (or ask me and I'll send you a copy).

In my current .login, there's stuff like:

    tty | grep -qv ttyv
    if ($status) /usr/sbin/vidcontrol green

on the FreeBSD machines.

I want something like that returns the current X display, or some
kind of indication that there is none.  Maybe a ps-and-grep for an X
server owned by me?  Nope, still doesn't help if the X server is on
a remote machine.  Maybe a netstat-and-grep to see if I'm coming
from a port at or near 6000?  Fails if I'm on my desktop using UNIX
sockets.

Anyway, you get the drift.  I believe there may be an oversight by
the X committee.

	-crl
--
Chad R. Larson (CRL15)   602-953-1392   Brother, can you paradigm?
chad@dcfinc.com         chad@larsons.org          larson1@home.com
DCF, Inc. - 14623 North 49th Place, Scottsdale, Arizona 85254-2207

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010726202622.A9940>