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

Proper handling of SIGINT #228

Open
norro opened this issue Dec 15, 2021 · 2 comments
Open

Proper handling of SIGINT #228

norro opened this issue Dec 15, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@norro
Copy link
Collaborator

norro commented Dec 15, 2021

The system test (#225) as well as manual tests revealed, that handling of SIGINT doesn't seem to work properly, yet.
That is, when using rclc_executor_spin() for example, code after rclc_executor_spin() (e.g. example_service_node.c#L81-L82) is not executed when program is aborted through SIGINT.
The current context check in rclc_executor_spin_some doesn't seem to do the trick.

One option is to expose this feature through an explicit rclc::ok(), similar to rclcpp::ok()

@norro norro added the enhancement New feature or request label Dec 16, 2021
@Zard-C
Copy link
Contributor

Zard-C commented Jan 17, 2024

In rclcpp, we use signal_handler to catch the signal SIGINT and SIGTERM, which creates a thread that capturing signals, I am wondering that could we use the same method to exit?

I used rclc humble to test if the SIGINT was caught, unfortunatly, the behavior is not as we expected.
Here is the test code https://github.com/Zard-C/rclc/blob/3f746c17bea4bd584b246967f9958e4b4baa54b1/rclc_examples/src/example_executor.c#L167

[INFO] [1702829664.805125046] []: Created a timer with period 1000 ms.

Created timer with timeout 1000 ms.
Created subscriber topic_0:
Debug: number of DDS handles: 2
Published message Hello World!
Callback: I heard: Hello World!
^C

Even when I used setvbuf to force flush the output, it still shows that the clean job codes can not be reached.

I am positive for this feature enabled in rclc as well, it can let the program exit elegently. 😸

@JanStaschulat
Copy link
Contributor

JanStaschulat commented Jan 18, 2024

That's a good point. Currently, this check in rclc_executor_spin_some is used to stop spinning. It could be extended by catching a SGINT as well, as you mentioned. Or the while(true) condition in rclc_executor_spin (and other functions) could be replaced. Could you provide a pull request?

The only issue I see is, that rclc cannot rely on pthread library. It has to be portable for other RTOS, that do not support this thread API. Or an additional abstraction layer is necessary for thread creation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants