chiark / gitweb /
log: increase socket buffers for logging by default
authorLennart Poettering <lennart@poettering.net>
Fri, 27 Jan 2012 17:57:37 +0000 (18:57 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 27 Jan 2012 17:57:37 +0000 (18:57 +0100)
src/journal/journal-send.c
src/log.c
src/util.c
src/util.h
units/syslog.socket
units/systemd-journald.socket

index 00029fe0b361d10ebbf714f875ca1aa32ccfe96b..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;
@@ -219,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
@@ -294,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 = "";
 
index 0594f7fde59cc208cc5940e31386f598d17d0545..c37ab226402c462f582b1ba1d8a8bafbbf6cfc39 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -33,6 +33,8 @@
 #include "macro.h"
 #include "socket-util.h"
 
+#define SNDBUF_SIZE (8*1024*1024)
+
 static LogTarget log_target = LOG_TARGET_CONSOLE;
 static int log_max_level = LOG_INFO;
 
@@ -127,6 +129,8 @@ static int create_log_socket(int type) {
         if (fd < 0)
                 return -errno;
 
+        fd_inc_sndbuf(fd, SNDBUF_SIZE);
+
         return fd;
 }
 
index c9ad831c6ca95fbad570f2640f919dcf2a0e4ebf..5fe22d2e50883b086628aa0a6e891a1bab3912e1 100644 (file)
@@ -6279,3 +6279,39 @@ void* memdup(const void *p, size_t l) {
         memcpy(r, p, l);
         return r;
 }
+
+int fd_inc_sndbuf(int fd, size_t n) {
+        int r, value;
+        socklen_t l = sizeof(value);
+
+        r = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &l);
+        if (r >= 0 &&
+            l == sizeof(value) &&
+            (size_t) value >= n*2)
+                return 0;
+
+        value = (int) n;
+        r = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value));
+        if (r < 0)
+                return -errno;
+
+        return 1;
+}
+
+int fd_inc_rcvbuf(int fd, size_t n) {
+        int r, value;
+        socklen_t l = sizeof(value);
+
+        r = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, &l);
+        if (r >= 0 &&
+            l == sizeof(value) &&
+            (size_t) value >= n*2)
+                return 0;
+
+        value = (int) n;
+        r = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value));
+        if (r < 0)
+                return -errno;
+
+        return 1;
+}
index 202d07a854cf7bb2addbfce8ebfc0f356a952e66..dcfc16d46083ceac938f38a32f8a7a88bb6be025 100644 (file)
@@ -536,4 +536,7 @@ int rtc_open(int flags);
 
 int is_kernel_thread(pid_t pid);
 
+int fd_inc_sndbuf(int fd, size_t n);
+int fd_inc_rcvbuf(int fd, size_t n);
+
 #endif
index 657e7913e34d89cb906732ab38b9106ef9b0aeab..1c54857762385592dfea0a9089e200ff1caad7c3 100644 (file)
@@ -21,6 +21,7 @@ Wants=syslog.target
 ListenDatagram=/run/systemd/journal/syslog
 SocketMode=0666
 PassCredentials=yes
+ReceiveBuffer=8M
 
 # The default syslog implementation should make syslog.service a
 # symlink to itself, so that this socket activates the right actual
index 1062390fff7030f54e74442c62fa0f88a8210c59..c752505d9fa1b009ab2a21ccacfde5c99eef1201 100644 (file)
@@ -23,3 +23,4 @@ ListenDatagram=/run/systemd/journal/socket
 ListenDatagram=/dev/log
 SocketMode=0666
 PassCredentials=yes
+ReceiveBuffer=8M