diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-03 16:41:36 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-06 09:41:02 +0200 |
commit | 79c7626d1f239e02152ad698298a1b5d0e9fbacf (patch) | |
tree | 8c44dacdd28f0ec358f5751c5a7733a9d72ebb6e /src/core/socket.c | |
parent | 6ec4ed645e37ba7dd5628747ea78ec1663599ab7 (diff) |
core: simplify fd collection code, return number of fds as return value
Let's simplify the fd collection code a bit, and return the number of
collected fds as positive integer, the way it's customary in our usual
code.
Diffstat (limited to 'src/core/socket.c')
-rw-r--r-- | src/core/socket.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/core/socket.c b/src/core/socket.c index f547d1ba7c..4462fbd72d 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -2628,49 +2628,43 @@ static int socket_dispatch_timer(sd_event_source *source, usec_t usec, void *use return 0; } -int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) { - int *rfds; - unsigned rn_fds, k; - int i; +int socket_collect_fds(Socket *s, int **fds) { + int *rfds, k = 0, n = 0; SocketPort *p; assert(s); assert(fds); - assert(n_fds); /* Called from the service code for requesting our fds */ - rn_fds = 0; LIST_FOREACH(port, p, s->ports) { if (p->fd >= 0) - rn_fds++; - rn_fds += p->n_auxiliary_fds; + n++; + n += p->n_auxiliary_fds; } - if (rn_fds <= 0) { + if (n <= 0) { *fds = NULL; - *n_fds = 0; return 0; } - rfds = new(int, rn_fds); + rfds = new(int, n); if (!rfds) return -ENOMEM; - k = 0; LIST_FOREACH(port, p, s->ports) { + int i; + if (p->fd >= 0) rfds[k++] = p->fd; for (i = 0; i < p->n_auxiliary_fds; ++i) rfds[k++] = p->auxiliary_fds[i]; } - assert(k == rn_fds); + assert(k == n); *fds = rfds; - *n_fds = rn_fds; - - return 0; + return n; } static void socket_reset_failed(Unit *u) { |