Skip to content

Commit

Permalink
flatcar-update: Don't end with SIGTERM
Browse files Browse the repository at this point in the history
The cleanup of all subprocesses through "kill 0" also ends up sending a
SIGTERM to the script itself, which prevents ending with a successful
return code.
Keep track of spawned subprocesses (at least the top ones) and only kill
them.
  • Loading branch information
pothos committed Sep 4, 2023
1 parent 242ad2e commit 879698a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bin/flatcar-update
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,12 @@ tee -a /tmp/response > /dev/null <<-EOF
</updatecheck><event status="ok"></event></app></response>
EOF

trap "umount /usr/share/update_engine/update-payload-key.pub.pem 2> /dev/null || true; rm -f /tmp/response /tmp/payload-server ; kill 0" EXIT INT
true > /tmp/payload-server-pids
trap "umount /usr/share/update_engine/update-payload-key.pub.pem 2> /dev/null || true; rm -f /tmp/response /tmp/payload-server ; cat /tmp/payload-server-pids | xargs -r kill ; rm -f /tmp/payload-server-pids" EXIT INT
ncat --keep-open -c "echo -en 'HTTP/1.1 200 OK\ncontent-type: text/xml\ncontent-length: $(stat --printf='%s\n' /tmp/response)\n\n'; cat /tmp/response" -l "$LISTEN_PORT_1" &
CHILDPID="$!"
echo "${CHILDPID}" >> /tmp/payload-server-pids


# Helper script because inline quoting is insane
tee /tmp/payload-server > /dev/null <<'EOF'
Expand All @@ -267,6 +271,8 @@ EOF

chmod +x /tmp/payload-server
socat TCP-LISTEN:"${LISTEN_PORT_2}",reuseaddr,fork SYSTEM:'/tmp/payload-server /var/tmp/flatcar-update/ application/gzip' &
CHILDPID="$!"
echo "${CHILDPID}" >> /tmp/payload-server-pids

if [ "${FORCE_DEV_KEY}" = "1" ] || [ "${FORCE_FLATCAR_KEY}" = "1" ]; then
rm -f /tmp/key
Expand Down

0 comments on commit 879698a

Please sign in to comment.