• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revisiond50223f2eb51a69c21e77c5337ba0ff037f93450 (tree)
Time2016-09-04 08:46:51
AuthorKeith Mok <kmok@cyng...>
CommiterSteve Kondik

Log Message

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

Change Summary

Incremental Difference

--- a/healthd/healthd_board_msm.cpp
+++ b/healthd/healthd_board_msm.cpp
@@ -32,6 +32,7 @@
3232
3333 #include <pthread.h>
3434 #include <linux/android_alarm.h>
35+#include <sys/timerfd.h>
3536 #include <linux/rtc.h>
3637
3738 #include <healthd.h>
@@ -113,6 +114,38 @@ static int alarm_is_alm_expired()
113114 alm_secs <= rtc_secs + ERR_SECS) ? 1 : 0;
114115 }
115116
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+
116149 static int alarm_set_reboot_time_and_wait(time_t secs)
117150 {
118151 int rc, fd;
@@ -120,8 +153,8 @@ static int alarm_set_reboot_time_and_wait(time_t secs)
120153
121154 fd = open("/dev/alarm", O_RDWR);
122155 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);
125158 }
126159
127160 /* get the elapsed realtime from boot time to now */