From: Lennart Poettering Date: Tue, 12 Mar 2024 13:33:33 +0000 (+0100) Subject: core: normalize how we issue sd_notify() from PID 1 X-Git-Tag: v256-rc1~521^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb44dc646b59989c1020a551e4721354e74610f1;p=thirdparty%2Fsystemd.git core: normalize how we issue sd_notify() from PID 1 Always cast to (void) if we ignore the return value. Always pass the first arg as boolean. Always prefix the first arg with /* unset_environment= */. --- diff --git a/src/core/main.c b/src/core/main.c index 07ec98252e8..551fb425c43 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -3282,7 +3282,8 @@ finish: #endif if (r < 0) - (void) sd_notifyf(0, "ERRNO=%i", -r); + (void) sd_notifyf(/* unset_environment= */ false, + "ERRNO=%i", -r); /* Try to invoke the shutdown binary unless we already failed. * If we failed above, we want to freeze after finishing cleanup. */ @@ -3295,7 +3296,8 @@ finish: /* This is primarily useful when running systemd in a VM, as it provides the user running the VM with * a mechanism to pick up systemd's exit status in the VM. */ - (void) sd_notifyf(0, "EXIT_STATUS=%i", retval); + (void) sd_notifyf(/* unset_environment= */ false, + "EXIT_STATUS=%i", retval); watchdog_free_device(); arg_watchdog_device = mfree(arg_watchdog_device); diff --git a/src/core/manager.c b/src/core/manager.c index d307c07a624..3cfccb79d60 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -264,12 +264,11 @@ static void manager_print_jobs_in_progress(Manager *m) { strempty(status_text)); } - sd_notifyf(false, - "STATUS=%sUser job %s/%s running (%s / %s)...", - job_of_n, - ident, - job_type_to_string(j->type), - time, limit); + (void) sd_notifyf(/* unset_environment= */ false, + "STATUS=%sUser job %s/%s running (%s / %s)...", + job_of_n, + ident, job_type_to_string(j->type), + time, limit); m->status_ready = false; } @@ -2869,8 +2868,8 @@ static void manager_start_special(Manager *m, const char *name, JobMode mode) { log_info("Activating special unit %s...", s); - sd_notifyf(false, - "STATUS=Activating special unit %s...", s); + (void) sd_notifyf(/* unset_environment= */ false, + "STATUS=Activating special unit %s...", s); m->status_ready = false; } @@ -3740,7 +3739,7 @@ static void user_manager_send_ready(Manager *m) { if (!MANAGER_IS_USER(m) || m->ready_sent) return; - r = sd_notify(false, + r = sd_notify(/* unset_environment= */ false, "READY=1\n" "STATUS=Reached " SPECIAL_BASIC_TARGET "."); if (r < 0) @@ -3757,7 +3756,7 @@ static void manager_send_ready(Manager *m) { /* Skip the notification if nothing changed. */ return; - r = sd_notify(false, + r = sd_notify(/* unset_environment= */ false, "READY=1\n" "STATUS=Ready."); if (r < 0) @@ -3842,7 +3841,7 @@ void manager_send_reloading(Manager *m) { assert(m); /* Let whoever invoked us know that we are now reloading */ - (void) sd_notifyf(/* unset= */ false, + (void) sd_notifyf(/* unset_environment= */ false, "RELOADING=1\n" "MONOTONIC_USEC=" USEC_FMT "\n", now(CLOCK_MONOTONIC));