public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
* reset/terminate problems; preventing multiple XWin instances
@ 2004-02-29  6:41 cygwinx2eran
  2004-02-29 13:49 ` Harold L Hunt II
  0 siblings, 1 reply; 10+ messages in thread
From: cygwinx2eran @ 2004-02-29  6:41 UTC (permalink / raw)
  To: cygwin-xfree

Hi,

First, I'd like to extend my gratitude and appreciation to the Cygwin/X 
developers. Your hard work has improved Cygwin/X by bounds and leaps, 
making it an increasingly attractive alternative to bloated and 
expensive commercial offerings. (Now if only multiwindow mode had decent 
performance, like the other two modes...)


A few issues I've encountered with Cygwin/X 4.3.0-47:

Issue #1:
In multiwindow mode, XWin doesn't reset when the last client exists.
Example:
   XWin :9 -terminate -multiwindow & sleep 5; DISPLAY=:9 xhost
XWin should terminate after 5 seconds, but it remains running.


Issue #2:
In the default mode, XWin sometimes terminates instead of resetting.
Example:
   XWin :9& sleep 5; DISPLAY=:9 xhost; sleep 5; DISPLAY=:9 xhost
XWin should reset after 5 seconds and again after 5 more seconds.
The first reset goes well, but on the second reset XWin usually terminates.


Issue #3:
Hoe does one write a batchfile that does "open an xterm window; run XWin 
first if necessary"? Being perhaps the most common usage case, such a 
batchfile should be bundled in the Cygwin/X package and mentioned in the 
documentation.
Note that /usr/X11R6/bin/startxwin.bat always runs a new instance of 
XWin, even if one is already running. This can result in inefficiency 
and confusion when the script is executed several times to open several 
xterm windows (a natural thing to do). It's made even worse by issue #1 
above.
Also, startxwin.bat doesn't use -clipboard.


   Eran


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
  2004-02-29  6:41 reset/terminate problems; preventing multiple XWin instances cygwinx2eran
@ 2004-02-29 13:49 ` Harold L Hunt II
  2004-02-29 14:13   ` Eran Tromer
  0 siblings, 1 reply; 10+ messages in thread
From: Harold L Hunt II @ 2004-02-29 13:49 UTC (permalink / raw)
  To: cygwin-xfree

  > A few issues I've encountered with Cygwin/X 4.3.0-47:
> 
> Issue #1:
> In multiwindow mode, XWin doesn't reset when the last client exists.
> Example:
>   XWin :9 -terminate -multiwindow & sleep 5; DISPLAY=:9 xhost
> XWin should terminate after 5 seconds, but it remains running.

It isn't supposed to.  Run 'twm' as your window manager and you will see 
that the X Server does not reset when the last non-window manager client 
exits; this is because the window manager itself is a client.

Also, the whole "reset" functionality is pretty much pointless for X 
Server that run on top of other windowing systems, which is the case for 
Cygwin/X.  The only time it makes sense to perform "resets" for Cygwin/X 
is when disconnecting from an Xdmcp session.  I have been thinking about 
removing or disabling the reset functionality in most non-Xdmcp cases 
for XWin.exe.

> Issue #2:
> In the default mode, XWin sometimes terminates instead of resetting.
> Example:
>   XWin :9& sleep 5; DISPLAY=:9 xhost; sleep 5; DISPLAY=:9 xhost
> XWin should reset after 5 seconds and again after 5 more seconds.
> The first reset goes well, but on the second reset XWin usually terminates.

You get two resets tops, then it crashes.  That is due to some generic 
bugs in the Xserver/dix/ and Xserver/os/ code that has been fixed in 
more recent source code trees.  We are working on cutting a release from 
a newer tree, but it hasn't happened yet.

> Issue #3:
> Hoe does one write a batchfile that does "open an xterm window; run XWin 
> first if necessary"? Being perhaps the most common usage case, such a 
> batchfile should be bundled in the Cygwin/X package and mentioned in the 
> documentation.

While a nice idea, you cannot currently.  It isn't that this has not 
been thought of previously, it is just that no one has the time to do 
such a thing.

> Note that /usr/X11R6/bin/startxwin.bat always runs a new instance of 
> XWin, even if one is already running. This can result in inefficiency 
> and confusion when the script is executed several times to open several 
> xterm windows (a natural thing to do). It's made even worse by issue #1 
> above.
> Also, startxwin.bat doesn't use -clipboard.

It is not a trivial thing to fix, and no one has asked for it 
previously.  However, you may be in luck because this is one of the 
things that is needed for a side project I am working on.  I think 
Takuma might have also been thinking about implementing this feature.

Harold


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
@ 2004-02-29 14:13   ` Eran Tromer
  2004-02-29 14:23     ` Harold L Hunt II
  2004-02-29 14:23     ` Takuma Murakami
  0 siblings, 2 replies; 10+ messages in thread
From: Eran Tromer @ 2004-02-29 14:13 UTC (permalink / raw)
  To: cygwin-xfree

On 2004-02-28 21:07, Harold L Hunt II wrote:

> > In multiwindow mode, XWin doesn't reset when the last client exists.
> It isn't supposed to. Run 'twm' as your window manager and you will
> see that the X Server does not reset when the last non-window manager
> client exits; this is because the window manager itself is a client.

ACK. I think this should be noted in the documentation -- I didn't
expect the "magical" window manager to count as a client.

As for preventing multiple instances of XWin, a kludgy way to do it is
by checking if anyone is listening on the X server port, using NETSTAT.
Example:

------------------------------
@echo off
rem Opens an xterm. Runs XWin first if needed.

set CYGWIN_ROOT=c:\cygwin
set DISPLAY_NUM=1

netstat -p tcp -a -n | %CYGWIN_ROOT%\bin\grep -E -q
    "^ +TCP +0\.0\.0\.0:600%DISPLAY_NUM% .* LISTENING"
set PATH=%CYGWIN_ROOT%\bin;%CYGWIN_ROOT%\usr\X11R6\bin
set HOME=
set DISPLAY=:%DISPLAY_NUM%
if not errorlevel 1 goto GOTX
start XWin %DISPLAY% -multiwindow -clipboard -dpi 96 -nowinkill
:GOTX
run xterm -ls -dpi 96
------------------------------

(Remove the linebreak from the the 'netstat' line above.)


BTW, -nounixkill seems to to be broken (Ctrl-Alt-Backspace still
terminates XWin).


   Eran


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
  2004-02-29 14:13   ` Eran Tromer
  2004-02-29 14:23     ` Harold L Hunt II
@ 2004-02-29 14:23     ` Takuma Murakami
  2004-02-29 18:21       ` Harold L Hunt II
  2004-03-03 21:54       ` cygwinx2eran
  1 sibling, 2 replies; 10+ messages in thread
From: Takuma Murakami @ 2004-02-29 14:23 UTC (permalink / raw)
  To: cygwin-xfree

Eran,

> As for preventing multiple instances of XWin, a kludgy way to do it is
> by checking if anyone is listening on the X server port, using NETSTAT.
> Example:

This feature is already implemented in my local tree (not
port based but mutex based detection).  It is in test and
documentation process and I will commit it to the public
CVS soon.

> BTW, -nounixkill seems to to be broken (Ctrl-Alt-Backspace still
> terminates XWin).

Thank you for reporting.

Takuma Murakami


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
  2004-02-29 14:13   ` Eran Tromer
@ 2004-02-29 14:23     ` Harold L Hunt II
  2004-02-29 14:23     ` Takuma Murakami
  1 sibling, 0 replies; 10+ messages in thread
From: Harold L Hunt II @ 2004-02-29 14:23 UTC (permalink / raw)
  To: cygwin-xfree

Eran Tromer wrote:
> On 2004-02-28 21:07, Harold L Hunt II wrote:
> 
>> > In multiwindow mode, XWin doesn't reset when the last client exists.
>> It isn't supposed to. Run 'twm' as your window manager and you will
>> see that the X Server does not reset when the last non-window manager
>> client exits; this is because the window manager itself is a client.
> 
> 
> ACK. I think this should be noted in the documentation -- I didn't
> expect the "magical" window manager to count as a client.

Well, it is a general sort of thing for all X Server based on the so 
called Sample Implementation that was made by X.Org years ago.  It isn't 
really specific to Cygwin/X.

Granted, it sometimes makes sense to describe general things in our 
documentation that get asked about a lot.  However, it may not be worth 
documenting since I am thinking about possibly disabling the automatic 
resets in most cases.

> As for preventing multiple instances of XWin, a kludgy way to do it is
> by checking if anyone is listening on the X server port, using NETSTAT.
> Example:

Well, that is certainly one way to do it, but we need a more general fix 
within XWin.exe itself that makes it automatically select an unused 
display number, verify that nothing is listening on that port already 
(some other application perhaps), then launch using that display number.

Of course, this also means that we need an option that says tells 
XWin.exe not to spawn another instance if if finds one is already 
running for the current user.  That way we can modify the 
XFree86-bin-icons package to automagically launch the X Server.  Hmm... 
but that will get tricky if we allow for multiple user machines and 
multiple instances of XWin.exe per user... that would mean that we would 
have to have a way to find out which of the current user's instances was 
a non-Xdmcp instance and what its display number was.

Yikes, this is starting to get complex.

> BTW, -nounixkill seems to to be broken (Ctrl-Alt-Backspace still
> terminates XWin).

Better report that in another thread so that interested parties will see it.

Harold


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
  2004-02-29 14:23     ` Takuma Murakami
@ 2004-02-29 18:21       ` Harold L Hunt II
  2004-03-03 21:54       ` cygwinx2eran
  1 sibling, 0 replies; 10+ messages in thread
From: Harold L Hunt II @ 2004-02-29 18:21 UTC (permalink / raw)
  To: cygwin-xfree

Takuma Murakami wrote:

> Eran,
> 
> 
>>As for preventing multiple instances of XWin, a kludgy way to do it is
>>by checking if anyone is listening on the X server port, using NETSTAT.
>>Example:
> 
> 
> This feature is already implemented in my local tree (not
> port based but mutex based detection).  It is in test and
> documentation process and I will commit it to the public
> CVS soon.

It is at least a good feature to fail when another instance of XWin.exe 
is operating on the same display number.  Your fix still allows running 
multiple instances like the following, right?

XWin :0 -query foo_host
XWin :1 -multiwindow
XWin :2 -fullscreen
...

As long as it allows the above and only fails if someone tries to do the 
following, then it will be fine:

XWin :0 ...
XWin :0 ... [should fail]
XWin :0 ... [should fail]

Harold


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
@ 2004-03-03 21:54       ` cygwinx2eran
  2004-03-04  9:02         ` Takuma Murakami
  2004-03-04 15:11         ` Ehud Karni
  0 siblings, 2 replies; 10+ messages in thread
From: cygwinx2eran @ 2004-03-03 21:54 UTC (permalink / raw)
  To: cygwin-xfree

Hi,

On 29-02-2004 14:11, Takuma Murakami wrote:

 >> As for preventing multiple instances of XWin
 > This feature is already implemented in my local tree (not
 > port based but mutex based detection).

I see that it's in 4.3.0-50 and working well, but I don't see how the 
current implementation addresses the common task I mentioned:
   "open an xterm; run XWin first if needed"
If I use a batchfile that always runs XWin and then xterm, from the 2nd 
invocation onwards it will produce the error popup reporting a "Fatal 
error" and directing me a to log file... Not quite what's needed here.[1]

Perhaps there should be a switch that says "if the display already 
exists, exit silently".

But that doesn't solve the case where I want to run additional programs 
(say, twm and xeyes) whenever a new display is created -- again a common 
scenario, I believe. One way to solve this is to add an option for 
checking the presence of an XWin instance on the given display number 
and exiting immediately with a corresponding errorcode; a batchfile can 
then check for the existance of an XWin instance, and if negative spawn 
XWin and related stuff. But this could lead to a race condition if two 
batchfiles do the check simultaneously. An alternative is to add an 
option for XWin to run some executable iff its startup succeeded.

Yes, I realize this is getting somewhat convoluted, but I think it's an 
important and common use case. I'm trying to move a certain large group 
of people to Cygwin/X, and the issue of "transparently" invoking 
Cygwin/X is one of the two major issues holding things back (the other 
one is multiwindow mode performance).

Regards,
   Eran


[1] For extra helpfulness, perhaps you could specify the nature of the 
fatal error at a prominent location inside the dialog box and not just 
inside the log file?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
  2004-03-03 21:54       ` cygwinx2eran
@ 2004-03-04  9:02         ` Takuma Murakami
  2004-03-04 15:11         ` Ehud Karni
  1 sibling, 0 replies; 10+ messages in thread
From: Takuma Murakami @ 2004-03-04  9:02 UTC (permalink / raw)
  To: cygwin-xfree

Eran,

> On 29-02-2004 14:11, Takuma Murakami wrote:
> 
>  >> As for preventing multiple instances of XWin
>  > This feature is already implemented in my local tree (not
>  > port based but mutex based detection).
> 
> I see that it's in 4.3.0-50 and working well, but I don't see how the 
> current implementation addresses the common task I mentioned:
>    "open an xterm; run XWin first if needed"
> If I use a batchfile that always runs XWin and then xterm, from the 2nd 
> invocation onwards it will produce the error popup reporting a "Fatal 
> error" and directing me a to log file... Not quite what's needed here.[1]
> 
> Perhaps there should be a switch that says "if the display already 
> exists, exit silently".

I agree.  We should have an option like "-silent" or "-quiet".

> But that doesn't solve the case where I want to run additional programs 
> (say, twm and xeyes) whenever a new display is created -- again a common 
> scenario, I believe. One way to solve this is to add an option for 
> checking the presence of an XWin instance on the given display number 
> and exiting immediately with a corresponding errorcode; a batchfile can 
> then check for the existance of an XWin instance, and if negative spawn 
> XWin and related stuff. But this could lead to a race condition if two 
> batchfiles do the check simultaneously. An alternative is to add an 
> option for XWin to run some executable iff its startup succeeded.

Let's suppose Cygwin/X has -silent option as above: then I
think startxwin.bat with -silent option is sufficient for your
purpose.  It will start a server (which silently fails if there
is the other) and then start some favorite applications.

Takuma Murakami


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
  2004-03-03 21:54       ` cygwinx2eran
  2004-03-04  9:02         ` Takuma Murakami
@ 2004-03-04 15:11         ` Ehud Karni
  1 sibling, 0 replies; 10+ messages in thread
From: Ehud Karni @ 2004-03-04 15:11 UTC (permalink / raw)
  To: cygwin-xfree

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 03 Mar 2004 23:57:22 +0200, cygwinx2eran@tromer.org wrote:
>
> On 29-02-2004 14:11, Takuma Murakami wrote:
>
>  >> As for preventing multiple instances of XWin
>  > This feature is already implemented in my local tree (not
>  > port based but mutex based detection).
>
> I see that it's in 4.3.0-50 and working well, but I don't see how the
> current implementation addresses the common task I mentioned:
>    "open an xterm; run XWin first if needed"
> If I use a batchfile that always runs XWin and then xterm, from the 2nd
> invocation onwards it will produce the error popup reporting a "Fatal
> error" and directing me a to log file... Not quite what's needed here.[1]

I have a similar problem on Linux (I use VNC virtual DISPLAY).
My solution is to use a shell script and check for the open port by
trying to connect to it. If this fails 5 times, I assume it is not
existing and do whats needed (I do check from remote computers too,
so "whats needed" varies). If the connection succeeds the application
is run with this DISPLAY. I wrote a small program that does the connect
with timeout, and a simple bash script that ensures killing the test
program if it hangs (which sometimes occurs).

Ehud.


- --
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry
-----BEGIN PGP SIGNATURE-----
Comment: use http://www.keyserver.net/ to get my key (and others)

iD8DBQFAR0cpLFvTvpjqOY0RAicrAJ9UfYPtmrdkZAEWvN0Wfn0dLT6iTACfW5ih
RTiI7UHJFx241QhRVoJ6V8w=
=Omh6
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: reset/terminate problems; preventing multiple XWin instances
@ 2004-03-04 10:37 gkorte
  0 siblings, 0 replies; 10+ messages in thread
From: gkorte @ 2004-03-04 10:37 UTC (permalink / raw)
  To: cygwin-xfree

>I see that it's in 4.3.0-50 and working well, but I don't see how the
>current implementation addresses the common task I mentioned:
>"open an xterm; run XWin first if needed"
>If I use a batchfile that always runs XWin and then xterm, from the 2nd
>invocation onwards it will produce the error popup reporting a "Fatal
>error" and directing me a to log file... Not quite what's needed here.[1]
>
>Perhaps there should be a switch that says "if the display already
>exists, exit silently".

Hi Eran,

I had the same problem and have solved it with the following Batch file:
-------------
@echo off
SET DISPLAY=127.0.0.1:0.0
SET CYGWIN_ROOT=\cygwin
SET PATH=.;%CYGWIN_ROOT%\bin;%CYGWIN_ROOT%\usr\X11R6\bin;%PATH%

REM Find a running version of XWin
c:\progra~1\resour~1\pulist |c:\progra~1\resour~1\qgrep XWin >nul
REM if Xwin is running then start an Xterm
if errorlevel 1 goto NEXT 
run C:\cygwin\usr\X11R6\bin\xterm -cr red -sl 1000 -sb -rightbar -ms red 
-fg white -bg black -e /usr/bin/bash --login
goto END

:NEXT
REM Delete temp and lock file and start XWin and Xterm.
attrib -s %CYGWIN_ROOT%\tmp\.X11-unix\X0 >nul
del %CYGWIN_ROOT%\tmp\.X11-unix\X0 >nul
start C:\cygwin\usr\X11R6\bin\XWin.exe -multiplemonitors -multiwindow -dpi 
100 -clipboard
run C:\cygwin\usr\X11R6\bin\xterm -cr red -sl 1000 -sb -rightbar -ms red 
-fg white -bg black -e /usr/bin/bash --login
:END
---------------
You will need pulist and qgrep which is included in w2k resource kit. 
Should you not have this then please contact me offlist cygwin@nai.nu

Basically this batch file start Xwin if pulist (like ps but for windows) 
does not return a XWin process.

Hope this helps

-- 
Kind regards
Geordy Korte


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-03-04 15:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-29  6:41 reset/terminate problems; preventing multiple XWin instances cygwinx2eran
2004-02-29 13:49 ` Harold L Hunt II
2004-02-29 14:13   ` Eran Tromer
2004-02-29 14:23     ` Harold L Hunt II
2004-02-29 14:23     ` Takuma Murakami
2004-02-29 18:21       ` Harold L Hunt II
2004-03-03 21:54       ` cygwinx2eran
2004-03-04  9:02         ` Takuma Murakami
2004-03-04 15:11         ` Ehud Karni
2004-03-04 10:37 gkorte

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).