LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   Connecting to X display in a startup script (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/connecting-to-x-display-in-a-startup-script-929785/)

mjoyce 02-16-2012 05:39 PM

Connecting to X display in a startup script
 
I'm running Ubuntu 10.04, rootstock filesys, on a Marvell ARM CPU. I am trying to start a Gtk application at system boot time. I created /etc/rc2.d/S50app and made it executable, and it contains:
/home/ubuntu/test.sh &

test.sh contains:
-----
#!/bin/sh
sleep 8
startx &
sleep 8
export DISPLAY=:0.0
my_program
-----

On startup startx runs normally, and my_program executes it's non-X components, but when it tries to write to the Xserver it fails with a
"cannot open display: :0.0" message.

Changing test.sh to run a normal video player instead of my_program gives a similar result. The audio track plays, but the video player gives me errors:
VIDEO: MPEG1 384x288 (aspect 1) 25.000 fps 0.0 kbps ( 0.0 kbyte/s)
No protocol specified
vo: couldn't open the X11 display (:0.0)!
Error opening/initializing the selected video_out (-vo) device.

All this works as expected if I don't do anything in /etc/rc2.d, and instead log in as a user and run test.sh.

How can I make my program or a video player connect to the X display, when everything is started from a rcN.d script?

ShadowCat8 02-16-2012 06:40 PM

Hmmmm...

Well, this sounds to me like an issue I encountered a while back when I was trying to use the xdm display for a framebuffer for a server-side application...

Now, first, I would ask: When the Xserver starts, and you log into the box from a console, can you run the following without error?
Code:

~ # DISPLAY=:0 xclock
If you don't have xclock on the system, just use any simple graphical app... xeyes or gedit will do just fine. Notice that I'm simplifying which DISPLAY you are trying to access. We want to pass it to the first Xserver and not a specific screen. Let's see if that will help.

If you run the app and get the same "cannot open display" message, then let's try the following and see what happens.
  • From the console, type the following:
    Code:

    xhost +localhost
  • Now try to run the "DISPLAY=:0 <app>" command again and see if it goes.

HTH. Let us know.

dumacx 02-17-2012 05:43 AM

try this, in the rcX:

/bin/xinit /etc/xinit-app -- :0.0


and in the /etc/xinit-app:

youraplication.sh

mjoyce 02-17-2012 02:49 PM

Thanks
 
ShadowCat8 - may app runs under those conditions, it's only when I try to run it all from startup that the app fails to connect to the X server. Starting X from rc2.d, and then logging in and from my tty running DISPLAY=:0 <my_app> worked. Sort of obviates the need for xhost +localhost, but even so that didn't fix things. The problem is centered around running both X, and the app, from a startup script.

dumacx - interesting idea. It worked. Now I need to try to understand what is going on. I should also try to figure out more about the difference between xinit and startx.

Thanks both.


All times are GMT -5. The time now is 08:34 AM.