Merge "cutils: return the remote uid on netlink recv failure"
diff --git a/init/builtins.c b/init/builtins.c
index adad353..0b9c0cf 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -75,12 +75,23 @@
     }
 }
 
+static int _open(const char *path)
+{
+    int fd;
+
+    fd = open(path, O_RDONLY | O_NOFOLLOW);
+    if (fd < 0)
+        fd = open(path, O_WRONLY | O_NOFOLLOW);
+
+    return fd;
+}
+
 static int _chown(const char *path, unsigned int uid, unsigned int gid)
 {
     int fd;
     int ret;
 
-    fd = open(path, O_RDONLY | O_NOFOLLOW);
+    fd = _open(path);
     if (fd < 0) {
         return -1;
     }
@@ -103,7 +114,7 @@
     int fd;
     int ret;
 
-    fd = open(path, O_RDONLY | O_NOFOLLOW);
+    fd = _open(path);
     if (fd < 0) {
         return -1;
     }
diff --git a/libsysutils/EventLogTags.logtags b/libsysutils/EventLogTags.logtags
index 27785f0..7aa5cad 100644
--- a/libsysutils/EventLogTags.logtags
+++ b/libsysutils/EventLogTags.logtags
@@ -2,3 +2,4 @@
 
 # FrameworkListener dispatchCommand overflow
 78001 dispatchCommand_overflow
+65537 netlink_failure (uid|1)
diff --git a/libsysutils/src/NetlinkListener.cpp b/libsysutils/src/NetlinkListener.cpp
index e67b5c6..9c447ca 100644
--- a/libsysutils/src/NetlinkListener.cpp
+++ b/libsysutils/src/NetlinkListener.cpp
@@ -45,9 +45,13 @@
 {
     int socket = cli->getSocket();
     ssize_t count;
+    uid_t uid = -1;
 
-    count = TEMP_FAILURE_RETRY(uevent_kernel_multicast_recv(socket, mBuffer, sizeof(mBuffer)));
+    count = TEMP_FAILURE_RETRY(uevent_kernel_multicast_uid_recv(
+                                       socket, mBuffer, sizeof(mBuffer), &uid));
     if (count < 0) {
+        if (uid > 0)
+            LOG_EVENT_INT(65537, uid);
         SLOGE("recvmsg failed (%s)", strerror(errno));
         return false;
     }
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index 438cf0a..07624c4 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -8,8 +8,9 @@
 /dev/ashmem               0666   root       root
 /dev/binder               0666   root       root
 
-# logger should be world writable (for logging) but not readable
-/dev/log/*                0662   root       log
+# Anyone can read the logs, but if they're not in the "logs"
+# group, then they'll only see log entries for their UID.
+/dev/log/*                0666   root       log
 
 # the msm hw3d client device node is world writable/readable.
 /dev/msm_hw3dc            0666   root       root