From 276535dad615e0ff085c5e1be72ea673bfb3dd68 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 25 Nov 2019 19:09:02 -0500 Subject: [PATCH] Fix incorrect kmsg path /proc/kmsg -> /dev/kmsg --- native/jni/init/init.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/native/jni/init/init.cpp b/native/jni/init/init.cpp index e6f632a2b..90d38cd32 100644 --- a/native/jni/init/init.cpp +++ b/native/jni/init/init.cpp @@ -38,23 +38,22 @@ static int vprintk(const char *fmt, va_list ap) { } void setup_klog() { // Shut down first 3 fds - int null; + int fd; if (access("/dev/null", W_OK) == 0) { - null = xopen("/dev/null", O_RDWR | O_CLOEXEC); + fd = xopen("/dev/null", O_RDWR | O_CLOEXEC); } else { mknod("/null", S_IFCHR | 0666, makedev(1, 3)); - null = xopen("/null", O_RDWR | O_CLOEXEC); + fd = xopen("/null", O_RDWR | O_CLOEXEC); unlink("/null"); } - xdup3(null, STDIN_FILENO, O_CLOEXEC); - xdup3(null, STDOUT_FILENO, O_CLOEXEC); - xdup3(null, STDERR_FILENO, O_CLOEXEC); - if (null > STDERR_FILENO) - close(null); + xdup3(fd, STDIN_FILENO, O_CLOEXEC); + xdup3(fd, STDOUT_FILENO, O_CLOEXEC); + xdup3(fd, STDERR_FILENO, O_CLOEXEC); + if (fd > STDERR_FILENO) + close(fd); - int fd; - if (access("/proc/kmsg", W_OK) == 0) { - fd = xopen("/proc/kmsg", O_WRONLY | O_CLOEXEC); + if (access("/dev/kmsg", W_OK) == 0) { + fd = xopen("/dev/kmsg", O_WRONLY | O_CLOEXEC); } else { mknod("/kmsg", S_IFCHR | 0666, makedev(1, 11)); fd = xopen("/kmsg", O_WRONLY | O_CLOEXEC);