X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournal-send.c;h=d92e84baab5e2ad53e7df3b5744ded6ca557c6ef;hb=5ea846cc5197682d07ee46398996a8c3ccfbcc38;hp=931c1e73306501714ffe1fc0b8aac3cebce196a2;hpb=1ae464e09376853c52075ec4d8a6bfc4b4036d0c;p=elogind.git diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index 931c1e733..d92e84baa 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; } @@ -216,10 +216,6 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) { uint8_t buf[CMSG_SPACE(sizeof(int))]; } control; struct cmsghdr *cmsg; - /* We use /dev/shm instead of /tmp here, since we want this to - * be a tmpfs, and one that is available from early boot on - * and where unprivileged users can create files. */ - char path[] = "/dev/shm/journal.XXXXXX"; bool have_syslog_identifier = false; assert_return(iov, -EINVAL); @@ -300,25 +296,27 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) { if (k >= 0) return 0; + /* Fail silently if the journal is not available */ + if (errno == ENOENT) + return 0; + if (errno != EMSGSIZE && errno != ENOBUFS) return -errno; /* Message doesn't fit... Let's dump the data in a temporary * file and just pass a file descriptor of it to the other - * side */ - - buffer_fd = mkostemp(path, O_CLOEXEC|O_RDWR); + * side. + * + * We use /dev/shm instead of /tmp here, since we want this to + * be a tmpfs, and one that is available from early boot on + * and where unprivileged users can create files. */ + buffer_fd = open_tmpfile("/dev/shm", O_RDWR | O_CLOEXEC); if (buffer_fd < 0) - return -errno; - - if (unlink(path) < 0) { - close_nointr_nofail(buffer_fd); - return -errno; - } + return buffer_fd; n = writev(buffer_fd, w, j); if (n < 0) { - close_nointr_nofail(buffer_fd); + safe_close(buffer_fd); return -errno; } @@ -338,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; @@ -414,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; } @@ -447,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; }