summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-03-27 23:20:44 -0700
committerElliott Hughes <enh@google.com>2015-03-28 00:25:22 -0700
commitda40c00137f75543a69972f1be506e2d14a41845 (patch)
treed24df4f9a94411205786227c26cd2a1a664420bc /libcutils
parente29744d94df787fa83307572d90a954b1592f69b (diff)
downloadsystem_core-da40c00137f75543a69972f1be506e2d14a41845.zip
system_core-da40c00137f75543a69972f1be506e2d14a41845.tar.gz
system_core-da40c00137f75543a69972f1be506e2d14a41845.tar.bz2
Log more timing information from init.
Also make important events in init's life NOTICE rather than INFO, and ensure that NOTICE events actually make it to the kernel log. Also fix the logging so that if you have a printf format string error, the compiler now catches it. Also give messages from init, ueventd, and watchdogd distinct tags. (Previously they'd all call themselves "init", and dmesg doesn't include pids, so you couldn't untangle them.) Also include the tag in SELinux messages. Bug: 19544788 Change-Id: Ica6daea065bfdb80155c52c0b06f346a7df208fe
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/klog.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/libcutils/klog.c b/libcutils/klog.c
index fbb7b72..fad2a8b 100644
--- a/libcutils/klog.c
+++ b/libcutils/klog.c
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-#include <sys/stat.h>
-#include <sys/types.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
#include <cutils/klog.h>
@@ -36,41 +37,39 @@ void klog_set_level(int level) {
klog_level = level;
}
-void klog_init(void)
-{
- static const char *name = "/dev/__kmsg__";
-
+void klog_init(void) {
if (klog_fd >= 0) return; /* Already initialized */
+ static const char *name = "/dev/__kmsg__";
if (mknod(name, S_IFCHR | 0600, (1 << 8) | 11) == 0) {
- klog_fd = open(name, O_WRONLY);
- if (klog_fd < 0)
- return;
- fcntl(klog_fd, F_SETFD, FD_CLOEXEC);
+ klog_fd = open(name, O_WRONLY | O_CLOEXEC);
+ if (klog_fd == -1) {
+ return;
+ }
unlink(name);
}
}
#define LOG_BUF_MAX 512
-void klog_vwrite(int level, const char *fmt, va_list ap)
-{
- char buf[LOG_BUF_MAX];
-
+void klog_writev(int level, const struct iovec* iov, int iov_count) {
if (level > klog_level) return;
if (klog_fd < 0) klog_init();
if (klog_fd < 0) return;
-
- vsnprintf(buf, LOG_BUF_MAX, fmt, ap);
- buf[LOG_BUF_MAX - 1] = 0;
-
- write(klog_fd, buf, strlen(buf));
+ TEMP_FAILURE_RETRY(writev(klog_fd, iov, iov_count));
}
-void klog_write(int level, const char *fmt, ...)
-{
+void klog_write(int level, const char* fmt, ...) {
+ char buf[LOG_BUF_MAX];
va_list ap;
va_start(ap, fmt);
- klog_vwrite(level, fmt, ap);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
+
+ buf[LOG_BUF_MAX - 1] = 0;
+
+ struct iovec iov[1];
+ iov[0].iov_base = buf;
+ iov[0].iov_len = strlen(buf);
+ klog_writev(level, iov, 1);
}