mirror of
https://github.com/systemd/systemd.git
synced 2025-01-21 22:04:01 +03:00
notify-example: also send STOPPING=1 at exit
I think the example should reflect the full set of lifecycle messages, including STOPPING=1, which tells the service manager that the service is already terminating. This is useful for reporting this information back to the user and to suppress repeated shutdown requests. It's not as important as the READY=1 and RELOADING=1 messages, since we actively wait for those from the service message if the right Type= is set. But it's still very valuable information, easy to do, and completes the state engine.
This commit is contained in:
parent
2dcc499bb8
commit
47fba8f925
@ -108,6 +108,10 @@ static int notify_reloading(void) {
|
||||
return notify(reload_message);
|
||||
}
|
||||
|
||||
static int notify_stopping(void) {
|
||||
return notify("STOPPING=1");
|
||||
}
|
||||
|
||||
static volatile sig_atomic_t reloading = 0;
|
||||
static volatile sig_atomic_t terminating = 0;
|
||||
|
||||
@ -169,5 +173,13 @@ int main(int argc, char **argv) {
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
r = notify_stopping();
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "Failed to report termination to $NOTIFY_SOCKET: %s\n", strerror(-r));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Do some shutdown work here … */
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user