Commit 3b37bd27 authored by Benjamin Berg's avatar Benjamin Berg

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.
parent 08e19e0e
......@@ -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
......
......@@ -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);
......
......@@ -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)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment