summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2015-05-18 18:41:23 -0700
committerNick Kralevich <nnk@google.com>2015-05-19 15:19:25 -0700
commit7eb3abdb3ba500d3acca82b95705f34128251015 (patch)
tree9d8e1293fd86b1946bef234c4ce2bba731468da5 /libcutils
parent0ebd13f0639ddfc3e6e96bbcc6ce5465ca489808 (diff)
downloadsystem_core-7eb3abdb3ba500d3acca82b95705f34128251015.zip
system_core-7eb3abdb3ba500d3acca82b95705f34128251015.tar.gz
system_core-7eb3abdb3ba500d3acca82b95705f34128251015.tar.bz2
klog: don't unconditionally call mknod()
If /dev/kmsg already exists, it's unnecessary for klog_init() to create it's own copy. This avoids needing to grant the mknod permission to everyone who uses kmsg. Typically the only time /dev/kmsg doesn't exist is before ueventd starts. (cherrypicked from commit 4d32a486fe62ef2c1440167604654a2f4e023fbd) Bug: 21242418 Change-Id: I0c88d80feca6899fcdbc8c9f2f99448ee0a3422d
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/klog.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/libcutils/klog.c b/libcutils/klog.c
index f574f08..710dc66 100644
--- a/libcutils/klog.c
+++ b/libcutils/klog.c
@@ -40,6 +40,11 @@ void klog_set_level(int level) {
void klog_init(void) {
if (klog_fd >= 0) return; /* Already initialized */
+ klog_fd = open("/dev/kmsg", O_WRONLY | O_CLOEXEC);
+ if (klog_fd >= 0) {
+ return;
+ }
+
static const char* name = "/dev/__kmsg__";
if (mknod(name, S_IFCHR | 0600, (1 << 8) | 11) == 0) {
klog_fd = open(name, O_WRONLY | O_CLOEXEC);