OSDN Git Service

Try SO_RCVBUF before SO_RCVBUFFORCE.
authorJunichi Uekawa <uekawa@google.com>
Wed, 4 Nov 2015 21:05:54 +0000 (06:05 +0900)
committerLuis Hector Chavez <lhchavez@google.com>
Tue, 11 Jul 2017 22:51:54 +0000 (15:51 -0700)
When running in a container, the process might be in a user/net
namespace, which would cause setting the SO_RCVBUFFORCE socket option to
fail with EPERM. But rmem_max is set to a high enough value which allows
SO_RCVBUF to succeed.

Bug: 62417946
Test: Run android in a new user and network namespace, vold does not
      abort here.

Change-Id: I2b678ddd886a406a3394d9fdd33f9c8800ef78a3
Signed-off-by: Junichi Uekawa <uekawa@google.com>
(cherry picked from commit b41155d4af0e00fc6f65d7d67b80e7b866f847d6)

NetlinkManager.cpp

index b5069a6..0ad182e 100644 (file)
@@ -64,8 +64,11 @@ int NetlinkManager::start() {
         return -1;
     }
 
-    if (setsockopt(mSock, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)) < 0) {
-        SLOGE("Unable to set uevent socket SO_RCVBUFFORCE option: %s", strerror(errno));
+    // When running in a net/user namespace, SO_RCVBUFFORCE is not available.
+    // Try using SO_RCVBUF first.
+    if ((setsockopt(mSock, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)) < 0) &&
+        (setsockopt(mSock, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)) < 0)) {
+        SLOGE("Unable to set uevent socket SO_RCVBUF/SO_RCVBUFFORCE option: %s", strerror(errno));
         goto out;
     }