From f81fd9a408d3c5d10dcb9fee12612e1672c574dc Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Mon, 22 Feb 2016 16:56:51 -0800 Subject: healthd: use timerfd if dev alarm not exist /dev/alarm driver is deprecated is M. If it does not exists, use timerfd instead. SAMBAR-1286 Change-Id: Ie1eac58fddc80a8a545848c2a4f5db0e64eae076 --- healthd/healthd_board_msm.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/healthd/healthd_board_msm.cpp b/healthd/healthd_board_msm.cpp index 81a8aa6..d17095f 100644 --- a/healthd/healthd_board_msm.cpp +++ b/healthd/healthd_board_msm.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -113,6 +114,38 @@ static int alarm_is_alm_expired() alm_secs <= rtc_secs + ERR_SECS) ? 1 : 0; } +static int timerfd_set_reboot_time_and_wait(time_t secs) +{ + int fd; + int ret = -1; + fd = timerfd_create(CLOCK_REALTIME_ALARM, 0); + if (fd < 0) { + LOGE("Can't open timerfd alarm node\n"); + goto err_return; + } + + struct itimerspec spec; + memset(&spec, 0, sizeof(spec)); + spec.it_value.tv_sec = secs; + + if (timerfd_settime(fd, 0 /* relative */, &spec, NULL)) { + LOGE("Can't set timerfd alarm\n"); + goto err_close; + } + + uint64_t unused; + if (read(fd, &unused, sizeof(unused)) < 0) { + LOGE("Wait alarm error\n"); + goto err_close; + } + + ret = 0; +err_close: + close(fd); +err_return: + return ret; +} + static int alarm_set_reboot_time_and_wait(time_t secs) { int rc, fd; @@ -120,8 +153,8 @@ static int alarm_set_reboot_time_and_wait(time_t secs) fd = open("/dev/alarm", O_RDWR); if (fd < 0) { - LOGE("Can't open alarm devfs node\n"); - goto err; + LOGE("Can't open alarm devfs node, trying timerfd\n"); + return timerfd_set_reboot_time_and_wait(secs); } /* get the elapsed realtime from boot time to now */ -- cgit v1.1