diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-03-18 19:22:43 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-03-18 19:31:34 +0100 |
commit | 03e334a1c7dc8c20c38902aa039440763acc9b17 (patch) | |
tree | bc30b522de8ef9c251bf3ff2fe2d52c92dd8b1ea /src/core/busname.c | |
parent | 9459781ee66eb57709c8b8701701365ba60a9f1c (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/busname.c')
-rw-r--r-- | src/core/busname.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/core/busname.c b/src/core/busname.c index bd7d02d73b..9d7a796538 100644 --- a/src/core/busname.c +++ b/src/core/busname.c @@ -56,11 +56,7 @@ static void busname_done(Unit *u) { unit_ref_unset(&n->service); n->event_source = sd_event_source_unref(n->event_source); - - if (n->starter_fd >= 0) { - close_nointr_nofail(n->starter_fd); - n->starter_fd = -1; - } + n->starter_fd = safe_close(n->starter_fd); } static int busname_add_default_default_dependencies(BusName *n) { @@ -122,8 +118,6 @@ static int busname_add_extras(BusName *n) { return 0; } - - static int busname_verify(BusName *n) { char *e; @@ -202,8 +196,7 @@ static void busname_close_fd(BusName *n) { if (n->starter_fd <= 0) return; - close_nointr_nofail(n->starter_fd); - n->starter_fd = -1; + n->starter_fd = safe_close(n->starter_fd); } static int busname_watch_fd(BusName *n) { @@ -454,8 +447,7 @@ static int busname_deserialize_item(Unit *u, const char *key, const char *value, if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd)) log_debug_unit(u->id, "Failed to parse starter fd value %s", value); else { - if (n->starter_fd >= 0) - close_nointr_nofail(n->starter_fd); + safe_close(n->starter_fd); n->starter_fd = fdset_remove(fds, fd); } } else |