1abbee
From a3b8feb9320f745f960fe8f7006183137f4969b1 Mon Sep 17 00:00:00 2001
1abbee
From: Lennart Poettering <lennart@poettering.net>
1abbee
Date: Mon, 2 Nov 2015 09:34:05 +0100
1abbee
Subject: [PATCH] core: bump net.unix.max_dgram_qlen really early during boot
1abbee
1abbee
Only that way it actually has an effect on all our sockets, including
1abbee
$NOTIFY_SOCKET.
1abbee
1abbee
(cherry picked from commit 19854865a877a3a4fa3d04550c15a99c0e1187ff)
1abbee
Related: #1267707
1abbee
---
1abbee
 src/core/main.c  | 36 ++++++++++++++++++++++++++++++++++++
1abbee
 src/shared/def.h |  3 +++
1abbee
 2 files changed, 39 insertions(+)
1abbee
1abbee
diff --git a/src/core/main.c b/src/core/main.c
Pablo Greco 48fc63
index 60ea36c3cb..c9d8ce4a40 100644
1abbee
--- a/src/core/main.c
1abbee
+++ b/src/core/main.c
1abbee
@@ -1198,6 +1198,7 @@ static int status_welcome(void) {
1abbee
 
1abbee
 static int write_container_id(void) {
1abbee
         const char *c;
1abbee
+        int r;
1abbee
 
1abbee
         c = getenv("container");
1abbee
         if (isempty(c))
1abbee
@@ -1206,6 +1207,40 @@ static int write_container_id(void) {
1abbee
         return write_string_file("/run/systemd/container", c);
1abbee
 }
1abbee
 
1abbee
+static int bump_unix_max_dgram_qlen(void) {
1abbee
+        _cleanup_free_ char *qlen = NULL;
1abbee
+        unsigned long v;
1abbee
+        int r;
1abbee
+
1abbee
+        /* Let's bump the net.unix.max_dgram_qlen sysctl. The kernel
1abbee
+         * default of 16 is simply too low. We set the value really
1abbee
+         * really early during boot, so that it is actually applied to
1abbee
+         * all our sockets, including the $NOTIFY_SOCKET one. */
1abbee
+
1abbee
+        r = read_one_line_file("/proc/sys/net/unix/max_dgram_qlen", &qlen);
1abbee
+        if (r < 0)
1abbee
+                return log_warning_errno(r, "Failed to read AF_UNIX datagram queue length, ignoring: %m");
1abbee
+
1abbee
+        r = safe_atolu(qlen, &v);
1abbee
+        if (r < 0)
1abbee
+                return log_warning_errno(r, "Failed to parse AF_UNIX datagram queue length, ignoring: %m");
1abbee
+
1abbee
+        if (v >= DEFAULT_UNIX_MAX_DGRAM_QLEN)
1abbee
+                return 0;
1abbee
+
1abbee
+        free(qlen);
1abbee
+        qlen = NULL;
1abbee
+        if (asprintf(&qlen, "%lu\n", DEFAULT_UNIX_MAX_DGRAM_QLEN) < 0)
1abbee
+                return log_oom();
1abbee
+
1abbee
+        r = write_string_file("/proc/sys/net/unix/max_dgram_qlen", qlen);
1abbee
+        if (r < 0)
1abbee
+                return log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING, r,
1abbee
+                                      "Failed to bump AF_UNIX datagram queue length, ignoring: %m");
1abbee
+
1abbee
+        return 1;
1abbee
+}
1abbee
+
1abbee
 int main(int argc, char *argv[]) {
1abbee
         Manager *m = NULL;
1abbee
         int r, retval = EXIT_FAILURE;
1abbee
@@ -1571,6 +1606,7 @@ int main(int argc, char *argv[]) {
1abbee
                 hostname_setup();
1abbee
                 machine_id_setup(NULL);
1abbee
                 loopback_setup();
1abbee
+                bump_unix_max_dgram_qlen();
1abbee
 
1abbee
                 test_mtab();
1abbee
                 test_usr();
1abbee
diff --git a/src/shared/def.h b/src/shared/def.h
Pablo Greco 48fc63
index a3d9fcf388..76daf012d7 100644
1abbee
--- a/src/shared/def.h
1abbee
+++ b/src/shared/def.h
1abbee
@@ -35,6 +35,9 @@
1abbee
  * the watchdog pings will keep the loop busy. */
1abbee
 #define DEFAULT_EXIT_USEC (30*USEC_PER_SEC)
1abbee
 
1abbee
+/* The default value for the net.unix.max_dgram_qlen sysctl */
1abbee
+#define DEFAULT_UNIX_MAX_DGRAM_QLEN 512UL
1abbee
+
1abbee
 #define SYSTEMD_CGROUP_CONTROLLER "name=systemd"
1abbee
 
1abbee
 #define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT