[Sugar-devel] [PATCH sugar] If available use systemd to reboot/shutdown the system

Simon Schampijer simon at schampijer.de
Wed Mar 14 13:31:59 EDT 2012


On 03/14/2012 04:43 PM, Manuel Quiñones wrote:
> 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>

Thanks for the review. Pushed as 
99bb52c5dbea01a3ffc9b8821ec12af2536f76ca after testing on F17 as working 
fine so we can get wider testing.

>> ---
>>   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.

Yes, we will remove ConsoleKit support at one point, that is why I did 
conclude that I should not spend too much time to get fancy here.

Regards,
    Simon



More information about the Sugar-devel mailing list