Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initramfs: fix killing child PIDs #496

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/initramfs-tools/scripts/local-bottom/clevis.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,22 @@ esac
[ -s /run/clevis.pid ] || exit 0

pid=$(cat /run/clevis.pid)
child_pids=$(ps -o pid,ppid | awk -v pid="$pid" '$2==pid { print $1 }')
child_pids="$({ ps -o pid,ppid 2>/dev/null || ps -l ||
{ echo 'clevis: unable to get list of processes' >&2; exit 1; }; } |
awk -v pid="$pid" '
NR==1 {
for (i=1; i<=NF; i++) if ($i == "PID") pid_col = i; else if ($i == "PPID") ppid_col = i
if (!pid_col || !ppid_col) { print "clevis: unable to find PID and/or PPID columns in ps output" | "cat >&2"; exit 1 }
next
}
{ if ($ppid_col == pid) print $pid_col }')"

for kill_pid in $pid $child_pids; do
kill "$kill_pid"
kill "$kill_pid" 2>/dev/null
done

rm -f /run/clevis.pid

# Not really worried about downing extra interfaces: they will come up
# during the actual boot. Might make this configurable later if needed.

Expand Down