Merge lp:~nataliabidart/ubuntu-sso-client/add-sighup-handler into lp:ubuntu-sso-client

Proposed by Natalia Bidart
Status: Merged
Approved by: John Lenton
Approved revision: 619
Merged at revision: 618
Proposed branch: lp:~nataliabidart/ubuntu-sso-client/add-sighup-handler
Merge into: lp:ubuntu-sso-client
Diff against target: 42 lines (+18/-0)
1 file modified
bin/ubuntu-sso-login (+18/-0)
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/add-sighup-handler
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Roman Yepishev (community) fieldtest Approve
Review via email: mp+34870@code.launchpad.net

Commit message

* Added handler for SIGHUP to stop the service (LP: #633300).

Description of the change

To test, please do:

nessita@dali:~/canonical/ubuntu-sso-client/add-sighup-handler$ killall ubuntu-sso-login; DEBUG=True PYTHONPATH=. bin/ubuntu-sso-login

And in other console, kill -SIGHUP <pid of ubuntu-sso-login>

To confirm the handler is working, you can see the logs:

Installing the Twisted gtk2reactor.
Hooking up SIGHUP with handler <function sighup_handler at 0x13f1050>.
Starting Ubuntu SSO login manager for bus 'com.ubuntu.sso'.
Stoping Ubuntu SSO login manager since SIGHUP was received .

To post a comment you must log in.
Revision history for this message
Roman Yepishev (rye) wrote :

Yup, it hangs up though w/o this code the process is killed with SIGHUP too :)

review: Approve (fieldtest)
619. By Natalia Bidart

Added disclaimer on SIGHUP handler.

Revision history for this message
John Lenton (chipaca) wrote :

Yeah.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/ubuntu-sso-login'
2--- bin/ubuntu-sso-login 2010-09-02 17:03:56 +0000
3+++ bin/ubuntu-sso-login 2010-09-08 18:37:40 +0000
4@@ -22,6 +22,7 @@
5 """Run the dbus service for UserManagement and ApplicationCredentials."""
6
7 import gtk
8+import signal
9 import sys
10
11 import dbus.service
12@@ -41,6 +42,20 @@
13 gtk.gdk.threads_init()
14 DBusGMainLoop(set_as_default=True)
15
16+
17+def sighup_handler(*a, **kw):
18+ """Stop the service.
19+
20+ This is not thread safe, see the link below for info:
21+ www.listware.net/201004/gtk-devel-list/115067-unix-signals-in-glib.html
22+ """
23+ from twisted.internet import reactor
24+ # Module 'twisted.internet.reactor' has no 'stop' member
25+ # pylint: disable=E1101
26+ logger.info("Stoping Ubuntu SSO login manager since SIGHUP was received.")
27+ reactor.stop()
28+
29+
30 if __name__ == "__main__":
31 # Register DBus service for making sure we run only one instance
32 bus = dbus.SessionBus()
33@@ -54,6 +69,9 @@
34 from twisted.internet import gtk2reactor
35 gtk2reactor.install()
36
37+ logger.debug("Hooking up SIGHUP with handler %r.", sighup_handler)
38+ signal.signal(signal.SIGHUP, sighup_handler)
39+
40 logger.info("Starting Ubuntu SSO login manager for bus %r.", DBUS_BUS_NAME)
41 SSOLogin(dbus.service.BusName(DBUS_BUS_NAME,
42 bus=dbus.SessionBus()))

Subscribers

People subscribed via source and target branches