From 32fd87f1db400350eadf87e84ae43d16df383bfb Mon Sep 17 00:00:00 2001
From: KatolaZ <katolaz@freaknet.org>
Date: Wed, 8 Mar 2017 11:14:14 +0000
Subject: [PATCH] Fixed bug in the restart of wpa_supplicant

---
 ChangeLog |  5 +++++
 setnet.sh | 17 ++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 146dc46..18e95e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-03-08  KatolaZ  <katolaz@freaknet.org>
+
+		* setnet.sh (wifi_restart_wpa): Corrected a bug in the restart of
+				wpa_supplicant.
+
 2017-03-07  KatolaZ  <katolaz@freaknet.org>
 
 		* setnet.sh (check_deps): Corrected a small bug in the parsing of options
diff --git a/setnet.sh b/setnet.sh
index c661fb8..34de178 100755
--- a/setnet.sh
+++ b/setnet.sh
@@ -1142,18 +1142,21 @@ wifi_restart_wpa(){
     WPA_PID=$(ps ax | grep wpa_supplicant | grep " -i ${DEVNAME} " | 
 sed -r -e 's/^\ +//g' | cut -d " " -f 1)
     
-	  log "wifi_restart_wpa" "WPA_PID: ${WPA_PID}"
-	  kill -9 ${WPA_PID}
-    
-	  wpa_supplicant -B -i ${DEVNAME} -c ${WPA_FILE} -P${WPA_PIDFILE} 2>&1 >/dev/null
-	  WPA_PID=$(ps ax | grep wpa_supplicant | grep " -i ${DEVNAME}" | \
+	if [ -n "${WPA_PID}" ]; then 
+		log "wifi_restart_wpa" "WPA_PID: ${WPA_PID}"
+		kill -9 ${WPA_PID}
+	else
+		log "wifi_restart_wpa" "no wpa_supplicant is running!!!"
+    fi
+	wpa_supplicant -B -i ${DEVNAME} -c ${WPA_FILE} -P${WPA_PIDFILE} 2>&1 >/dev/null
+	WPA_PID=$(ps ax | grep wpa_supplicant | grep " -i ${DEVNAME}" | \
                      sed -r -e 's/^\ +//g' | cut -d " " -f 1 )
-	  WPA_PID_SAVED=$(cat ${WPA_PIDFILE})
+	WPA_PID_SAVED=$(cat ${WPA_PIDFILE})
     log "wifi_restart_wpa" "WPA_PID: ${WPA_PID} WPA_PID_SAVED: ${WPA_PID_SAVED}"
 	  if [ -n "${WPA_PID}" ] &&  [ "${WPA_PID}" != "${WPA_PID_SAVED}" ]; then
 		    eval "${DIALOG}   --msgbox 'Error restarting wpa_supplicant' \
 			   ${INFO_HEIGHT} ${INFO_WIDTH}"
-	  else
+	   else
 		    eval "${DIALOG}   --msgbox 'wpa_supplicant restarted successfully' \
 			   ${INFO_HEIGHT} ${INFO_WIDTH}"
 	  fi