RE: Checking if the X Server is running

2007-10-01 Thread Phil Betts
O. Olson wrote on Monday, October 01, 2007 1:49 AM::

>   I still don't think I can get this to work. I tried
> this from the command line (and my file is in
> /usr/local/bin/sd.sh)
> 
> C:\cygwin\bin\bash --login /usr/local/bin/sd.sh
> 
> This still brings up the Fatal Error Window.
> 

It's probably not the cause of your problem, but you should
never use "ps | grep xxx" to detect if a process is running.
This is because the grep process will (sometimes) detect 
itself and give you a false positive, and your xterm will 
try to start when there is no server running.

Since you already installed checkx, that's what you should 
be using, because (I believe) it actually connects to the X
server.

What you may be experiencing, is a race condition between
whatever process actually started X and the sd.sh.

I.e. if you initially start X using startxwin.bat (or similar),
and it hasn't got as far as starting the server when sd.sh 
checks if it's running, sd.sh will try to start the server.  
However, by the time sd.sh gets round to starting X, the 
first server has started, and therefore the second gives you 
the error.

Try something like this:


#!/bin/bash -l

# wait up to 5 seconds before deciding if X needs starting. You may
# need to up this to 10 seconds or more depending on your system.
wait_for_x ()
{
x_down=1
for (( i=0 ; i < 5 ; i++ ));do
echo "waiting for X"
if checkx;then
x_down=0
break
fi
sleep 1
done
return $x_down
}

if ! wait_for_x;then
  # X not yet up
  run XWin  # see [1]
  wait_for_x# see [2]
fi

exec xterm


[1] I don't advise running XWin directly.  It is better to use 
startxwin.sh.  This ensures that the required environment variables 
are set up, and that any stray socket left from an earlier unclean 
exit is cleaned up.  The script does what it does for good reasons.
Of course the default startxwin.sh starts xterm anyway, so you may
want to edit it.  (IMHO it was a big mistake to start xterm in the 
server start scripts.  It confuses way too many newbies, who think 
the scripts are the proper way to start xterm, then complain when 
they get errors trying to open a second xterm.)

[2] The run command returns control to bash before XWin has finished 
initialising, so the wait is necessary to ensure that xterm isn't
started before the server is usable.


Phil

--
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/



Re: Checking if the X Server is running

2007-10-01 Thread Holger Krull
Holger Krull schrieb:
> Holger Krull schrieb:
> I was to fast on my last email. I tested it now:
> You need (on windows):
> set DISPLAY=127.0.0.1:0.0& c:\cygwin\bin\bash.exe -l /home/krull/test.sh
> 
> (it is important that there is no space between 0.0 and &)
> 
> test.sh:
> #!/bin/sh
> ps |grep -i /xwin >/dev/null
> if [ $? -eq "0" ]
> then
>xterm -e /usr/bin/bash -l &
> else
>run XWin :2 -multiwindow -clipboard -silent-dup-error

that :2 is from my testing, sorry, doesn't belong there

>xterm -e /usr/bin/bash -l &
> fi
> 
> 
> 
> --
> 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/
> 


--
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/



Re: Checking if the X Server is running

2007-10-01 Thread Holger Krull
Holger Krull schrieb:
I was to fast on my last email. I tested it now:
You need (on windows):
set DISPLAY=127.0.0.1:0.0& c:\cygwin\bin\bash.exe -l /home/krull/test.sh

(it is important that there is no space between 0.0 and &)

test.sh:
#!/bin/sh
ps |grep -i /xwin >/dev/null
if [ $? -eq "0" ]
then
   xterm -e /usr/bin/bash -l &
else
   run XWin :2 -multiwindow -clipboard -silent-dup-error
   xterm -e /usr/bin/bash -l &
fi



--
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/



Re: Checking if the X Server is running

2007-10-01 Thread Holger Krull
O. Olson schrieb:
> --- Holger Krull <[EMAIL PROTECTED]> ha scritto:

Teach your email program to not include the full email adress while quoting!

 
> #!/bin/sh
> if `ps | grep XWin > /dev/null`

I suggest using grep -i 
to make it case ignoring. I found a cygwin installation that has Xwin and not 
XWin in the process list.


> Now I modified the above shell script to: 
> 
> --
> #!/bin/sh
> if `ps | grep XWin > /dev/null`
>then
>   xterm -e /usr/bin/bash -l
>else
>   XWin -multiwindow -clipboard -silent-dup-error

My guess is access control, try adding -ac to the xwin parameters to find out.




--
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/