summaryrefslogtreecommitdiff
path: root/src/core/service.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-03 16:41:36 +0200
committerLennart Poettering <lennart@poettering.net>2015-10-06 09:41:02 +0200
commit79c7626d1f239e02152ad698298a1b5d0e9fbacf (patch)
tree8c44dacdd28f0ec358f5751c5a7733a9d72ebb6e /src/core/service.c
parent6ec4ed645e37ba7dd5628747ea78ec1663599ab7 (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/service.c')
-rw-r--r--src/core/service.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/core/service.c b/src/core/service.c
index cb0394f930..2c78cb96c2 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -957,57 +957,51 @@ static int service_coldplug(Unit *u) {
return 0;
}
-static int service_collect_fds(Service *s, int **fds, unsigned *n_fds) {
+static int service_collect_fds(Service *s, int **fds) {
_cleanup_free_ int *rfds = NULL;
- unsigned rn_fds = 0;
+ int rn_fds = 0;
Iterator i;
- int r;
Unit *u;
assert(s);
assert(fds);
- assert(n_fds);
if (s->socket_fd >= 0)
- return 0;
+ return -EINVAL;
SET_FOREACH(u, UNIT(s)->dependencies[UNIT_TRIGGERED_BY], i) {
- int *cfds;
- unsigned cn_fds;
+ _cleanup_free_ int *cfds = NULL;
Socket *sock;
+ int cn_fds;
if (u->type != UNIT_SOCKET)
continue;
sock = SOCKET(u);
- r = socket_collect_fds(sock, &cfds, &cn_fds);
- if (r < 0)
- return r;
+ cn_fds = socket_collect_fds(sock, &cfds);
+ if (cn_fds < 0)
+ return cn_fds;
- if (cn_fds <= 0) {
- free(cfds);
+ if (cn_fds <= 0)
continue;
- }
if (!rfds) {
rfds = cfds;
rn_fds = cn_fds;
+
+ cfds = NULL;
} else {
int *t;
t = realloc(rfds, (rn_fds + cn_fds) * sizeof(int));
- if (!t) {
- free(cfds);
+ if (!t)
return -ENOMEM;
- }
memcpy(t + rn_fds, cfds, cn_fds * sizeof(int));
+
rfds = t;
rn_fds += cn_fds;
-
- free(cfds);
-
}
}
@@ -1025,10 +1019,9 @@ static int service_collect_fds(Service *s, int **fds, unsigned *n_fds) {
}
*fds = rfds;
- *n_fds = rn_fds;
-
rfds = NULL;
- return 0;
+
+ return rn_fds;
}
static int service_spawn(
@@ -1082,11 +1075,12 @@ static int service_spawn(
fds = &s->socket_fd;
n_fds = 1;
} else {
- r = service_collect_fds(s, &fdsbuf, &n_fds);
+ r = service_collect_fds(s, &fdsbuf);
if (r < 0)
goto fail;
fds = fdsbuf;
+ n_fds = r;
}
}