[Sugar-devel] [PATCH sugar] If available use systemd to reboot/shutdown the system
Manuel Quiñones
manuq at laptop.org
Wed Mar 14 11:43:42 EDT 2012
El día 2 de marzo de 2012 05:51, Simon Schampijer
<simon at schampijer.de> escribió:
> ConsoleKit is being obsoleted by systemd [1]. Accordingly use the
> systemd D-Bus API now to Reboot and PowerOff the system. We keep the
> fallback for ConsoleKit around. This adds a dependency on systemd.
>
> [1] http://fedoraproject.org/wiki/Features/ckremoval
>
> Signed-off-by: Simon Schampijer <simon at laptop.org>
Reviewed-by: Manuel Quiñones <manuq at laptop.org>
> ---
> src/jarabe/model/session.py | 51 ++++++++++++++++++++++++++++++------------
> 1 files changed, 36 insertions(+), 15 deletions(-)
>
> diff --git a/src/jarabe/model/session.py b/src/jarabe/model/session.py
> index 9b277ff..4e66bdc 100644
> --- a/src/jarabe/model/session.py
> +++ b/src/jarabe/model/session.py
> @@ -28,6 +28,10 @@ from sugar import env
> _session_manager = None
>
>
> +def have_systemd():
> + return os.access("/sys/fs/cgroup/systemd", 0) >= 0
> +
> +
> class SessionManager(session.SessionManager):
> MODE_LOGOUT = 0
> MODE_SHUTDOWN = 1
> @@ -53,21 +57,38 @@ class SessionManager(session.SessionManager):
> if env.is_emulator():
> self._close_emulator()
> elif self._logout_mode != self.MODE_LOGOUT:
> - try:
> - bus = dbus.SystemBus()
> - proxy = bus.get_object('org.freedesktop.ConsoleKit',
> - '/org/freedesktop/ConsoleKit/Manager')
> - pm = dbus.Interface(proxy,
> - 'org.freedesktop.ConsoleKit.Manager')
> -
> - if self._logout_mode == self.MODE_SHUTDOWN:
> - pm.Stop()
> - elif self._logout_mode == self.MODE_REBOOT:
> - pm.Restart()
> - except:
> - logging.exception('Can not stop sugar')
> - self.session.cancel_shutdown()
> - return
> + bus = dbus.SystemBus()
> + if have_systemd():
> + try:
> + proxy = bus.get_object('org.freedesktop.login1',
> + '/org/freedesktop/login1')
> + pm = dbus.Interface(proxy,
> + 'org.freedesktop.login1.Manager')
> +
> + if self._logout_mode == self.MODE_SHUTDOWN:
> + pm.PowerOff(False)
> + elif self._logout_mode == self.MODE_REBOOT:
> + pm.Reboot(True)
> + except:
> + logging.exception('Can not stop sugar')
> + self.session.cancel_shutdown()
> + return
> + else:
> + CONSOLEKIT_DBUS_PATH = '/org/freedesktop/ConsoleKit/Manager'
> + try:
> + proxy = bus.get_object('org.freedesktop.ConsoleKit',
> + CONSOLEKIT_DBUS_PATH)
> + pm = dbus.Interface(proxy,
> + 'org.freedesktop.ConsoleKit.Manager')
> +
> + if self._logout_mode == self.MODE_SHUTDOWN:
> + pm.Stop()
> + elif self._logout_mode == self.MODE_REBOOT:
> + pm.Restart()
> + except:
> + logging.exception('Can not stop sugar')
> + self.session.cancel_shutdown()
> + return
Would be great to unify those try/except clauses, but the APIS differ
slightly, one uses pm.Stop/Restart, the other pm.PowerOff/Reboot, so
the separation is ok for me.
>
> session.SessionManager.shutdown_completed(self)
> gtk.main_quit()
> --
> 1.7.7.6
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
--
.. manuq ..
More information about the Sugar-devel
mailing list