Skip to content

Commit

Permalink
fix(axevent_example): Return Break from signal handlers (#125)
Browse files Browse the repository at this point in the history
Benefits include:
- The signal handler is automatically unregistered and subsequent
  signals of the same type will cause the program to exit immediately.
- The space of possible behaviors suggested by the code better match
  the space of actual behaviors; I can find no literature and come up
  with no experiment that causes the signal handler to be called twice
  even when the signal handler returns continue.

Note however that:
- If a task is already running, the signal handler will not run until
  it has returned.
- If other tasks were already scheduled before the signal was received,
  these may still run before the main loop returns; I am unsure about
  the details.
- Other sources are not automatically cleaned up; if the `SourceId` is
  kept then we can call `.remove()` on this to clean them up.

---

`apps/axstorage_example/src/main.rs`:
- Use `unix_signal_add_once` because it is more concise.
  • Loading branch information
apljungquist authored Nov 4, 2024
1 parent aacb7e4 commit 4abd748
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps-aarch64.checksum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
5ffc7c3b88bd966b8f0310ac7299ff05df37cfb9 target-aarch64/acap/axstorage_example_0_0_0_aarch64.eap
0018f1c3b46545bebbef794b68900c254a7785e7 target-aarch64/acap/axstorage_example_0_0_0_aarch64.eap
10227865e8dadfeeda0e4a3c1a0d88ed18bc019a target-aarch64/acap/bounding_box_example_0_0_0_aarch64.eap
27016805520639a6a1029661f1225f1f6df180fd target-aarch64/acap/consume_analytics_metadata_0_0_0_aarch64.eap
51f9e2ce6cfc81264afa310c9c51ee05ff45666d target-aarch64/acap/embedded_web_page_0_0_0_aarch64.eap
Expand Down
2 changes: 1 addition & 1 deletion apps-aarch64.filesize
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
3694 target-aarch64/acap/axstorage_example_0_0_0_aarch64.eap
3698 target-aarch64/acap/axstorage_example_0_0_0_aarch64.eap
2213 target-aarch64/acap/bounding_box_example_0_0_0_aarch64.eap
2083 target-aarch64/acap/consume_analytics_metadata_0_0_0_aarch64.eap
859 target-aarch64/acap/embedded_web_page_0_0_0_aarch64.eap
Expand Down
14 changes: 4 additions & 10 deletions apps/axstorage_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,13 @@ fn main() -> ExitCode {

glib::timeout_add_seconds(10, || write_data("file1"));
glib::timeout_add_seconds(10, || write_data("file2"));
glib::unix_signal_add(SIGTERM, {
glib::unix_signal_add_once(SIGTERM, {
let main_loop = main_loop.clone();
move || {
main_loop.quit();
ControlFlow::Continue
}
move || main_loop.quit()
});
glib::unix_signal_add(SIGINT, {
glib::unix_signal_add_once(SIGINT, {
let main_loop = main_loop.clone();
move || {
main_loop.quit();
ControlFlow::Continue
}
move || main_loop.quit()
});

main_loop.run();
Expand Down

0 comments on commit 4abd748

Please sign in to comment.