From: Mike Yuan Date: Tue, 8 Oct 2024 13:48:49 +0000 (+0200) Subject: core/service: add missing serialization for extra fds X-Git-Tag: v257-rc1~251^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e66f42b06d19edf80d511d3548cbfdbfa4d483e;p=thirdparty%2Fsystemd.git core/service: add missing serialization for extra fds --- diff --git a/src/core/service.c b/src/core/service.c index eddec763e16..8f4cd636700 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3144,6 +3144,21 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) { (void) serialize_item_format(f, "fd-store-fd", "%i \"%s\" %s", copy, c, one_zero(fs->do_poll)); } + FOREACH_ARRAY(i, s->extra_fds, s->n_extra_fds) { + _cleanup_free_ char *c = NULL; + int copy; + + copy = fdset_put_dup(fds, i->fd); + if (copy < 0) + return log_error_errno(copy, "Failed to copy file descriptor for serialization: %m"); + + c = cescape(i->fdname); + if (!c) + return log_oom(); + + (void) serialize_item_format(f, "extra-fd", "%i \"%s\"", copy, c); + } + if (s->main_exec_status.pid > 0) { (void) serialize_item_format(f, "main-exec-status-pid", PID_FMT, s->main_exec_status.pid); (void) serialize_dual_timestamp(f, "main-exec-status-start", &s->main_exec_status.start_timestamp); @@ -3394,6 +3409,29 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value, } TAKE_FD(fd); + } else if (streq(key, "extra-fd")) { + _cleanup_free_ char *fdv = NULL, *fdn = NULL; + _cleanup_close_ int fd = -EBADF; + + r = extract_many_words(&value, " ", EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE, &fdv, &fdn); + if (r != 2) { + log_unit_debug(u, "Failed to deserialize extra-fd, ignoring: %s", value); + return 0; + } + + fd = deserialize_fd(fds, fdv); + if (fd < 0) + return 0; + + if (!GREEDY_REALLOC(s->extra_fds, s->n_extra_fds + 1)) { + log_oom_debug(); + return 0; + } + + s->extra_fds[s->n_extra_fds++] = (ServiceExtraFD) { + .fd = TAKE_FD(fd), + .fdname = TAKE_PTR(fdn), + }; } else if (streq(key, "main-exec-status-pid")) { pid_t pid;