From 7bced397c9fd66965753e5fc0fd3dfa535ca1c9b Mon Sep 17 00:00:00 2001 From: xiongshenglan Date: Wed, 19 Jul 2023 15:13:06 +0800 Subject: [PATCH] shadow userdel: add the adaptation to the busybox ps in 01-kill_user_procs.sh In some embedded systems, users only use the ps provided by the busybox. But the ps provided by the busybox does not support the -eo option by default. As a result, an error is reported when the userdel is used. So add a judgment on ps. If there is no ps -eo, traverse the process directly. The error information is as follows: # userdel xsl ps: invalid option -- 'e' Signed-off-by: xiongshenglan Reference: https://github.com/shadow-maint/shadow/commit/7bced397c9fd66965753e5fc0fd3dfa535ca1c9b Conflict: NA --- .../userdel-pre.d/01-kill_user_procs.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/etc/shadow-maint/userdel-pre.d/01-kill_user_procs.sh b/etc/shadow-maint/userdel-pre.d/01-kill_user_procs.sh index ca481b1b..d2d7ef26 100755 --- a/etc/shadow-maint/userdel-pre.d/01-kill_user_procs.sh +++ b/etc/shadow-maint/userdel-pre.d/01-kill_user_procs.sh @@ -4,14 +4,17 @@ PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Check user exists, and if so, send sigkill to processes that the user owns -RUNNING=`ps -eo user | grep -Fx "$SUBJECT" | wc -l` - -# if the user does not exist, RUNNING will be 0 - -if [ "${RUNNING}x" = "0x" ]; then - exit 0 +ps -eo user >/dev/null 2>&1 +if [ $? -eq 0 ]; then + RUNNING=`ps -eo user | grep -Fx "$SUBJECT" | wc -l` + # if the user does not exist, RUNNING will be 0 + if [ "${RUNNING}x" = "0x" ]; then + exit 0 + fi fi +# If there is no ps -eo, traverse the process directly. + ls -1 /proc | while IFS= read -r PROC; do echo "$PROC" | grep -E '^[0-9]+$' >/dev/null if [ $? -ne 0 ]; then -- 2.27.0