system/corennnnn
Revision | d50223f2eb51a69c21e77c5337ba0ff037f93450 (tree) |
---|---|
Time | 2016-09-04 08:46:51 |
Author | Keith Mok <kmok@cyng...> |
Commiter | Steve Kondik |
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
@@ -32,6 +32,7 @@ | ||
32 | 32 | |
33 | 33 | #include <pthread.h> |
34 | 34 | #include <linux/android_alarm.h> |
35 | +#include <sys/timerfd.h> | |
35 | 36 | #include <linux/rtc.h> |
36 | 37 | |
37 | 38 | #include <healthd.h> |
@@ -113,6 +114,38 @@ static int alarm_is_alm_expired() | ||
113 | 114 | alm_secs <= rtc_secs + ERR_SECS) ? 1 : 0; |
114 | 115 | } |
115 | 116 | |
117 | +static int timerfd_set_reboot_time_and_wait(time_t secs) | |
118 | +{ | |
119 | + int fd; | |
120 | + int ret = -1; | |
121 | + fd = timerfd_create(CLOCK_REALTIME_ALARM, 0); | |
122 | + if (fd < 0) { | |
123 | + LOGE("Can't open timerfd alarm node\n"); | |
124 | + goto err_return; | |
125 | + } | |
126 | + | |
127 | + struct itimerspec spec; | |
128 | + memset(&spec, 0, sizeof(spec)); | |
129 | + spec.it_value.tv_sec = secs; | |
130 | + | |
131 | + if (timerfd_settime(fd, 0 /* relative */, &spec, NULL)) { | |
132 | + LOGE("Can't set timerfd alarm\n"); | |
133 | + goto err_close; | |
134 | + } | |
135 | + | |
136 | + uint64_t unused; | |
137 | + if (read(fd, &unused, sizeof(unused)) < 0) { | |
138 | + LOGE("Wait alarm error\n"); | |
139 | + goto err_close; | |
140 | + } | |
141 | + | |
142 | + ret = 0; | |
143 | +err_close: | |
144 | + close(fd); | |
145 | +err_return: | |
146 | + return ret; | |
147 | +} | |
148 | + | |
116 | 149 | static int alarm_set_reboot_time_and_wait(time_t secs) |
117 | 150 | { |
118 | 151 | int rc, fd; |
@@ -120,8 +153,8 @@ static int alarm_set_reboot_time_and_wait(time_t secs) | ||
120 | 153 | |
121 | 154 | fd = open("/dev/alarm", O_RDWR); |
122 | 155 | if (fd < 0) { |
123 | - LOGE("Can't open alarm devfs node\n"); | |
124 | - goto err; | |
156 | + LOGE("Can't open alarm devfs node, trying timerfd\n"); | |
157 | + return timerfd_set_reboot_time_and_wait(secs); | |
125 | 158 | } |
126 | 159 | |
127 | 160 | /* get the elapsed realtime from boot time to now */ |