0

I built an image with X11 using yocto for a Raspberry Pi 3 and a touchscreen. I can start my app built with Electron (chromium) by running commands manually in a serial session:

export DISPLAY=:0
/usr/lib/node/electron/dist/electron --no-sandbox /home/root/app

I though to use an init.d script to do it automatically at startup but I'd like to do it the proper way. I tried to create an .Xsession file in my user directory with the commands above but it doesn't work and I don't know if I can get logs of what happened.

According to this wiki, there is a lot of steps at X11 startup. Currently, I only see a Terminal (from Matchbox I guess) and a mouse cursor.

What's the "standard" way to start an app with the system and is there a way to remove the cursor for a touchscreen?

Edit

Here is the content of my /etc/X11 directory:

  • Xsession
  • Xsession.d/
  • xinit/
  • xorg.conf

Xsession:

#!/bin/sh

if [ -x /usr/bin/dbus-launch ]; then
    # As this is the X session script, always start a new DBus session.
    eval `dbus-launch --sh-syntax --exit-with-session </dev/null`
    echo "D-BUS per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi

. /etc/profile

if [ -f $HOME/.profile ]; then
    . $HOME/.profile
fi

SYSSESSIONDIR=/etc/X11/Xsession.d

export CLUTTER_DISABLE_MIPMAPPED_TEXT=1

for SESSIONFILE in $SYSSESSIONDIR/*; do
    set +e
    case "$SESSIONFILE" in
        *.sh)
            . "$SESSIONFILE"
            ;;
        *.shbg)
            "$SESSIONFILE" &
            ;;
        *~)
            # Ignore backup files
            ;;
        *)
            "$SESSIONFILE"
            ;;
    esac
    set -e
done

exit 0

xorg.conf: empty.

Xsession.d/:

  • 13xdgbasedirs.sh
  • 30xinput_calibrate.sh
  • 89xdgautostart.sh
  • 90XWindowManager.sh

89xdgautostart.sh:

XDGAUTOSTART=/etc/xdg/autostart
if [ -d $XDGAUTOSTART ]; then
    for SCRIPT in $XDGAUTOSTART/*; do
        CMD=`grep ^Exec= $SCRIPT | cut -d '=' -f 2`
        $CMD &
    done
fi

90XWindowManager.sh:

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

There is also a file /etc/xserver-nodm/Xserver:

#!/bin/sh

# This script is only needed to make sure /etc/X11/xserver-common
# can affect XSERVER, ARGS & DPI: otherwise systemd could just use
# /etc/default/xserver-nodm as EnvironmentFile and sysvinit could just
# source the same file

. /etc/profile

# load default values for XSERVER, ARGS, DISPLAY...
. /etc/default/xserver-nodm

# Allow xserver-common to override ARGS, XSERVER, DPI
if [ -e /etc/X11/xserver-common ] ; then
    . /etc/X11/xserver-common
    if [ ! -e $XSERVER ] ; then
        XSERVER=$(which $XSERVER)
    fi
fi

if [ -n "$DPI" ] ; then
    ARGS="$ARGS -dpi $DPI"
fi

exec xinit /etc/X11/Xsession -- $XSERVER $DISPLAY $ARGS $*

and a file /etc/rc5.d/S09xserver-nodm:

#!/bin/sh
#
### BEGIN INIT INFO
# Provides: xserver
# Required-Start: $local_fs $remote_fs dbus
# Required-Stop: $local_fs $remote_fs
# Default-Start:     5
# Default-Stop:      0 1 2 3 6
### END INIT INFO

killproc() {            # kill the named process(es)
        pid=`/bin/pidof $1`
        [ "$pid" != "" ] && kill $pid
}

read CMDLINE < /proc/cmdline
for x in $CMDLINE; do
        case $x in
        x11=false)
        echo "X Server disabled" 
        exit 0;
                ;;
        esac
done

case "$1" in
  start)
       . /etc/profile

       #default for USER
       . /etc/default/xserver-nodm
       echo "Starting Xserver"
       if [ "$USER" != "root" ]; then
           # setting for rootless X
           chmod o+w /var/log
           chmod g+r /dev/tty[0-3]
           # hidraw device is probably needed
           if [ -e /dev/hidraw0 ]; then
               chmod o+rw /dev/hidraw*
           fi
       fi

       # Using su rather than sudo as latest 1.8.1 cause failure [YOCTO #1211]
       su -l -c '/etc/xserver-nodm/Xserver &' $USER
       # Wait for the desktop to say its finished loading
       # before loading the rest of the system
       # dbus-wait org.matchbox_project.desktop Loaded
  ;;

  stop)
        echo "Stopping XServer"
        killproc xinit
        sleep 1
        chvt 1 &
  ;;

  restart)
    $0 stop
        $0 start
  ;;

  *)
        echo "usage: $0 { start | stop | restart }"
  ;;
esac

exit 0

1 Answer 1

1

The correct way to define a complete X session depends on your session manager: on Yocto that is often matchbox-session or mini-x-session. From your description I'd guess you're using mini-x-session (it happens to start a terminal and a window-manager if session file is not found).

Quoting mini-x-session:

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

So adding a /etc/mini_x/session script should work.

By the way, in your session file you may also want to start a window manager (X can do weird things without one):

your-app-here &
exec matchbox-window-manager
3
  • I don't have a /etc/mini_x directory. I added the content of the probably most relevant files from the /etc directory to my question.
    – didil
    Commented Jan 16, 2020 at 12:48
  • Well, if you are using mini-x-session you can just create the directory and the file... Commented Jan 16, 2020 at 14:47
  • I created a new .Xsession file but instead of !/bin/bash I've written !/bin/sh at the beginning and it works! Thanks.
    – didil
    Commented Jan 16, 2020 at 15:18

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