mirror of
https://github.com/gryf/wicd.git
synced 2025-12-22 14:07:59 +01:00
Make client survive the daemon going down.
Port a few fixes from trunk.
This commit is contained in:
36
wicd/gui.py
36
wicd/gui.py
@@ -53,20 +53,24 @@ except:
|
|||||||
proxy_obj = daemon = wireless = wired = bus = None
|
proxy_obj = daemon = wireless = wired = bus = None
|
||||||
language = misc.get_language_list_gui()
|
language = misc.get_language_list_gui()
|
||||||
|
|
||||||
def setup_dbus():
|
def setup_dbus(force=True):
|
||||||
global bus, daemon, wireless, wired
|
global bus, daemon, wireless, wired
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
print "Can't connect to the daemon, trying to start it automatically..."
|
if force:
|
||||||
misc.PromptToStartDaemon()
|
print "Can't connect to the daemon, trying to start it automatically..."
|
||||||
try:
|
misc.PromptToStartDaemon()
|
||||||
dbusmanager.connect_to_dbus()
|
try:
|
||||||
except DBusException:
|
dbusmanager.connect_to_dbus()
|
||||||
error(None, "Could not connect to wicd's D-Bus interface. " +
|
except DBusException:
|
||||||
"Make sure the daemon is started.")
|
error(None, "Could not connect to wicd's D-Bus interface. " +
|
||||||
sys.exit(1)
|
"Check the wicd log for error messages.")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
bus = dbusmanager.get_bus()
|
bus = dbusmanager.get_bus()
|
||||||
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
||||||
@@ -76,6 +80,16 @@ def setup_dbus():
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@misc.threaded
|
||||||
|
def handle_no_dbus():
|
||||||
|
print "Wicd daemon is shutting down!"
|
||||||
|
error(None, "The wicd daemon has shut down, the UI will not function properly until it is restarted.")
|
||||||
|
while True:
|
||||||
|
time.sleep(10)
|
||||||
|
print "Trying to reconnect.."
|
||||||
|
if not setup_dbus(force=False):
|
||||||
|
print "Failed to reconnect to the daemon."
|
||||||
|
|
||||||
def error(parent, message):
|
def error(parent, message):
|
||||||
""" Shows an error dialog """
|
""" Shows an error dialog """
|
||||||
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
|
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
|
||||||
@@ -277,7 +291,9 @@ class appGui(object):
|
|||||||
'org.wicd.daemon.wireless')
|
'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(self.update_connect_buttons, 'StatusChanged',
|
bus.add_signal_receiver(self.update_connect_buttons, 'StatusChanged',
|
||||||
'org.wicd.daemon')
|
'org.wicd.daemon')
|
||||||
bus.add_signal_receiver(setup_dbus, "DaemonClosing", "org.wicd.daemon")
|
if standalone:
|
||||||
|
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
|
||||||
|
"org.wicd.daemon")
|
||||||
try:
|
try:
|
||||||
gobject.timeout_add_seconds(1, self.update_statusbar)
|
gobject.timeout_add_seconds(1, self.update_statusbar)
|
||||||
except:
|
except:
|
||||||
|
|||||||
12
wicd/misc.py
12
wicd/misc.py
@@ -69,7 +69,7 @@ def Run(cmd, include_stderr=False, return_pipe=False):
|
|||||||
one output string from the command.
|
one output string from the command.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if type(cmd) is not list:
|
if not isinstance(cmd, list):
|
||||||
cmd = to_unicode(str(cmd))
|
cmd = to_unicode(str(cmd))
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
if include_stderr:
|
if include_stderr:
|
||||||
@@ -82,8 +82,12 @@ def Run(cmd, include_stderr=False, return_pipe=False):
|
|||||||
tmpenv = os.environ.copy()
|
tmpenv = os.environ.copy()
|
||||||
tmpenv["LC_ALL"] = "C"
|
tmpenv["LC_ALL"] = "C"
|
||||||
tmpenv["LANG"] = "C"
|
tmpenv["LANG"] = "C"
|
||||||
f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds, cwd='/',
|
try:
|
||||||
env=tmpenv)
|
f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds,
|
||||||
|
cwd='/', env=tmpenv)
|
||||||
|
except OSError, e:
|
||||||
|
print "Running command %s failed: %s" % (str(cmd), str(e))
|
||||||
|
return ""
|
||||||
|
|
||||||
if return_pipe:
|
if return_pipe:
|
||||||
return f.stdout
|
return f.stdout
|
||||||
@@ -383,7 +387,7 @@ def find_path(cmd):
|
|||||||
the file can not be found.
|
the file can not be found.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
paths = os.getenv("PATH", default=["/usr/bin", "/usr/local/bin"]).split(':')
|
paths = os.getenv("PATH", default="/usr/bin:/usr/local/bin").split(':')
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if os.access(os.path.join(path, cmd), os.F_OK):
|
if os.access(os.path.join(path, cmd), os.F_OK):
|
||||||
return os.path.join(path, cmd)
|
return os.path.join(path, cmd)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ if not hasattr(gtk, "StatusIcon"):
|
|||||||
import egg.trayicon
|
import egg.trayicon
|
||||||
USE_EGG = True
|
USE_EGG = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print 'Unable to load tray icon: Missing egg.trayicon module.'
|
print 'Unable to load tray icon: Missing both egg.trayicon and gtk.StatusIcon modules.'
|
||||||
ICON_AVAIL = False
|
ICON_AVAIL = False
|
||||||
|
|
||||||
misc.RenameProcess("wicd-client")
|
misc.RenameProcess("wicd-client")
|
||||||
@@ -125,7 +125,10 @@ class TrayIcon(object):
|
|||||||
self.max_snd_gain = 10000
|
self.max_snd_gain = 10000
|
||||||
self.max_rcv_gain = 10000
|
self.max_rcv_gain = 10000
|
||||||
self.animate = animate
|
self.animate = animate
|
||||||
self.update_tray_icon()
|
if DBUS_AVAIL:
|
||||||
|
self.update_tray_icon()
|
||||||
|
else:
|
||||||
|
handle_no_dbus()
|
||||||
|
|
||||||
def wired_profile_chooser(self):
|
def wired_profile_chooser(self):
|
||||||
""" Launch the wired profile chooser. """
|
""" Launch the wired profile chooser. """
|
||||||
@@ -350,15 +353,6 @@ class TrayIcon(object):
|
|||||||
self._is_scanning = False
|
self._is_scanning = False
|
||||||
self.populate_network_menu()
|
self.populate_network_menu()
|
||||||
|
|
||||||
def dbus_lost(self):
|
|
||||||
""" Callback for when the daemon is going down. """
|
|
||||||
global DBUS_AVAIL
|
|
||||||
print "The daemon is going down!!"
|
|
||||||
DBUS_AVAIL = False
|
|
||||||
time.sleep(1)
|
|
||||||
while not setup_dbus():
|
|
||||||
time.sleep(20)
|
|
||||||
|
|
||||||
def on_activate(self, data=None):
|
def on_activate(self, data=None):
|
||||||
""" Opens the wicd GUI. """
|
""" Opens the wicd GUI. """
|
||||||
global DBUS_AVAIL
|
global DBUS_AVAIL
|
||||||
@@ -638,26 +632,49 @@ Arguments:
|
|||||||
\t-a\t--no-animate\tRun the tray without network traffic tray animations.
|
\t-a\t--no-animate\tRun the tray without network traffic tray animations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setup_dbus():
|
def setup_dbus(force=True):
|
||||||
global daemon, wireless, wired, DBUS_AVAIL
|
global bus, daemon, wireless, wired, DBUS_AVAIL
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
print "Can't connect to the daemon, trying to start it automatically..."
|
if force:
|
||||||
misc.PromptToStartDaemon()
|
print "Can't connect to the daemon, trying to start it automatically..."
|
||||||
try:
|
misc.PromptToStartDaemon()
|
||||||
dbusmanager.connect_to_dbus()
|
try:
|
||||||
except DBusException:
|
dbusmanager.connect_to_dbus()
|
||||||
gui.error(None, language['cannot_start_daemon'])
|
except DBusException:
|
||||||
sys.exit(1)
|
gui.error(None, "Could not connect to wicd's D-Bus interface. " +
|
||||||
|
"Check the wicd log for error messages.")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
bus = dbusmanager.get_bus()
|
||||||
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
||||||
daemon = dbus_ifaces['daemon']
|
daemon = dbus_ifaces['daemon']
|
||||||
wireless = dbus_ifaces['wireless']
|
wireless = dbus_ifaces['wireless']
|
||||||
wired = dbus_ifaces['wired']
|
wired = dbus_ifaces['wired']
|
||||||
DBUS_AVAIL = True
|
DBUS_AVAIL = True
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@misc.threaded
|
||||||
|
def handle_no_dbus():
|
||||||
|
global DBUS_AVAIL
|
||||||
|
print "Wicd daemon is shutting down!"
|
||||||
|
gui.error(None, "The wicd daemon has shut down, the UI will not function " +
|
||||||
|
"properly until it is restarted.")
|
||||||
|
while True:
|
||||||
|
time.sleep(10)
|
||||||
|
print "Trying to reconnect.."
|
||||||
|
if not setup_dbus(force=False):
|
||||||
|
print "Failed to reconnect to the daemon."
|
||||||
|
else:
|
||||||
|
gui.setup_dbus(force=False)
|
||||||
|
DBUS_AVAIL = True
|
||||||
|
return True
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
""" The main frontend program.
|
""" The main frontend program.
|
||||||
|
|
||||||
@@ -702,7 +719,7 @@ def main(argv):
|
|||||||
|
|
||||||
# Check to see if wired profile chooser was called before icon
|
# Check to see if wired profile chooser was called before icon
|
||||||
# was launched (typically happens on startup or daemon restart).
|
# was launched (typically happens on startup or daemon restart).
|
||||||
if daemon.GetNeedWiredProfileChooser():
|
if DBUS_AVAIL and daemon.GetNeedWiredProfileChooser():
|
||||||
daemon.SetNeedWiredProfileChooser(False)
|
daemon.SetNeedWiredProfileChooser(False)
|
||||||
tray_icon.icon_info.wired_profile_chooser()
|
tray_icon.icon_info.wired_profile_chooser()
|
||||||
|
|
||||||
@@ -715,8 +732,7 @@ def main(argv):
|
|||||||
'org.wicd.daemon.wireless')
|
'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
||||||
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(tray_icon.tr.dbus_lost,
|
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing", 'org.wicd.daemon')
|
||||||
"DaemonClosing", 'org.wicd.daemon')
|
|
||||||
print 'Done.'
|
print 'Done.'
|
||||||
mainloop = gobject.MainLoop()
|
mainloop = gobject.MainLoop()
|
||||||
mainloop.run()
|
mainloop.run()
|
||||||
|
|||||||
@@ -1540,10 +1540,11 @@ def main(argv):
|
|||||||
daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect)
|
daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect)
|
||||||
gobject.threads_init()
|
gobject.threads_init()
|
||||||
if not no_poll:
|
if not no_poll:
|
||||||
(child_pid, x, x, x) = gobject.spawn_async(["/usr/bin/python", "-O",
|
(child_pid, x, x, x) = gobject.spawn_async(
|
||||||
wpath.lib + "monitor.py"],
|
[misc.find_path("python"), "-O", os.path.join(wpath.lib, "monitor.py")],
|
||||||
flags=gobject.SPAWN_CHILD_INHERITS_STDIN)
|
flags=gobject.SPAWN_CHILD_INHERITS_STDIN
|
||||||
signal.signal(signal.SIGTERM, sigterm_caught)
|
)
|
||||||
|
signal.signal(signal.SIGTERM, sigterm_caught)
|
||||||
|
|
||||||
# Enter the main loop
|
# Enter the main loop
|
||||||
mainloop = gobject.MainLoop()
|
mainloop = gobject.MainLoop()
|
||||||
@@ -1557,8 +1558,9 @@ def main(argv):
|
|||||||
def sigterm_caught(sig=None, frame=None):
|
def sigterm_caught(sig=None, frame=None):
|
||||||
""" 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
|
global child_pid
|
||||||
print 'Daemon going down, killing wicd-monitor...'
|
if child_pid:
|
||||||
os.kill(child_pid, signal.SIGTERM)
|
print 'Daemon going down, killing wicd-monitor...'
|
||||||
|
os.kill(child_pid, signal.SIGTERM)
|
||||||
print 'Removing PID file...'
|
print 'Removing PID file...'
|
||||||
if os.path.exists(wpath.pidfile):
|
if os.path.exists(wpath.pidfile):
|
||||||
os.remove(wpath.pidfile)
|
os.remove(wpath.pidfile)
|
||||||
|
|||||||
Reference in New Issue
Block a user