The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* system/debuggerd/debuggerd.c |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 8 | ** |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 10 | ** |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <stdio.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 19 | #include <errno.h> |
| 20 | #include <signal.h> |
| 21 | #include <pthread.h> |
| 22 | #include <stdarg.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <dirent.h> |
| 26 | |
| 27 | #include <sys/ptrace.h> |
| 28 | #include <sys/wait.h> |
| 29 | #include <sys/exec_elf.h> |
| 30 | #include <sys/stat.h> |
| 31 | |
| 32 | #include <cutils/sockets.h> |
| 33 | #include <cutils/logd.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 34 | #include <cutils/properties.h> |
| 35 | |
| 36 | #include <linux/input.h> |
| 37 | |
| 38 | #include <private/android_filesystem_config.h> |
| 39 | |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 40 | #include "debuggerd.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 41 | #include "utility.h" |
| 42 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 43 | #define ANDROID_LOG_INFO 4 |
| 44 | |
| 45 | /* Log information onto the tombstone */ |
| 46 | void _LOG(int tfd, bool in_tombstone_only, const char *fmt, ...) |
| 47 | { |
Meng Hu | ae7b91b | 2009-11-05 16:10:50 -0600 | [diff] [blame] | 48 | char buf[512]; |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 49 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 50 | va_list ap; |
| 51 | va_start(ap, fmt); |
| 52 | |
| 53 | if (tfd >= 0) { |
| 54 | int len; |
| 55 | vsnprintf(buf, sizeof(buf), fmt, ap); |
| 56 | len = strlen(buf); |
| 57 | if(tfd >= 0) write(tfd, buf, len); |
| 58 | } |
| 59 | |
| 60 | if (!in_tombstone_only) |
| 61 | __android_log_vprint(ANDROID_LOG_INFO, "DEBUG", fmt, ap); |
| 62 | } |
| 63 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 64 | // 6f000000-6f01e000 rwxp 00000000 00:0c 16389419 /system/lib/libcomposer.so |
| 65 | // 012345678901234567890123456789012345678901234567890123456789 |
| 66 | // 0 1 2 3 4 5 |
| 67 | |
| 68 | mapinfo *parse_maps_line(char *line) |
| 69 | { |
| 70 | mapinfo *mi; |
| 71 | int len = strlen(line); |
| 72 | |
Andy McFadden | 136dcc5 | 2011-09-22 16:37:06 -0700 | [diff] [blame^] | 73 | if (len < 1) return 0; /* not expected */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 74 | line[--len] = 0; |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 75 | |
Andy McFadden | 136dcc5 | 2011-09-22 16:37:06 -0700 | [diff] [blame^] | 76 | if (len < 50) { |
| 77 | mi = malloc(sizeof(mapinfo) + 1); |
| 78 | } else { |
| 79 | mi = malloc(sizeof(mapinfo) + (len - 47)); |
| 80 | } |
| 81 | if (mi == 0) return 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 82 | |
Andy McFadden | 136dcc5 | 2011-09-22 16:37:06 -0700 | [diff] [blame^] | 83 | mi->isExecutable = (line[20] == 'x'); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 84 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 85 | mi->start = strtoul(line, 0, 16); |
| 86 | mi->end = strtoul(line + 9, 0, 16); |
Meng Hu | ae7b91b | 2009-11-05 16:10:50 -0600 | [diff] [blame] | 87 | /* To be filled in parse_elf_info if the mapped section starts with |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 88 | * elf_header |
| 89 | */ |
| 90 | mi->exidx_start = mi->exidx_end = 0; |
Meng Hu | ae7b91b | 2009-11-05 16:10:50 -0600 | [diff] [blame] | 91 | mi->symbols = 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 92 | mi->next = 0; |
Andy McFadden | 136dcc5 | 2011-09-22 16:37:06 -0700 | [diff] [blame^] | 93 | if (len < 50) { |
| 94 | mi->name[0] = '\0'; |
| 95 | } else { |
| 96 | strcpy(mi->name, line + 49); |
| 97 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 98 | |
| 99 | return mi; |
| 100 | } |
| 101 | |
| 102 | void dump_build_info(int tfd) |
| 103 | { |
| 104 | char fingerprint[PROPERTY_VALUE_MAX]; |
| 105 | |
| 106 | property_get("ro.build.fingerprint", fingerprint, "unknown"); |
| 107 | |
| 108 | _LOG(tfd, false, "Build fingerprint: '%s'\n", fingerprint); |
| 109 | } |
| 110 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 111 | const char *get_signame(int sig) |
| 112 | { |
| 113 | switch(sig) { |
| 114 | case SIGILL: return "SIGILL"; |
| 115 | case SIGABRT: return "SIGABRT"; |
| 116 | case SIGBUS: return "SIGBUS"; |
| 117 | case SIGFPE: return "SIGFPE"; |
| 118 | case SIGSEGV: return "SIGSEGV"; |
| 119 | case SIGSTKFLT: return "SIGSTKFLT"; |
| 120 | default: return "?"; |
| 121 | } |
| 122 | } |
| 123 | |
Carl Shapiro | 83c6b05 | 2010-10-08 18:10:24 -0700 | [diff] [blame] | 124 | const char *get_sigcode(int signo, int code) |
| 125 | { |
| 126 | switch (signo) { |
| 127 | case SIGILL: |
| 128 | switch (code) { |
| 129 | case ILL_ILLOPC: return "ILL_ILLOPC"; |
| 130 | case ILL_ILLOPN: return "ILL_ILLOPN"; |
| 131 | case ILL_ILLADR: return "ILL_ILLADR"; |
| 132 | case ILL_ILLTRP: return "ILL_ILLTRP"; |
| 133 | case ILL_PRVOPC: return "ILL_PRVOPC"; |
| 134 | case ILL_PRVREG: return "ILL_PRVREG"; |
| 135 | case ILL_COPROC: return "ILL_COPROC"; |
| 136 | case ILL_BADSTK: return "ILL_BADSTK"; |
| 137 | } |
| 138 | break; |
| 139 | case SIGBUS: |
| 140 | switch (code) { |
| 141 | case BUS_ADRALN: return "BUS_ADRALN"; |
| 142 | case BUS_ADRERR: return "BUS_ADRERR"; |
| 143 | case BUS_OBJERR: return "BUS_OBJERR"; |
| 144 | } |
| 145 | break; |
| 146 | case SIGFPE: |
| 147 | switch (code) { |
| 148 | case FPE_INTDIV: return "FPE_INTDIV"; |
| 149 | case FPE_INTOVF: return "FPE_INTOVF"; |
| 150 | case FPE_FLTDIV: return "FPE_FLTDIV"; |
| 151 | case FPE_FLTOVF: return "FPE_FLTOVF"; |
| 152 | case FPE_FLTUND: return "FPE_FLTUND"; |
| 153 | case FPE_FLTRES: return "FPE_FLTRES"; |
| 154 | case FPE_FLTINV: return "FPE_FLTINV"; |
| 155 | case FPE_FLTSUB: return "FPE_FLTSUB"; |
| 156 | } |
| 157 | break; |
| 158 | case SIGSEGV: |
| 159 | switch (code) { |
| 160 | case SEGV_MAPERR: return "SEGV_MAPERR"; |
| 161 | case SEGV_ACCERR: return "SEGV_ACCERR"; |
| 162 | } |
| 163 | break; |
| 164 | } |
| 165 | return "?"; |
| 166 | } |
| 167 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 168 | void dump_fault_addr(int tfd, int pid, int sig) |
| 169 | { |
| 170 | siginfo_t si; |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 171 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 172 | memset(&si, 0, sizeof(si)); |
| 173 | if(ptrace(PTRACE_GETSIGINFO, pid, 0, &si)){ |
| 174 | _LOG(tfd, false, "cannot get siginfo: %s\n", strerror(errno)); |
Andy McFadden | 136dcc5 | 2011-09-22 16:37:06 -0700 | [diff] [blame^] | 175 | } else if (signal_has_address(sig)) { |
Carl Shapiro | 83c6b05 | 2010-10-08 18:10:24 -0700 | [diff] [blame] | 176 | _LOG(tfd, false, "signal %d (%s), code %d (%s), fault addr %08x\n", |
| 177 | sig, get_signame(sig), |
| 178 | si.si_code, get_sigcode(sig, si.si_code), |
| 179 | si.si_addr); |
Andy McFadden | 136dcc5 | 2011-09-22 16:37:06 -0700 | [diff] [blame^] | 180 | } else { |
| 181 | _LOG(tfd, false, "signal %d (%s), code %d (%s), fault addr --------\n", |
| 182 | sig, get_signame(sig), si.si_code, get_sigcode(sig, si.si_code)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
| 186 | void dump_crash_banner(int tfd, unsigned pid, unsigned tid, int sig) |
| 187 | { |
| 188 | char data[1024]; |
| 189 | char *x = 0; |
| 190 | FILE *fp; |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 191 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 192 | sprintf(data, "/proc/%d/cmdline", pid); |
| 193 | fp = fopen(data, "r"); |
| 194 | if(fp) { |
| 195 | x = fgets(data, 1024, fp); |
| 196 | fclose(fp); |
| 197 | } |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 198 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 199 | _LOG(tfd, false, |
| 200 | "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n"); |
| 201 | dump_build_info(tfd); |
| 202 | _LOG(tfd, false, "pid: %d, tid: %d >>> %s <<<\n", |
| 203 | pid, tid, x ? x : "UNKNOWN"); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 204 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 205 | if(sig) dump_fault_addr(tfd, tid, sig); |
| 206 | } |
| 207 | |
Meng Hu | ae7b91b | 2009-11-05 16:10:50 -0600 | [diff] [blame] | 208 | static void parse_elf_info(mapinfo *milist, pid_t pid) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 209 | { |
| 210 | mapinfo *mi; |
| 211 | for (mi = milist; mi != NULL; mi = mi->next) { |
Andy McFadden | 136dcc5 | 2011-09-22 16:37:06 -0700 | [diff] [blame^] | 212 | if (!mi->isExecutable) |
| 213 | continue; |
| 214 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 215 | Elf32_Ehdr ehdr; |
| 216 | |
| 217 | memset(&ehdr, 0, sizeof(Elf32_Ehdr)); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 218 | /* Read in sizeof(Elf32_Ehdr) worth of data from the beginning of |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 219 | * mapped section. |
| 220 | */ |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 221 | get_remote_struct(pid, (void *) (mi->start), &ehdr, |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 222 | sizeof(Elf32_Ehdr)); |
| 223 | /* Check if it has the matching magic words */ |
| 224 | if (IS_ELF(ehdr)) { |
| 225 | Elf32_Phdr phdr; |
| 226 | Elf32_Phdr *ptr; |
| 227 | int i; |
| 228 | |
| 229 | ptr = (Elf32_Phdr *) (mi->start + ehdr.e_phoff); |
| 230 | for (i = 0; i < ehdr.e_phnum; i++) { |
| 231 | /* Parse the program header */ |
Mike Dodd | 6b65747 | 2010-07-14 11:28:29 -0700 | [diff] [blame] | 232 | get_remote_struct(pid, (char *) (ptr+i), &phdr, |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 233 | sizeof(Elf32_Phdr)); |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 234 | #ifdef __arm__ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 235 | /* Found a EXIDX segment? */ |
| 236 | if (phdr.p_type == PT_ARM_EXIDX) { |
| 237 | mi->exidx_start = mi->start + phdr.p_offset; |
| 238 | mi->exidx_end = mi->exidx_start + phdr.p_filesz; |
| 239 | break; |
| 240 | } |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 241 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 242 | } |
Meng Hu | ae7b91b | 2009-11-05 16:10:50 -0600 | [diff] [blame] | 243 | |
| 244 | /* Try to load symbols from this file */ |
| 245 | mi->symbols = symbol_table_create(mi->name); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | void dump_crash_report(int tfd, unsigned pid, unsigned tid, bool at_fault) |
| 251 | { |
| 252 | char data[1024]; |
| 253 | FILE *fp; |
| 254 | mapinfo *milist = 0; |
| 255 | unsigned int sp_list[STACK_CONTENT_DEPTH]; |
| 256 | int stack_depth; |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 257 | #ifdef __arm__ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 258 | int frame0_pc_sane = 1; |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 259 | #endif |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 260 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 261 | if (!at_fault) { |
| 262 | _LOG(tfd, true, |
| 263 | "--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n"); |
| 264 | _LOG(tfd, true, "pid: %d, tid: %d\n", pid, tid); |
| 265 | } |
| 266 | |
| 267 | dump_registers(tfd, tid, at_fault); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 268 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 269 | /* Clear stack pointer records */ |
| 270 | memset(sp_list, 0, sizeof(sp_list)); |
| 271 | |
| 272 | sprintf(data, "/proc/%d/maps", pid); |
| 273 | fp = fopen(data, "r"); |
| 274 | if(fp) { |
| 275 | while(fgets(data, 1024, fp)) { |
| 276 | mapinfo *mi = parse_maps_line(data); |
| 277 | if(mi) { |
| 278 | mi->next = milist; |
| 279 | milist = mi; |
| 280 | } |
| 281 | } |
| 282 | fclose(fp); |
| 283 | } |
| 284 | |
Meng Hu | ae7b91b | 2009-11-05 16:10:50 -0600 | [diff] [blame] | 285 | parse_elf_info(milist, tid); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 286 | |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 287 | #if __arm__ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 288 | /* If stack unwinder fails, use the default solution to dump the stack |
| 289 | * content. |
| 290 | */ |
| 291 | stack_depth = unwind_backtrace_with_ptrace(tfd, tid, milist, sp_list, |
| 292 | &frame0_pc_sane, at_fault); |
| 293 | |
| 294 | /* The stack unwinder should at least unwind two levels of stack. If less |
| 295 | * level is seen we make sure at lease pc and lr are dumped. |
| 296 | */ |
| 297 | if (stack_depth < 2) { |
| 298 | dump_pc_and_lr(tfd, tid, milist, stack_depth, at_fault); |
| 299 | } |
| 300 | |
Ben Cheng | 2854db8 | 2010-01-28 10:00:03 -0800 | [diff] [blame] | 301 | dump_stack_and_code(tfd, tid, milist, stack_depth, sp_list, at_fault); |
Bruce Beare | 6cc4923 | 2010-10-13 16:11:15 -0700 | [diff] [blame] | 302 | #elif __i386__ |
| 303 | /* If stack unwinder fails, use the default solution to dump the stack |
| 304 | * content. |
| 305 | */ |
| 306 | stack_depth = unwind_backtrace_with_ptrace_x86(tfd, tid, milist,at_fault); |
| 307 | #else |
| 308 | #error "Unsupported architecture" |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 309 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 310 | |
| 311 | while(milist) { |
| 312 | mapinfo *next = milist->next; |
Meng Hu | ae7b91b | 2009-11-05 16:10:50 -0600 | [diff] [blame] | 313 | symbol_table_free(milist->symbols); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 314 | free(milist); |
| 315 | milist = next; |
| 316 | } |
| 317 | } |
| 318 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 319 | #define MAX_TOMBSTONES 10 |
| 320 | |
| 321 | #define typecheck(x,y) { \ |
| 322 | typeof(x) __dummy1; \ |
| 323 | typeof(y) __dummy2; \ |
| 324 | (void)(&__dummy1 == &__dummy2); } |
| 325 | |
| 326 | #define TOMBSTONE_DIR "/data/tombstones" |
| 327 | |
| 328 | /* |
| 329 | * find_and_open_tombstone - find an available tombstone slot, if any, of the |
| 330 | * form tombstone_XX where XX is 00 to MAX_TOMBSTONES-1, inclusive. If no |
| 331 | * file is available, we reuse the least-recently-modified file. |
| 332 | */ |
| 333 | static int find_and_open_tombstone(void) |
| 334 | { |
| 335 | unsigned long mtime = ULONG_MAX; |
| 336 | struct stat sb; |
| 337 | char path[128]; |
| 338 | int fd, i, oldest = 0; |
| 339 | |
| 340 | /* |
| 341 | * XXX: Our stat.st_mtime isn't time_t. If it changes, as it probably ought |
| 342 | * to, our logic breaks. This check will generate a warning if that happens. |
| 343 | */ |
| 344 | typecheck(mtime, sb.st_mtime); |
| 345 | |
| 346 | /* |
| 347 | * In a single wolf-like pass, find an available slot and, in case none |
| 348 | * exist, find and record the least-recently-modified file. |
| 349 | */ |
| 350 | for (i = 0; i < MAX_TOMBSTONES; i++) { |
| 351 | snprintf(path, sizeof(path), TOMBSTONE_DIR"/tombstone_%02d", i); |
| 352 | |
| 353 | if (!stat(path, &sb)) { |
| 354 | if (sb.st_mtime < mtime) { |
| 355 | oldest = i; |
| 356 | mtime = sb.st_mtime; |
| 357 | } |
| 358 | continue; |
| 359 | } |
| 360 | if (errno != ENOENT) |
| 361 | continue; |
| 362 | |
| 363 | fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0600); |
| 364 | if (fd < 0) |
| 365 | continue; /* raced ? */ |
| 366 | |
| 367 | fchown(fd, AID_SYSTEM, AID_SYSTEM); |
| 368 | return fd; |
| 369 | } |
| 370 | |
| 371 | /* we didn't find an available file, so we clobber the oldest one */ |
| 372 | snprintf(path, sizeof(path), TOMBSTONE_DIR"/tombstone_%02d", oldest); |
| 373 | fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600); |
| 374 | fchown(fd, AID_SYSTEM, AID_SYSTEM); |
| 375 | |
| 376 | return fd; |
| 377 | } |
| 378 | |
| 379 | /* Return true if some thread is not detached cleanly */ |
| 380 | static bool dump_sibling_thread_report(int tfd, unsigned pid, unsigned tid) |
| 381 | { |
| 382 | char task_path[1024]; |
| 383 | |
| 384 | sprintf(task_path, "/proc/%d/task", pid); |
| 385 | DIR *d; |
| 386 | struct dirent *de; |
| 387 | int need_cleanup = 0; |
| 388 | |
| 389 | d = opendir(task_path); |
| 390 | /* Bail early if cannot open the task directory */ |
| 391 | if (d == NULL) { |
| 392 | XLOG("Cannot open /proc/%d/task\n", pid); |
| 393 | return false; |
| 394 | } |
| 395 | while ((de = readdir(d)) != NULL) { |
| 396 | unsigned new_tid; |
| 397 | /* Ignore "." and ".." */ |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 398 | if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 399 | continue; |
| 400 | new_tid = atoi(de->d_name); |
| 401 | /* The main thread at fault has been handled individually */ |
| 402 | if (new_tid == tid) |
| 403 | continue; |
| 404 | |
| 405 | /* Skip this thread if cannot ptrace it */ |
| 406 | if (ptrace(PTRACE_ATTACH, new_tid, 0, 0) < 0) |
| 407 | continue; |
| 408 | |
| 409 | dump_crash_report(tfd, pid, new_tid, false); |
| 410 | need_cleanup |= ptrace(PTRACE_DETACH, new_tid, 0, 0); |
| 411 | } |
| 412 | closedir(d); |
| 413 | return need_cleanup != 0; |
| 414 | } |
| 415 | |
| 416 | /* Return true if some thread is not detached cleanly */ |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 417 | static bool engrave_tombstone(unsigned pid, unsigned tid, int debug_uid, |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 418 | int signal) |
| 419 | { |
| 420 | int fd; |
| 421 | bool need_cleanup = false; |
| 422 | |
| 423 | mkdir(TOMBSTONE_DIR, 0755); |
| 424 | chown(TOMBSTONE_DIR, AID_SYSTEM, AID_SYSTEM); |
| 425 | |
| 426 | fd = find_and_open_tombstone(); |
| 427 | if (fd < 0) |
| 428 | return need_cleanup; |
| 429 | |
| 430 | dump_crash_banner(fd, pid, tid, signal); |
| 431 | dump_crash_report(fd, pid, tid, true); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 432 | /* |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 433 | * If the user has requested to attach gdb, don't collect the per-thread |
| 434 | * information as it increases the chance to lose track of the process. |
| 435 | */ |
| 436 | if ((signed)pid > debug_uid) { |
| 437 | need_cleanup = dump_sibling_thread_report(fd, pid, tid); |
| 438 | } |
| 439 | |
| 440 | close(fd); |
| 441 | return need_cleanup; |
| 442 | } |
| 443 | |
| 444 | static int |
| 445 | write_string(const char* file, const char* string) |
| 446 | { |
| 447 | int len; |
| 448 | int fd; |
| 449 | ssize_t amt; |
| 450 | fd = open(file, O_RDWR); |
| 451 | len = strlen(string); |
| 452 | if (fd < 0) |
| 453 | return -errno; |
| 454 | amt = write(fd, string, len); |
| 455 | close(fd); |
| 456 | return amt >= 0 ? 0 : -errno; |
| 457 | } |
| 458 | |
| 459 | static |
| 460 | void init_debug_led(void) |
| 461 | { |
| 462 | // trout leds |
| 463 | write_string("/sys/class/leds/red/brightness", "0"); |
| 464 | write_string("/sys/class/leds/green/brightness", "0"); |
| 465 | write_string("/sys/class/leds/blue/brightness", "0"); |
| 466 | write_string("/sys/class/leds/red/device/blink", "0"); |
| 467 | // sardine leds |
| 468 | write_string("/sys/class/leds/left/cadence", "0,0"); |
| 469 | } |
| 470 | |
| 471 | static |
| 472 | void enable_debug_led(void) |
| 473 | { |
| 474 | // trout leds |
| 475 | write_string("/sys/class/leds/red/brightness", "255"); |
| 476 | // sardine leds |
| 477 | write_string("/sys/class/leds/left/cadence", "1,0"); |
| 478 | } |
| 479 | |
| 480 | static |
| 481 | void disable_debug_led(void) |
| 482 | { |
| 483 | // trout leds |
| 484 | write_string("/sys/class/leds/red/brightness", "0"); |
| 485 | // sardine leds |
| 486 | write_string("/sys/class/leds/left/cadence", "0,0"); |
| 487 | } |
| 488 | |
| 489 | extern int init_getevent(); |
| 490 | extern void uninit_getevent(); |
| 491 | extern int get_event(struct input_event* event, int timeout); |
| 492 | |
| 493 | static void wait_for_user_action(unsigned tid, struct ucred* cr) |
| 494 | { |
| 495 | (void)tid; |
| 496 | /* First log a helpful message */ |
| 497 | LOG( "********************************************************\n" |
Andy McFadden | 3bfdcc9 | 2009-12-01 12:37:26 -0800 | [diff] [blame] | 498 | "* Process %d has been suspended while crashing. To\n" |
| 499 | "* attach gdbserver for a gdb connection on port 5039:\n" |
| 500 | "*\n" |
| 501 | "* adb shell gdbserver :5039 --attach %d &\n" |
| 502 | "*\n" |
| 503 | "* Press HOME key to let the process continue crashing.\n" |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 504 | "********************************************************\n", |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 505 | cr->pid, cr->pid); |
| 506 | |
Andy McFadden | 3bfdcc9 | 2009-12-01 12:37:26 -0800 | [diff] [blame] | 507 | /* wait for HOME key (TODO: something useful for devices w/o HOME key) */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 508 | if (init_getevent() == 0) { |
| 509 | int ms = 1200 / 10; |
| 510 | int dit = 1; |
| 511 | int dah = 3*dit; |
| 512 | int _ = -dit; |
| 513 | int ___ = 3*_; |
| 514 | int _______ = 7*_; |
| 515 | const signed char codes[] = { |
| 516 | dit,_,dit,_,dit,___,dah,_,dah,_,dah,___,dit,_,dit,_,dit,_______ |
| 517 | }; |
| 518 | size_t s = 0; |
| 519 | struct input_event e; |
| 520 | int home = 0; |
| 521 | init_debug_led(); |
| 522 | enable_debug_led(); |
| 523 | do { |
| 524 | int timeout = abs((int)(codes[s])) * ms; |
| 525 | int res = get_event(&e, timeout); |
| 526 | if (res == 0) { |
| 527 | if (e.type==EV_KEY && e.code==KEY_HOME && e.value==0) |
| 528 | home = 1; |
| 529 | } else if (res == 1) { |
| 530 | if (++s >= sizeof(codes)/sizeof(*codes)) |
| 531 | s = 0; |
| 532 | if (codes[s] > 0) { |
| 533 | enable_debug_led(); |
| 534 | } else { |
| 535 | disable_debug_led(); |
| 536 | } |
| 537 | } |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 538 | } while (!home); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 539 | uninit_getevent(); |
| 540 | } |
| 541 | |
| 542 | /* don't forget to turn debug led off */ |
| 543 | disable_debug_led(); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 544 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 545 | /* close filedescriptor */ |
| 546 | LOG("debuggerd resuming process %d", cr->pid); |
| 547 | } |
| 548 | |
| 549 | static void handle_crashing_process(int fd) |
| 550 | { |
| 551 | char buf[64]; |
| 552 | struct stat s; |
| 553 | unsigned tid; |
| 554 | struct ucred cr; |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 555 | int n, len, status; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 556 | int tid_attach_status = -1; |
| 557 | unsigned retry = 30; |
| 558 | bool need_cleanup = false; |
| 559 | |
| 560 | char value[PROPERTY_VALUE_MAX]; |
| 561 | property_get("debug.db.uid", value, "-1"); |
| 562 | int debug_uid = atoi(value); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 563 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 564 | XLOG("handle_crashing_process(%d)\n", fd); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 565 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 566 | len = sizeof(cr); |
| 567 | n = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &len); |
| 568 | if(n != 0) { |
| 569 | LOG("cannot get credentials\n"); |
| 570 | goto done; |
| 571 | } |
| 572 | |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 573 | XLOG("reading tid\n"); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 574 | fcntl(fd, F_SETFL, O_NONBLOCK); |
| 575 | while((n = read(fd, &tid, sizeof(unsigned))) != sizeof(unsigned)) { |
| 576 | if(errno == EINTR) continue; |
| 577 | if(errno == EWOULDBLOCK) { |
| 578 | if(retry-- > 0) { |
| 579 | usleep(100 * 1000); |
| 580 | continue; |
| 581 | } |
| 582 | LOG("timed out reading tid\n"); |
| 583 | goto done; |
| 584 | } |
| 585 | LOG("read failure? %s\n", strerror(errno)); |
| 586 | goto done; |
| 587 | } |
| 588 | |
David 'Digit' Turner | 02526d4 | 2011-01-21 04:27:12 +0100 | [diff] [blame] | 589 | snprintf(buf, sizeof buf, "/proc/%d/task/%d", cr.pid, tid); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 590 | if(stat(buf, &s)) { |
Andy McFadden | 3bfdcc9 | 2009-12-01 12:37:26 -0800 | [diff] [blame] | 591 | LOG("tid %d does not exist in pid %d. ignoring debug request\n", |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 592 | tid, cr.pid); |
| 593 | close(fd); |
| 594 | return; |
| 595 | } |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 596 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 597 | XLOG("BOOM: pid=%d uid=%d gid=%d tid=%d\n", cr.pid, cr.uid, cr.gid, tid); |
| 598 | |
David 'Digit' Turner | 02526d4 | 2011-01-21 04:27:12 +0100 | [diff] [blame] | 599 | /* Note that at this point, the target thread's signal handler |
| 600 | * is blocked in a read() call. This gives us the time to PTRACE_ATTACH |
| 601 | * to it before it has a chance to really fault. |
| 602 | * |
| 603 | * After the attach, the thread is stopped, and we write to the file |
| 604 | * descriptor to ensure that it will run as soon as we call PTRACE_CONT |
| 605 | * below. See details in bionic/libc/linker/debugger.c, in function |
| 606 | * debugger_signal_handler(). |
| 607 | */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 608 | tid_attach_status = ptrace(PTRACE_ATTACH, tid, 0, 0); |
Andy McFadden | 655835b | 2011-07-26 07:50:37 -0700 | [diff] [blame] | 609 | int ptrace_error = errno; |
David 'Digit' Turner | 02526d4 | 2011-01-21 04:27:12 +0100 | [diff] [blame] | 610 | |
Andy McFadden | 655835b | 2011-07-26 07:50:37 -0700 | [diff] [blame] | 611 | if (TEMP_FAILURE_RETRY(write(fd, &tid, 1)) != 1) { |
| 612 | XLOG("failed responding to client: %s\n", |
| 613 | strerror(errno)); |
| 614 | goto done; |
| 615 | } |
David 'Digit' Turner | 02526d4 | 2011-01-21 04:27:12 +0100 | [diff] [blame] | 616 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 617 | if(tid_attach_status < 0) { |
Andy McFadden | 655835b | 2011-07-26 07:50:37 -0700 | [diff] [blame] | 618 | LOG("ptrace attach failed: %s\n", strerror(ptrace_error)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 619 | goto done; |
| 620 | } |
| 621 | |
| 622 | close(fd); |
| 623 | fd = -1; |
| 624 | |
Andy McFadden | 655835b | 2011-07-26 07:50:37 -0700 | [diff] [blame] | 625 | const int sleep_time_usec = 200000; /* 0.2 seconds */ |
| 626 | const int max_total_sleep_usec = 3000000; /* 3 seconds */ |
| 627 | int loop_limit = max_total_sleep_usec / sleep_time_usec; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 628 | for(;;) { |
Andy McFadden | 655835b | 2011-07-26 07:50:37 -0700 | [diff] [blame] | 629 | if (loop_limit-- == 0) { |
| 630 | LOG("timed out waiting for pid=%d tid=%d uid=%d to die\n", |
| 631 | cr.pid, tid, cr.uid); |
| 632 | goto done; |
| 633 | } |
| 634 | n = waitpid(tid, &status, __WALL | WNOHANG); |
| 635 | |
| 636 | if (n == 0) { |
| 637 | /* not ready yet */ |
| 638 | XLOG("not ready yet\n"); |
| 639 | usleep(sleep_time_usec); |
| 640 | continue; |
| 641 | } |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 642 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 643 | if(n < 0) { |
| 644 | if(errno == EAGAIN) continue; |
| 645 | LOG("waitpid failed: %s\n", strerror(errno)); |
| 646 | goto done; |
| 647 | } |
| 648 | |
| 649 | XLOG("waitpid: n=%d status=%08x\n", n, status); |
| 650 | |
| 651 | if(WIFSTOPPED(status)){ |
| 652 | n = WSTOPSIG(status); |
| 653 | switch(n) { |
| 654 | case SIGSTOP: |
| 655 | XLOG("stopped -- continuing\n"); |
| 656 | n = ptrace(PTRACE_CONT, tid, 0, 0); |
| 657 | if(n) { |
| 658 | LOG("ptrace failed: %s\n", strerror(errno)); |
| 659 | goto done; |
| 660 | } |
| 661 | continue; |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 662 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 663 | case SIGILL: |
| 664 | case SIGABRT: |
| 665 | case SIGBUS: |
| 666 | case SIGFPE: |
| 667 | case SIGSEGV: |
| 668 | case SIGSTKFLT: { |
| 669 | XLOG("stopped -- fatal signal\n"); |
| 670 | need_cleanup = engrave_tombstone(cr.pid, tid, debug_uid, n); |
| 671 | kill(tid, SIGSTOP); |
| 672 | goto done; |
| 673 | } |
| 674 | |
| 675 | default: |
| 676 | XLOG("stopped -- unexpected signal\n"); |
| 677 | goto done; |
| 678 | } |
| 679 | } else { |
| 680 | XLOG("unexpected waitpid response\n"); |
| 681 | goto done; |
| 682 | } |
| 683 | } |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 684 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 685 | done: |
| 686 | XLOG("detaching\n"); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 687 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 688 | /* stop the process so we can debug */ |
| 689 | kill(cr.pid, SIGSTOP); |
| 690 | |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 691 | /* |
| 692 | * If a thread has been attached by ptrace, make sure it is detached |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 693 | * successfully otherwise we will get a zombie. |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 694 | */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 695 | if (tid_attach_status == 0) { |
| 696 | int detach_status; |
| 697 | /* detach so we can attach gdbserver */ |
| 698 | detach_status = ptrace(PTRACE_DETACH, tid, 0, 0); |
| 699 | need_cleanup |= (detach_status != 0); |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * if debug.db.uid is set, its value indicates if we should wait |
| 704 | * for user action for the crashing process. |
| 705 | * in this case, we log a message and turn the debug LED on |
| 706 | * waiting for a gdb connection (for instance) |
| 707 | */ |
| 708 | |
| 709 | if ((signed)cr.uid <= debug_uid) { |
| 710 | wait_for_user_action(tid, &cr); |
| 711 | } |
| 712 | |
| 713 | /* resume stopped process (so it can crash in peace) */ |
| 714 | kill(cr.pid, SIGCONT); |
| 715 | |
| 716 | if (need_cleanup) { |
| 717 | LOG("debuggerd committing suicide to free the zombie!\n"); |
| 718 | kill(getpid(), SIGKILL); |
| 719 | } |
| 720 | |
| 721 | if(fd != -1) close(fd); |
| 722 | } |
| 723 | |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 724 | |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 725 | int main() |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 726 | { |
| 727 | int s; |
| 728 | struct sigaction act; |
Bruce Beare | 8492490 | 2010-10-13 14:21:30 -0700 | [diff] [blame] | 729 | int logsocket = -1; |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 730 | |
Andy McFadden | 44e12ec | 2011-07-29 12:36:47 -0700 | [diff] [blame] | 731 | /* |
| 732 | * debuggerd crashes can't be reported to debuggerd. Reset all of the |
| 733 | * crash handlers. |
| 734 | */ |
| 735 | signal(SIGILL, SIG_DFL); |
| 736 | signal(SIGABRT, SIG_DFL); |
| 737 | signal(SIGBUS, SIG_DFL); |
| 738 | signal(SIGFPE, SIG_DFL); |
| 739 | signal(SIGSEGV, SIG_DFL); |
| 740 | signal(SIGSTKFLT, SIG_DFL); |
| 741 | signal(SIGPIPE, SIG_DFL); |
| 742 | |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 743 | logsocket = socket_local_client("logd", |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 744 | ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_DGRAM); |
| 745 | if(logsocket < 0) { |
| 746 | logsocket = -1; |
| 747 | } else { |
| 748 | fcntl(logsocket, F_SETFD, FD_CLOEXEC); |
| 749 | } |
| 750 | |
| 751 | act.sa_handler = SIG_DFL; |
| 752 | sigemptyset(&act.sa_mask); |
| 753 | sigaddset(&act.sa_mask,SIGCHLD); |
| 754 | act.sa_flags = SA_NOCLDWAIT; |
| 755 | sigaction(SIGCHLD, &act, 0); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 756 | |
| 757 | s = socket_local_server("android:debuggerd", |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 758 | ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); |
| 759 | if(s < 0) return -1; |
| 760 | fcntl(s, F_SETFD, FD_CLOEXEC); |
| 761 | |
| 762 | LOG("debuggerd: " __DATE__ " " __TIME__ "\n"); |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 763 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 764 | for(;;) { |
| 765 | struct sockaddr addr; |
| 766 | socklen_t alen; |
| 767 | int fd; |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 768 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 769 | alen = sizeof(addr); |
Andy McFadden | 655835b | 2011-07-26 07:50:37 -0700 | [diff] [blame] | 770 | XLOG("waiting for connection\n"); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 771 | fd = accept(s, &addr, &alen); |
Andy McFadden | 655835b | 2011-07-26 07:50:37 -0700 | [diff] [blame] | 772 | if(fd < 0) { |
| 773 | XLOG("accept failed: %s\n", strerror(errno)); |
| 774 | continue; |
| 775 | } |
Ben Cheng | 09e7137 | 2009-09-28 11:06:09 -0700 | [diff] [blame] | 776 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 777 | fcntl(fd, F_SETFD, FD_CLOEXEC); |
| 778 | |
| 779 | handle_crashing_process(fd); |
| 780 | } |
| 781 | return 0; |
| 782 | } |