From 4cbf560edf64569bc6780e3c67b660c20743560d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 4 Apr 2024 10:57:30 +0200 Subject: [PATCH] man/notify-selfcontained-example: check argument first This is just good style. In this particular case, if the argument is incorrect and the function is not tested with $NOTIFY_SOCKET set, the user could not get the proper error until running for real. Also, remove mention of systemd. The protocol is fully generic on purpose. --- man/notify-selfcontained-example.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/man/notify-selfcontained-example.c b/man/notify-selfcontained-example.c index 90c38613741..6bbe4f2e3ba 100644 --- a/man/notify-selfcontained-example.c +++ b/man/notify-selfcontained-example.c @@ -41,10 +41,7 @@ static int notify(const char *message) { _cleanup_(closep) int fd = -1; const char *socket_path; - socket_path = getenv("NOTIFY_SOCKET"); - if (!socket_path) - return 0; /* Not running under systemd? Nothing to do */ - + /* Verify the argument first */ if (!message) return -EINVAL; @@ -52,6 +49,11 @@ static int notify(const char *message) { if (message_length == 0) return -EINVAL; + /* If the variable is not set, the protocol is a noop */ + socket_path = getenv("NOTIFY_SOCKET"); + if (!socket_path) + return 0; /* Not set? Nothing to do */ + /* Only AF_UNIX is supported, with path or abstract sockets */ if (socket_path[0] != '/' && socket_path[0] != '@') return -EAFNOSUPPORT; -- 2.47.3