OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <sys/types.h> |
| 6 #include <sys/stat.h> |
5 #include <stdio.h> | 7 #include <stdio.h> |
6 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <time.h> |
7 #include <unistd.h> | 10 #include <unistd.h> |
8 | 11 |
9 int main(int argc, char ** argv) { | 12 int main(int argc, char ** argv) { |
10 int i = fork(); | 13 int i = fork(); |
| 14 struct stat ft; |
| 15 time_t ct; |
| 16 |
11 if (i < 0) { | 17 if (i < 0) { |
12 printf("fork error"); | 18 printf("fork error"); |
13 return 1; | 19 return 1; |
14 } | 20 } |
15 if (i > 0) | 21 if (i > 0) |
16 return 0; | 22 return 0; |
17 | 23 |
18 /* child (daemon) continues */ | 24 /* child (daemon) continues */ |
19 int j; | 25 int j; |
20 for (j = 0; j < getdtablesize(); j++) | 26 for (j = 0; j < getdtablesize(); j++) |
21 close(j); | 27 close(j); |
22 | 28 |
23 setsid(); /* obtain a new process group */ | 29 setsid(); /* obtain a new process group */ |
24 | 30 |
25 while (1) { | 31 while (1) { |
26 system("touch /sdcard/host_heartbeat"); | |
27 sleep(120); | 32 sleep(120); |
28 if (fopen("/sdcard/host_heartbeat", "r") != NULL) { | 33 |
29 // File exists, was not removed from host. | 34 stat("/sdcard/host_heartbeat", &ft); |
30 system("stop adbd"); | 35 time(&ct); |
| 36 if (ct - ft.st_mtime > 120) { |
| 37 /* File was not touched for some time. */ |
| 38 system("su -c stop adbd"); |
31 system("sleep 2"); | 39 system("sleep 2"); |
32 system("start adbd"); | 40 system("su -c start adbd"); |
33 } | 41 } |
34 } | 42 } |
35 | 43 |
36 return 0; | 44 return 0; |
37 } | 45 } |
OLD | NEW |