]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: slightly beef up READY= logic in nspawn
authorLennart Poettering <lennart@poettering.net>
Mon, 16 Jun 2025 08:46:37 +0000 (10:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 11 Jul 2025 16:15:12 +0000 (18:15 +0200)
Let's also send out a STATUS= message when we get READY=1 if it didn't
come with a STATUS= message itself.

Also, let's initially say the container is "started", and only once the
READY=1 is seen claim it was "running".

src/nspawn/nspawn.c

index 805dd91389c21675af2720614738e586d2c69b67..8f18d2fc60ef8f414937b7f7d049073e978bdf3a 100644 (file)
@@ -4612,15 +4612,18 @@ static int nspawn_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t r
                 log_debug("Got sd_notify() message: %s", strnull(joined));
         }
 
+        char *status = strv_find_startswith(tags, "STATUS=");
+        if (status)
+                (void) sd_notifyf(/* unset_environment= */ false, "STATUS=Container running: %s", status);
+
         if (strv_contains(tags, "READY=1")) {
-                r = sd_notify(false, "READY=1\n");
+                r = sd_notify(/* unset_environment= */ false, "READY=1\n");
                 if (r < 0)
                         log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
-        }
 
-        char *p = strv_find_startswith(tags, "STATUS=");
-        if (p)
-                (void) sd_notifyf(false, "STATUS=Container running: %s", p);
+                if (!status)
+                        (void) sd_notifyf(/* unset_environment= */ false, "STATUS=Container running.");
+        }
 
         return 0;
 }
@@ -5632,11 +5635,11 @@ static int run_container(
          * will make them appear in getpwuid(), thus we can release the /etc/passwd lock. */
         etc_passwd_lock = safe_close(etc_passwd_lock);
 
-        (void) sd_notifyf(false,
-                          "STATUS=Container running.\n"
+        (void) sd_notifyf(/* unset_environment= */ false,
+                          "STATUS=Container started.\n"
                           "X_NSPAWN_LEADER_PID=" PID_FMT, pid->pid);
         if (!arg_notify_ready) {
-                r = sd_notify(false, "READY=1\n");
+                r = sd_notify(/* unset_environment= */ false, "READY=1\n");
                 if (r < 0)
                         log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
         }