core/service: service_add_fd_store() consumes passed fd
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 21 Nov 2024 20:15:49 +0000 (05:15 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 29 Nov 2024 13:26:56 +0000 (14:26 +0100)
Without this change, the fd is closed twice on failure.

Fixes a bug introduced by dff9808a628c31b7ecb1f1aba8fdc3be06ce8372.

Fixes #35288.

(cherry picked from commit d99198819caeff6f40a0a520364e59b8a0cbaa4f)

src/core/service.c

index 549847e3f932375ce553de5fd05e7c9aff62c837..0c7adb3a0ac077fadbb5eca77bd0b848f387ad07 100644 (file)
@@ -3259,14 +3259,13 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
                         return 0;
                 }
 
-                r = service_add_fd_store(s, fd, fdn, do_poll);
+                r = service_add_fd_store(s, TAKE_FD(fd), fdn, do_poll);
                 if (r < 0) {
                         log_unit_debug_errno(u, r,
                                              "Failed to store deserialized fd '%s', ignoring: %m", fdn);
                         return 0;
                 }
 
-                TAKE_FD(fd);
         } else if (streq(key, "main-exec-status-pid")) {
                 pid_t pid;