tree-wide: warn when sd_notify fails with READY=1 or FDSTOREREMOVE=1

Most sd_notify() calls are like log_info() — the result is only informative
and if they fail, it's best ignore this. But if a call with READY=1 fails,
the unit may enter a failed state, so we should warn about this. Similarly
for FSTOREREMOVE=1: the manager may be left with a stale fd, at least wasting
resources.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-11-03 11:29:49 +01:00
parent 9214f2999b
commit 4bf4f50faa
8 changed files with 71 additions and 46 deletions
+17 -6
View File
@@ -3457,27 +3457,38 @@ static void manager_notify_finished(Manager *m) {
}
static void user_manager_send_ready(Manager *m) {
int r;
assert(m);
/* We send READY=1 on reaching basic.target only when running in --user mode. */
if (!MANAGER_IS_USER(m) || m->ready_sent)
return;
sd_notifyf(false,
"READY=1\n"
"STATUS=Reached " SPECIAL_BASIC_TARGET ".");
r = sd_notifyf(false,
"READY=1\n"
"STATUS=Reached " SPECIAL_BASIC_TARGET ".");
if (r < 0)
log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
m->ready_sent = true;
m->status_ready = false;
}
static void manager_send_ready(Manager *m) {
int r;
if (m->ready_sent && m->status_ready)
/* Skip the notification if nothing changed. */
return;
sd_notifyf(false,
"%sSTATUS=Ready.",
m->ready_sent ? "READY=1\n" : "");
r = sd_notifyf(false,
"%sSTATUS=Ready.",
m->ready_sent ? "READY=1\n" : "");
if (r < 0)
log_full_errno(m->ready_sent ? LOG_DEBUG : LOG_WARNING, r,
"Failed to send readiness notification, ignoring: %m");
m->ready_sent = m->status_ready = true;
}