1
0
mirror of https://github.com/gryf/wicd.git synced 2026-02-23 02:25:48 +01:00

Use atexit instead of catching SIGTERM in wicd-daemon.

Use Popen to launch wicd-monitor instead of gobject.spawn_async.
This commit is contained in:
Dan O'Reilly
2009-04-21 20:30:40 -04:00
parent dccaec9a95
commit 97d553bce3
2 changed files with 8 additions and 10 deletions

View File

@@ -660,7 +660,7 @@ def setup_dbus(force=True):
misc.PromptToStartDaemon() misc.PromptToStartDaemon()
try: try:
dbusmanager.connect_to_dbus() dbusmanager.connect_to_dbus()
except dbusmanager.DBusException: except DBusException:
error(None, "Could not connect to wicd's D-Bus interface. " + error(None, "Could not connect to wicd's D-Bus interface. " +
"Check the wicd log for error messages.") "Check the wicd log for error messages.")
return False return False

View File

@@ -37,6 +37,8 @@ import sys
import time import time
import getopt import getopt
import signal import signal
import atexit
from subprocess import Popen
# DBUS # DBUS
import gobject import gobject
@@ -1601,8 +1603,6 @@ def daemonize():
os.dup2(0, 2) os.dup2(0, 2)
child_pid = None
def main(argv): def main(argv):
""" The main daemon program. """ The main daemon program.
@@ -1610,7 +1610,6 @@ def main(argv):
argv -- The arguments passed to the script. argv -- The arguments passed to the script.
""" """
global child_pid
do_daemonize = True do_daemonize = True
redirect_stderr = True redirect_stderr = True
redirect_stdout = True redirect_stdout = True
@@ -1667,9 +1666,10 @@ def main(argv):
wicd_bus = dbus.service.BusName('org.wicd.daemon', bus=bus) wicd_bus = dbus.service.BusName('org.wicd.daemon', bus=bus)
daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect) daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect)
if not no_poll: if not no_poll:
(child_pid, x, y, z) = gobject.spawn_async( child_pid = Popen([misc.find_path("python"), "-O",
[misc.find_path("python"), "-O", os.path.join(wpath.lib, "monitor.py")]) os.path.join(wpath.lib, "monitor.py")],
signal.signal(signal.SIGTERM, sigterm_caught) shell=False, close_fds=True).pid
atexit.register(on_exit, child_pid)
# Enter the main loop # Enter the main loop
mainloop = gobject.MainLoop() mainloop = gobject.MainLoop()
@@ -1678,11 +1678,9 @@ def main(argv):
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
daemon.DaemonClosing() daemon.DaemonClosing()
sigterm_caught()
def sigterm_caught(sig=None, frame=None): def on_exit(child_pid):
""" Called when a SIGTERM is caught, kills monitor.py before exiting. """ """ Called when a SIGTERM is caught, kills monitor.py before exiting. """
global child_pid
if child_pid: if child_pid:
print 'Daemon going down, killing wicd-monitor...' print 'Daemon going down, killing wicd-monitor...'
try: try: