From 39fb8c3edc74a7e419d95e2946a0b5a1206edc25 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 28 Dec 2020 14:42:30 +0100 Subject: [PATCH] wireless: add support for not killing processes on teardown When using a global hostapd/wpa_supplicant instance, it should not be killed if a single radio is torn down Signed-off-by: Felix Fietkau --- scripts/netifd-wireless.sh | 1 + wireless.c | 7 ++++++- wireless.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/netifd-wireless.sh b/scripts/netifd-wireless.sh index 72f36d6..73bce3d 100644 --- a/scripts/netifd-wireless.sh +++ b/scripts/netifd-wireless.sh @@ -174,6 +174,7 @@ _wireless_add_process() { json_add_int pid "$1" json_add_string exe "$exe" [ -n "$3" ] && json_add_boolean required 1 + [ -n "$4" ] && json_add_boolean keep 1 exe2="$(readlink -f /proc/$1/exe)" [ "$exe" != "$exe2" ] && echo "WARNING (wireless_add_process): executable path $exe does not match process $1 path ($exe2)" _wdev_notify diff --git a/wireless.c b/wireless.c index a9917a3..818f7c9 100644 --- a/wireless.c +++ b/wireless.c @@ -254,7 +254,7 @@ wireless_process_kill_all(struct wireless_device *wdev, int signal, bool free) list_for_each_entry_safe(proc, tmp, &wdev->script_proc, list) { bool check = wireless_process_check(proc); - if (check) { + if (check && !proc->keep) { D(WIRELESS, "Wireless device '%s' kill pid %d\n", wdev->name, proc->pid); kill(proc->pid, signal); } @@ -1250,12 +1250,14 @@ wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data PROC_ATTR_PID, PROC_ATTR_EXE, PROC_ATTR_REQUIRED, + PROC_ATTR_KEEP, __PROC_ATTR_MAX }; static const struct blobmsg_policy proc_policy[__PROC_ATTR_MAX] = { [PROC_ATTR_PID] = { .name = "pid", .type = BLOBMSG_TYPE_INT32 }, [PROC_ATTR_EXE] = { .name = "exe", .type = BLOBMSG_TYPE_STRING }, [PROC_ATTR_REQUIRED] = { .name = "required", .type = BLOBMSG_TYPE_BOOL }, + [PROC_ATTR_KEEP] = { .name = "keep", .type = BLOBMSG_TYPE_BOOL }, }; struct blob_attr *tb[__PROC_ATTR_MAX]; struct wireless_process *proc; @@ -1282,6 +1284,9 @@ wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data if (tb[PROC_ATTR_REQUIRED]) proc->required = blobmsg_get_bool(tb[PROC_ATTR_REQUIRED]); + if (tb[PROC_ATTR_KEEP]) + proc->keep = blobmsg_get_bool(tb[PROC_ATTR_KEEP]); + D(WIRELESS, "Wireless device '%s' add pid %d\n", wdev->name, proc->pid); list_add(&proc->list, &wdev->script_proc); uloop_timeout_set(&wdev->script_check, 0); diff --git a/wireless.h b/wireless.h index 5fedd20..9a2d512 100644 --- a/wireless.h +++ b/wireless.h @@ -127,6 +127,7 @@ struct wireless_process { int pid; bool required; + bool keep; }; void wireless_device_create(struct wireless_driver *drv, const char *name, struct blob_attr *data); -- 2.30.2