[openwrt/openwrt] base-files: stage2: improve /proc/*/stat parser
LEDE Commits
lede-commits at lists.infradead.org
Sat Nov 13 10:38:10 PST 2021
dangole pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/4d3303b1bddf3c66fc0a05fb5eb45ceac48cd0d5
commit 4d3303b1bddf3c66fc0a05fb5eb45ceac48cd0d5
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Sat Nov 13 16:29:52 2021 +0000
base-files: stage2: improve /proc/*/stat parser
Simply reading /proc/*/stat as a space-separated string will not work
as the process name may itself contain spaces. Hence we must match on
the '(' and ')' characters around the process name and can then handle
the remaining string as space-separated values.
This fixes shell error messages which have been popping up the console
due to spaces in process names being interpreted as field separators.
Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
package/base-files/files/lib/upgrade/stage2 | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/package/base-files/files/lib/upgrade/stage2 b/package/base-files/files/lib/upgrade/stage2
index 45fb98d889..74edd61104 100755
--- a/package/base-files/files/lib/upgrade/stage2
+++ b/package/base-files/files/lib/upgrade/stage2
@@ -97,12 +97,15 @@ kill_remaining() { # [ <signal> [ <loop> ] ]
[ -f "$stat" ] || continue
local pid name state ppid rest
- read pid name state ppid rest < $stat
- name="${name#(}"; name="${name%)}"
+ read pid rest < $stat
+ name="${rest#\(}" ; rest="${name##*\) }" ; name="${name%\)*}"
+ set -- $rest ; state="$1" ; ppid="$2"
# Skip PID1, our parent, ourself and our children
[ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$ -a $ppid -ne $$ ] || continue
+ [ -f "/proc/$pid/cmdline" ] || continue
+
local cmdline
read cmdline < /proc/$pid/cmdline
More information about the lede-commits
mailing list