diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:18:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:18:39 +0000 |
commit | 5242eef8fc54636a41701fd9d7083ba6e4a4e0b3 (patch) | |
tree | e6a0980092957865a937cc0f34446df3d5194e99 /etc/shadow-maint/userdel-pre.d | |
parent | Releasing progress-linux version 1:4.13+dfsg1-5~progress7.99u1. (diff) | |
download | shadow-5242eef8fc54636a41701fd9d7083ba6e4a4e0b3.tar.xz shadow-5242eef8fc54636a41701fd9d7083ba6e4a4e0b3.zip |
Merging upstream version 1:4.15.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'etc/shadow-maint/userdel-pre.d')
-rwxr-xr-x | etc/shadow-maint/userdel-pre.d/01-kill_user_procs.sh | 31 |
1 files changed, 31 insertions, 0 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 new file mode 100755 index 0000000..d2d7ef2 --- /dev/null +++ b/etc/shadow-maint/userdel-pre.d/01-kill_user_procs.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +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 + +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 + continue + fi + if [ -d "/proc/${PROC}" ]; then + USR=`stat -c "%U" /proc/${PROC}` + if [ "${USR}" = "${SUBJECT}" ]; then + echo "Killing ${SUBJECT} owned ${PROC}" + kill -9 "${PROC}" + fi + fi +done + |