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> |
7 #include <unistd.h> | 9 #include <unistd.h> |
8 | 10 |
9 int main(int argc, char ** argv) { | 11 int main(int argc, char ** argv) { |
10 int i = fork(); | 12 int i = fork(); |
| 13 struct stat ft; |
| 14 time_t ct; |
| 15 |
11 if (i < 0) { | 16 if (i < 0) { |
12 printf("fork error"); | 17 printf("fork error"); |
13 return 1; | 18 return 1; |
14 } | 19 } |
15 if (i > 0) | 20 if (i > 0) |
16 return 0; | 21 return 0; |
17 | 22 |
18 /* child (daemon) continues */ | 23 /* child (daemon) continues */ |
19 int j; | 24 int j; |
20 for (j = 0; j < getdtablesize(); j++) | 25 for (j = 0; j < getdtablesize(); j++) |
21 close(j); | 26 close(j); |
22 | 27 |
23 setsid(); /* obtain a new process group */ | 28 setsid(); /* obtain a new process group */ |
24 | 29 |
25 while (1) { | 30 while (1) { |
26 system("touch /sdcard/host_heartbeat"); | |
27 sleep(120); | 31 sleep(120); |
28 if (fopen("/sdcard/host_heartbeat", "r") != NULL) { | 32 |
29 // File exists, was not removed from host. | 33 stat("/sdcard/host_heartbeat", &ft); |
| 34 time(&ct); |
| 35 if (ct - ft.st_mtime > 120) { |
| 36 /* File was not touched for some time. */ |
30 system("stop adbd"); | 37 system("stop adbd"); |
31 system("sleep 2"); | 38 system("sleep 2"); |
32 system("start adbd"); | 39 system("start adbd"); |
33 } | 40 } |
34 } | 41 } |
35 | 42 |
36 return 0; | 43 return 0; |
37 } | 44 } |
OLD | NEW |