-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
f3d7bba
to
3149db7
Compare
sink_service/source/main.c
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
sink_service/source/main.c
Outdated
@@ -308,7 +338,7 @@ int main(int argc, char * argv[]) | |||
goto finish; | |||
} | |||
|
|||
for (;;) | |||
while (!stop_requested) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
3149db7
to
42fa87e
Compare
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).