summaryrefslogtreecommitdiff
path: root/src/conf_mode/interfaces-wireless.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-29 15:46:12 +0200
committerChristian Poessinger <christian@poessinger.com>2020-03-29 15:46:12 +0200
commit35e0254622f8f099db3c7829cd61b85f6976c416 (patch)
tree77014e7562e26edf4f0561a79c72babcdf52df14 /src/conf_mode/interfaces-wireless.py
parent552106b0fb27003e5e5be5494f2213f54a699b9e (diff)
downloadvyos-1x-35e0254622f8f099db3c7829cd61b85f6976c416.tar.gz
vyos-1x-35e0254622f8f099db3c7829cd61b85f6976c416.zip
vyos.util: increase usage of process_running() and remove duplicated code
OpenVPN, WIFI, SSTP all had the same boiler plate copied about checking if a process associated with a pidfile is running or not. This has been migrated to the common library function vyos.util.process_running().
Diffstat (limited to 'src/conf_mode/interfaces-wireless.py')
-rwxr-xr-xsrc/conf_mode/interfaces-wireless.py23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py
index 454ad96dc..82a80d247 100755
--- a/src/conf_mode/interfaces-wireless.py
+++ b/src/conf_mode/interfaces-wireless.py
@@ -25,15 +25,15 @@ from grp import getgrnam
from re import findall
from subprocess import Popen, PIPE
-from psutil import pid_exists
from netifaces import interfaces
from netaddr import *
-from vyos.ifconfig import WiFiIf
-from vyos.ifconfig_vlan import apply_vlan_config, verify_vlan_config
+from vyos import ConfigError
from vyos.configdict import list_diff, vlan_to_dict
from vyos.config import Config
-from vyos import ConfigError
+from vyos.ifconfig import WiFiIf
+from vyos.ifconfig_vlan import apply_vlan_config, verify_vlan_config
+from vyos.util import process_running
user = 'root'
group = 'vyattacfg'
@@ -1364,15 +1364,9 @@ def verify(wifi):
return None
def generate(wifi):
- pid = 0
# always stop hostapd service first before reconfiguring it
pidfile = get_pid('hostapd', wifi['intf'])
- if os.path.isfile(pidfile):
- pid = 0
- with open(pidfile, 'r') as f:
- pid = int(f.read())
-
- if pid_exists(pid):
+ if process_running(pidfile):
cmd = 'start-stop-daemon'
cmd += ' --stop '
cmd += ' --quiet'
@@ -1382,12 +1376,7 @@ def generate(wifi):
# always stop wpa_supplicant service first before reconfiguring it
pidfile = get_pid('wpa_supplicant', wifi['intf'])
- if os.path.isfile(pidfile):
- pid = 0
- with open(pidfile, 'r') as f:
- pid = int(f.read())
-
- if pid_exists(pid):
+ if process_running(pidfile):
cmd = 'start-stop-daemon'
cmd += ' --stop '
cmd += ' --quiet'