diff options
author | Keith Mok <kmok@cyngn.com> | 2016-02-22 16:56:51 -0800 |
---|---|---|
committer | Ethan Chen <intervigil@gmail.com> | 2016-02-23 17:13:29 -0800 |
commit | f81fd9a408d3c5d10dcb9fee12612e1672c574dc (patch) | |
tree | d083f178e235875da9aec3ba059736031c306979 /healthd | |
parent | 1724115cc329e59331185a4c723f68b874b2d6b9 (diff) | |
download | system_core-f81fd9a408d3c5d10dcb9fee12612e1672c574dc.zip system_core-f81fd9a408d3c5d10dcb9fee12612e1672c574dc.tar.gz system_core-f81fd9a408d3c5d10dcb9fee12612e1672c574dc.tar.bz2 |
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
Diffstat (limited to 'healthd')
-rw-r--r-- | healthd/healthd_board_msm.cpp | 37 |
1 files 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 <pthread.h> #include <linux/android_alarm.h> +#include <sys/timerfd.h> #include <linux/rtc.h> #include <healthd.h> @@ -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 */ |