return NULL;
}
int len = strlen(dir) + strlen(filename) + 2;
- char *buffer = calloc(len, 1);
+ char *buffer = calloc(1, len);
strcat(buffer, dir);
strcat(buffer, "/");
strcat(buffer, filename);
return buffer;
}
+static void
+update_activation_env(const char *env_keys)
+{
+ if (!getenv("DBUS_SESSION_BUS_ADDRESS")) {
+ /* Prevent accidentally auto-launching a dbus session */
+ wlr_log(WLR_INFO, "Not updating dbus execution environment: "
+ "DBUS_SESSION_BUS_ADDRESS not set");
+ return;
+ }
+ wlr_log(WLR_INFO, "Updating dbus execution environment");
+
+ char *cmd;
+ const char *dbus = "dbus-update-activation-environment ";
+ const char *systemd = "systemctl --user import-environment ";
+
+ cmd = calloc(1, strlen(dbus) + strlen(env_keys) + 1);
+ strcat(cmd, dbus);
+ strcat(cmd, env_keys);
+ spawn_async_no_shell(cmd);
+ free(cmd);
+
+ cmd = calloc(1, strlen(systemd) + strlen(env_keys) + 1);
+ strcat(cmd, systemd);
+ strcat(cmd, env_keys);
+ spawn_async_no_shell(cmd);
+ free(cmd);
+}
+
void
session_environment_init(const char *dir)
{
+ /*
+ * Set default for XDG_CURRENT_DESKTOP so xdg-desktop-portal-wlr is happy.
+ * May be overriden either by already having a value set or by the user
+ * supplied environment file.
+ */
+ setenv("XDG_CURRENT_DESKTOP", "wlroots", 0);
+
const char *environment = build_path(dir, "environment");
if (!environment) {
return;
void
session_autostart_init(const char *dir)
{
+ /* Update dbus and systemd user environment, each may fail gracefully */
+ update_activation_env("DISPLAY WAYLAND_DISPLAY XDG_CURRENT_DESKTOP");
+
const char *autostart = build_path(dir, "autostart");
if (!autostart) {
return;
}
wlr_log(WLR_INFO, "run autostart file %s", autostart);
int len = strlen(autostart) + 4;
- char *cmd = calloc(len, 1);
+ char *cmd = calloc(1, len);
strcat(cmd, "sh ");
strcat(cmd, autostart);
spawn_async_no_shell(cmd);