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

Handle SIGINT and SIGTERM signals for graceful shutdown of sink service #287

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

sgunes-wirepas
Copy link
Contributor

This makes it easier to test the sink service for memory issues (like in #286) using valgrind or sanitizers

Also speeds up the stopping of the docker container (docker sends SIGTERM when stopping).

@sgunes-wirepas sgunes-wirepas marked this pull request as ready for review January 15, 2025 13:26
@@ -149,6 +150,30 @@ static int open_and_check_connection(unsigned long baudrate, char * port_name)
return 0;
}

static volatile sig_atomic_t stop_requested = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you prefix it with m_ as it is a global variable of the module.

@@ -308,7 +338,7 @@ int main(int argc, char * argv[])
goto finish;
}

for (;;)
while (!stop_requested)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I miss something here, but how does sd_bus_wait exit in order to evaluate this condition?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would their be a way to force it from stop_signal_handler ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point, thanks. At least when I ran it, sd_bus_wait was returning quite fast (almost immediately) but maybe it is different when there is an unresponsive sink? Do you think calling sd_bus_wait with a timeout value of some seconds be safer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like sd_bus_wait is using ppoll internally, and that is returning also when any signal is caught.

sd_bus_wait seems to treat the EINTR error from ppoll as a success:
https://github.com/systemd/systemd/blob/9ef559a0363f6baea17a7dfdc15ff52ba43bc4f6/src/libsystemd/sd-bus/sd-bus.c#L3426

This makes it easier to test the sink service for memory issues, and
speeds up the stopping of the docker container (docker sends SIGTERM
when stopping).
@sgunes-wirepas sgunes-wirepas merged commit dfb5876 into master Jan 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants