Skip to content
Snippets Groups Projects
Verified Commit b46683a4 authored by Karel Koci's avatar Karel Koci :metal:
Browse files

patches/openwrt: add patch for procd for process check

This fixes restarts of hostapd process by netifd when wpad (hostapd)
program file is removed/replaced.

This happes on update and tiggers start of new hostapd instance while
old one is still running.
parent b9a661cb
Branches
Tags
1 merge request!177patches/openwrt: add patch for procd for process check
From 816bdf25140d76ff563f67c753d8392eff19b2d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <karel.koci@nic.cz>
Date: Thu, 28 May 2020 11:54:37 +0200
Subject: [PATCH] Improve netifd process detection
---
package/network/config/netifd/Makefile | 2 +-
...pid_path-to-work-with-delted-file-as.patch | 69 +++++++++++++++++++
2 files changed, 70 insertions(+), 1 deletion(-)
create mode 100644 package/network/config/netifd/patches/0001-utils-fix-check_pid_path-to-work-with-delted-file-as.patch
diff --git a/package/network/config/netifd/Makefile b/package/network/config/netifd/Makefile
index 31640c80cd..0edd27795b 100644
--- a/package/network/config/netifd/Makefile
+++ b/package/network/config/netifd/Makefile
@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=netifd
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git
diff --git a/package/network/config/netifd/patches/0001-utils-fix-check_pid_path-to-work-with-delted-file-as.patch b/package/network/config/netifd/patches/0001-utils-fix-check_pid_path-to-work-with-delted-file-as.patch
new file mode 100644
index 0000000000..82a6441399
--- /dev/null
+++ b/package/network/config/netifd/patches/0001-utils-fix-check_pid_path-to-work-with-delted-file-as.patch
@@ -0,0 +1,69 @@
+From 8ce3d13d9ba56543c2d627fd429fab171b40994e Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <cynerd@email.cz>
+Date: Thu, 28 May 2020 10:43:44 +0200
+Subject: [PATCH] utils: fix check_pid_path to work with delted file as well
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+check_pid_patch is checking if process with given PID and executable
+path is running. If this code fails the rest of the code can be
+convinced that program is no longer running and possibly spawns new
+instance that can collide with already running one. This behavior was
+reproduced with hostapd.
+
+Symbolic link exe in process subdirectory in /proc points to original
+executable. The problem is that it reads as original path plus string
+' (deleted)' if file is removed. The process is still running but
+original file is no longer available on files ystem.
+
+This behavior is triggered not only when file is removed (unlinked) but
+also when file is replaced. This happens clearly on package update. In
+general this happens any time all references (hard links) to file are
+removed from file system.
+
+This is not ultimate fix as exe link points to any last reference on
+file system with preference for original one. The problem is if there
+are multiple references and the original one is removed. This can be
+reproduced just by copying executable (hard linking) and unlinking the
+original one. In such case exe link would point to copy and not to
+original deleted one.
+
+Signed-off-by: Karel Kočí <cynerd@email.cz>
+---
+ utils.c | 11 ++++++++---
+ 1 file changed, 8 insertions(+), 3 deletions(-)
+
+diff --git a/utils.c b/utils.c
+index ba26952..4f40b4b 100644
+--- a/utils.c
++++ b/utils.c
+@@ -176,6 +176,8 @@ crc32_file(FILE *fp)
+
+ bool check_pid_path(int pid, const char *exe)
+ {
++ const char deleted[] = " (deleted)";
++ const int deleted_len = strlen(deleted);
+ int proc_exe_len;
+ int exe_len = strlen(exe);
+
+@@ -191,10 +193,13 @@ bool check_pid_path(int pid, const char *exe)
+ proc_exe_len = readlink(proc_exe, proc_exe_buf, exe_len);
+ #endif
+
+- if (proc_exe_len != exe_len)
++ if (proc_exe_len == exe_len)
++ return !memcmp(exe, proc_exe_buf, exe_len);
++ else if (proc_exe_len == exe_len + deleted_len)
++ return !memcmp(exe, proc_exe_buf, exe_len) &&
++ !memcmp(exe + exe_len, deleted, deleted_len);
++ else
+ return false;
+-
+- return !memcmp(exe, proc_exe_buf, exe_len);
+ }
+
+ static const char * const uci_validate_name[__BLOBMSG_TYPE_LAST] = {
+--
+2.26.2
+
--
2.26.2
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment