From 47fba8f9253a3a9f08a39f5ee5a13e9286c046b7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 3 Apr 2024 15:54:49 +0200 Subject: 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. --- man/notify-selfcontained-example.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'man') diff --git a/man/notify-selfcontained-example.c b/man/notify-selfcontained-example.c index 9a7553e301..39f0dbe3fd 100644 --- a/man/notify-selfcontained-example.c +++ b/man/notify-selfcontained-example.c @@ -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; } -- cgit v1.2.3