allow dumpstate to work with dmesg_restrict=1

Ensure that dumpstate has the CAP_SYSLOG permission, so that
it can always read the kernel syslog buffer. This is needed
to ensure that "adb bugreport" shows the dmesg log buffer.

Bug: 5585365
Change-Id: I4b561b77ada83dc875de80fe3ed15743c5958d09
diff --git a/cmds/dumpstate/utils.c b/cmds/dumpstate/utils.c
index 14984ec..21526f9 100644
--- a/cmds/dumpstate/utils.c
+++ b/cmds/dumpstate/utils.c
@@ -28,6 +28,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/wait.h>
+#include <sys/klog.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -96,6 +97,30 @@
     return;
 }
 
+void do_dmesg() {
+    printf("------ KERNEL LOG (dmesg) ------\n");
+    int size = klogctl(10, NULL, 0); /* Get size of kernel buffer */
+    if (size <= 0) {
+        printf("Unexpected klogctl return value: %d\n\n", size);
+        return;
+    }
+    char *buf = (char *) malloc(size + 1);
+    if (buf == NULL) {
+        printf("memory allocation failed\n\n");
+        return;
+    }
+    int retval = klogctl(KLOG_READ_ALL, buf, size);
+    if (retval < 0) {
+        printf("klogctl failure\n\n");
+        free(buf);
+        return;
+    }
+    buf[retval] = '\0';
+    printf("%s\n\n", buf);
+    free(buf);
+    return;
+}
+
 void do_showmap(int pid, const char *name) {
     char title[255];
     char arg[255];