public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
* CygwinX at MS Terminalserver?
@ 2010-08-12  7:31 Steffen Sledz
  2010-08-12 16:07 ` Jon TURNEY
  0 siblings, 1 reply; 11+ messages in thread
From: Steffen Sledz @ 2010-08-12  7:31 UTC (permalink / raw)
  To: cygwin-xfree

Does anyone has experiences running CygwinX at an MS Terminalserver? We like to use it at one based on Windows Server 2003 with NTFS.

Is it possible to run multiple XWin instances for multiple user sessions in parallel?

Any suggestions how to setup the rights in /tmp, /var/log, /var/run, etc.?

Steffen


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* Re: CygwinX at MS Terminalserver?
  2010-08-12  7:31 CygwinX at MS Terminalserver? Steffen Sledz
@ 2010-08-12 16:07 ` Jon TURNEY
  2010-08-13  8:23   ` Steffen Sledz
  2010-08-13 21:07   ` CygwinX at MS Terminalserver? Kurt Franke
  0 siblings, 2 replies; 11+ messages in thread
From: Jon TURNEY @ 2010-08-12 16:07 UTC (permalink / raw)
  To: cygwin-xfree; +Cc: sledz

On 12/08/2010 08:31, Steffen Sledz wrote:
> Does anyone has experiences running CygwinX at an MS Terminalserver? We like to use it at one based on Windows Server 2003 with NTFS.
>
> Is it possible to run multiple XWin instances for multiple user sessions in parallel?
>
> Any suggestions how to setup the rights in /tmp, /var/log, /var/run, etc.?

You shouldn't change the rights on any of these, as this could affect the 
security or functioning of other cygwin apps.

Fortunately, you shouldn't need to, as, provided each X server instance has a 
unique display number, everything should work :-)

Where you may experience problems is if the X server crashes whilst being run 
by an Administrator, and then a non-Adminstrator user tries to run X server 
using the same display number, which will fail due being unable to remove the 
stale lock file and unix socket.  Unfortunately, there is no obvious way to 
fix that without introducing a security hole (not that it is known to be 
secure anyhow)

-- 
Jon TURNEY
Volunteer Cygwin/X X Server maintainer

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* Re: CygwinX at MS Terminalserver?
  2010-08-12 16:07 ` Jon TURNEY
@ 2010-08-13  8:23   ` Steffen Sledz
  2010-08-13 10:39     ` Hermann-Josef Beckers
  2010-08-13 11:15     ` Jon TURNEY
  2010-08-13 21:07   ` CygwinX at MS Terminalserver? Kurt Franke
  1 sibling, 2 replies; 11+ messages in thread
From: Steffen Sledz @ 2010-08-13  8:23 UTC (permalink / raw)
  To: cygwin-xfree

Am 12.08.2010 18:04, schrieb Jon TURNEY:
> On 12/08/2010 08:31, Steffen Sledz wrote:
>> Does anyone has experiences running CygwinX at an MS
>> Terminalserver? We like to use it at one based on Windows
>> Server 2003 with NTFS.
>>
>> Is it possible to run multiple XWin instances for multiple
>> user sessions in parallel?
>>
>> Any suggestions how to setup the rights in /tmp, /var/log,
>> /var/run, etc.?
> 
> You shouldn't change the rights on any of these, as this could
> affect the security or functioning of other cygwin apps.
> 
> Fortunately, you shouldn't need to, as, provided each X server
> instance has a unique display number, everything should work :-)

This seems not to be right. :(

Here are the results of my tests:

testuser0001 starts an X server using the item "XWin Server" from the start menu. This results in the creation of some files/dirs with these rights.

------------>snip<----------------
$ ls -la /tmp /var/log
/tmp:
total 1
drwxrwxrwt+ 1 Administrator Administrators  0 Aug 13 08:55 .
drwxr-xr-x+ 1 Administrator Administrators  0 May 17 15:51 ..
-r--r--r--  1 testuser0001  Domain Users   11 Aug 13 08:54 .X0-lock
drwxrwxrwt+ 1 testuser0001  Domain Users    0 Aug 13 08:54 .X11-unix

/var/log:
total 2316
drwxrwxrwt+ 1 Administrator Administrators       0 Aug 13 08:54 .
drwxr-xr-x+ 1 Administrator Administrators       0 May 17 16:21 ..
-rw-r--r--  1 Administrator Administrators  139786 Aug 13 08:48 setup.log
-rw-r--r--  1 Administrator Administrators 2219958 Aug 13 08:48 setup.log.full
-rw-r--r--  1 testuser0001  Domain Users      4447 Aug 13 08:54 XWin.0.log
------------>snap<----------------

Now testuser0002 tries to start another server in parallel. This gives this error:

/usr/bin/startxwin:  Resource temporarily unavailable (errno 11):  Another X server instance is running on DISPLAY :0

Now testuser0001 stops his server by using the "Exit" item from the server menu. After this the files/dirs look like this.

------------>snip<----------------
$ ls -la /tmp /var/log
/tmp:
total 0
drwxrwxrwt+ 1 Administrator Administrators 0 Aug 13 08:58 .
drwxr-xr-x+ 1 Administrator Administrators 0 May 17 15:51 ..
drwxrwxrwt+ 1 testuser0001  Domain Users   0 Aug 13 08:58 .X11-unix

/var/log:
total 2316
drwxrwxrwt+ 1 Administrator Administrators       0 Aug 13 08:54 .
drwxr-xr-x+ 1 Administrator Administrators       0 May 17 16:21 ..
-rw-r--r--  1 Administrator Administrators  139786 Aug 13 08:48 setup.log
-rw-r--r--  1 Administrator Administrators 2219958 Aug 13 08:48 setup.log.full
-rw-r--r--  1 testuser0001  Domain Users      4871 Aug 13 08:58 XWin.0.log
------------>snap<----------------

Now testuser0002 tries to start a server. This results in an error popup:

------------>snip<----------------
A fatal error has occured and Cygwin/X will now exit.

Cannot open log file "/var/log/XWin.0.log"

Please open /var/log/XWin.%s.log for more information.

Vendor: The Cygwin/X Project
Release: 1.8.2.0 (10802000)
Contact: cygwin-xfree@cygwin.com
Build Date: 2010-08-06

XWin was started with the following command-line:

X :0 -multiwindow
------------>snap<----------------

> Where you may experience problems is if the X server crashes
> whilst being run by an Administrator, and then a non-Adminstrator
> user tries to run X server using the same display number, which
> will fail due being unable to remove the stale lock file and unix
> socket.  Unfortunately, there is no obvious way to fix that
> without introducing a security hole (not that it is known to be
> secure anyhow)

I think that's not the problem in this case.

Steffen


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* Re: CygwinX at MS Terminalserver?
  2010-08-13  8:23   ` Steffen Sledz
@ 2010-08-13 10:39     ` Hermann-Josef Beckers
  2010-08-13 11:15     ` Jon TURNEY
  1 sibling, 0 replies; 11+ messages in thread
From: Hermann-Josef Beckers @ 2010-08-13 10:39 UTC (permalink / raw)
  To: cygwin-xfree

cygwin-xfree-owner@cygwin.com schrieb am 13.08.2010 09:13:44:

...> 
> Am 12.08.2010 18:04, schrieb Jon TURNEY:
> > On 12/08/2010 08:31, Steffen Sledz wrote:
> >> Does anyone has experiences running CygwinX at an MS
> >> Terminalserver? We like to use it at one based on Windows
> >> Server 2003 with NTFS.
> >>
> >> Is it possible to run multiple XWin instances for multiple
> >> user sessions in parallel?
> >>
> >> Any suggestions how to setup the rights in /tmp, /var/log,
> >> /var/run, etc.?
> > 
> > You shouldn't change the rights on any of these, as this could
> > affect the security or functioning of other cygwin apps.
> > 
> > Fortunately, you shouldn't need to, as, provided each X server
> > instance has a unique display number, everything should work :-)
> 
> This seems not to be right. :(
> 
Maybe my way can help you. The following three lines are from my startup 
script:

(1) OLDDPY=$(netstat -an | grep 0:60|tail -1|gawk -F: '{print 
substr($2,3,2)  }')
(2) DPY=$(expr $OLDDPY + 1)
(3) run  Xwin  :$DPY -dpi 75 -swcursor  -logfile $HOME/$USER.log  ... more 
options

All X servers  use a port 60xx, so line (1) lists all net connections and
greps the relevant 60xx lines. tail -1 gives the highest used 60xx port.
The gawk returns the relevant 2 digits. Those get assigned to OLDDPY 
(old/last
display number). Line (2) simply adds 1 to OLDDPY and assigns that number
to DPY (you guess it, thats the new DISPLAY number ...). Line (3) starts
X(win) with the new $DPY number and the parameter "--logfile 
$HOME/$USER.log"
assigns a different logfile for each user. 

HTH
hjb



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* Re: CygwinX at MS Terminalserver?
  2010-08-13  8:23   ` Steffen Sledz
  2010-08-13 10:39     ` Hermann-Josef Beckers
@ 2010-08-13 11:15     ` Jon TURNEY
  2010-08-16 10:14       ` Steffen Sledz
  1 sibling, 1 reply; 11+ messages in thread
From: Jon TURNEY @ 2010-08-13 11:15 UTC (permalink / raw)
  To: cygwin-xfree; +Cc: sledz

On 13/08/2010 08:13, Steffen Sledz wrote:
> Am 12.08.2010 18:04, schrieb Jon TURNEY:
>> On 12/08/2010 08:31, Steffen Sledz wrote:
>>> Does anyone has experiences running CygwinX at an MS
>>> Terminalserver? We like to use it at one based on Windows
>>> Server 2003 with NTFS.
>>>
>>> Is it possible to run multiple XWin instances for multiple
>>> user sessions in parallel?
>>>
>>> Any suggestions how to setup the rights in /tmp, /var/log,
>>> /var/run, etc.?
>>
>> You shouldn't change the rights on any of these, as this could
>> affect the security or functioning of other cygwin apps.
>>
>> Fortunately, you shouldn't need to, as, provided each X server
>> instance has a unique display number, everything should work :-)
>
> This seems not to be right. :(
>
> Here are the results of my tests:
>
[snip]
>
> Now testuser0002 tries to start another server in parallel. This gives this error:
>
> /usr/bin/startxwin:  Resource temporarily unavailable (errno 11):  Another X server instance is running on DISPLAY :0

This is expected.  As I said, each X server instance must have a unique 
display number.

This can't possibly work any other way.  If two users both have an X server 
with display number 0, to which server should a client started with 
DISPLAY=:0.0 connect?

> Now testuser0001 stops his server by using the "Exit" item from the server menu. After this the files/dirs look like this.
[snip]
> /var/log:
> total 2316
> drwxrwxrwt+ 1 Administrator Administrators       0 Aug 13 08:54 .
> drwxr-xr-x+ 1 Administrator Administrators       0 May 17 16:21 ..
> -rw-r--r--  1 Administrator Administrators  139786 Aug 13 08:48 setup.log
> -rw-r--r--  1 Administrator Administrators 2219958 Aug 13 08:48 setup.log.full
> -rw-r--r--  1 testuser0001  Domain Users      4871 Aug 13 08:58 XWin.0.log
> ------------>snap<----------------
>
> Now testuser0002 tries to start a server. This results in an error popup:
>
> ------------>snip<----------------
> A fatal error has occured and Cygwin/X will now exit.
>
> Cannot open log file "/var/log/XWin.0.log"

This is interesting.  On my systems, /var/log has mode 777, rather than 1777.

Having the restricted deletion flag set on /var/log prevents other users from 
deleting the logfile from a previous run.

However, checking the source for setup.exe, I see that it does create /var/log 
with 1777 permissions, so how I got into this state I don't know...

I'm not sure that is right, but assuming it is intentional, I guess we need to 
create a /var/log/xwin with mode 777 and arrange for that to be the default 
logfile location

mkdir /var/log/xwin
chmod 777 /var/log/xwin
adding '-logfile /var/log/xwin/XWin.%s.log' to your xwin command line.

-- 
Jon TURNEY
Volunteer Cygwin/X X Server maintainer

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* Re: CygwinX at MS Terminalserver?
  2010-08-12 16:07 ` Jon TURNEY
  2010-08-13  8:23   ` Steffen Sledz
@ 2010-08-13 21:07   ` Kurt Franke
  1 sibling, 0 replies; 11+ messages in thread
From: Kurt Franke @ 2010-08-13 21:07 UTC (permalink / raw)
  To: cygwin-xfree

Jon TURNEY <jon.turney <at> dronecode.org.uk> writes:


> Where you may experience problems is if the X server crashes whilst being run 
> by an Administrator, and then a non-Adminstrator user tries to run X server 
> using the same display number, which will fail due being unable to remove the 
> stale lock file and unix socket.  Unfortunately, there is no obvious way to 
> fix that without introducing a security hole (not that it is known to be 
> secure anyhow)

Hi,

this problem could be handled.
Create a script which checks for existence of the PID written into the
file(s) /tmp/.X${DISPLAY_NUMBER}-lock and remove the Lockfile and also 
the Domainsocket for the same DISPLAY_NUMBER if the process doesn't exist. 
It is a good strategy to check for the string Xwin in the process command 
to ignore other processes which may got the same PID as the previous 
XServer process.
Either do this periodically in the script itself and start it via inittab 
or as a windows service, or run it via cron. Checking once a minute should 
be sufficient.

regards

kf




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* Re: CygwinX at MS Terminalserver?
  2010-08-13 11:15     ` Jon TURNEY
@ 2010-08-16 10:14       ` Steffen Sledz
  2010-08-27 16:32         ` Jon TURNEY
  0 siblings, 1 reply; 11+ messages in thread
From: Steffen Sledz @ 2010-08-16 10:14 UTC (permalink / raw)
  To: cygwin-xfree

Am 13.08.2010 13:09, schrieb Jon TURNEY:
>> Now testuser0002 tries to start another server in parallel.
>> This gives this error:
>>
>> /usr/bin/startxwin:  Resource temporarily unavailable (errno 11):  Another X server instance is running on DISPLAY :0
> 
> This is expected.  As I said, each X server instance must
> have a unique display number.
> 
> This can't possibly work any other way.  If two users both
> have an X server with display number 0, to which server should
> a client started with DISPLAY=:0.0 connect?

That's clear. I thought (or hoped) that starting X server using the "XWin Server" menu item automatically searches for an unused display number and uses it. I think that would be a good default behaviour.

>> A fatal error has occured and Cygwin/X will now exit.
>>
>> Cannot open log file "/var/log/XWin.0.log"
> 
> This is interesting.  On my systems, /var/log has mode 777,
> rather than 1777.
> 
> Having the restricted deletion flag set on /var/log prevents
> other users from deleting the logfile from a previous run.
> 
> However, checking the source for setup.exe, I see that it does
> create /var/log with 1777 permissions, so how I got into this
> state I don't know...
> 
> I'm not sure that is right, but assuming it is intentional, I
> guess we need to create a /var/log/xwin with mode 777 and arrange
> for that to be the default logfile location
> 
> mkdir /var/log/xwin
> chmod 777 /var/log/xwin
> adding '-logfile /var/log/xwin/XWin.%s.log' to your xwin command line.

I tested this with success. :)

It would be very helpfully too if this can become the default behaviour of the "XWin Server" menu item (or XWin).

Steffen



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* Re: CygwinX at MS Terminalserver?
  2010-08-16 10:14       ` Steffen Sledz
@ 2010-08-27 16:32         ` Jon TURNEY
  2010-09-20 14:21           ` Jon TURNEY
  0 siblings, 1 reply; 11+ messages in thread
From: Jon TURNEY @ 2010-08-27 16:32 UTC (permalink / raw)
  To: cygwin-xfree; +Cc: sledz

On 16/08/2010 07:35, Steffen Sledz wrote:
> Am 13.08.2010 13:09, schrieb Jon TURNEY:
>>> Now testuser0002 tries to start another server in parallel.
>>> This gives this error:
>>>
>>> /usr/bin/startxwin:  Resource temporarily unavailable (errno 11):  Another X server instance is running on DISPLAY :0
>>
>> This is expected.  As I said, each X server instance must
>> have a unique display number.
>>
>> This can't possibly work any other way.  If two users both
>> have an X server with display number 0, to which server should
>> a client started with DISPLAY=:0.0 connect?
>
> That's clear. I thought (or hoped) that starting X server using the "XWin Server" menu item automatically searches for an unused display number and uses it. I think that would be a good default behaviour.

I agree it would be useful, and it is on the todo list [1], but there's a 
non-trivial problem to solve first:

How is the display number which the server has allocated communicated to other 
processes, so that the users clients appear on the right display?

If you start the X server first and then launch everything from the traymenu, 
everything would works fine, as the X server places a correct DISPLAY variable 
into the environment inherited by the child process.

But if you start the X server via xinit/startx/startxwin, the display number 
needs to be communicated back to xinit, so that the correct display number is 
used for clients which are subsequently started by xinit.

Fedora ships with a patch [2] which adds the -displayfd option, which 
allocates a display number and writes it to the specified fd.  But to be 
useful to us, xinit would needs some code to use that flag (under some 
circumstances) and read that display number and use it for the clients it creates.

There's also the case where the user explicitly sets DISPLAY programmatically 
or manually before starting clients. I think with some suitable shell 
scripting, -displayfd probably can be used for that also.

[1] http://x.cygwin.com/devel/todo.html
[2] 
http://cvs.fedoraproject.org/viewvc/devel/xorg-x11-server/xserver-1.6.0-displayfd.patch

>>> A fatal error has occured and Cygwin/X will now exit.
>>>
>>> Cannot open log file "/var/log/XWin.0.log"
>>
>> This is interesting.  On my systems, /var/log has mode 777,
>> rather than 1777.
>>
>> Having the restricted deletion flag set on /var/log prevents
>> other users from deleting the logfile from a previous run.
>>
>> However, checking the source for setup.exe, I see that it does
>> create /var/log with 1777 permissions, so how I got into this
>> state I don't know...
>>
>> I'm not sure that is right, but assuming it is intentional, I
>> guess we need to create a /var/log/xwin with mode 777 and arrange
>> for that to be the default logfile location
>>
>> mkdir /var/log/xwin
>> chmod 777 /var/log/xwin
>> adding '-logfile /var/log/xwin/XWin.%s.log' to your xwin command line.
>
> I tested this with success. :)
>
> It would be very helpfully too if this can become the default behaviour of the "XWin Server" menu item (or XWin).

Well, it's not clear here how this should be fixed.

I *think* that  this is just a setup bug, and we can simply create /var/log 
with mode 777.

-- 
Jon TURNEY
Volunteer Cygwin/X X Server maintainer

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* Re: CygwinX at MS Terminalserver?
  2010-08-27 16:32         ` Jon TURNEY
@ 2010-09-20 14:21           ` Jon TURNEY
  2010-09-20 14:26             ` [PATCH] os: Add -displayfd option Jon TURNEY
  2010-09-20 14:27             ` [PATCH] Handle X server -displayfd option transparently Jon TURNEY
  0 siblings, 2 replies; 11+ messages in thread
From: Jon TURNEY @ 2010-09-20 14:21 UTC (permalink / raw)
  To: cygwin-xfree; +Cc: sledz

On 27/08/2010 16:52, Jon TURNEY wrote:
> On 16/08/2010 07:35, Steffen Sledz wrote:
>> Am 13.08.2010 13:09, schrieb Jon TURNEY:
>>>> Now testuser0002 tries to start another server in parallel.
>>>> This gives this error:
>>>>
>>>> /usr/bin/startxwin: Resource temporarily unavailable (errno 11): Another X
>>>> server instance is running on DISPLAY :0
>>>
>>> This is expected. As I said, each X server instance must
>>> have a unique display number.
>>>
>>> This can't possibly work any other way. If two users both
>>> have an X server with display number 0, to which server should
>>> a client started with DISPLAY=:0.0 connect?
>>
>> That's clear. I thought (or hoped) that starting X server using the "XWin
>> Server" menu item automatically searches for an unused display number and
>> uses it. I think that would be a good default behaviour.
>
> I agree it would be useful, and it is on the todo list [1], but there's a
> non-trivial problem to solve first:
>
> How is the display number which the server has allocated communicated to other
> processes, so that the users clients appear on the right display?

The fedora -displayfd patch seems to have moved and now lives at [1]

I've built an Xserver including an updated and modified version of this patch 
and uploaded it at [2].  Perhaps you could give that a try and see if it works 
for your purposes?

"-displayfd fd
specifies  a file descriptor in the launching process.  Rather than specify a 
display number, the X server will attempt to listen on successively higher 
display numbers, and upon finding a  free one, will write the display number 
back on this file descriptor as a newline-terminated string.  The -pn option 
is ignored when using -displayfd."

> If you start the X server first and then launch everything from the traymenu,
> everything would works fine, as the X server places a correct DISPLAY variable
> into the environment inherited by the child process.
>
> But if you start the X server via xinit/startx/startxwin, the display number
> needs to be communicated back to xinit, so that the correct display number is
> used for clients which are subsequently started by xinit.

I've also patched xinit/startxwin so they transparently handle the -displayfd 
X server option, uploaded at [3],[4]. They handle the -displayfd option 
specially to modify the fd number passed to the Xserver so they can read it's 
output and set the display number correctly for clients which xinit/startxwin 
starts, then write that display number to the originally specified fd.

(Patch to follow. Note that this patch probably won't apply to a stock 
xinit-1.2.1 as it's based on top of the patch which adds startxwin)

> Fedora ships with a patch [2] which adds the -displayfd option, which
> allocates a display number and writes it to the specified fd. But to be useful
> to us, xinit would needs some code to use that flag (under some circumstances)
> and read that display number and use it for the clients it creates.
>
> There's also the case where the user explicitly sets DISPLAY programmatically
> or manually before starting clients. I think with some suitable shell
> scripting, -displayfd probably can be used for that also.

Something along the lines of adding '-displayfd 3 3>~/.display' to the Xserver 
invocation, and then 'export DISPLAY=:`cat ~/.display`' to ~/.bashrc might be 
sufficient.

> [1] http://x.cygwin.com/devel/todo.html
> [2]
> http://cvs.fedoraproject.org/viewvc/devel/xorg-x11-server/xserver-1.6.0-displayfd.patch

[1] http://pkgs.fedoraproject.org/gitweb/?p=xorg-x11-server.git;a=tree
[2] ftp://cygwin.com/pub/cygwinx/XWin.20100916-git-df5773ea3927d9c1.exe.bz2
[3] ftp://cygwin.com/pub/cygwinx/startxwin.exe
[4] ftp://cygwin.com/pub/cygwinx/xinit.exe

-- 
Jon TURNEY
Volunteer Cygwin/X X Server maintainer

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* [PATCH] os: Add -displayfd option.
  2010-09-20 14:21           ` Jon TURNEY
@ 2010-09-20 14:26             ` Jon TURNEY
  2010-09-20 14:27             ` [PATCH] Handle X server -displayfd option transparently Jon TURNEY
  1 sibling, 0 replies; 11+ messages in thread
From: Jon TURNEY @ 2010-09-20 14:26 UTC (permalink / raw)
  To: cygwin-xfree; +Cc: Jon TURNEY, Adam Jackson

This option specifies a file descriptor in the launching process. X
will scan for an available display number and write that number back to
the launching process, at the same time as SIGUSR1 generation. This
means display managers don't need to guess at available display numbers.
As a consequence, if X fails to start when using -displayfd, it's not
because the display was in use, so there's no point in retrying the X
launch on a higher display number.

Signed-off-by: Adam Jackson <ajax@redhat.com>

Update for current X server
Fix null DISPLAY crash when stderr is closed
Rearrange init order to avoid null DISPLAY crash and correctly use
DISPLAY in default logfile name when logfile isn't specified on command line
Don't put '\'n on end of DISPLAY so internal XWin uses work correctly
Do a bit more logging about what we are trying to do

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 dix/globals.c        |    1 +
 dix/main.c           |    7 +++-
 doc/Xserver.man.pre  |    7 ++++
 hw/xwin/InitOutput.c |   10 +++---
 include/opaque.h     |    1 +
 os/connection.c      |   75 ++++++++++++++++++++++++++++++++++---------------
 os/osinit.c          |    4 +-
 os/utils.c           |   11 +++++++
 8 files changed, 84 insertions(+), 32 deletions(-)

diff --git a/dix/globals.c b/dix/globals.c
index c24a94f..19168f4 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -134,6 +134,7 @@ int defaultColorVisualClass = -1;
 int monitorResolution = 0;
 
 char *display;
+int displayfd;
 char *ConnectionInfo;
 
 CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND;
diff --git a/dix/main.c b/dix/main.c
index f023536..4e0ec93 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -168,8 +168,7 @@ int main(int argc, char *argv[], char *envp[])
 	DPMSPowerLevel = 0;
 #endif
 	InitBlockAndWakeupHandlers();
-	/* Perform any operating system dependent initializations you'd like */
-	OsInit();
+
 	if(serverGeneration == 1)
 	{
 	    CreateWellKnownSockets();
@@ -183,6 +182,10 @@ int main(int argc, char *argv[], char *envp[])
 	}
 	else
 	    ResetWellKnownSockets ();
+
+	/* Perform any operating system dependent initializations you'd like */
+	OsInit();
+
 	clients[0] = serverClient;
 	currentMaxClients = 1;
 
diff --git a/doc/Xserver.man.pre b/doc/Xserver.man.pre
index ce3b3a1..a6bd906 100644
--- a/doc/Xserver.man.pre
+++ b/doc/Xserver.man.pre
@@ -121,6 +121,13 @@ Not obeyed by all servers.
 .B \-core
 causes the server to generate a core dump on fatal errors.
 .TP 8
+.B \-displayfd \fIfd\fP
+specifies a file descriptor in the launching process.  Rather than specify
+a display number, the X server will attempt to listen on successively higher
+display numbers, and upon finding a free one, will write the display number back
+on this file descriptor as a newline-terminated string.  The \-pn option is
+ignored when using \-displayfd.
+.TP 8
 .B \-deferglyphs \fIwhichfonts\fP
 specifies the types of fonts for which the server should attempt to use
 deferred glyph loading.  \fIwhichfonts\fP can be all (all fonts),
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index b144136..295c010 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -700,13 +700,13 @@ OsVendorInit (void)
 
   if (!g_fLogInited) {
     /* keep this order. If LogInit fails it calls Abort which then calls
-     * ddxGiveUp where LogInit is called again and creates an infinite 
-     * recursion. If we set g_fLogInited to TRUE before the init we 
-     * avoid the second call 
-     */  
+     * ddxGiveUp where LogInit is called again and creates an infinite
+     * recursion. If we set g_fLogInited to TRUE before the init we
+     * avoid the second call
+     */
     g_fLogInited = TRUE;
     g_pszLogFile = LogInit (g_pszLogFile, NULL);
-  } 
+  }
   LogSetParameter (XLOG_FLUSH, 1);
   LogSetParameter (XLOG_VERBOSITY, g_iLogVerbose);
   LogSetParameter (XLOG_FILE_VERBOSITY, g_iLogVerbose);
diff --git a/include/opaque.h b/include/opaque.h
index b3c7c70..ea0ac13 100644
--- a/include/opaque.h
+++ b/include/opaque.h
@@ -50,6 +50,7 @@ extern _X_EXPORT int ScreenSaverAllowExposures;
 extern _X_EXPORT int defaultScreenSaverBlanking;
 extern _X_EXPORT int defaultScreenSaverAllowExposures;
 extern _X_EXPORT char *display;
+extern _X_EXPORT int displayfd;
 
 extern _X_EXPORT int defaultBackingStore;
 extern _X_EXPORT Bool disableBackingStore;
diff --git a/os/connection.c b/os/connection.c
index 85d0d10..9712729 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -146,6 +146,7 @@ Bool NewOutputPending;		/* not yet attempted to write some new output */
 Bool AnyClientsWriteBlocked;	/* true if some client blocked on write */
 
 static Bool RunFromSmartParent;	/* send SIGUSR1 to parent process */
+static char dynamic_display[7];
 Bool PartialNetwork;	/* continue even if unable to bind all addrs */
 static Pid_t ParentProcess;
 
@@ -374,9 +375,25 @@ NotifyParentProcess(void)
 	    kill (ParentProcess, SIGUSR1);
 	}
     }
+    if (dynamic_display[0]) {
+        write(displayfd, dynamic_display, strlen(dynamic_display));
+        write(displayfd, "\n", 1);
+    }
 #endif
 }
 
+static Bool
+TryCreateSocket(int num, int *partial)
+{
+    char port[20];
+
+    sprintf(port, "%d", num);
+
+    return _XSERVTransMakeAllCOTSServerListeners(port, partial,
+						 &ListenTransCount,
+						 &ListenTransConns);
+}
+
 /*****************
  * CreateWellKnownSockets
  *    At initialization, create the sockets to listen on for new clients.
@@ -387,7 +404,6 @@ CreateWellKnownSockets(void)
 {
     int		i;
     int		partial;
-    char 	port[20];
 
     FD_ZERO(&AllSockets);
     FD_ZERO(&AllClients);
@@ -402,32 +418,45 @@ CreateWellKnownSockets(void)
 
     FD_ZERO (&WellKnownConnections);
 
-    sprintf (port, "%d", atoi (display));
-
-    if ((_XSERVTransMakeAllCOTSServerListeners (port, &partial,
-	&ListenTransCount, &ListenTransConns) >= 0) &&
-	(ListenTransCount >= 1))
+    if (display)
     {
-	if (!PartialNetwork && partial)
-	{
-	    FatalError ("Failed to establish all listening sockets");
-	}
-	else
+	if (TryCreateSocket(atoi(display), &partial) &&
+	    (ListenTransCount >= 1))
+	    if (!PartialNetwork && partial)
+		FatalError ("Failed to establish all listening sockets");
+    }
+    else /* -displayfd */
+    {
+	Bool found = 0;
+	for (i = 0; i < 65535 - 1024; i++)
 	{
-	    ListenTransFds = xalloc (ListenTransCount * sizeof (int));
-
-	    for (i = 0; i < ListenTransCount; i++)
+	    ErrorF("Trying to create socket for display number %d\n", i);
+	    if (!TryCreateSocket(i, &partial) && !partial)
 	    {
-		int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i]);
-		
-		ListenTransFds[i] = fd;
-		FD_SET (fd, &WellKnownConnections);
-
-		if (!_XSERVTransIsLocal (ListenTransConns[i]))
-		{
-		    DefineSelf (fd);
-		}
+		found = 1;
+		break;
 	    }
+	    else
+		CloseWellKnownConnections();
+	}
+	if (!found)
+	    FatalError("Failed to find a socket to listen on");
+	sprintf(dynamic_display, "%d", i);
+	display = dynamic_display;
+    }
+
+    ListenTransFds = xalloc(ListenTransCount * sizeof (int));
+
+    for (i = 0; i < ListenTransCount; i++)
+    {
+	int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i]);
+
+	ListenTransFds[i] = fd;
+	FD_SET (fd, &WellKnownConnections);
+
+	if (!_XSERVTransIsLocal (ListenTransConns[i]))
+	{
+	    DefineSelf (fd);
 	}
     }
 
diff --git a/os/osinit.c b/os/osinit.c
index e8fcd45..0043d46 100644
--- a/os/osinit.c
+++ b/os/osinit.c
@@ -229,8 +229,8 @@ OsInit(void)
 	{
 	    FILE *err;
 
-	    if (strlen (display) + strlen (admpath) + 1 < sizeof fname)
-		sprintf (fname, admpath, display);
+	    if ((display) && (strlen (display) + strlen (ADMPATH) + 1 < sizeof fname))
+		sprintf (fname, ADMPATH, display);
 	    else
 		strcpy (fname, devnull);
 	    /*
diff --git a/os/utils.c b/os/utils.c
index 2a73a57..db53099 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -670,6 +670,17 @@ ProcessCommandLine(int argc, char *argv[])
 	    else
 		UseMsg();
 	}
+	else if (strcmp(argv[i], "-displayfd") == 0)
+	{
+	    if (++i < argc)
+	    {
+		displayfd = atoi(argv[i]);
+		display = NULL;
+		nolock = TRUE;
+	    }
+	    else
+		UseMsg();
+	}
 #ifdef DPMSExtension
 	else if ( strcmp( argv[i], "dpms") == 0)
 	    /* ignored for compatibility */ ;
-- 
1.7.1


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

* [PATCH] Handle X server -displayfd option transparently
  2010-09-20 14:21           ` Jon TURNEY
  2010-09-20 14:26             ` [PATCH] os: Add -displayfd option Jon TURNEY
@ 2010-09-20 14:27             ` Jon TURNEY
  1 sibling, 0 replies; 11+ messages in thread
From: Jon TURNEY @ 2010-09-20 14:27 UTC (permalink / raw)
  To: cygwin-xfree; +Cc: Jon TURNEY


Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 xinit.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/xinit.c b/xinit.c
index 918f83e..95ba13c 100644
--- a/xinit.c
+++ b/xinit.c
@@ -168,6 +168,11 @@ int serverpid = -1;
 int clientpid = -1;
 volatile int gotSignal = 0;
 
+static int original_displayfd = -1;
+static int server_displayfd_read = -1;
+static char server_displayfd_write[256];
+static char displayfd_buf[256];
+
 static void Execute ( char **vec, char **envp );
 static Bool waitforserver ( void );
 static Bool processTimeout ( int timeout, char *string );
@@ -319,14 +324,40 @@ main(int argc, char *argv[], char *envp[])
 	}
 	if (argc > 0 && (argv[0][0] == ':' && isdigit(argv[0][1])))
 		displayNum = *argv;
-	else
-		displayNum = *sptr++ = default_display;
 
 	start_of_server_args = (sptr - server);
 	while (--argc >= 0) {
+		/* Handle the -displayfd server argument transparently */
+		if ((argc > 0) && (strcmp(argv[0],"-displayfd") == 0))
+                  {
+                    int filedes[2];
+
+                    original_displayfd = atoi(argv[1]);
+
+                    if (pipe(filedes) == 0)
+                      {
+                        server_displayfd_read = filedes[0];
+                        sprintf(server_displayfd_write, "%d", filedes[1]);
+                        argv[1] = server_displayfd_write;
+                      }
+                    else
+                      {
+                        Fatal("pipe() for -displayfd failed");
+                      }
+                  }
+
 		server_args_given++;
 		*sptr++ = *argv++;
 	}
+
+        /*
+          if there was neither an explicit displayNum nor a
+          -displayfd option, add the default display number
+          to server arguments
+        */
+        if ((displayNum == NULL) && (original_displayfd == -1))
+          displayNum = *sptr++ = default_display;
+
 #ifdef STARTXWIN
 	*sptr++ = "-multiwindow";
 #endif
@@ -391,11 +422,6 @@ main(int argc, char *argv[], char *envp[])
 #endif
 
 	/*
-	 * put the display name into the environment
-	 */
-	set_environment ();
-
-	/*
 	 * Start the server and client.
 	 */
 #ifdef SIGCHLD
@@ -423,7 +449,7 @@ main(int argc, char *argv[], char *envp[])
 #endif
 #endif
 
-	if (XOpenDisplay(displayNum)) {
+	if (displayNum && XOpenDisplay(displayNum)) {
 		Error("Another X server instance is running on DISPLAY %s\r\n", displayNum);
 		exit(ERR_EXIT);
 	}
@@ -487,6 +513,32 @@ waitforserver(void)
 	sleep(2);
 #endif
 
+        if (server_displayfd_read != -1)
+          {
+            /* wait for the server to write the DISPLAY number to the displayfd pipe */
+            int length;
+
+            displayfd_buf[0] = ':';
+            length = read(server_displayfd_read, displayfd_buf+1, 255);
+
+            if (length < 0)
+              Fatal("reading displayfd pipe failed");
+            displayfd_buf[length] = '\0';
+
+            printf("read display number '%s' from X server\n", displayfd_buf);
+            displayNum = displayfd_buf;
+
+            /* write the DISPLAY received from the server to the original displayfd */
+            /* XXX: this should happen after connections are being accepted */
+            write(original_displayfd, displayfd_buf+1, length);
+            write(original_displayfd, "\n", 1);
+          }
+
+	/*
+	 * put the display name into the environment
+	 */
+	set_environment ();
+
 	for (cycles = 0; cycles < ncycles; cycles++) {
 		if ((xd = XOpenDisplay(displayNum))) {
 			return(TRUE);
-- 
1.7.1


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


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

end of thread, other threads:[~2010-09-20 14:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12  7:31 CygwinX at MS Terminalserver? Steffen Sledz
2010-08-12 16:07 ` Jon TURNEY
2010-08-13  8:23   ` Steffen Sledz
2010-08-13 10:39     ` Hermann-Josef Beckers
2010-08-13 11:15     ` Jon TURNEY
2010-08-16 10:14       ` Steffen Sledz
2010-08-27 16:32         ` Jon TURNEY
2010-09-20 14:21           ` Jon TURNEY
2010-09-20 14:26             ` [PATCH] os: Add -displayfd option Jon TURNEY
2010-09-20 14:27             ` [PATCH] Handle X server -displayfd option transparently Jon TURNEY
2010-08-13 21:07   ` CygwinX at MS Terminalserver? Kurt Franke

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).