Error when executing Totalcross application as SystemD Service

Hi,

I’m working on a sample application that I want to be automatically executed when the system initializes/boots.

When starting the application from the command-line, everything works fine, I can see the application on the screen and interact with it.

But when trying to start the application from its service, I got the following error:

Jan 20 14:00:19 apalis-imx6 systemd[1]: Started GUI Autorun Testing.
Jan 20 14:00:19 apalis-imx6 tcdemoapp[743]: free(): invalid pointer
Jan 20 14:00:19 apalis-imx6 systemd[1]: autoruntest.service: Main process exited, code=killed, status=6/ABRT
Jan 20 14:00:19 apalis-imx6 systemd[1]: autoruntest.service: Failed with result 'signal'.

This is my sample service:

[Unit]
Description=GUI Totalcross Autorun Testing
After=multi-user.target
[Service]
Environment=XDG_RUNTIME_DIR=/var/run/user/0
Environment=DISPLAY=:0
Type=simple
ExecStart=/home/root/app/tcdemoapp
[Install]
WantedBy=multi-user.targe

Even if the system is already running, and I try to start it with systemctl start tcdemoapp, the same error occurs.

My environment is a Yocto Build Dunfell with BSP 5.1.0 from Toradex on an Apalis iMX6DL Arm32v7, running Wayland. And TotalCross library 6.1.0 (from meta-totalcross).

Could you help me indicating what I may be doing wrong?

Thanks.

Best regards,
André Curvello

One curious thing, not wanting to deviate from the topic of the original conversation, is that this “invalid pointer” error does also occurs simply with the execution from command-line of the totalcross-launcher sample app. This app was loaded in the image as recipe from the meta-totalcross layer.

See:

[email protected]:/usr/lib/totalcross# ls
TCBase.tcz  TCFont.tcz TCUI.tcz  libtcvm.so  libtcvm.so.1  totalcross-launcher
[email protected]:/usr/lib/totalcross# ./totalcross-launcher
free(): invalid pointer
Aborted
[email protected]:/usr/lib/totalcross#

Can you give us more details on your application, and on which version of totalcross are you using?

Hi @VicMisael,

It was a demo using the TotalCross 6.1.0 (or even 6.1.1).

The only error I got from system when it was starting was that

Jan 20 14:00:19 apalis-imx6 systemd[1]: Started GUI Autorun Testing.
Jan 20 14:00:19 apalis-imx6 tcdemoapp[743]: free(): invalid pointer
Jan 20 14:00:19 apalis-imx6 systemd[1]: autoruntest.service: Main process exited, code=killed, status=6/ABRT
Jan 20 14:00:19 apalis-imx6 systemd[1]: autoruntest.service: Failed with result 'signal'.

Then, after some deep analysis, I ended solving this solution by using this initialization script, which is called wayland-app-launch.sh:

#!/bin/sh
if test -z "$XDG_RUNTIME_DIR"; then
    export XDG_RUNTIME_DIR=/run/user/`id -u`
    if ! test -d "$XDG_RUNTIME_DIR"; then
        mkdir --parents $XDG_RUNTIME_DIR
        chmod 0700 $XDG_RUNTIME_DIR
    fi
fi

# wait for weston
while [ ! -e  $XDG_RUNTIME_DIR/wayland-0 ] ; do sleep 0.1; done
sleep 1

export DISPLAY=:0.0

/home/root/toradex/ToradexLauncherApplication &

And this service:

[Unit]
Description=Start a wayland application
[email protected]
[email protected]

[Service]
Restart=on-failure
Type=forking
ExecStart=/usr/bin/wayland-app-launch.sh
RestartSec=1

[Install]
WantedBy=multi-user.target

Hello, @andrecurvello, Have you tried using X11?, we need this info to know if it’s an issue related to systemd

Hi @VicMisael,

I have not tried because the BSP 5.1.0 of Toradex has support for Wayland, not X11.

Best regards,
André Curvello

Maybe you try to time the application start after the GUI start

Hi @VicMisael,

Adapting the script to wait till Weston is up and running solved the issue.
I posted the solution above.

Best regards,
André Curvello

Thank you @andrecurvello, If you need anything else, just ask