Skip to content

Commit

Permalink
initramfs: fix killing child PIDs
Browse files Browse the repository at this point in the history
Ubuntu's initramfs Busybox does not support `ps -o pid,ppid`, so fallback
to unpredictable `ps -l`. In any case use `awk` to find the position of PID
and PPID columns and dump appropriate child PIDs. This should be hopefully
bullet-proof.

Also clean-up leftover PID file.

Signed-off-by: Oldřich Jedlička <[email protected]>
  • Loading branch information
oldium authored and sergio-correia committed Nov 7, 2024
1 parent 0cad2e0 commit 55eb002
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit 55eb002

Please sign in to comment.