From 998fd807373ee7e28cc88717f5f20dd3f4a0c342 Mon Sep 17 00:00:00 2001 From: Jos Dehaes Date: Wed, 29 Apr 2026 11:14:21 +0200 Subject: [PATCH] session: run activation env update synchronously dbus-update-activation-environment and systemctl --user import-environment were fired asynchronously via spawn_async_no_shell, racing with the autostart script. Any systemd user service started from autostart (e.g. via labwc-session.target) could start before the import completed, leaving WAYLAND_DISPLAY and related variables absent from its environment and those of any apps it launches. Run both commands synchronously via a new spawn_sync_no_shell helper so the import is guaranteed to complete before the autostart script executes. --- include/common/spawn.h | 6 ++++++ src/common/spawn.c | 32 ++++++++++++++++++++++++++++++++ src/config/session.c | 4 ++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/common/spawn.h b/include/common/spawn.h index 43123269..4df5ed0b 100644 --- a/include/common/spawn.h +++ b/include/common/spawn.h @@ -16,6 +16,12 @@ pid_t spawn_primary_client(const char *command); */ void spawn_async_no_shell(char const *command); +/** + * spawn_sync_no_shell - execute synchronously + * @command: command to be executed + */ +void spawn_sync_no_shell(char const *command); + /** * spawn_piped - execute asynchronously * @command: command to be executed diff --git a/src/common/spawn.c b/src/common/spawn.c index 898c4800..a703bee5 100644 --- a/src/common/spawn.c +++ b/src/common/spawn.c @@ -89,6 +89,38 @@ out: g_strfreev(argv); } +void +spawn_sync_no_shell(char const *command) +{ + GError *err = NULL; + gchar **argv = NULL; + + assert(command); + + g_shell_parse_argv((gchar *)command, NULL, &argv, &err); + if (err) { + g_message("%s", err->message); + g_error_free(err); + return; + } + + pid_t child = fork(); + switch (child) { + case -1: + wlr_log(WLR_ERROR, "unable to fork()"); + goto out; + case 0: + reset_signals_and_limits(); + execvp(argv[0], argv); + _exit(1); + default: + waitpid(child, NULL, 0); + break; + } +out: + g_strfreev(argv); +} + pid_t spawn_primary_client(const char *command) { diff --git a/src/config/session.c b/src/config/session.c index 7df6236c..61ce156f 100644 --- a/src/config/session.c +++ b/src/config/session.c @@ -219,12 +219,12 @@ execute_update(const char *env_keys, const char *env_unset_keys, bool initialize char *cmd = strdup_printf("dbus-update-activation-environment %s", initialize ? env_keys : env_unset_keys); - spawn_async_no_shell(cmd); + spawn_sync_no_shell(cmd); free(cmd); cmd = strdup_printf("systemctl --user %s %s", initialize ? "import-environment" : "unset-environment", env_keys); - spawn_async_no_shell(cmd); + spawn_sync_no_shell(cmd); free(cmd); }