Description: Use systemd CanReboot etc. to check for rebootability Just checking PolicyKit for org.freedesktop.login1.reboot etc. is not sufficient as that will say yes even if reboot-multiple-sessions would say no. --- The information above should follow the Patch Tagging Guidelines, please checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here are templates for supplementary fields that you might want to add: Origin: , Bug: Bug-Debian: https://bugs.debian.org/ Bug-Ubuntu: https://launchpad.net/bugs/ Forwarded: Reviewed-By: Last-Update: --- xfce4-session-4.12.1.orig/xfce4-session/xfsm-systemd.c +++ xfce4-session-4.12.1/xfce4-session/xfsm-systemd.c @@ -38,10 +38,10 @@ #define SYSTEMD_POWEROFF_ACTION "PowerOff" #define SYSTEMD_SUSPEND_ACTION "Suspend" #define SYSTEMD_HIBERNATE_ACTION "Hibernate" -#define SYSTEMD_REBOOT_TEST "org.freedesktop.login1.reboot" -#define SYSTEMD_POWEROFF_TEST "org.freedesktop.login1.power-off" -#define SYSTEMD_SUSPEND_TEST "org.freedesktop.login1.suspend" -#define SYSTEMD_HIBERNATE_TEST "org.freedesktop.login1.hibernate" +#define SYSTEMD_REBOOT_TEST "CanReboot" +#define SYSTEMD_POWEROFF_TEST "CanPowerOff" +#define SYSTEMD_SUSPEND_TEST "CanSuspend" +#define SYSTEMD_HIBERNATE_TEST "CanHibernate" @@ -121,45 +121,87 @@ xfsm_systemd_lock_screen (GError **error +/* static gboolean */ +/* xfsm_systemd_can_method (XfsmSystemd *systemd, */ +/* gboolean *can_method, */ +/* const gchar *method, */ +/* GError **error) */ +/* { */ +/* #ifdef HAVE_POLKIT */ +/* PolkitAuthorizationResult *res; */ +/* GError *local_error = NULL; */ +/* #endif */ + +/* *can_method = FALSE; */ + +/* #ifdef HAVE_POLKIT */ +/* res = polkit_authority_check_authorization_sync (systemd->authority, */ +/* systemd->subject, */ +/* method, */ +/* NULL, */ +/* POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE, */ +/* NULL, */ +/* &local_error); */ + +/* if (res == NULL) */ +/* { */ +/* g_propagate_error (error, local_error); */ +/* return FALSE; */ +/* } */ + +/* *can_method = polkit_authorization_result_get_is_authorized (res) */ +/* || polkit_authorization_result_get_is_challenge (res); */ + +/* g_object_unref (G_OBJECT (res)); */ +/* #endif */ + +/* return TRUE; */ +/* } */ + static gboolean xfsm_systemd_can_method (XfsmSystemd *systemd, - gboolean *can_method, - const gchar *method, - GError **error) -{ -#ifdef HAVE_POLKIT - PolkitAuthorizationResult *res; - GError *local_error = NULL; -#endif - + gboolean *can_method, + const gchar *method, + GError **error) +{ + GDBusConnection *bus; + GError *local_error = NULL; + GVariant *dbus_ret; + const gchar *str; *can_method = FALSE; + + bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); + if (G_UNLIKELY (bus == NULL)) + return FALSE; + + dbus_ret = g_dbus_connection_call_sync (bus, + SYSTEMD_DBUS_NAME, + SYSTEMD_DBUS_PATH, + SYSTEMD_DBUS_INTERFACE, + method, + NULL, + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &local_error); + + g_variant_get(dbus_ret, "(&s)", &str); + if (! strcmp (str, "yes")) { + *can_method = TRUE; + } + + g_object_unref (G_OBJECT (bus)); -#ifdef HAVE_POLKIT - res = polkit_authority_check_authorization_sync (systemd->authority, - systemd->subject, - method, - NULL, - POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE, - NULL, - &local_error); - - if (res == NULL) + if (local_error != NULL) { g_propagate_error (error, local_error); return FALSE; } - *can_method = polkit_authorization_result_get_is_authorized (res) - || polkit_authorization_result_get_is_challenge (res); - - g_object_unref (G_OBJECT (res)); -#endif - return TRUE; } - - - + static gboolean xfsm_systemd_try_method (XfsmSystemd *systemd, const gchar *method,