[systemd-commits] 3 commits - src/journal src/log.c src/socket.c src/util.c src/util.h units/syslog.socket units/systemd-journald.socket
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Jan 27 09:58:21 PST 2012
src/journal/journal-send.c | 8 +++++++-
src/journal/journald.c | 21 ++++++---------------
src/log.c | 18 +++++-------------
src/socket.c | 9 +++++++--
src/util.c | 36 ++++++++++++++++++++++++++++++++++++
src/util.h | 3 +++
units/syslog.socket | 1 +
units/systemd-journald.socket | 1 +
8 files changed, 66 insertions(+), 31 deletions(-)
New commits:
commit 7d9eaa8461da2a4ef5ae840f41a3434c112dae37
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Jan 27 18:58:02 2012 +0100
socket: if SO_RCVBUFFORCE fails, fall back to SO_RCVBUF, to have at least a little effect
diff --git a/src/socket.c b/src/socket.c
index 7409aea..67cd0cc 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -680,14 +680,19 @@ static void socket_apply_socket_options(Socket *s, int fd) {
if (s->receive_buffer > 0) {
int value = (int) s->receive_buffer;
+
+ /* We first try with SO_RCVBUFFORCE, in case we have the perms for that */
+
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &value, sizeof(value)) < 0)
- log_warning("SO_RCVBUFFORCE failed: %m");
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value)) < 0)
+ log_warning("SO_RCVBUF failed: %m");
}
if (s->send_buffer > 0) {
int value = (int) s->send_buffer;
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &value, sizeof(value)) < 0)
- log_warning("SO_SNDBUFFORCE failed: %m");
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value)) < 0)
+ log_warning("SO_SNDBUF failed: %m");
}
if (s->mark >= 0)
commit bb99a35a873c35e80b0b47fe045081022660374d
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Jan 27 18:57:37 2012 +0100
log: increase socket buffers for logging by default
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index 00029fe..b5b4fbf 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -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 = "";
diff --git a/src/log.c b/src/log.c
index 0594f7f..c37ab22 100644
--- 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;
}
diff --git a/src/util.c b/src/util.c
index c9ad831..5fe22d2 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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;
+}
diff --git a/src/util.h b/src/util.h
index 202d07a..dcfc16d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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
diff --git a/units/syslog.socket b/units/syslog.socket
index 657e791..1c54857 100644
--- a/units/syslog.socket
+++ b/units/syslog.socket
@@ -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
diff --git a/units/systemd-journald.socket b/units/systemd-journald.socket
index 1062390..c752505 100644
--- a/units/systemd-journald.socket
+++ b/units/systemd-journald.socket
@@ -23,3 +23,4 @@ ListenDatagram=/run/systemd/journal/socket
ListenDatagram=/dev/log
SocketMode=0666
PassCredentials=yes
+ReceiveBuffer=8M
commit 632117b71fdd2d1b9da7418d00ec21c18d60dedd
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Jan 27 18:14:06 2012 +0100
log: never delay logging if the log server is stuck, always drop messages quickly
diff --git a/src/journal/journald.c b/src/journal/journald.c
index f63a12f..73f8ed6 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -66,8 +66,6 @@
#define RECHECK_VAR_AVAILABLE_USEC (30*USEC_PER_SEC)
-#define SYSLOG_TIMEOUT_USEC (250*USEC_PER_MSEC)
-
#define N_IOVEC_META_FIELDS 17
#define ENTRY_SIZE_MAX (1024*1024*32)
@@ -2220,7 +2218,6 @@ static int open_syslog_socket(Server *s) {
union sockaddr_union sa;
int one, r;
struct epoll_event ev;
- struct timeval tv;
assert(s);
@@ -2245,7 +2242,8 @@ static int open_syslog_socket(Server *s) {
}
chmod(sa.un.sun_path, 0666);
- }
+ } else
+ fd_nonblock(s->syslog_fd, 1);
one = 1;
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
@@ -2261,15 +2259,6 @@ static int open_syslog_socket(Server *s) {
return -errno;
}
- /* Since we use the same socket for forwarding this to some
- * other syslog implementation, make sure we don't hang
- * forever */
- timeval_store(&tv, SYSLOG_TIMEOUT_USEC);
- if (setsockopt(s->syslog_fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0) {
- log_error("SO_SNDTIMEO failed: %m");
- return -errno;
- }
-
zero(ev);
ev.events = EPOLLIN;
ev.data.fd = s->syslog_fd;
@@ -2309,7 +2298,8 @@ static int open_native_socket(Server*s) {
}
chmod(sa.un.sun_path, 0666);
- }
+ } else
+ fd_nonblock(s->native_fd, 1);
one = 1;
r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
@@ -2369,7 +2359,8 @@ static int open_stdout_socket(Server *s) {
log_error("liste() failed: %m");
return -errno;
}
- }
+ } else
+ fd_nonblock(s->stdout_fd, 1);
zero(ev);
ev.events = EPOLLIN;
diff --git a/src/log.c b/src/log.c
index 1a6ea7e..0594f7f 100644
--- a/src/log.c
+++ b/src/log.c
@@ -33,8 +33,6 @@
#include "macro.h"
#include "socket-util.h"
-#define SOCKET_TIMEOUT_USEC (5*USEC_PER_SEC)
-
static LogTarget log_target = LOG_TARGET_CONSOLE;
static int log_max_level = LOG_INFO;
@@ -120,25 +118,15 @@ void log_close_syslog(void) {
}
static int create_log_socket(int type) {
- struct timeval tv;
int fd;
- if (getpid() == 1)
- /* systemd should not block on syslog */
- type |= SOCK_NONBLOCK;
+ /* All output to the syslog/journal fds we do asynchronously,
+ * and if the buffers are full we just drop the messages */
- fd = socket(AF_UNIX, type|SOCK_CLOEXEC, 0);
+ fd = socket(AF_UNIX, type|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (fd < 0)
return -errno;
- /* Make sure we don't block for more than 5s when talking to
- * syslog */
- timeval_store(&tv, SOCKET_TIMEOUT_USEC);
- if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0) {
- close_nointr_nofail(fd);
- return -errno;
- }
-
return fd;
}
More information about the systemd-commits
mailing list