[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[[RFC] Netcfg add WPA support 4/4] Remove killwpa.sh



Make wpasupplicant create a pidfile so we can kill it without having to use system().
(cherry picked from commit d339676e3a6b6234f717e2911637b4231b9dacfe)
---
 packages/netcfg/dhcp.c     |    6 ------
 packages/netcfg/killwpa.sh |   16 ----------------
 packages/netcfg/netcfg.h   |    2 ++
 packages/netcfg/wpa.c      |   24 +++++++++++++++++++++++-
 4 files changed, 25 insertions(+), 23 deletions(-)
 delete mode 100755 packages/netcfg/killwpa.sh

diff --git a/packages/netcfg/dhcp.c b/packages/netcfg/dhcp.c
index 5a705ad..40d911f 100644
--- a/packages/netcfg/dhcp.c
+++ b/packages/netcfg/dhcp.c
@@ -200,12 +200,6 @@ static int kill_dhcp_client(void)
     return 0;
 }
 
-static int kill_wpa_supplicant(void)
-{
-    system("killwpa.sh");
-    return 0;
-}
-
 /*
  * Poll the started DHCP client for netcfg/dhcp_timeout seconds (def. 15)
  * and return 0 if a lease is known to have been acquired,
diff --git a/packages/netcfg/killwpa.sh b/packages/netcfg/killwpa.sh
deleted file mode 100755
index b370bb0..0000000
--- a/packages/netcfg/killwpa.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-# Killall for wpasupplicant
-
-# Use [] in sed /address/ to avoid matching sed command itself in ps output
-pids=$(ps ax | sed -n '/[w]pa/s/^[ ]*\([0-9]*\).*/\1/p')
-
-for pid in $pids; do
-  if kill -0 $pid 2>/dev/null; then
-    kill -TERM $pid
-    sleep 1
-    # Still alive? Die!
-    if kill -0 $pid 2>/dev/null; then
-      kill -KILL $pid
-    fi
-  fi
-done
diff --git a/packages/netcfg/netcfg.h b/packages/netcfg/netcfg.h
index da4f82a..5aed8c0 100644
--- a/packages/netcfg/netcfg.h
+++ b/packages/netcfg/netcfg.h
@@ -11,6 +11,7 @@
 #define DOMAIN_FILE     "/tmp/domain_name"
 #define NTP_SERVER_FILE "/tmp/dhcp-ntp-servers"
 #define WPASUPP_FILE    "/etc/wpa_supplicant/wpa_supplicant.conf"
+#define WPAPID	 	"/var/run/wpa_supplicat/wpa_supplicant.pid"
 
 #define DEVNAMES	"/etc/network/devnames"
 #define DEVHOTPLUG	"/etc/network/devhotplug"
@@ -118,6 +119,7 @@ extern int netcfg_wireless_set_essid (struct debconfclient *client, char* iface,
 extern int netcfg_wireless_set_wep (struct debconfclient *client, char* iface);
 extern int netcfg_wireless_set_security (struct debconfclient *client, char* iface);
 extern int netcfg_set_passphrase (struct debconfclient *client, char* iface);
+extern int kill_wpa_supplicant (void);
 
 extern int netcfg_write_wpa (char *essid, char *passphrase);
 extern int start_wpa_supplicant (struct debconfclient *client);
diff --git a/packages/netcfg/wpa.c b/packages/netcfg/wpa.c
index ab936f6..6cac3a2 100644
--- a/packages/netcfg/wpa.c
+++ b/packages/netcfg/wpa.c
@@ -52,6 +52,27 @@ static void wpa_supplicant_sigchild (int sig __attribute__ ((unused)))
   wpa_supplicant_pid = -1;
 }
 
+int kill_wpa_supplicant(void)
+{
+  int ret;
+  pid_t wpa_pid;
+  FILE *fp;
+
+  fp = (file_open (WPAPID, "r"));
+  if (fp == NULL)
+    di_warning ("Couldn't read Wpasupplicant pid file");
+  else {
+    fscanf (fp, "%d", &wpa_pid);
+    fclose (fp);
+    }
+    if ((ret = kill(wpa_pid, SIGTERM)) == 0)
+      return 0;
+    else {
+      kill(wpa_pid, SIGKILL);
+      return 0;
+    }
+}
+
 int start_wpa_supplicant (struct debconfclient *client)
 {
 
@@ -67,7 +88,8 @@ wpa_supplicant_pid = fork();
 
   if (wpa_supplicant_pid == 0) {
         fclose(client->out);
-        if (execlp ("wpa_supplicant", "wpa_supplicant", "-i", interface, "-c", "/etc/wpa_supplicant/wpa_supplicant.conf", "-B", NULL) == -1) {
+         if (execlp ("wpa_supplicant", "wpa_supplicant", "-i", interface, "-c",
+                     "/etc/wpa_supplicant/wpa_supplicant.conf", "-P", WPAPID, "-B", NULL) == -1) {
             di_error("could not exec wpasupplicant: %s", strerror(errno));
             return 1;
           }
-- 
1.5.5.1


Reply to: