SVN: wireless-net/trunk/sysconfig/interfaces/up.d/ppp/wlan-up.py

arekm arekm at pld-linux.org
Mon Nov 6 21:21:16 CET 2006


Author: arekm
Date: Mon Nov  6 21:21:14 2006
New Revision: 7941

Modified:
   wireless-net/trunk/sysconfig/interfaces/up.d/ppp/wlan-up.py
Log:
Try SIGTERM and later SIGKILL for stale sessions.

Modified: wireless-net/trunk/sysconfig/interfaces/up.d/ppp/wlan-up.py
==============================================================================
--- wireless-net/trunk/sysconfig/interfaces/up.d/ppp/wlan-up.py	(original)
+++ wireless-net/trunk/sysconfig/interfaces/up.d/ppp/wlan-up.py	Mon Nov  6 21:21:14 2006
@@ -2,7 +2,14 @@
 # Arkadiusz Miskiewicz <arekm at pld-linux.org>
 # License: GPL
 
-import os, string, re, time, ConfigParser;
+import os, signal, errno, string, re, time, ConfigParser;
+
+def pid_exists(pid):
+    try:
+        os.kill(pid, 0)
+        return 1
+    except OSError, err:
+        return err.errno == errno.EPERM
 
 config = ConfigParser.ConfigParser()
 config.read('/etc/wireless-net/wlan.conf')
@@ -67,9 +74,28 @@
     if len(used_ifaces):
         fl.write("%s: \"%s\" already logged in - killing stale sessions [stale=%s, iface=%s, ip=%s, mac=%s]\n" % (time.asctime(time.gmtime()), user, used_ifaces, ppp_iface, ip, reth_mac))
     for iface in used_ifaces:
-        os.system("/bin/kill -TERM `/bin/cat /var/run/%s.pid` > /dev/null 2>&1" % iface)
-    fl.write("%s: \"%s\" logged in [iface=%s, ip=%s, mac=%s]\n"
-            % (time.asctime(time.gmtime()), user, ppp_iface, ip, reth_mac))
+        pid_file = "/var/run/%s.pid" % iface
+        if not os.path.isfile(pid_file):
+            fl.write("%s: \"%s\" unreadable %s file, can't kill stale session [iface=%s]\n" % (time.asctime(time.gmtime()), user, pid_file, iface))
+            continue
+        fp_pid = open("/var/run/%s.pid" % iface, "r")
+        pid = fp_pid.readline()
+        fp_pid.close()
+        pid = int(pid)
+        if len(pid) and pid > 0 and pid_exists(pid):
+            try:
+                os.kill(pid, signal.SIGTERM)
+            except OSError, e:
+                fl.write("%s: \"%s\" SIGTERM unable to kill stale session [iface=%s, pid=%d]\n" % (time.asctime(time.gmtime()), user, iface, pid)
+            if pid_exists(pid):
+                time.sleep(1)
+            if pid_exists(pid):
+                try:
+                    os.kill(pid, signal.SIGKILL)
+                except OSError, e:
+                    fl.write("%s: \"%s\" SIGKILL unable to kill stale session [iface=%s, pid=%d]\n" % (time.asctime(time.gmtime()), user, iface, pid)
+    
+    fl.write("%s: \"%s\" logged in [iface=%s, ip=%s, mac=%s]\n" % (time.asctime(time.gmtime()), user, ppp_iface, ip, reth_mac))
 
     # filtering
     os.system("iptables --flush wlanfilter_%s 2> /dev/null" % ppp_iface)


More information about the pld-cvs-commit mailing list