Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: tools/android/adb_reboot/adb_reboot.c

Issue 349323003: [Android]: Replace calls to getdtablesize with sysconf(_SC_OPEN_MAX) in tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/test/multiprocess_test_android.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 5 #include <sys/types.h>
6 #include <sys/stat.h> 6 #include <sys/stat.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <time.h> 9 #include <time.h>
10 #include <unistd.h> 10 #include <unistd.h>
11 11
12 int main(int argc, char ** argv) { 12 int main(int argc, char ** argv) {
13 int i = fork(); 13 int i = fork();
14 struct stat ft; 14 struct stat ft;
15 time_t ct; 15 time_t ct;
16 16
17 if (i < 0) { 17 if (i < 0) {
18 printf("fork error"); 18 printf("fork error");
19 return 1; 19 return 1;
20 } 20 }
21 if (i > 0) 21 if (i > 0)
22 return 0; 22 return 0;
23 23
24 /* child (daemon) continues */ 24 /* child (daemon) continues */
25 int j; 25 int j;
26 for (j = 0; j < getdtablesize(); j++) 26 for (j = 0; j < sysconf(_SC_OPEN_MAX); j++)
27 close(j); 27 close(j);
28 28
29 setsid(); /* obtain a new process group */ 29 setsid(); /* obtain a new process group */
30 30
31 while (1) { 31 while (1) {
32 sleep(120); 32 sleep(120);
33 33
34 stat("/sdcard/host_heartbeat", &ft); 34 stat("/sdcard/host_heartbeat", &ft);
35 time(&ct); 35 time(&ct);
36 if (ct - ft.st_mtime > 120) { 36 if (ct - ft.st_mtime > 120) {
37 /* File was not touched for some time. */ 37 /* File was not touched for some time. */
38 system("su -c reboot"); 38 system("su -c reboot");
39 } 39 }
40 } 40 }
41 41
42 return 0; 42 return 0;
43 } 43 }
OLDNEW
« no previous file with comments | « base/test/multiprocess_test_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698