mirror of
https://github.com/gryf/wicd.git
synced 2025-12-19 20:38:00 +01:00
Changed script execution behavior to fork before running. Causes more reliable execution but can leave zombies.
This commit is contained in:
36
daemon.py
36
daemon.py
@@ -299,7 +299,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
else:
|
||||
defaultNetwork = self.GetDefaultWiredNetwork()
|
||||
if defaultNetwork != None:
|
||||
self.ReadWiredNetworkProfile(defaultNetwork)
|
||||
self.ReadWiredNetworkProfile(defaultNetwork)
|
||||
self.ConnectWired()
|
||||
time.sleep(1)
|
||||
print "Attempting to autoconnect with wired interface..."
|
||||
@@ -353,14 +353,14 @@ class ConnectionWizard(dbus.service.Object):
|
||||
else:
|
||||
print 'autoconnect failed because wireless interface == None'
|
||||
#end function AutoConnect
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def GetGlobalDNSAddresses(self):
|
||||
'''returns the global dns addresses'''
|
||||
print 'returning global dns addresses to client'
|
||||
return (misc.noneToString(self.dns1),misc.noneToString(self.dns2),misc.noneToString(self.dns3))
|
||||
#end function GetWirelessInterface
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def CheckIfConnecting(self):
|
||||
'''returns if a network connection is being made'''
|
||||
@@ -369,12 +369,12 @@ class ConnectionWizard(dbus.service.Object):
|
||||
else:
|
||||
return True
|
||||
#end function CheckIfConnecting
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def SetNeedWiredProfileChooser(self,val):
|
||||
self.need_profile_chooser = val
|
||||
#end function SetNeedWiredProfileChooser
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def GetNeedWiredProfileChooser(self):
|
||||
return self.need_profile_chooser
|
||||
@@ -417,7 +417,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.SetWirelessProperty(networkid,"beforescript",script)
|
||||
self.wifi.before_script = script
|
||||
#end function SetWirelessBeforeScript
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetWirelessDisconnectScript(self,networkid,script):
|
||||
if script == '':
|
||||
@@ -621,7 +621,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.SetWiredProperty("beforescript",script)
|
||||
self.wired.before_script = script
|
||||
#end function SetWiredBeforeScript
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def SetWiredDisconnectScript(self,script):
|
||||
'''sets script to run on connection disconnect'''
|
||||
@@ -639,7 +639,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.SetWiredProperty("afterscript",script)
|
||||
self.wired.after_script = script
|
||||
#end function SetWiredAfterScript
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def SetWiredAutoConnectMethod(self,method):
|
||||
'''sets which method the user wants to autoconnect to wired networks'''
|
||||
@@ -651,13 +651,13 @@ class ConnectionWizard(dbus.service.Object):
|
||||
config.set("Settings","wired_connect_mode",int(method))
|
||||
config.write(open(self.app_conf,"w"))
|
||||
self.wired_connect_mode = method
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def GetWiredAutoConnectMethod(self):
|
||||
'''returns the wired autoconnect method'''
|
||||
return int(self.wired_connect_mode)
|
||||
#end function GetWiredAutoConnectMethod
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def CheckWiredConnectingMessage(self):
|
||||
'''returns the wired interface\'s status message'''
|
||||
@@ -691,7 +691,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
print 'WiredNetwork does not exist'
|
||||
return False
|
||||
#end function GetWiredProperty
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def SetAlwaysShowWiredInterface(self,value):
|
||||
print 'setting always show wired interface'
|
||||
@@ -795,7 +795,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.config')
|
||||
def DeleteWiredNetworkProfile(self,profilename):
|
||||
profilename = profilename.encode('utf-8')
|
||||
profilename = profilename.encode('utf-8')
|
||||
print "deleting profile for " + str(profilename)
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(self.wired_conf)
|
||||
@@ -806,7 +806,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
config.write( open(self.wired_conf,"w"))
|
||||
return "100: Profile Deleted"
|
||||
#end function DeleteWiredNetworkProfile
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.config')
|
||||
def SaveWiredNetworkProfile(self,profilename):
|
||||
#should include: profilename,ip,netmask,gateway,dns1,dns2
|
||||
@@ -894,7 +894,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.LastScan[id]["disconnectscript"]=misc.Noneify(config.get(self.LastScan[id]["bssid"],"disconnectscript"))
|
||||
else:
|
||||
self.LastScan[id]["disconnectscript"] = None
|
||||
|
||||
|
||||
#read the essid because we be needing to name those hidden
|
||||
#wireless networks now - but only read it if it is hidden
|
||||
if self.LastScan[id]["hidden"] == True:
|
||||
@@ -1123,11 +1123,11 @@ def daemonize():
|
||||
|
||||
|
||||
def main(argv):
|
||||
""" The main daemon program.
|
||||
""" The main daemon program.
|
||||
|
||||
Keyword arguments:
|
||||
argv -- The arguments passed to the script.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
do_daemonize = True
|
||||
@@ -1136,7 +1136,7 @@ def main(argv):
|
||||
auto_scan = True
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'feos',
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'feos',
|
||||
['help', 'no-daemon', 'no-stderr', 'no-stdout', 'no-scan'])
|
||||
except getopt.GetoptError:
|
||||
# Print help information and exit
|
||||
@@ -1159,7 +1159,7 @@ def main(argv):
|
||||
if do_daemonize: daemonize()
|
||||
|
||||
if redirect_stderr or redirect_stdout: output = LogWriter()
|
||||
if redirect_stdout: sys.stdout = output
|
||||
if redirect_stdout: sys.stdout = output
|
||||
if redirect_stderr: sys.stderr = output
|
||||
|
||||
print '---------------------------'
|
||||
|
||||
17
misc.py
17
misc.py
@@ -37,7 +37,7 @@ def PromptToStartDaemon():
|
||||
print 'You need to start the daemon before using the gui or tray. Use the command \'sudo /etc/init.d/wicd start\'.'
|
||||
|
||||
def RunRegex(regex,string):
|
||||
m = regex.search( string )
|
||||
m = regex.search(string)
|
||||
if m:
|
||||
return m.groups()[0]
|
||||
else:
|
||||
@@ -46,6 +46,19 @@ def RunRegex(regex,string):
|
||||
def WriteLine(file,text):
|
||||
file.write(text + "\n")
|
||||
|
||||
def ExecuteScript(script):
|
||||
pid = os.fork()
|
||||
if not pid:
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
pid = os.fork()
|
||||
if not pid:
|
||||
print Run('./run-script.py ' + script)
|
||||
os._exit(0)
|
||||
os._exit(0)
|
||||
os.wait()
|
||||
|
||||
|
||||
def ReadFile(filename):
|
||||
if not os.path.exists(filename):
|
||||
return None
|
||||
@@ -136,6 +149,6 @@ def LoadEncryptionMethods():
|
||||
def noneToString(text):
|
||||
'''used for putting text in a text box if the value to put in is 'None' the box will be blank'''
|
||||
if text == None or text == "None" or text == "":
|
||||
return "None"
|
||||
return "None"
|
||||
else:
|
||||
return str(text)
|
||||
|
||||
@@ -75,18 +75,18 @@ class ConnectThread(threading.Thread):
|
||||
|
||||
Useless on it's own, this class provides the generic functions
|
||||
necessary for connecting using a separate thread. """
|
||||
|
||||
|
||||
is_connecting = None
|
||||
connecting_thread = None
|
||||
should_die = False
|
||||
lock = thread.allocate_lock()
|
||||
|
||||
|
||||
def __init__(self, network, wireless, wired,
|
||||
def __init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3):
|
||||
""" Initialise the required object variables and the thread.
|
||||
|
||||
""" Initialise the required object variables and the thread.
|
||||
|
||||
Keyword arguments:
|
||||
network -- the network to connect to
|
||||
wireless -- name of the wireless interface
|
||||
@@ -107,7 +107,7 @@ class ConnectThread(threading.Thread):
|
||||
self.before_script = before_script
|
||||
self.after_script = after_script
|
||||
self.disconnect_script = disconnect_script
|
||||
|
||||
|
||||
self.global_dns_1 = gdns1
|
||||
self.global_dns_2 = gdns2
|
||||
self.global_dns_3 = gdns3
|
||||
@@ -116,8 +116,8 @@ class ConnectThread(threading.Thread):
|
||||
|
||||
|
||||
def SetStatus(self, status):
|
||||
""" Set the threads current status message in a thread-safe way.
|
||||
|
||||
""" Set the threads current status message in a thread-safe way.
|
||||
|
||||
Keyword arguments:
|
||||
status -- the current connection status
|
||||
|
||||
@@ -128,8 +128,8 @@ class ConnectThread(threading.Thread):
|
||||
|
||||
|
||||
def GetStatus(self):
|
||||
""" Get the threads current status message in a thread-safe way.
|
||||
|
||||
""" Get the threads current status message in a thread-safe way.
|
||||
|
||||
Returns:
|
||||
The current connection status.
|
||||
|
||||
@@ -275,7 +275,7 @@ class Wireless(Controller):
|
||||
misc.Run('iptables -A FORWARD -j REJECT --reject-with icmp-host-unreachable')
|
||||
misc.Run('iptables -P FORWARD DROP')
|
||||
misc.Run('iptables -A fw-interfaces -i ' + self.wireless_interface + ' -j ACCEPT')
|
||||
net_ip = '.'.join(ip_parts[0:3]) + '.0'
|
||||
net_ip = '.'.join(ip_parts[0:3]) + '.0'
|
||||
misc.Run('iptables -t nat -A POSTROUTING -s ' + net_ip + '/255.255.255.0 -o ' + self.wired_interface + ' -j MASQUERADE')
|
||||
misc.Run('echo 1 > /proc/sys/net/ipv4/ip_forward') # Enable routing
|
||||
|
||||
@@ -285,9 +285,9 @@ class Wireless(Controller):
|
||||
|
||||
Returns:
|
||||
The first available wireless interface.
|
||||
|
||||
|
||||
"""
|
||||
return wnettools.GetWirelessInterfaces()
|
||||
wnettools.GetWirelessInterfaces()
|
||||
|
||||
|
||||
def Disconnect(self):
|
||||
@@ -295,7 +295,7 @@ class Wireless(Controller):
|
||||
wiface = wnettools.WirelessInterface(self.wireless_interface, self.wpa_driver)
|
||||
if self.disconnect_script != None:
|
||||
print 'Running wireless network disconnect script'
|
||||
misc.Run(self.disconnect_script)
|
||||
misc.ExecuteScript(self.disconnect_script)
|
||||
|
||||
wiface.SetAddress('0.0.0.0')
|
||||
wiface.Down()
|
||||
@@ -328,7 +328,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
gdns3 -- global DNS server 3
|
||||
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wireless, wired,
|
||||
ConnectThread.__init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3)
|
||||
self.wpa_driver = wpa_driver
|
||||
@@ -356,7 +356,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
# Execute pre-connection script if necessary
|
||||
if self.before_script != '' and self.before_script != None:
|
||||
print 'Executing pre-connection script'
|
||||
print misc.Run('run-script.py ' + self.before_script)
|
||||
print misc.ExecuteScript(self.before_script)
|
||||
|
||||
# Put it down
|
||||
print 'Interface down'
|
||||
@@ -408,7 +408,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
self.network['channel'], self.network['bssid'])
|
||||
|
||||
# Authenticate after association for Ralink legacy cards.
|
||||
if self.wpa_driver == 'ralink legacy':
|
||||
if self.wpa_driver == 'ralink legacy':
|
||||
if self.network.get('key') != None:
|
||||
wiface.Authenticate(self.network)
|
||||
|
||||
@@ -437,7 +437,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
self.SetStatus('setting_static_dns')
|
||||
if self.network.get('use_global_dns'):
|
||||
wnettools.SetDNS(misc.Noneify(self.global_dns_1),
|
||||
misc.Noneify(self.global_dns_2),
|
||||
misc.Noneify(self.global_dns_2),
|
||||
misc.Noneify(self.global_dns_3))
|
||||
else:
|
||||
wnettools.SetDNS(self.network.get('dns1'),
|
||||
@@ -445,8 +445,8 @@ class WirelessConnectThread(ConnectThread):
|
||||
|
||||
#execute post-connection script if necessary
|
||||
if misc.Noneify(self.after_script):
|
||||
print 'executing post connection script'
|
||||
print misc.Run('./run-script.py ' + self.after_script)
|
||||
print 'Executing post-connection script'
|
||||
misc.ExecuteScript(self.after_script)
|
||||
|
||||
self.SetStatus('done')
|
||||
print 'Connecting thread exiting.'
|
||||
@@ -479,7 +479,7 @@ class Wired(Controller):
|
||||
Keyword arguments:
|
||||
network -- network to connect to
|
||||
|
||||
"""
|
||||
"""
|
||||
self.connecting_thread = WiredConnectThread(network,
|
||||
self.wireless_interface, self.wired_interface,
|
||||
self.before_script, self.after_script,
|
||||
@@ -521,7 +521,7 @@ class WiredConnectThread(ConnectThread):
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, network, wireless, wired,
|
||||
def __init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3):
|
||||
""" Initialise the thread with network information.
|
||||
@@ -538,7 +538,7 @@ class WiredConnectThread(ConnectThread):
|
||||
gdns3 -- global DNS server 3
|
||||
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wireless, wired,
|
||||
ConnectThread.__init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3)
|
||||
|
||||
@@ -563,8 +563,8 @@ class WiredConnectThread(ConnectThread):
|
||||
|
||||
# Execute pre-connection script if necessary
|
||||
if self.before_script != '' and self.before_script != None:
|
||||
print 'Executing pre-connection script'
|
||||
print misc.Run('run-script.py ' + self.before_script)
|
||||
print 'executing pre-connectiong script'
|
||||
misc.ExecuteScript(self.before_script)
|
||||
|
||||
# Put it down
|
||||
print 'Interface down'
|
||||
@@ -617,7 +617,7 @@ class WiredConnectThread(ConnectThread):
|
||||
self.SetStatus('setting_static_dns')
|
||||
if self.network.get('use_global_dns'):
|
||||
wnettools.SetDNS(misc.Noneify(self.global_dns_1),
|
||||
misc.Noneify(self.global_dns_2),
|
||||
misc.Noneify(self.global_dns_2),
|
||||
misc.Noneify(self.global_dns_3))
|
||||
else:
|
||||
wnettools.SetDNS(self.network.get('dns1'),
|
||||
@@ -626,7 +626,7 @@ class WiredConnectThread(ConnectThread):
|
||||
#execute post-connection script if necessary
|
||||
if misc.Noneify(self.after_script):
|
||||
print 'executing post connection script'
|
||||
print misc.Run('./run-script.py ' + self.after_script)
|
||||
misc.ExecuteScript(self.after_script)
|
||||
|
||||
self.SetStatus('done')
|
||||
print 'Connecting thread exiting.'
|
||||
|
||||
Reference in New Issue
Block a user