summaryrefslogtreecommitdiffstats
path: root/man
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-04-03 15:54:49 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2024-04-03 16:52:07 +0200
commit47fba8f9253a3a9f08a39f5ee5a13e9286c046b7 (patch)
tree5262b0d80aa82888a28b335305b2f37185195611 /man
parentMerge pull request #32057 from yuwata/man-example (diff)
downloadsystemd-47fba8f9253a3a9f08a39f5ee5a13e9286c046b7.tar.xz
systemd-47fba8f9253a3a9f08a39f5ee5a13e9286c046b7.zip
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.
Diffstat (limited to 'man')
-rw-r--r--man/notify-selfcontained-example.c12
1 files changed, 12 insertions, 0 deletions
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;
}