qt.qpa.xcb: could not connect to display
-
Failing to start QT5 application from a privileged process. The application starts normally if it is started from a bash shell.
To be more precise, we are using AWS Greengrass Edge runtime environment that runs "components" (apps, that can be any language). We have a service script that usually starts the QT5 application when the environment initially boots. The service script is the following:
#!/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 cd until pids=$(pidof weston) do sleep 1 done echo "Starting Dash Display" export QT_DEBUG_PLUGINS=1 QT_IM_MODULE=qtvirtualkeyboard /usr/bin/dashV3 --fullscreen & unset QT_DEBUG_PLUGINS
NOTE: I've done the QT_DEBUG_PLUGINS=1 to see the output, and it fails when it attempts to load xcb plugin:
Got keys from plugin meta data ("xcb"). QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms" loaded library "/usr/lib/plugins/platforms/libqxcb.so". qt.qpa.xcb: could not connect to display. qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found..
If I run the application normally in an opened bash environment, it spins it up, loading up all of the plugins available, but when ran within another process (in a privilege mode, from Greengrass runtime environment, which is still ROOT privilege uid/gid of 0), it fails about the 3rd of 4th plugin loading (XCB)
(I've omitted the other plugins as part of the QT_DEBUG_PLUGINS=1, since the logs in Greengrass environment come out funny prefixed and suffixed with Greengrass-specific log format, and it is notoriously hard for me to "edit" it).
I guess, the key question is: why does it run normally when the same command is ran from BASH, but fails on the above, when another process kicks it off.
I thought I'd provide some additional details, how the script is run, from Greengrass component (via, what they call "recipes"):
RecipeFormatVersion: "2020-01-25" ComponentName: "{COMPONENT_NAME}" ComponentVersion: "{COMPONENT_VERSION}" ComponentDescription: "Savic MC Dash App" ComponentPublisher: "{COMPONENT_AUTHOR}" Manifests: - Platform: os: linux Lifecycle: Run: RequiresPrivilege: true script: bash {artifacts:decompressedPath}/Dash/run.sh Artifacts: - URI: "s3://BUCKET_NAME/COMPONENT_NAME/COMPONENT_VERSION/Dash.zip" Unarchive: ZIP Permission: Execute: OWNER
The key thing here to note is:
Run: RequiresPrivilege: true script: bash {artifacts:decompressedPath}/Dash/run.sh
Nothing special about this part of the config, other than it tells Greengrass to run
run.sh
as root.Are there some env variables that may be missing?
Do I need to run it in some other "mode"?Thanks for your help.
Additional notes:
The OS that our QT5 runs on is YOCTO Linux (Embedded Linux), on a Toradex IMX8 board.The reason why we've moved from running it as a system process, to a Greengrass runtime environment is that Greengrass has an entire ecosystem surrounding over-the-air updates, lifecycle management of apps/components/services, visibility, access to MQTT etc. etc.
-
@overfl0w said in qt.qpa.xcb: could not connect to display:
which is still ROOT privilege uid/gid of 0), it fails about the 3rd of 4th plugin loading (XCB)
Usually, root cannot access X server when running from other user account. Do you really have to start your app as root?
Regarding plug-ins: set QT_DEBUG_PLUGINS=1 in a terminal and start your app there: there should be much more output providing more details why exactly the plug-in isn't loaded, please post it.