summaryrefslogtreecommitdiff
path: root/src/core/service.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-03-18 19:22:43 +0100
committerLennart Poettering <lennart@poettering.net>2014-03-18 19:31:34 +0100
commit03e334a1c7dc8c20c38902aa039440763acc9b17 (patch)
treebc30b522de8ef9c251bf3ff2fe2d52c92dd8b1ea /src/core/service.c
parent9459781ee66eb57709c8b8701701365ba60a9f1c (diff)
util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed, and returns -1 unconditionally. This makes it easy to write lines like this: fd = safe_close(fd); Which will close an fd if it is open, and reset the fd variable correctly. By making use of this new scheme we can drop a > 200 lines of code that was required to test for non-negative fds or to reset the closed fd variable afterwards.
Diffstat (limited to 'src/core/service.c')
-rw-r--r--src/core/service.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/core/service.c b/src/core/service.c
index 386692a10a..fe7ddd1841 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -226,8 +226,7 @@ static void service_close_socket_fd(Service *s) {
if (s->socket_fd < 0)
return;
- close_nointr_nofail(s->socket_fd);
- s->socket_fd = -1;
+ s->socket_fd = safe_close(s->socket_fd);
}
static void service_connection_unref(Service *s) {
@@ -2684,8 +2683,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
log_debug_unit(u->id, "Failed to parse socket-fd value %s", value);
else {
- if (s->socket_fd >= 0)
- close_nointr_nofail(s->socket_fd);
+ safe_close(s->socket_fd);
s->socket_fd = fdset_remove(fds, fd);
}
} else if (streq(key, "main-exec-status-pid")) {