diff options
author | Ray Strode <rstrode@redhat.com> | 2016-08-25 14:40:58 -0400 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2016-08-31 15:53:39 -0400 |
commit | 448134d3cdbc54e5359ea33d387993b0defdaefa (patch) | |
tree | 2dadb472895ee972d7c8eb9a6d9d13a000df50fc /daemon/gdm-x-session.c | |
parent | 15c84a4f7d966d3062e33326f1433280941145d0 (diff) | |
download | gdm-448134d3cdbc54e5359ea33d387993b0defdaefa.tar.gz |
gdm-{wayland,x}-session: import environment from systemd manager
The user may have configured the user environment via
user.conf or other means. This commit makes sure this session gets
those environment changes.
https://bugzilla.gnome.org/show_bug.cgi?id=736660
Diffstat (limited to 'daemon/gdm-x-session.c')
-rw-r--r-- | daemon/gdm-x-session.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/daemon/gdm-x-session.c b/daemon/gdm-x-session.c index d0a00cad..d835b347 100644 --- a/daemon/gdm-x-session.c +++ b/daemon/gdm-x-session.c @@ -53,6 +53,8 @@ typedef struct GDBusConnection *bus_connection; char *bus_address; + char **environment; + GSubprocess *session_subprocess; char *session_command; int session_exit_status; @@ -528,6 +530,38 @@ out: return is_running; } +static gboolean +import_environment (State *state, + GCancellable *cancellable) +{ + g_autoptr(GVariant) reply = NULL; + g_autoptr(GVariant) environment_variant = NULL; + g_autoptr(GError) error = NULL; + + reply = g_dbus_connection_call_sync (state->bus_connection, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + "org.freedesktop.systemd1.Manager", + "Environment"), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, cancellable, &error); + + if (reply == NULL) { + g_debug ("could not fetch environment: %s", error->message); + return FALSE; + } + + g_variant_get (reply, "(v)", &environment_variant); + + state->environment = g_variant_dup_strv (environment_variant, NULL); + + return TRUE; +} + static void on_session_finished (GSubprocess *subprocess, GAsyncResult *result, @@ -579,6 +613,26 @@ spawn_session (State *state, g_subprocess_launcher_setenv (launcher, "DISPLAY", state->display_name, TRUE); g_subprocess_launcher_setenv (launcher, "XAUTHORITY", state->auth_file, TRUE); + if (state->environment != NULL) { + size_t i; + + for (i = 0; state->environment[i] != NULL; i++) { + g_auto(GStrv) environment_entry = NULL; + + if (state->environment[i] == '\0') { + continue; + } + + environment_entry = g_strsplit (state->environment[i], "=", 2); + + if (environment_entry[0] == NULL || environment_entry[1] == NULL) { + continue; + } + + g_subprocess_launcher_setenv (launcher, environment_entry[0], environment_entry[1], FALSE); + } + } + if (state->bus_address != NULL) { g_subprocess_launcher_setenv (launcher, "DBUS_SESSION_BUS_ADDRESS", state->bus_address, TRUE); } @@ -723,6 +777,7 @@ clear_state (State **out_state) g_clear_object (&state->bus_connection); g_clear_object (&state->session_subprocess); g_clear_object (&state->x_subprocess); + g_clear_pointer (&state->environment, g_strfreev); g_clear_pointer (&state->auth_file, g_free); g_clear_pointer (&state->display_name, g_free); g_clear_pointer (&state->main_loop, g_main_loop_unref); @@ -817,6 +872,8 @@ main (int argc, goto out; } + import_environment (state, state->cancellable); + ret = update_bus_environment (state, state->cancellable); if (!ret) { |