From: Mike Yuan Date: Sat, 23 Mar 2024 17:07:30 +0000 (+0800) Subject: core/socket: use FOREACH_ARRAY at one more place X-Git-Tag: v256-rc1~428^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F31916%2Fhead;p=thirdparty%2Fsystemd.git core/socket: use FOREACH_ARRAY at one more place --- diff --git a/src/core/socket.c b/src/core/socket.c index 2ce197e3287..45656cbda77 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -3256,12 +3256,11 @@ static int socket_dispatch_timer(sd_event_source *source, usec_t usec, void *use return 0; } -int socket_collect_fds(Socket *s, int **fds) { - size_t k = 0, n = 0; - int *rfds; +int socket_collect_fds(Socket *s, int **ret) { + size_t n = 0, k = 0; assert(s); - assert(fds); + assert(ret); /* Called from the service code for requesting our fds */ @@ -3271,25 +3270,25 @@ int socket_collect_fds(Socket *s, int **fds) { n += p->n_auxiliary_fds; } - if (n <= 0) { - *fds = NULL; + if (n == 0) { + *ret = NULL; return 0; } - rfds = new(int, n); - if (!rfds) + int *fds = new(int, n); + if (!fds) return -ENOMEM; LIST_FOREACH(port, p, s->ports) { if (p->fd >= 0) - rfds[k++] = p->fd; - for (size_t i = 0; i < p->n_auxiliary_fds; ++i) - rfds[k++] = p->auxiliary_fds[i]; + fds[k++] = p->fd; + FOREACH_ARRAY(i, p->auxiliary_fds, p->n_auxiliary_fds) + fds[k++] = *i; } assert(k == n); - *fds = rfds; + *ret = fds; return (int) n; } diff --git a/src/core/socket.h b/src/core/socket.h index 5efe01d2bf0..973a697f861 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -171,7 +171,7 @@ int socket_acquire_peer(Socket *s, int fd, SocketPeer **p); DEFINE_TRIVIAL_CLEANUP_FUNC(SocketPeer*, socket_peer_unref); /* Called from the service code when collecting fds */ -int socket_collect_fds(Socket *s, int **fds); +int socket_collect_fds(Socket *s, int **ret); /* Called from the service code when a per-connection service ended */ void socket_connection_unref(Socket *s);