[gnome-session/benzea/systemd-fixes-2] util, main: Reset all failed states on startup



commit 3b37bd27dbd796c61b41a193f05be067afba924c
Author: Benjamin Berg <bberg redhat com>
Date:   Mon Feb 3 13:45:51 2020 +0100

    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.

 gnome-session/gsm-util.c | 30 ++++++++++++++++++++++++++++++
 gnome-session/gsm-util.h |  2 ++
 gnome-session/main.c     | 10 ++++++++++
 3 files changed, 42 insertions(+)
---
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)) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]