Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016, 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 | #include <arpa/inet.h> |
| 18 | #include <dirent.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <stdlib.h> |
Josh Gao | 85bcaf6 | 2017-02-01 16:35:31 -0800 | [diff] [blame] | 21 | #include <sys/prctl.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 22 | #include <sys/ptrace.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/un.h> |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 25 | #include <sys/wait.h> |
Josh Gao | 85bcaf6 | 2017-02-01 16:35:31 -0800 | [diff] [blame] | 26 | #include <syscall.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 27 | #include <unistd.h> |
| 28 | |
| 29 | #include <limits> |
Josh Gao | 57f58f8 | 2017-03-15 23:23:22 -0700 | [diff] [blame] | 30 | #include <map> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 31 | #include <memory> |
| 32 | #include <set> |
| 33 | #include <vector> |
| 34 | |
| 35 | #include <android-base/file.h> |
| 36 | #include <android-base/logging.h> |
Josh Gao | 8d44b14 | 2018-09-18 13:22:22 -0700 | [diff] [blame] | 37 | #include <android-base/macros.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 38 | #include <android-base/parseint.h> |
| 39 | #include <android-base/properties.h> |
| 40 | #include <android-base/stringprintf.h> |
Josh Gao | 57f58f8 | 2017-03-15 23:23:22 -0700 | [diff] [blame] | 41 | #include <android-base/strings.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 42 | #include <android-base/unique_fd.h> |
Josh Gao | a48b41b | 2019-12-13 14:11:04 -0800 | [diff] [blame] | 43 | #include <bionic/reserved_signals.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 44 | #include <cutils/sockets.h> |
Vijay Venkatraman | a95acea | 2017-01-23 20:11:51 -0800 | [diff] [blame] | 45 | #include <log/log.h> |
Josh Gao | b0e51e3 | 2017-06-01 12:08:10 -0700 | [diff] [blame] | 46 | #include <private/android_filesystem_config.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 47 | #include <procinfo/process.h> |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 48 | |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 49 | #define ATRACE_TAG ATRACE_TAG_BIONIC |
| 50 | #include <utils/Trace.h> |
| 51 | |
David Srbecky | b9cc4fb | 2019-04-05 18:23:32 +0000 | [diff] [blame] | 52 | #include <unwindstack/DexFiles.h> |
Christopher Ferris | 60eb197 | 2019-01-15 15:18:43 -0800 | [diff] [blame] | 53 | #include <unwindstack/JitDebug.h> |
| 54 | #include <unwindstack/Maps.h> |
| 55 | #include <unwindstack/Memory.h> |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 56 | #include <unwindstack/Regs.h> |
Christopher Ferris | 60eb197 | 2019-01-15 15:18:43 -0800 | [diff] [blame] | 57 | #include <unwindstack/Unwinder.h> |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 58 | |
Josh Gao | c370666 | 2017-08-29 13:08:32 -0700 | [diff] [blame] | 59 | #include "libdebuggerd/backtrace.h" |
| 60 | #include "libdebuggerd/tombstone.h" |
| 61 | #include "libdebuggerd/utility.h" |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 62 | |
| 63 | #include "debuggerd/handler.h" |
Narayan Kamath | 2d377cd | 2017-05-10 10:58:59 +0100 | [diff] [blame] | 64 | #include "tombstoned/tombstoned.h" |
Josh Gao | c370666 | 2017-08-29 13:08:32 -0700 | [diff] [blame] | 65 | |
| 66 | #include "protocol.h" |
Narayan Kamath | 2d377cd | 2017-05-10 10:58:59 +0100 | [diff] [blame] | 67 | #include "util.h" |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 68 | |
| 69 | using android::base::unique_fd; |
| 70 | using android::base::StringPrintf; |
Josh Gao | 57f58f8 | 2017-03-15 23:23:22 -0700 | [diff] [blame] | 71 | |
Josh Gao | fe90276 | 2017-02-01 16:31:43 -0800 | [diff] [blame] | 72 | static bool pid_contains_tid(int pid_proc_fd, pid_t tid) { |
| 73 | struct stat st; |
| 74 | std::string task_path = StringPrintf("task/%d", tid); |
| 75 | return fstatat(pid_proc_fd, task_path.c_str(), &st, 0) == 0; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 78 | static pid_t get_tracer(pid_t tracee) { |
| 79 | // Check to see if the thread is being ptraced by another process. |
| 80 | android::procinfo::ProcessInfo process_info; |
| 81 | if (android::procinfo::GetProcessInfo(tracee, &process_info)) { |
| 82 | return process_info.tracer; |
| 83 | } |
| 84 | return -1; |
| 85 | } |
| 86 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 87 | // Attach to a thread, and verify that it's still a member of the given process |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 88 | static bool ptrace_seize_thread(int pid_proc_fd, pid_t tid, std::string* error, int flags = 0) { |
| 89 | if (ptrace(PTRACE_SEIZE, tid, 0, flags) != 0) { |
Josh Gao | fd13bf0 | 2017-08-18 15:37:26 -0700 | [diff] [blame] | 90 | if (errno == EPERM) { |
| 91 | pid_t tracer = get_tracer(tid); |
| 92 | if (tracer != -1) { |
| 93 | *error = StringPrintf("failed to attach to thread %d, already traced by %d (%s)", tid, |
| 94 | tracer, get_process_name(tracer).c_str()); |
| 95 | return false; |
| 96 | } |
| 97 | } |
| 98 | |
Josh Gao | 42fd74b | 2017-01-20 12:51:11 -0800 | [diff] [blame] | 99 | *error = StringPrintf("failed to attach to thread %d: %s", tid, strerror(errno)); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | // Make sure that the task we attached to is actually part of the pid we're dumping. |
Josh Gao | fe90276 | 2017-02-01 16:31:43 -0800 | [diff] [blame] | 104 | if (!pid_contains_tid(pid_proc_fd, tid)) { |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 105 | if (ptrace(PTRACE_DETACH, tid, 0, 0) != 0) { |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 106 | PLOG(WARNING) << "failed to detach from thread " << tid; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 107 | } |
Josh Gao | fe90276 | 2017-02-01 16:31:43 -0800 | [diff] [blame] | 108 | *error = StringPrintf("thread %d is not in process", tid); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 109 | return false; |
| 110 | } |
Josh Gao | 122479f | 2017-01-22 16:42:32 -0800 | [diff] [blame] | 111 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 112 | return true; |
| 113 | } |
| 114 | |
| 115 | static bool wait_for_stop(pid_t tid, int* received_signal) { |
| 116 | while (true) { |
| 117 | int status; |
| 118 | pid_t result = waitpid(tid, &status, __WALL); |
| 119 | if (result != tid) { |
| 120 | PLOG(ERROR) << "waitpid failed on " << tid << " while detaching"; |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | if (WIFSTOPPED(status)) { |
| 125 | if (status >> 16 == PTRACE_EVENT_STOP) { |
| 126 | *received_signal = 0; |
| 127 | } else { |
| 128 | *received_signal = WSTOPSIG(status); |
| 129 | } |
| 130 | return true; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // Interrupt a process and wait for it to be interrupted. |
| 136 | static bool ptrace_interrupt(pid_t tid, int* received_signal) { |
| 137 | if (ptrace(PTRACE_INTERRUPT, tid, 0, 0) == 0) { |
| 138 | return wait_for_stop(tid, received_signal); |
Josh Gao | 3407d7c | 2017-06-13 17:21:12 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 141 | PLOG(ERROR) << "failed to interrupt " << tid << " to detach"; |
| 142 | return false; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Josh Gao | b0e51e3 | 2017-06-01 12:08:10 -0700 | [diff] [blame] | 145 | static bool activity_manager_notify(pid_t pid, int signal, const std::string& amfd_data) { |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 146 | ATRACE_CALL(); |
Josh Gao | b0e51e3 | 2017-06-01 12:08:10 -0700 | [diff] [blame] | 147 | android::base::unique_fd amfd(socket_local_client( |
| 148 | "/data/system/ndebugsocket", ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM)); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 149 | if (amfd.get() == -1) { |
| 150 | PLOG(ERROR) << "unable to connect to activity manager"; |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | struct timeval tv = { |
| 155 | .tv_sec = 1, |
| 156 | .tv_usec = 0, |
| 157 | }; |
| 158 | if (setsockopt(amfd.get(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) { |
| 159 | PLOG(ERROR) << "failed to set send timeout on activity manager socket"; |
| 160 | return false; |
| 161 | } |
| 162 | tv.tv_sec = 3; // 3 seconds on handshake read |
| 163 | if (setsockopt(amfd.get(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) { |
| 164 | PLOG(ERROR) << "failed to set receive timeout on activity manager socket"; |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | // Activity Manager protocol: binary 32-bit network-byte-order ints for the |
| 169 | // pid and signal number, followed by the raw text of the dump, culminating |
| 170 | // in a zero byte that marks end-of-data. |
| 171 | uint32_t datum = htonl(pid); |
| 172 | if (!android::base::WriteFully(amfd, &datum, 4)) { |
| 173 | PLOG(ERROR) << "AM pid write failed"; |
| 174 | return false; |
| 175 | } |
| 176 | datum = htonl(signal); |
| 177 | if (!android::base::WriteFully(amfd, &datum, 4)) { |
| 178 | PLOG(ERROR) << "AM signal write failed"; |
| 179 | return false; |
| 180 | } |
| 181 | if (!android::base::WriteFully(amfd, amfd_data.c_str(), amfd_data.size() + 1)) { |
| 182 | PLOG(ERROR) << "AM data write failed"; |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | // 3 sec timeout reading the ack; we're fine if the read fails. |
| 187 | char ack; |
| 188 | android::base::ReadFully(amfd, &ack, 1); |
| 189 | return true; |
| 190 | } |
| 191 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 192 | // Globals used by the abort handler. |
| 193 | static pid_t g_target_thread = -1; |
| 194 | static bool g_tombstoned_connected = false; |
| 195 | static unique_fd g_tombstoned_socket; |
| 196 | static unique_fd g_output_fd; |
Josh Gao | 5759411 | 2017-01-22 17:41:15 -0800 | [diff] [blame] | 197 | |
Josh Gao | 38ac45d | 2018-04-27 13:31:47 -0700 | [diff] [blame] | 198 | static void DefuseSignalHandlers() { |
| 199 | // Don't try to dump ourselves. |
| 200 | struct sigaction action = {}; |
| 201 | action.sa_handler = SIG_DFL; |
| 202 | debuggerd_register_handlers(&action); |
| 203 | |
| 204 | sigset_t mask; |
| 205 | sigemptyset(&mask); |
| 206 | if (sigprocmask(SIG_SETMASK, &mask, nullptr) != 0) { |
| 207 | PLOG(FATAL) << "failed to set signal mask"; |
| 208 | } |
| 209 | } |
| 210 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 211 | static void Initialize(char** argv) { |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 212 | android::base::InitLogging(argv); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 213 | android::base::SetAborter([](const char* abort_msg) { |
| 214 | // If we abort before we get an output fd, contact tombstoned to let any |
| 215 | // potential listeners know that we failed. |
| 216 | if (!g_tombstoned_connected) { |
| 217 | if (!tombstoned_connect(g_target_thread, &g_tombstoned_socket, &g_output_fd, |
| 218 | kDebuggerdAnyIntercept)) { |
| 219 | // We failed to connect, not much we can do. |
| 220 | LOG(ERROR) << "failed to connected to tombstoned to report failure"; |
| 221 | _exit(1); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | dprintf(g_output_fd.get(), "crash_dump failed to dump process"); |
| 226 | if (g_target_thread != 1) { |
| 227 | dprintf(g_output_fd.get(), " %d: %s\n", g_target_thread, abort_msg); |
| 228 | } else { |
| 229 | dprintf(g_output_fd.get(), ": %s\n", abort_msg); |
| 230 | } |
| 231 | |
| 232 | _exit(1); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 233 | }); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 234 | } |
Josh Gao | e740250 | 2017-06-01 11:55:25 -0700 | [diff] [blame] | 235 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 236 | static void ParseArgs(int argc, char** argv, pid_t* pseudothread_tid, DebuggerdDumpType* dump_type) { |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 237 | if (argc != 4) { |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 238 | LOG(FATAL) << "wrong number of args: " << argc << " (expected 4)"; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 241 | if (!android::base::ParseInt(argv[1], &g_target_thread, 1, std::numeric_limits<pid_t>::max())) { |
| 242 | LOG(FATAL) << "invalid target tid: " << argv[1]; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 245 | if (!android::base::ParseInt(argv[2], pseudothread_tid, 1, std::numeric_limits<pid_t>::max())) { |
Josh Gao | f6ad585 | 2017-02-15 12:21:11 -0800 | [diff] [blame] | 246 | LOG(FATAL) << "invalid pseudothread tid: " << argv[2]; |
Josh Gao | 2f11a25 | 2017-02-13 14:46:19 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 249 | int dump_type_int; |
| 250 | if (!android::base::ParseInt(argv[3], &dump_type_int, 0, 1)) { |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 251 | LOG(FATAL) << "invalid requested dump type: " << argv[3]; |
| 252 | } |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 253 | *dump_type = static_cast<DebuggerdDumpType>(dump_type_int); |
| 254 | } |
Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 255 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 256 | static void ReadCrashInfo(unique_fd& fd, siginfo_t* siginfo, |
Peter Collingbourne | 843f7e6 | 2020-02-28 19:07:33 -0800 | [diff] [blame^] | 257 | std::unique_ptr<unwindstack::Regs>* regs, ProcessInfo* process_info) { |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 258 | std::aligned_storage<sizeof(CrashInfo) + 1, alignof(CrashInfo)>::type buf; |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 259 | CrashInfo* crash_info = reinterpret_cast<CrashInfo*>(&buf); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 260 | ssize_t rc = TEMP_FAILURE_RETRY(read(fd.get(), &buf, sizeof(buf))); |
| 261 | if (rc == -1) { |
| 262 | PLOG(FATAL) << "failed to read target ucontext"; |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 263 | } else { |
| 264 | ssize_t expected_size = 0; |
| 265 | switch (crash_info->header.version) { |
| 266 | case 1: |
| 267 | expected_size = sizeof(CrashInfoHeader) + sizeof(CrashInfoDataV1); |
| 268 | break; |
| 269 | |
| 270 | case 2: |
| 271 | expected_size = sizeof(CrashInfoHeader) + sizeof(CrashInfoDataV2); |
| 272 | break; |
| 273 | |
Mitch Phillips | e0b4bb1 | 2020-02-14 14:54:31 -0800 | [diff] [blame] | 274 | case 3: |
| 275 | expected_size = sizeof(CrashInfoHeader) + sizeof(CrashInfoDataV3); |
| 276 | break; |
| 277 | |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 278 | default: |
| 279 | LOG(FATAL) << "unexpected CrashInfo version: " << crash_info->header.version; |
| 280 | break; |
| 281 | }; |
| 282 | |
| 283 | if (rc != expected_size) { |
| 284 | LOG(FATAL) << "read " << rc << " bytes when reading target crash information, expected " |
| 285 | << expected_size; |
| 286 | } |
Josh Gao | c7fe060 | 2017-03-13 14:13:29 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 289 | switch (crash_info->header.version) { |
Mitch Phillips | e0b4bb1 | 2020-02-14 14:54:31 -0800 | [diff] [blame] | 290 | case 3: |
Peter Collingbourne | 843f7e6 | 2020-02-28 19:07:33 -0800 | [diff] [blame^] | 291 | process_info->gwp_asan_state = crash_info->data.v3.gwp_asan_state; |
| 292 | process_info->gwp_asan_metadata = crash_info->data.v3.gwp_asan_metadata; |
Mitch Phillips | e0b4bb1 | 2020-02-14 14:54:31 -0800 | [diff] [blame] | 293 | FALLTHROUGH_INTENDED; |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 294 | case 2: |
Peter Collingbourne | 843f7e6 | 2020-02-28 19:07:33 -0800 | [diff] [blame^] | 295 | process_info->fdsan_table_address = crash_info->data.v2.fdsan_table_address; |
Josh Gao | 8d44b14 | 2018-09-18 13:22:22 -0700 | [diff] [blame] | 296 | FALLTHROUGH_INTENDED; |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 297 | case 1: |
Peter Collingbourne | 843f7e6 | 2020-02-28 19:07:33 -0800 | [diff] [blame^] | 298 | process_info->abort_msg_address = crash_info->data.v1.abort_msg_address; |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 299 | *siginfo = crash_info->data.v1.siginfo; |
Christopher Ferris | 60eb197 | 2019-01-15 15:18:43 -0800 | [diff] [blame] | 300 | regs->reset(unwindstack::Regs::CreateFromUcontext(unwindstack::Regs::CurrentArch(), |
| 301 | &crash_info->data.v1.ucontext)); |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 302 | break; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 303 | |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 304 | default: |
| 305 | __builtin_unreachable(); |
| 306 | } |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // Wait for a process to clone and return the child's pid. |
| 310 | // Note: this leaves the parent in PTRACE_EVENT_STOP. |
| 311 | static pid_t wait_for_clone(pid_t pid, bool resume_child) { |
| 312 | int status; |
| 313 | pid_t result = TEMP_FAILURE_RETRY(waitpid(pid, &status, __WALL)); |
| 314 | if (result == -1) { |
| 315 | PLOG(FATAL) << "failed to waitpid"; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 318 | if (WIFEXITED(status)) { |
| 319 | LOG(FATAL) << "traced process exited with status " << WEXITSTATUS(status); |
| 320 | } else if (WIFSIGNALED(status)) { |
| 321 | LOG(FATAL) << "traced process exited with signal " << WTERMSIG(status); |
| 322 | } else if (!WIFSTOPPED(status)) { |
| 323 | LOG(FATAL) << "process didn't stop? (status = " << status << ")"; |
| 324 | } |
| 325 | |
| 326 | if (status >> 8 != (SIGTRAP | (PTRACE_EVENT_CLONE << 8))) { |
| 327 | LOG(FATAL) << "process didn't stop due to PTRACE_O_TRACECLONE (status = " << status << ")"; |
| 328 | } |
| 329 | |
| 330 | pid_t child; |
| 331 | if (ptrace(PTRACE_GETEVENTMSG, pid, 0, &child) != 0) { |
| 332 | PLOG(FATAL) << "failed to get child pid via PTRACE_GETEVENTMSG"; |
| 333 | } |
| 334 | |
| 335 | int stop_signal; |
| 336 | if (!wait_for_stop(child, &stop_signal)) { |
| 337 | PLOG(FATAL) << "failed to waitpid on child"; |
| 338 | } |
| 339 | |
| 340 | CHECK_EQ(0, stop_signal); |
| 341 | |
| 342 | if (resume_child) { |
| 343 | if (ptrace(PTRACE_CONT, child, 0, 0) != 0) { |
| 344 | PLOG(FATAL) << "failed to resume child (pid = " << child << ")"; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | return child; |
| 349 | } |
| 350 | |
| 351 | static pid_t wait_for_vm_process(pid_t pseudothread_tid) { |
| 352 | // The pseudothread will double-fork, we want its grandchild. |
| 353 | pid_t intermediate = wait_for_clone(pseudothread_tid, true); |
| 354 | pid_t vm_pid = wait_for_clone(intermediate, false); |
| 355 | if (ptrace(PTRACE_DETACH, intermediate, 0, 0) != 0) { |
| 356 | PLOG(FATAL) << "failed to detach from intermediate vm process"; |
| 357 | } |
| 358 | |
| 359 | return vm_pid; |
| 360 | } |
| 361 | |
Jinguang Dong | 8ac2f27 | 2018-11-24 17:12:33 +0800 | [diff] [blame] | 362 | static void InstallSigPipeHandler() { |
| 363 | struct sigaction action = {}; |
| 364 | action.sa_handler = SIG_IGN; |
| 365 | action.sa_flags = SA_RESTART; |
| 366 | sigaction(SIGPIPE, &action, nullptr); |
| 367 | } |
| 368 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 369 | int main(int argc, char** argv) { |
Josh Gao | 38ac45d | 2018-04-27 13:31:47 -0700 | [diff] [blame] | 370 | DefuseSignalHandlers(); |
Jinguang Dong | 8ac2f27 | 2018-11-24 17:12:33 +0800 | [diff] [blame] | 371 | InstallSigPipeHandler(); |
Josh Gao | 38ac45d | 2018-04-27 13:31:47 -0700 | [diff] [blame] | 372 | |
Josh Gao | 18cb681 | 2019-04-16 13:17:08 -0700 | [diff] [blame] | 373 | // There appears to be a bug in the kernel where our death causes SIGHUP to |
| 374 | // be sent to our process group if we exit while it has stopped jobs (e.g. |
| 375 | // because of wait_for_gdb). Use setsid to create a new process group to |
| 376 | // avoid hitting this. |
| 377 | setsid(); |
| 378 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 379 | atrace_begin(ATRACE_TAG, "before reparent"); |
| 380 | pid_t target_process = getppid(); |
| 381 | |
| 382 | // Open /proc/`getppid()` before we daemonize. |
| 383 | std::string target_proc_path = "/proc/" + std::to_string(target_process); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 384 | int target_proc_fd = open(target_proc_path.c_str(), O_DIRECTORY | O_RDONLY); |
| 385 | if (target_proc_fd == -1) { |
| 386 | PLOG(FATAL) << "failed to open " << target_proc_path; |
| 387 | } |
| 388 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 389 | // Make sure getppid() hasn't changed. |
| 390 | if (getppid() != target_process) { |
| 391 | LOG(FATAL) << "parent died"; |
Josh Gao | 2a18b82 | 2017-02-16 19:17:28 -0800 | [diff] [blame] | 392 | } |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 393 | atrace_end(ATRACE_TAG); |
| 394 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 395 | // Reparent ourselves to init, so that the signal handler can waitpid on the |
| 396 | // original process to avoid leaving a zombie for non-fatal dumps. |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 397 | // Move the input/output pipes off of stdout/stderr, out of paranoia. |
| 398 | unique_fd output_pipe(dup(STDOUT_FILENO)); |
| 399 | unique_fd input_pipe(dup(STDIN_FILENO)); |
| 400 | |
| 401 | unique_fd fork_exit_read, fork_exit_write; |
| 402 | if (!Pipe(&fork_exit_read, &fork_exit_write)) { |
| 403 | PLOG(FATAL) << "failed to create pipe"; |
| 404 | } |
| 405 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 406 | pid_t forkpid = fork(); |
| 407 | if (forkpid == -1) { |
| 408 | PLOG(FATAL) << "fork failed"; |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 409 | } else if (forkpid == 0) { |
| 410 | fork_exit_read.reset(); |
| 411 | } else { |
| 412 | // We need the pseudothread to live until we get around to verifying the vm pid against it. |
| 413 | // The last thing it does is block on a waitpid on us, so wait until our child tells us to die. |
| 414 | fork_exit_write.reset(); |
| 415 | char buf; |
| 416 | TEMP_FAILURE_RETRY(read(fork_exit_read.get(), &buf, sizeof(buf))); |
| 417 | _exit(0); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 420 | ATRACE_NAME("after reparent"); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 421 | pid_t pseudothread_tid; |
| 422 | DebuggerdDumpType dump_type; |
Peter Collingbourne | 843f7e6 | 2020-02-28 19:07:33 -0800 | [diff] [blame^] | 423 | ProcessInfo process_info; |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 424 | |
| 425 | Initialize(argv); |
| 426 | ParseArgs(argc, argv, &pseudothread_tid, &dump_type); |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 427 | |
Josh Gao | 7c6e313 | 2017-01-22 17:59:02 -0800 | [diff] [blame] | 428 | // Die if we take too long. |
Andreas Gampe | b02851a | 2017-06-22 19:45:53 -0700 | [diff] [blame] | 429 | // |
| 430 | // Note: processes with many threads and minidebug-info can take a bit to |
| 431 | // unwind, do not make this too small. b/62828735 |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 432 | alarm(30); |
Josh Gao | 7c6e313 | 2017-01-22 17:59:02 -0800 | [diff] [blame] | 433 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 434 | // Get the process name (aka cmdline). |
| 435 | std::string process_name = get_process_name(g_target_thread); |
Josh Gao | 2f11a25 | 2017-02-13 14:46:19 -0800 | [diff] [blame] | 436 | |
| 437 | // Collect the list of open files. |
| 438 | OpenFilesList open_files; |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 439 | { |
| 440 | ATRACE_NAME("open files"); |
Josh Gao | ce841d9 | 2018-08-06 18:26:42 -0700 | [diff] [blame] | 441 | populate_open_files_list(&open_files, g_target_thread); |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 442 | } |
Josh Gao | 2f11a25 | 2017-02-13 14:46:19 -0800 | [diff] [blame] | 443 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 444 | // In order to reduce the duration that we pause the process for, we ptrace |
| 445 | // the threads, fetch their registers and associated information, and then |
| 446 | // fork a separate process as a snapshot of the process's address space. |
| 447 | std::set<pid_t> threads; |
| 448 | if (!android::procinfo::GetProcessTids(g_target_thread, &threads)) { |
| 449 | PLOG(FATAL) << "failed to get process threads"; |
| 450 | } |
Josh Gao | 3407d7c | 2017-06-13 17:21:12 +0000 | [diff] [blame] | 451 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 452 | std::map<pid_t, ThreadInfo> thread_info; |
| 453 | siginfo_t siginfo; |
| 454 | std::string error; |
| 455 | |
| 456 | { |
| 457 | ATRACE_NAME("ptrace"); |
| 458 | for (pid_t thread : threads) { |
| 459 | // Trace the pseudothread separately, so we can use different options. |
| 460 | if (thread == pseudothread_tid) { |
| 461 | continue; |
| 462 | } |
| 463 | |
| 464 | if (!ptrace_seize_thread(target_proc_fd, thread, &error)) { |
| 465 | bool fatal = thread == g_target_thread; |
| 466 | LOG(fatal ? FATAL : WARNING) << error; |
| 467 | } |
| 468 | |
| 469 | ThreadInfo info; |
| 470 | info.pid = target_process; |
| 471 | info.tid = thread; |
Josh Gao | 5df504c | 2019-05-09 12:48:17 -0700 | [diff] [blame] | 472 | info.uid = getuid(); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 473 | info.process_name = process_name; |
| 474 | info.thread_name = get_thread_name(thread); |
| 475 | |
| 476 | if (!ptrace_interrupt(thread, &info.signo)) { |
| 477 | PLOG(WARNING) << "failed to ptrace interrupt thread " << thread; |
| 478 | ptrace(PTRACE_DETACH, thread, 0, 0); |
| 479 | continue; |
| 480 | } |
| 481 | |
| 482 | if (thread == g_target_thread) { |
| 483 | // Read the thread's registers along with the rest of the crash info out of the pipe. |
Peter Collingbourne | 843f7e6 | 2020-02-28 19:07:33 -0800 | [diff] [blame^] | 484 | ReadCrashInfo(input_pipe, &siginfo, &info.registers, &process_info); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 485 | info.siginfo = &siginfo; |
| 486 | info.signo = info.siginfo->si_signo; |
| 487 | } else { |
Christopher Ferris | 60eb197 | 2019-01-15 15:18:43 -0800 | [diff] [blame] | 488 | info.registers.reset(unwindstack::Regs::RemoteGet(thread)); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 489 | if (!info.registers) { |
| 490 | PLOG(WARNING) << "failed to fetch registers for thread " << thread; |
| 491 | ptrace(PTRACE_DETACH, thread, 0, 0); |
| 492 | continue; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | thread_info[thread] = std::move(info); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // Trace the pseudothread with PTRACE_O_TRACECLONE and tell it to fork. |
| 501 | if (!ptrace_seize_thread(target_proc_fd, pseudothread_tid, &error, PTRACE_O_TRACECLONE)) { |
| 502 | LOG(FATAL) << "failed to seize pseudothread: " << error; |
| 503 | } |
| 504 | |
| 505 | if (TEMP_FAILURE_RETRY(write(output_pipe.get(), "\1", 1)) != 1) { |
| 506 | PLOG(FATAL) << "failed to write to pseudothread"; |
| 507 | } |
| 508 | |
| 509 | pid_t vm_pid = wait_for_vm_process(pseudothread_tid); |
| 510 | if (ptrace(PTRACE_DETACH, pseudothread_tid, 0, 0) != 0) { |
| 511 | PLOG(FATAL) << "failed to detach from pseudothread"; |
| 512 | } |
| 513 | |
| 514 | // The pseudothread can die now. |
| 515 | fork_exit_write.reset(); |
| 516 | |
| 517 | // Defer the message until later, for readability. |
| 518 | bool wait_for_gdb = android::base::GetBoolProperty("debug.debuggerd.wait_for_gdb", false); |
Josh Gao | a48b41b | 2019-12-13 14:11:04 -0800 | [diff] [blame] | 519 | if (siginfo.si_signo == BIONIC_SIGNAL_DEBUGGER) { |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 520 | wait_for_gdb = false; |
| 521 | } |
| 522 | |
| 523 | // Detach from all of our attached threads before resuming. |
| 524 | for (const auto& [tid, thread] : thread_info) { |
Josh Gao | a48b41b | 2019-12-13 14:11:04 -0800 | [diff] [blame] | 525 | int resume_signal = thread.signo == BIONIC_SIGNAL_DEBUGGER ? 0 : thread.signo; |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 526 | if (wait_for_gdb) { |
| 527 | resume_signal = 0; |
| 528 | if (tgkill(target_process, tid, SIGSTOP) != 0) { |
| 529 | PLOG(WARNING) << "failed to send SIGSTOP to " << tid; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | LOG(DEBUG) << "detaching from thread " << tid; |
| 534 | if (ptrace(PTRACE_DETACH, tid, 0, resume_signal) != 0) { |
| 535 | PLOG(ERROR) << "failed to detach from thread " << tid; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | // Drop our capabilities now that we've fetched all of the information we need. |
Josh Gao | 2f11a25 | 2017-02-13 14:46:19 -0800 | [diff] [blame] | 540 | drop_capabilities(); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 541 | |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 542 | { |
| 543 | ATRACE_NAME("tombstoned_connect"); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 544 | LOG(INFO) << "obtaining output fd from tombstoned, type: " << dump_type; |
| 545 | g_tombstoned_connected = |
| 546 | tombstoned_connect(g_target_thread, &g_tombstoned_socket, &g_output_fd, dump_type); |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 547 | } |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 548 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 549 | if (g_tombstoned_connected) { |
| 550 | if (TEMP_FAILURE_RETRY(dup2(g_output_fd.get(), STDOUT_FILENO)) == -1) { |
| 551 | PLOG(ERROR) << "failed to dup2 output fd (" << g_output_fd.get() << ") to STDOUT_FILENO"; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 552 | } |
| 553 | } else { |
| 554 | unique_fd devnull(TEMP_FAILURE_RETRY(open("/dev/null", O_RDWR))); |
| 555 | TEMP_FAILURE_RETRY(dup2(devnull.get(), STDOUT_FILENO)); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 556 | g_output_fd = std::move(devnull); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 559 | LOG(INFO) << "performing dump of process " << target_process |
| 560 | << " (target tid = " << g_target_thread << ")"; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 561 | |
| 562 | int signo = siginfo.si_signo; |
Josh Gao | a48b41b | 2019-12-13 14:11:04 -0800 | [diff] [blame] | 563 | bool fatal_signal = signo != BIONIC_SIGNAL_DEBUGGER; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 564 | bool backtrace = false; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 565 | |
Josh Gao | a48b41b | 2019-12-13 14:11:04 -0800 | [diff] [blame] | 566 | // si_value is special when used with BIONIC_SIGNAL_DEBUGGER. |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 567 | // 0: dump tombstone |
| 568 | // 1: dump backtrace |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 569 | if (!fatal_signal) { |
| 570 | int si_val = siginfo.si_value.sival_int; |
| 571 | if (si_val == 0) { |
| 572 | backtrace = false; |
| 573 | } else if (si_val == 1) { |
| 574 | backtrace = true; |
| 575 | } else { |
| 576 | LOG(WARNING) << "unknown si_value value " << si_val; |
| 577 | } |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 580 | // TODO: Use seccomp to lock ourselves down. |
Christopher Ferris | 60eb197 | 2019-01-15 15:18:43 -0800 | [diff] [blame] | 581 | unwindstack::UnwinderFromPid unwinder(256, vm_pid); |
David Srbecky | b9cc4fb | 2019-04-05 18:23:32 +0000 | [diff] [blame] | 582 | if (!unwinder.Init(unwindstack::Regs::CurrentArch())) { |
Christopher Ferris | 60eb197 | 2019-01-15 15:18:43 -0800 | [diff] [blame] | 583 | LOG(FATAL) << "Failed to init unwinder object."; |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 584 | } |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 585 | |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 586 | std::string amfd_data; |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 587 | if (backtrace) { |
Josh Gao | 8bb0390 | 2017-05-30 15:31:02 -0700 | [diff] [blame] | 588 | ATRACE_NAME("dump_backtrace"); |
Christopher Ferris | 60eb197 | 2019-01-15 15:18:43 -0800 | [diff] [blame] | 589 | dump_backtrace(std::move(g_output_fd), &unwinder, thread_info, g_target_thread); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 590 | } else { |
Josh Gao | ce841d9 | 2018-08-06 18:26:42 -0700 | [diff] [blame] | 591 | { |
| 592 | ATRACE_NAME("fdsan table dump"); |
Peter Collingbourne | 843f7e6 | 2020-02-28 19:07:33 -0800 | [diff] [blame^] | 593 | populate_fdsan_table(&open_files, unwinder.GetProcessMemory(), |
| 594 | process_info.fdsan_table_address); |
Josh Gao | ce841d9 | 2018-08-06 18:26:42 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | { |
| 598 | ATRACE_NAME("engrave_tombstone"); |
Peter Collingbourne | 843f7e6 | 2020-02-28 19:07:33 -0800 | [diff] [blame^] | 599 | engrave_tombstone(std::move(g_output_fd), &unwinder, thread_info, g_target_thread, process_info, |
| 600 | &open_files, &amfd_data); |
Josh Gao | ce841d9 | 2018-08-06 18:26:42 -0700 | [diff] [blame] | 601 | } |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 604 | if (fatal_signal) { |
| 605 | // Don't try to notify ActivityManager if it just crashed, or we might hang until timeout. |
| 606 | if (thread_info[target_process].thread_name != "system_server") { |
| 607 | activity_manager_notify(target_process, signo, amfd_data); |
Josh Gao | 7c6e313 | 2017-01-22 17:59:02 -0800 | [diff] [blame] | 608 | } |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | if (wait_for_gdb) { |
Josh Gao | 7c6e313 | 2017-01-22 17:59:02 -0800 | [diff] [blame] | 612 | // Use ALOGI to line up with output from engrave_tombstone. |
| 613 | ALOGI( |
dimitry | 6429e20 | 2017-09-12 10:46:20 +0200 | [diff] [blame] | 614 | "***********************************************************\n" |
| 615 | "* Process %d has been suspended while crashing.\n" |
| 616 | "* To attach gdbserver and start gdb, run this on the host:\n" |
| 617 | "*\n" |
| 618 | "* gdbclient.py -p %d\n" |
| 619 | "*\n" |
| 620 | "***********************************************************", |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 621 | target_process, target_process); |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | // Close stdout before we notify tombstoned of completion. |
| 625 | close(STDOUT_FILENO); |
Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 626 | if (g_tombstoned_connected && !tombstoned_notify_completion(g_tombstoned_socket.get())) { |
Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 627 | LOG(ERROR) << "failed to notify tombstoned of completion"; |
| 628 | } |
| 629 | |
| 630 | return 0; |
| 631 | } |