system/core
修订版 | 855333f346ec98423a96efa7032174488114c2f7 (tree) |
---|---|
时间 | 2017-06-13 14:35:09 |
作者 | TreeHugger Robot <treehugger-gerrit@goog...> |
Commiter | Android (Google) Code Review |
Merge "tombstoned: log where we're writing the tombstone." into oc-dev
@@ -61,6 +61,7 @@ struct Crash { | ||
61 | 61 | unique_fd crash_fd; |
62 | 62 | pid_t crash_pid; |
63 | 63 | event* crash_event = nullptr; |
64 | + std::string crash_path; | |
64 | 65 | }; |
65 | 66 | |
66 | 67 | static constexpr char kTombstoneDirectory[] = "/data/tombstones/"; |
@@ -104,32 +105,31 @@ static void find_oldest_tombstone() { | ||
104 | 105 | next_tombstone = oldest_tombstone; |
105 | 106 | } |
106 | 107 | |
107 | -static unique_fd get_tombstone_fd() { | |
108 | +static std::pair<unique_fd, std::string> get_tombstone() { | |
108 | 109 | // If kMaxConcurrentDumps is greater than 1, then theoretically the same |
109 | 110 | // filename could be handed out to multiple processes. Unlink and create the |
110 | 111 | // file, instead of using O_TRUNC, to avoid two processes interleaving their |
111 | 112 | // output. |
112 | 113 | unique_fd result; |
113 | - char buf[PATH_MAX]; | |
114 | - snprintf(buf, sizeof(buf), "tombstone_%02d", next_tombstone); | |
115 | - if (unlinkat(tombstone_directory_fd, buf, 0) != 0 && errno != ENOENT) { | |
116 | - PLOG(FATAL) << "failed to unlink tombstone at " << kTombstoneDirectory << buf; | |
114 | + std::string file_name = StringPrintf("tombstone_%02d", next_tombstone); | |
115 | + if (unlinkat(tombstone_directory_fd, file_name.c_str(), 0) != 0 && errno != ENOENT) { | |
116 | + PLOG(FATAL) << "failed to unlink tombstone at " << kTombstoneDirectory << "/" << file_name; | |
117 | 117 | } |
118 | 118 | |
119 | - result.reset( | |
120 | - openat(tombstone_directory_fd, buf, O_CREAT | O_EXCL | O_WRONLY | O_APPEND | O_CLOEXEC, 0640)); | |
119 | + result.reset(openat(tombstone_directory_fd, file_name.c_str(), | |
120 | + O_CREAT | O_EXCL | O_WRONLY | O_APPEND | O_CLOEXEC, 0640)); | |
121 | 121 | if (result == -1) { |
122 | - PLOG(FATAL) << "failed to create tombstone at " << kTombstoneDirectory << buf; | |
122 | + PLOG(FATAL) << "failed to create tombstone at " << kTombstoneDirectory << "/" << file_name; | |
123 | 123 | } |
124 | 124 | |
125 | 125 | next_tombstone = (next_tombstone + 1) % kTombstoneCount; |
126 | - return result; | |
126 | + return {std::move(result), std::string(kTombstoneDirectory) + "/" + file_name}; | |
127 | 127 | } |
128 | 128 | |
129 | 129 | static void perform_request(Crash* crash) { |
130 | 130 | unique_fd output_fd; |
131 | 131 | if (!intercept_manager->GetIntercept(crash->crash_pid, &output_fd)) { |
132 | - output_fd = get_tombstone_fd(); | |
132 | + std::tie(output_fd, crash->crash_path) = get_tombstone(); | |
133 | 133 | } |
134 | 134 | |
135 | 135 | TombstonedCrashPacket response = { |
@@ -251,6 +251,10 @@ static void crash_completed_cb(evutil_socket_t sockfd, short ev, void* arg) { | ||
251 | 251 | goto fail; |
252 | 252 | } |
253 | 253 | |
254 | + if (!crash->crash_path.empty()) { | |
255 | + LOG(ERROR) << "Tombstone written to: " << crash->crash_path; | |
256 | + } | |
257 | + | |
254 | 258 | fail: |
255 | 259 | delete crash; |
256 | 260 |