chiark / gitweb /
journald: take corrupted files into account when calculating disk space
[elogind.git] / src / journal / journal-send.c
index 03bd17072830c3000911d8adb8fa10b1eadc0b04..b5b4fbfa0da9f32f48a575289ded8650804f7dfc 100644 (file)
@@ -30,6 +30,8 @@
 #include "util.h"
 #include "socket-util.h"
 
+#define SNDBUF_SIZE (8*1024*1024)
+
 /* We open a single fd, and we'll share it with the current process,
  * all its threads, and all its subprocesses. This means we need to
  * initialize it atomically, and need to operate on it atomically
@@ -47,6 +49,8 @@ retry:
         if (fd < 0)
                 return -errno;
 
+        fd_inc_sndbuf(fd, SNDBUF_SIZE);
+
         if (!__sync_bool_compare_and_swap(&fd_plus_one, 0, fd+1)) {
                 close_nointr_nofail(fd);
                 goto retry;
@@ -140,13 +144,16 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
         int i, j = 0;
         struct msghdr mh;
         struct sockaddr_un sa;
-        char path[] = "/tmp/journal.XXXXXX";
         ssize_t k;
         union {
                 struct cmsghdr cmsghdr;
                 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";
 
         if (!iov || n <= 0)
                 return -EINVAL;
@@ -216,7 +223,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
         if (k >= 0)
                 return 0;
 
-        if (errno != EMSGSIZE)
+        if (errno != EMSGSIZE && errno != ENOBUFS)
                 return -errno;
 
         /* Message doesn't fit... Let's dump the data in a temporary
@@ -291,6 +298,8 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve
                 return -errno;
         }
 
+        fd_inc_sndbuf(fd, SNDBUF_SIZE);
+
         if (!identifier)
                 identifier = "";