summaryrefslogtreecommitdiff
path: root/gnome-session
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2020-02-03 13:45:51 +0100
committerBenjamin Berg <benjamin@sipsolutions.net>2020-07-31 08:54:40 +0000
commitbd02b91408a41609c3a6e76c9af0a1fd91e74e9f (patch)
treeccec499f52a4afa9ea3fc14737b9bde17d3c9202 /gnome-session
parentb1f9ea623c6c88f00086286dd4898b727d134223 (diff)
downloadgnome-session-bd02b91408a41609c3a6e76c9af0a1fd91e74e9f.tar.gz
util, main: Reset all failed states on startup
In the event that the user logs back in after a session failure, it is likely that some failed units cannot start. Reset all failed states to ensure that systemd at least tries to start all previously failed units on every login.
Diffstat (limited to 'gnome-session')
-rw-r--r--gnome-session/gsm-util.c30
-rw-r--r--gnome-session/gsm-util.h2
-rw-r--r--gnome-session/main.c10
3 files changed, 42 insertions, 0 deletions
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
index 5a52de57..18a94700 100644
--- a/gnome-session/gsm-util.c
+++ b/gnome-session/gsm-util.c
@@ -769,6 +769,36 @@ gsm_util_start_systemd_unit (const char *unit,
return TRUE;
}
+
+gboolean
+gsm_util_systemd_reset_failed (GError **error)
+{
+ g_autoptr(GDBusConnection) connection = NULL;
+ g_autoptr(GVariant) reply = NULL;
+ GError *bus_error = NULL;
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+
+ if (connection == NULL)
+ return FALSE;
+
+ reply = g_dbus_connection_call_sync (connection,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "ResetFailed",
+ NULL,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &bus_error);
+
+ if (bus_error != NULL) {
+ g_propagate_error (error, bus_error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
#endif
void
diff --git a/gnome-session/gsm-util.h b/gnome-session/gsm-util.h
index bd7b6986..bc26a21e 100644
--- a/gnome-session/gsm-util.h
+++ b/gnome-session/gsm-util.h
@@ -58,6 +58,8 @@ gboolean gsm_util_export_user_environment (GError **error);
gboolean gsm_util_start_systemd_unit (const char *unit,
const char *mode,
GError **error);
+gboolean gsm_util_systemd_reset_failed (GError **error);
+
#endif
void gsm_quit (void);
diff --git a/gnome-session/main.c b/gnome-session/main.c
index a5ce4cce..84edfbe5 100644
--- a/gnome-session/main.c
+++ b/gnome-session/main.c
@@ -551,6 +551,16 @@ main (int argc, char **argv)
session_name = _gsm_manager_get_default_session (NULL);
}
+ /* Reset all failed units; we are going to start a lof ot things and
+ * really do not want to run into errors because units have failed
+ * in a previous session
+ */
+ gsm_util_systemd_reset_failed (&error);
+ if (error) {
+ g_warning ("Failed to reset failed state of units: %s", error->message);
+ g_clear_error (&error);
+ }
+
/* We don't escape the name (i.e. we leave any '-' intact). */
gnome_session_target = g_strdup_printf ("gnome-session-%s@%s.target", session_type, session_name);
if (gsm_util_start_systemd_unit (gnome_session_target, "fail", &error)) {