Skip to content

Commit

Permalink
Add guarded_halt for completeness
Browse files Browse the repository at this point in the history
  • Loading branch information
fhunleth committed Nov 25, 2022
1 parent ff0ddbf commit cd9536a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/heart.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ static int message_loop()

print_log("heart: poweroff signaled. No longer petting the WDT");
sync();
} else if (mp_len == 13 && memcmp(m.fill, "guarded_halt", 12) == 0) {
pet_watchdog(now);
stop_petting_watchdog();
kill(1, SIGUSR1); // SIGUSR1 signals "halt" to PID 1

print_log("heart: halt signaled. No longer petting the WDT");
sync();
} else if (mp_len == 15 && memcmp(m.fill, "init_handshake", 14) == 0) {
/* Application has said that it's completed initialization */
init_handshake_happened = 1;
Expand Down
24 changes: 24 additions & 0 deletions tests/heart_test/test/guarded_reboot_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,28 @@ defmodule GuardedRebootTest do
Heart.shutdown(heart)
assert_receive {:exit, 0}
end

test "guarded halt", context do
heart = start_supervised!({Heart, context.init_args})
assert_receive {:heart, :heart_ack}
assert_receive {:event, "open(/dev/watchdog0) succeeded"}
assert_receive {:event, "pet(1)"}

{:ok, :heart_ack} = Heart.set_cmd(heart, "guarded_halt")

# Final WDT pet
assert_receive {:event, "pet(1)"}

# Tell PID 1 to halt
assert_receive {:event, "kill(1, SIGUSR1)"}

# Proactive sync
assert_receive {:event, "sync()"}

Process.sleep(6)

# Run normal shutdown and check that there aren't any more WDT pets
Heart.shutdown(heart)
assert_receive {:exit, 0}
end
end

0 comments on commit cd9536a

Please sign in to comment.