1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _DUMPSTATE_H_ 18 #define _DUMPSTATE_H_ 19 20 #include <time.h> 21 22 // Commands time out after 60 seconds 23 #define TIMEOUT 60 24 25 #define PRINT(s) printf("%s\n", s) 26 27 #define DUMP(file) dump_file(file) 28 29 #define DUMP_FILES(path) dump_files(path) 30 31 #define DUMP_PROMPT(prompt, file) \ 32 { \ 33 printf(prompt); \ 34 dump_file(file); \ 35 } 36 37 #define EXEC(cmd) \ 38 { \ 39 static struct Command c = { \ 40 "/system/bin/" cmd, \ 41 { cmd, 0 } \ 42 }; \ 43 run_command(&c, TIMEOUT); \ 44 } 45 46 #define EXEC_TIMEOUT(cmd, tmout)\ 47 { \ 48 static struct Command c = { \ 49 "/system/bin/" cmd, \ 50 { cmd, 0 } \ 51 }; \ 52 run_command(&c, tmout); \ 53 } 54 55 #define EXEC_XBIN(cmd) \ 56 { \ 57 static struct Command c = { \ 58 "/system/xbin/" cmd, \ 59 { cmd, 0 } \ 60 }; \ 61 run_command(&c, TIMEOUT); \ 62 } 63 64 #define EXEC1(cmd, a1) \ 65 { \ 66 static struct Command c = { \ 67 "/system/bin/" cmd, \ 68 { cmd, a1, 0 } \ 69 }; \ 70 run_command(&c, TIMEOUT); \ 71 } 72 73 #define EXEC2(cmd, a1, a2) \ 74 { \ 75 static struct Command c = { \ 76 "/system/bin/" cmd, \ 77 { cmd, a1, a2, 0 } \ 78 }; \ 79 run_command(&c, TIMEOUT); \ 80 } 81 82 #define EXEC3(cmd, a1, a2, a3) \ 83 { \ 84 static struct Command c = { \ 85 "/system/bin/" cmd, \ 86 { cmd, a1, a2, a3, 0 } \ 87 }; \ 88 run_command(&c, TIMEOUT); \ 89 } 90 91 #define EXEC4(cmd, a1, a2, a3, a4) \ 92 { \ 93 static struct Command c = { \ 94 "/system/bin/" cmd, \ 95 { cmd, a1, a2, a3, a4, 0 } \ 96 }; \ 97 run_command(&c, TIMEOUT); \ 98 } 99 100 #define EXEC6(cmd, a1, a2, a3, a4, a5, a6) \ 101 { \ 102 static struct Command c = { \ 103 "/system/bin/" cmd, \ 104 { cmd, a1, a2, a3, a4, a5, a6, 0 } \ 105 }; \ 106 run_command(&c, TIMEOUT); \ 107 } 108 109 #define EXEC7(cmd, a1, a2, a3, a4, a5, a6, a7) \ 110 { \ 111 static struct Command c = { \ 112 "/system/bin/" cmd, \ 113 { cmd, a1, a2, a3, a4, a5, a6, a7, 0 } \ 114 }; \ 115 run_command(&c, TIMEOUT); \ 116 } 117 118 #define EXEC8(cmd, a1, a2, a3, a4, a5, a6, a7, a8) \ 119 { \ 120 static struct Command c = { \ 121 "/system/bin/" cmd, \ 122 { cmd, a1, a2, a3, a4, a5, a6, a7, a8, 0 } \ 123 }; \ 124 run_command(&c, TIMEOUT); \ 125 } 126 127 #define PROPERTY(name) print_property(name) 128 129 struct Command { 130 const char* path; 131 char* const args[]; 132 }; 133 typedef struct Command Command; 134 135 /* prints the contents of a file */ 136 int dump_file(const char* path); 137 138 /* prints the contents of all files in a directory */ 139 void dump_files(const char* path); 140 141 /* forks a command and waits for it to finish */ 142 int run_command(struct Command* cmd, int timeout); 143 144 /* reads the current time into tm */ 145 void get_time(struct tm *tm); 146 147 /* prints the date in tm */ 148 void print_date(const char* prompt, struct tm *tm); 149 150 /* prints the name and value of a system property */ 151 int print_property(const char* name); 152 153 /* prints all the system properties */ 154 void print_properties(); 155 156 /* creates directories as needed for the given path */ 157 void create_directories(char *path); 158 159 /* runs the vibrator using the given pattern */ 160 void vibrate_pattern(int fd, int* pattern); 161 162 /* prevents the OOM killer from killing us */ 163 void protect_from_oom_killer(); 164 165 #endif /* _DUMPSTATE_H_ */ 166