summaryrefslogtreecommitdiffstats
path: root/init/watchdogd.cpp
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 /init/watchdogd.cpp
parente29744d94df787fa83307572d90a954b1592f69b (diff)
downloadcore-da40c00137f75543a69972f1be506e2d14a41845.tar.gz
core-da40c00137f75543a69972f1be506e2d14a41845.tar.bz2
core-da40c00137f75543a69972f1be506e2d14a41845.zip
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 'init/watchdogd.cpp')
-rw-r--r--init/watchdogd.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/init/watchdogd.cpp b/init/watchdogd.cpp
index 079081129..881a4dfb5 100644
--- a/init/watchdogd.cpp
+++ b/init/watchdogd.cpp
@@ -27,52 +27,45 @@
#define DEV_NAME "/dev/watchdog"
-int watchdogd_main(int argc, char **argv)
-{
- int fd;
- int ret;
- int interval = 10;
- int margin = 10;
- int timeout;
-
+int watchdogd_main(int argc, char **argv) {
open_devnull_stdio();
klog_init();
+ klog_set_level(KLOG_NOTICE_LEVEL);
- INFO("Starting watchdogd\n");
-
- if (argc >= 2)
- interval = atoi(argv[1]);
+ int interval = 10;
+ if (argc >= 2) interval = atoi(argv[1]);
- if (argc >= 3)
- margin = atoi(argv[2]);
+ int margin = 10;
+ if (argc >= 3) margin = atoi(argv[2]);
- timeout = interval + margin;
+ NOTICE("watchdogd started (interval %d, margin %d)!\n", interval, margin);
- fd = open(DEV_NAME, O_RDWR|O_CLOEXEC);
- if (fd < 0) {
+ int fd = open(DEV_NAME, O_RDWR|O_CLOEXEC);
+ if (fd == -1) {
ERROR("watchdogd: Failed to open %s: %s\n", DEV_NAME, strerror(errno));
return 1;
}
- ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
+ int timeout = interval + margin;
+ int ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
if (ret) {
ERROR("watchdogd: Failed to set timeout to %d: %s\n", timeout, strerror(errno));
ret = ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
if (ret) {
ERROR("watchdogd: Failed to get timeout: %s\n", strerror(errno));
} else {
- if (timeout > margin)
+ if (timeout > margin) {
interval = timeout - margin;
- else
+ } else {
interval = 1;
+ }
ERROR("watchdogd: Adjusted interval to timeout returned by driver: timeout %d, interval %d, margin %d\n",
timeout, interval, margin);
}
}
- while(1) {
+ while (true) {
write(fd, "", 1);
sleep(interval);
}
}
-