Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to launch get a Qt application to launch after immediately after booting up. When booted, the Linux image does nothing more than launch an X server and a terminal. It also has the cron daemon running in the background. Obviously, my Qt application needs the X server to be running to do anything.

I've seen a similar question for Red Hat and SUSE linux: http://stackoverflow.com/questions/4144222/running-a-qt-application-at-startup

However, I don't see this working for my image.

I'm wondering if there is a standard way in Linux/UNIX to make a GUI application start immediately after the X Server.


EDIT 1

[sj755@localhost X11]$ tree /etc/X11/
/etc/X11/
|-- functions
|-- Xdefaults
|-- Xinit
|-- Xinit.d
|   |-- 01xrandr
|   |-- 11zaurus
|   |-- 12keymap
|   |-- 40xmodmap
|   |-- 50setdpi
|   |-- 55xScreenSaver
|   |-- 60xXDefaults
|   |-- 89xTs_Calibrate
|   `-- 98keymap-fixup
|-- xmodmap
|   |-- a716.xmodmap
|   |-- collie.xmodmap
|   |-- default.xmodmap
|   |-- h1910.xmodmap
|   |-- h2200.xmodmap
|   |-- h6300.xmodmap
|   |-- hx4700.xmodmap
|   |-- keyboardless.xmodmap
|   |-- omap5912osk.xmodmap
|   |-- poodle.xmodmap
|   |-- shepherd.xmodmap
|   |-- simpad.xmodmap
|   |-- slcXXXX.xmodmap
|   |-- xmodmap-invert
|   |-- xmodmap-left
|   |-- xmodmap-portrait
|   `-- xmodmap-right
|-- xorg.conf
|-- Xserver
|-- xserver-common
|-- Xsession
`-- Xsession.d
    |-- 60xXDefaults
    |-- 89xdgautostart
    `-- 90xXWindowManager

3 directories, 36 files

EDIT 2

root@devboard:~# cat /etc/X11/Xsession.d/90xXWindowManager
if [ -x $HOME/.Xsession ]; then
    exec $HOME/.Xsession
elif [ -x /usr/bin/x-session-manager ]; then
    exec /usr/bin/x-session-manager
else
    exec /usr/bin/x-window-manager
fi

EDIT 3

#!/bin/sh
#
# Very simple session manager for Mini X
#

# Uncomment below to enable parsing of debian menu entrys
# export MB_USE_DEB_MENUS=1 

if [ -e $HOME/.mini_x/session ]
then
exec $HOME/.mini_x/session
fi

if [ -e /etc/mini_x/session ]
then
exec /etc/mini_x/session
fi

MINI_X_SESSION_DIR=/etc/mini_x/session.d
if [ -d "$MINI_X_SESSION_DIR" ]; then
    # Execute session file on behalf of file owner
    find $MINI_X_SESSION_DIR -type f | while read SESSIONFILE; do
        set +e
        USERNAME=`stat -c %U $SESSIONFILE`
        # Using su rather than sudo as latest 1.8.1 cause failure [YOCTO #1211]
#       su -l -c '$SESSIONFILE&' $USERNAME
        sudo -b -i -u $USERNAME $SESSIONFILE&
        set -e
    done
fi

# This resolution is big enough for hob2's max window size.
xrandr -s 1024x768

# Default files to run if $HOME/.mini_x/session or /etc/mini_x/session
# dont exist. 

matchbox-terminal&
exec matchbox-window-manager
share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Have a look at /etc/X11/xinit/xinitrc (this may be different places on different systems) to see what files it sources. Generally, this will have an if..elif..else structure, so that only one initialization file is read, with $HOME/.Xclients prioritized then /etc/X11/xinit/Xclients. That's almost certainly where the terminal that appears comes from (I am presuming you do not have a desktop environment installed or anything).

Anyway, if you just want to run a single GUI app, create (or modify) an Xclients file like this:

#!/bin/sh

myGUIapp

This should be executable. It's pretty much a normal shell script, I believe, so you can have more stuff in there, although obviously not backgrounding a GUI app will block execution at that point.

[later addition]

Your installation doesn't have exactly those files, but it does have an /etc/X11/Xinit.d and if you look, I am sure those are short shell scripts and they are sourced from somewhere, probably one of the files in /etc/X11 -- Xsession, Xserver, or xserver-common. You might want to check if $XINITRC is defined in your environment; that will be a clue.

Your best bet is probably to just create a $HOME/.Xclients file (or as jofel mentions, $HOME/.xinitrc, which is probably more universal) and try it -- exactly that spelling and case, with a leading dot, and it should be set chmod 755 (the group and other permissions may not matter). Almost certainly this will be sourced from somewhere properly.

You can put files in /etc/X11/Xinit.d yourself, but doing it for this purpose is not a good idea because yours should run last and block further execution. So have a look at the scripts in /etc/X11 (again: Xsession, etc., they don't have a .sh suffix) and try to figure out in what order they all chain together. It is also likely that somewhere one of them checks for an Xclients file, eg via something like

if [ -x /some/path/Xclients ]; then

$HOME may also be used, and .xinitrc. Which is why creating at least one of these variations should work (write the file and move around/rename it if at first you don't succeed). To summarize: prime candidates for the name: .xinitrx and .Xclients, in either $HOME or /etc/X11/, but if in the later, ditch the leading dot.

share|improve this answer
    
I've updated my question, showing the /etc/X11 directory tree. I don't see an xinitrc file. –  sj755 Jul 18 '13 at 16:17
1  
@sj755: Okay, read what I've added after "later addition". –  goldilocks Jul 18 '13 at 16:51
    
I found a file of interest. I've posted its contents. It seems to execute a file called $HOME/.Xsessions. I tried putting my script in that. It seems I broke the X Server. Luckily it's only an embedded Linux device and I can quickly recreate the image. –  sj755 Jul 18 '13 at 17:18
1  
:( $HOME/.Xsessions looks to be it to me. I'm not sure what you mean by "broke" the X Server -- do you have logging available? If so check /var/log/Xorg.0.log. –  goldilocks Jul 18 '13 at 17:30
1  
@sj755: That's exactly right. Try removing/commenting out matchbox-terminal& and replacing matchbox-window-manager with your app. You may not need a window manager running in order to get your QT code to fullscreen the app, so that is worth trying to save a bit of RAM (this will also mean the window can't be manipulated by the user, if there is any interaction applicable). Otherwise do with &, like the terminal. –  goldilocks Jul 18 '13 at 18:10
show 3 more comments

You can add the command to the $HOME/.xinitrc of the user which starts the X server.

Need to be an executable $HOME/.xinitrc shell script (first line #!/bin/sh and chmod +x $HOME/.xinitrc).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.