summaryrefslogtreecommitdiff
path: root/src/journal/journal-send.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/journal/journal-send.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/journal/journal-send.c')
-rw-r--r--src/journal/journal-send.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index ca9199f718..d92e84baab 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -66,7 +66,7 @@ retry:
fd_inc_sndbuf(fd, SNDBUF_SIZE);
if (!__sync_bool_compare_and_swap(&fd_plus_one, 0, fd+1)) {
- close_nointr_nofail(fd);
+ safe_close(fd);
goto retry;
}
@@ -316,7 +316,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
n = writev(buffer_fd, w, j);
if (n < 0) {
- close_nointr_nofail(buffer_fd);
+ safe_close(buffer_fd);
return -errno;
}
@@ -336,7 +336,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
mh.msg_controllen = cmsg->cmsg_len;
k = sendmsg(fd, &mh, MSG_NOSIGNAL);
- close_nointr_nofail(buffer_fd);
+ safe_close(buffer_fd);
if (k < 0)
return -errno;
@@ -412,12 +412,12 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve
r = connect(fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
if (r < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
if (shutdown(fd, SHUT_RD) < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
@@ -445,12 +445,12 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve
r = loop_write(fd, header, l, false);
if (r < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return (int) r;
}
if ((size_t) r != l) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}