Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 1 | /* |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 2 | * Copyright (C) 2006-2017 The Android Open Source Project |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 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 | */ |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 16 | |
Mark Salyzyn | 12af965 | 2013-12-13 11:10:11 -0800 | [diff] [blame] | 17 | #include <ctype.h> |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 18 | #include <dirent.h> |
Mark Salyzyn | 12af965 | 2013-12-13 11:10:11 -0800 | [diff] [blame] | 19 | #include <errno.h> |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 20 | #include <error.h> |
Mark Salyzyn | 12af965 | 2013-12-13 11:10:11 -0800 | [diff] [blame] | 21 | #include <fcntl.h> |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 22 | #include <getopt.h> |
Aristidis Papaioannou | f7cc662 | 2014-10-16 22:19:55 -0700 | [diff] [blame] | 23 | #include <math.h> |
Mark Salyzyn | 38fc72c | 2015-06-02 07:57:16 -0700 | [diff] [blame] | 24 | #include <sched.h> |
Mark Salyzyn | 38fc72c | 2015-06-02 07:57:16 -0700 | [diff] [blame] | 25 | #include <stdarg.h> |
Mark Salyzyn | 12af965 | 2013-12-13 11:10:11 -0800 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
Mark Salyzyn | 12af965 | 2013-12-13 11:10:11 -0800 | [diff] [blame] | 28 | #include <string.h> |
Traian Schiau | 9f97860 | 2015-04-10 15:51:39 +0300 | [diff] [blame] | 29 | #include <sys/cdefs.h> |
Jaegeuk Kim | 64352f2 | 2019-07-04 18:09:38 -0700 | [diff] [blame] | 30 | #include <sys/ioctl.h> |
Riley Andrews | 53fe1b0 | 2015-06-08 23:36:34 -0700 | [diff] [blame] | 31 | #include <sys/resource.h> |
Mark Salyzyn | 12af965 | 2013-12-13 11:10:11 -0800 | [diff] [blame] | 32 | #include <sys/stat.h> |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 33 | #include <sys/types.h> |
Mark Salyzyn | 38fc72c | 2015-06-02 07:57:16 -0700 | [diff] [blame] | 34 | #include <time.h> |
| 35 | #include <unistd.h> |
Mark Salyzyn | 12af965 | 2013-12-13 11:10:11 -0800 | [diff] [blame] | 36 | |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 37 | #include <memory> |
Elliott Hughes | accc101 | 2019-08-08 08:53:59 -0700 | [diff] [blame] | 38 | #include <regex> |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 39 | #include <string> |
Wei Wang | 8b58417 | 2018-09-05 11:05:57 -0700 | [diff] [blame] | 40 | #include <utility> |
Mark Salyzyn | a511fef | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 41 | #include <vector> |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 42 | |
Elliott Hughes | 0a7adf0 | 2015-12-04 22:00:26 -0800 | [diff] [blame] | 43 | #include <android-base/file.h> |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 44 | #include <android-base/macros.h> |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 45 | #include <android-base/parseint.h> |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 46 | #include <android-base/properties.h> |
Mark Salyzyn | 2a1233e | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 47 | #include <android-base/stringprintf.h> |
Elliott Hughes | 0a7adf0 | 2015-12-04 22:00:26 -0800 | [diff] [blame] | 48 | #include <android-base/strings.h> |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 49 | #include <android-base/unique_fd.h> |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 50 | #include <android/log.h> |
Mark Salyzyn | 38fc72c | 2015-06-02 07:57:16 -0700 | [diff] [blame] | 51 | #include <log/event_tag_map.h> |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 52 | #include <log/log_id.h> |
Colin Cross | e355ded | 2013-07-23 16:59:20 -0700 | [diff] [blame] | 53 | #include <log/logprint.h> |
Mark Salyzyn | 8b8bfd2 | 2016-09-30 13:30:33 -0700 | [diff] [blame] | 54 | #include <private/android_logger.h> |
Suren Baghdasaryan | 3e671a5 | 2019-01-25 05:32:52 +0000 | [diff] [blame] | 55 | #include <processgroup/sched_policy.h> |
Elliott Hughes | 411f863 | 2016-02-17 11:58:01 -0800 | [diff] [blame] | 56 | #include <system/thread_defs.h> |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 57 | |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 58 | #define DEFAULT_MAX_ROTATED_LOGS 4 |
| 59 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 60 | using android::base::Join; |
| 61 | using android::base::ParseByteCount; |
| 62 | using android::base::ParseUint; |
| 63 | using android::base::Split; |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 64 | using android::base::StringPrintf; |
| 65 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 66 | class Logcat { |
| 67 | public: |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 68 | int Run(int argc, char** argv); |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 69 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 70 | private: |
| 71 | void RotateLogs(); |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 72 | void ProcessBuffer(struct log_msg* buf); |
| 73 | void PrintDividers(log_id_t log_id, bool print_dividers); |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 74 | void SetupOutputAndSchedulingPolicy(bool blocking); |
| 75 | int SetLogFormat(const char* format_string); |
| 76 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 77 | // Used for all options |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 78 | android::base::unique_fd output_fd_{dup(STDOUT_FILENO)}; |
| 79 | std::unique_ptr<AndroidLogFormat, decltype(&android_log_format_free)> logformat_{ |
| 80 | android_log_format_new(), &android_log_format_free}; |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 81 | |
| 82 | // For logging to a file and log rotation |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 83 | const char* output_file_name_ = nullptr; |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 84 | size_t log_rotate_size_kb_ = 0; // 0 means "no log rotation" |
| 85 | size_t max_rotated_logs_ = DEFAULT_MAX_ROTATED_LOGS; // 0 means "unbounded" |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 86 | size_t out_byte_count_ = 0; |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 87 | |
| 88 | // For binary log buffers |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 89 | int print_binary_ = 0; |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 90 | std::unique_ptr<EventTagMap, decltype(&android_closeEventTagMap)> event_tag_map_{ |
| 91 | nullptr, &android_closeEventTagMap}; |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 92 | bool has_opened_event_tag_map_ = false; |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 93 | |
| 94 | // For the related --regex, --max-count, --print |
| 95 | std::unique_ptr<std::regex> regex_; |
| 96 | size_t max_count_ = 0; // 0 means "infinite" |
| 97 | size_t print_count_ = 0; |
| 98 | bool print_it_anyways_ = false; |
| 99 | |
| 100 | // For PrintDividers() |
| 101 | log_id_t last_printed_id_ = LOG_ID_MAX; |
| 102 | bool printed_start_[LOG_ID_MAX] = {}; |
| 103 | |
| 104 | bool debug_ = false; |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Jaegeuk Kim | 64352f2 | 2019-07-04 18:09:38 -0700 | [diff] [blame] | 107 | #ifndef F2FS_IOC_SET_PIN_FILE |
| 108 | #define F2FS_IOCTL_MAGIC 0xf5 |
| 109 | #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) |
| 110 | #endif |
| 111 | |
| 112 | static int openLogFile(const char* pathname, size_t sizeKB) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 113 | int fd = open(pathname, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, S_IRUSR | S_IWUSR); |
Jaegeuk Kim | 64352f2 | 2019-07-04 18:09:38 -0700 | [diff] [blame] | 114 | if (fd < 0) { |
| 115 | return fd; |
| 116 | } |
| 117 | |
| 118 | // no need to check errors |
| 119 | __u32 set = 1; |
| 120 | ioctl(fd, F2FS_IOC_SET_PIN_FILE, &set); |
| 121 | fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, (sizeKB << 10)); |
| 122 | return fd; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 123 | } |
| 124 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 125 | void Logcat::RotateLogs() { |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 126 | // Can't rotate logs if we're not outputting to a file |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 127 | if (!output_file_name_) return; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 128 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 129 | output_fd_.reset(); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 130 | |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 131 | // Compute the maximum number of digits needed to count up to |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 132 | // maxRotatedLogs in decimal. eg: |
| 133 | // maxRotatedLogs == 30 |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 134 | // -> log10(30) == 1.477 |
| 135 | // -> maxRotationCountDigits == 2 |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 136 | int max_rotation_count_digits = |
| 137 | max_rotated_logs_ > 0 ? (int)(floor(log10(max_rotated_logs_) + 1)) : 0; |
Aristidis Papaioannou | f7cc662 | 2014-10-16 22:19:55 -0700 | [diff] [blame] | 138 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 139 | for (int i = max_rotated_logs_; i > 0; i--) { |
| 140 | std::string file1 = |
| 141 | StringPrintf("%s.%.*d", output_file_name_, max_rotation_count_digits, i); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 142 | |
Mark Salyzyn | 2a1233e | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 143 | std::string file0; |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 144 | if (!(i - 1)) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 145 | file0 = output_file_name_; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 146 | } else { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 147 | file0 = StringPrintf("%s.%.*d", output_file_name_, max_rotation_count_digits, i - 1); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 150 | if (!file0.length() || !file1.length()) { |
Traian Schiau | 9f97860 | 2015-04-10 15:51:39 +0300 | [diff] [blame] | 151 | perror("while rotating log files"); |
| 152 | break; |
| 153 | } |
| 154 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 155 | int err = rename(file0.c_str(), file1.c_str()); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 156 | |
| 157 | if (err < 0 && errno != ENOENT) { |
| 158 | perror("while rotating log files"); |
| 159 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 162 | output_fd_.reset(openLogFile(output_file_name_, log_rotate_size_kb_)); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 163 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 164 | if (!output_fd_.ok()) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 165 | error(EXIT_FAILURE, errno, "Couldn't open output file"); |
Mark Salyzyn | 7e0bbab | 2017-02-17 13:15:51 -0800 | [diff] [blame] | 166 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 167 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 168 | out_byte_count_ = 0; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 171 | void Logcat::ProcessBuffer(struct log_msg* buf) { |
Mathias Agopian | b9218fb | 2010-03-17 16:10:26 -0700 | [diff] [blame] | 172 | int bytesWritten = 0; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 173 | int err; |
| 174 | AndroidLogEntry entry; |
| 175 | char binaryMsgBuf[1024]; |
| 176 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 177 | bool is_binary = |
| 178 | buf->id() == LOG_ID_EVENTS || buf->id() == LOG_ID_STATS || buf->id() == LOG_ID_SECURITY; |
| 179 | |
| 180 | if (is_binary) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 181 | if (!event_tag_map_ && !has_opened_event_tag_map_) { |
| 182 | event_tag_map_.reset(android_openEventTagMap(nullptr)); |
| 183 | has_opened_event_tag_map_ = true; |
Mark Salyzyn | 784d64f | 2015-02-26 14:33:35 -0800 | [diff] [blame] | 184 | } |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 185 | err = android_log_processBinaryLogBuffer(&buf->entry, &entry, event_tag_map_.get(), |
Tom Cherry | 47856dd | 2019-10-15 16:53:11 -0700 | [diff] [blame] | 186 | binaryMsgBuf, sizeof(binaryMsgBuf)); |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 187 | // printf(">>> pri=%d len=%d msg='%s'\n", |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 188 | // entry.priority, entry.messageLen, entry.message); |
| 189 | } else { |
Tom Cherry | 47856dd | 2019-10-15 16:53:11 -0700 | [diff] [blame] | 190 | err = android_log_processLogBuffer(&buf->entry, &entry); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 191 | } |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 192 | if (err < 0 && !debug_) return; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 193 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 194 | if (android_log_shouldPrintLine(logformat_.get(), std::string(entry.tag, entry.tagLen).c_str(), |
| 195 | entry.priority)) { |
| 196 | bool match = !regex_ || |
| 197 | std::regex_search(entry.message, entry.message + entry.messageLen, *regex_); |
Joe Onorato | 400da4a | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 198 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 199 | print_count_ += match; |
| 200 | if (match || print_it_anyways_) { |
| 201 | bytesWritten = android_log_printLogLine(logformat_.get(), output_fd_.get(), &entry); |
Casey Dahlin | ed028f9 | 2016-03-17 14:04:52 -0700 | [diff] [blame] | 202 | |
Mark Salyzyn | 1181ec0 | 2016-03-30 09:38:31 -0700 | [diff] [blame] | 203 | if (bytesWritten < 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 204 | error(EXIT_FAILURE, 0, "Output error."); |
Mark Salyzyn | 1181ec0 | 2016-03-30 09:38:31 -0700 | [diff] [blame] | 205 | } |
Joe Onorato | 400da4a | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 206 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 209 | out_byte_count_ += bytesWritten; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 210 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 211 | if (log_rotate_size_kb_ > 0 && (out_byte_count_ / 1024) >= log_rotate_size_kb_) { |
| 212 | RotateLogs(); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 213 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 216 | void Logcat::PrintDividers(log_id_t log_id, bool print_dividers) { |
| 217 | if (log_id == last_printed_id_ || print_binary_) { |
| 218 | return; |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 219 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 220 | if (!printed_start_[log_id] || print_dividers) { |
| 221 | if (dprintf(output_fd_.get(), "--------- %s %s\n", |
| 222 | printed_start_[log_id] ? "switch to" : "beginning of", |
| 223 | android_log_id_to_name(log_id)) < 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 224 | error(EXIT_FAILURE, errno, "Output error"); |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | last_printed_id_ = log_id; |
| 228 | printed_start_[log_id] = true; |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 231 | void Logcat::SetupOutputAndSchedulingPolicy(bool blocking) { |
| 232 | if (!output_file_name_) return; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 233 | |
Mark Salyzyn | 60231da | 2016-08-04 07:53:52 -0700 | [diff] [blame] | 234 | if (blocking) { |
| 235 | // Lower priority and set to batch scheduling if we are saving |
| 236 | // the logs into files and taking continuous content. |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 237 | if (set_sched_policy(0, SP_BACKGROUND) < 0) { |
| 238 | fprintf(stderr, "failed to set background scheduling policy\n"); |
Mark Salyzyn | 38fc72c | 2015-06-02 07:57:16 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 241 | struct sched_param param = {}; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 242 | if (sched_setscheduler((pid_t)0, SCHED_BATCH, ¶m) < 0) { |
Mark Salyzyn | 38fc72c | 2015-06-02 07:57:16 -0700 | [diff] [blame] | 243 | fprintf(stderr, "failed to set to batch scheduler\n"); |
| 244 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 245 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 246 | if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND) < 0) { |
| 247 | fprintf(stderr, "failed set to priority\n"); |
Riley Andrews | 53fe1b0 | 2015-06-08 23:36:34 -0700 | [diff] [blame] | 248 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 249 | } |
Mark Salyzyn | 60231da | 2016-08-04 07:53:52 -0700 | [diff] [blame] | 250 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 251 | output_fd_.reset(openLogFile(output_file_name_, log_rotate_size_kb_)); |
Mark Salyzyn | 60231da | 2016-08-04 07:53:52 -0700 | [diff] [blame] | 252 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 253 | if (!output_fd_.ok()) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 254 | error(EXIT_FAILURE, errno, "Couldn't open output file"); |
Mark Salyzyn | 60231da | 2016-08-04 07:53:52 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | struct stat statbuf; |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 258 | if (fstat(output_fd_.get(), &statbuf) == -1) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 259 | error(EXIT_FAILURE, errno, "Couldn't get output file stat"); |
Mark Salyzyn | 60231da | 2016-08-04 07:53:52 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 262 | if ((size_t)statbuf.st_size > SIZE_MAX || statbuf.st_size < 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 263 | error(EXIT_FAILURE, 0, "Invalid output file stat."); |
Mark Salyzyn | 60231da | 2016-08-04 07:53:52 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 266 | out_byte_count_ = statbuf.st_size; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 269 | // clang-format off |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 270 | static void show_help() { |
| 271 | const char* cmd = getprogname(); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 272 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 273 | fprintf(stderr, "Usage: %s [options] [filterspecs]\n", cmd); |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 274 | |
Tom Cherry | a59bde4 | 2019-11-21 10:31:06 -0800 | [diff] [blame] | 275 | fprintf(stderr, R"init( |
| 276 | General options: |
| 277 | -b, --buffer=<buffer> Request alternate ring buffer(s): |
| 278 | main system radio events crash default all |
| 279 | Additionally, 'kernel' for userdebug and eng builds, and |
| 280 | 'security' for Device Owner installations. |
| 281 | Multiple -b parameters or comma separated list of buffers are |
| 282 | allowed. Buffers are interleaved. |
| 283 | Default -b main,system,crash,kernel. |
| 284 | -L, --last Dump logs from prior to last reboot from pstore. |
| 285 | -c, --clear Clear (flush) the entire log and exit. |
| 286 | if -f is specified, clear the specified file and its related rotated |
| 287 | log files instead. |
| 288 | if -L is specified, clear pstore log instead. |
| 289 | -d Dump the log and then exit (don't block). |
| 290 | --pid=<pid> Only print logs from the given pid. |
| 291 | --wrap Sleep for 2 hours or when buffer about to wrap whichever |
| 292 | comes first. Improves efficiency of polling by providing |
| 293 | an about-to-wrap wakeup. |
| 294 | |
| 295 | Formatting: |
| 296 | -v, --format=<format> Sets log print format verb and adverbs, where <format> is one of: |
| 297 | brief help long process raw tag thread threadtime time |
| 298 | Modifying adverbs can be added: |
| 299 | color descriptive epoch monotonic printable uid usec UTC year zone |
| 300 | Multiple -v parameters or comma separated list of format and format |
| 301 | modifiers are allowed. |
| 302 | -D, --dividers Print dividers between each log buffer. |
| 303 | -B, --binary Output the log in binary. |
| 304 | |
| 305 | Outfile files: |
| 306 | -f, --file=<file> Log to file instead of stdout. |
| 307 | -r, --rotate-kbytes=<n> Rotate log every <n> kbytes. Requires -f option. |
| 308 | -n, --rotate-count=<count> Sets max number of rotated logs to <count>, default 4. |
| 309 | --id=<id> If the signature <id> for logging to file changes, then clear the |
| 310 | associated files and continue. |
| 311 | |
| 312 | Logd control: |
| 313 | These options send a control message to the logd daemon on device, print its return message if |
| 314 | applicable, then exit. They are incompatible with -L, as these attributes do not apply to pstore. |
| 315 | -g, --buffer-size Get the size of the ring buffers within logd. |
| 316 | -G, --buffer-size=<size> Set size of a ring buffer in logd. May suffix with K or M. |
| 317 | This can individually control each buffer's size with -b. |
| 318 | -S, --statistics Output statistics. |
| 319 | --pid can be used to provide pid specific stats. |
| 320 | -p, --prune Print prune white and ~black list. Service is specified as UID, |
| 321 | UID/PID or /PID. Weighed for quicker pruning if prefix with ~, |
| 322 | otherwise weighed for longevity if unadorned. All other pruning |
| 323 | activity is oldest first. Special case ~! represents an automatic |
| 324 | quicker pruning for the noisiest UID as determined by the current |
| 325 | statistics. |
| 326 | -P, --prune='<list> ...' Set prune white and ~black list, using same format as listed above. |
| 327 | Must be quoted. |
| 328 | |
| 329 | Filtering: |
| 330 | -s Set default filter to silent. Equivalent to filterspec '*:S' |
| 331 | -e, --regex=<expr> Only print lines where the log message matches <expr> where <expr> is |
| 332 | an ECMAScript regular expression. |
| 333 | -m, --max-count=<count> Quit after printing <count> lines. This is meant to be paired with |
| 334 | --regex, but will work on its own. |
| 335 | --print This option is only applicable when --regex is set and only useful if |
| 336 | --max-count is also provided. |
| 337 | With --print, logcat will print all messages even if they do not |
| 338 | match the regex. Logcat will quit after printing the max-count number |
| 339 | of lines that match the regex. |
| 340 | -t <count> Print only the most recent <count> lines (implies -d). |
| 341 | -t '<time>' Print the lines since specified time (implies -d). |
| 342 | -T <count> Print only the most recent <count> lines (does not imply -d). |
| 343 | -T '<time>' Print the lines since specified time (not imply -d). |
| 344 | count is pure numerical, time is 'MM-DD hh:mm:ss.mmm...' |
| 345 | 'YYYY-MM-DD hh:mm:ss.mmm...' or 'sssss.mmm...' format. |
| 346 | )init"); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 347 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 348 | fprintf(stderr, "\nfilterspecs are a series of \n" |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 349 | " <tag>[:priority]\n\n" |
| 350 | "where <tag> is a log component tag (or * for all) and priority is:\n" |
Mark Salyzyn | 438b822 | 2015-03-09 09:32:56 -0700 | [diff] [blame] | 351 | " V Verbose (default for <tag>)\n" |
| 352 | " D Debug (default for '*')\n" |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 353 | " I Info\n" |
| 354 | " W Warn\n" |
| 355 | " E Error\n" |
| 356 | " F Fatal\n" |
Mark Salyzyn | 438b822 | 2015-03-09 09:32:56 -0700 | [diff] [blame] | 357 | " S Silent (suppress all output)\n" |
| 358 | "\n'*' by itself means '*:D' and <tag> by itself means <tag>:V.\n" |
| 359 | "If no '*' filterspec or -s on command line, all filter defaults to '*:V'.\n" |
| 360 | "eg: '*:S <tag>' prints only <tag>, '<tag>:S' suppresses all <tag> log messages.\n" |
| 361 | "\nIf not specified on the command line, filterspec is set from ANDROID_LOG_TAGS.\n" |
| 362 | "\nIf not specified with -v on command line, format is set from ANDROID_PRINTF_LOG\n" |
Mark Salyzyn | dd569af | 2014-09-16 09:15:15 -0700 | [diff] [blame] | 363 | "or defaults to \"threadtime\"\n\n"); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 364 | } |
| 365 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 366 | static void show_format_help() { |
| 367 | fprintf(stderr, |
Mark Salyzyn | 604679a | 2016-10-18 11:30:11 -0700 | [diff] [blame] | 368 | "-v <format>, --format=<format> options:\n" |
| 369 | " Sets log print format verb and adverbs, where <format> is:\n" |
| 370 | " brief long process raw tag thread threadtime time\n" |
| 371 | " and individually flagged modifying adverbs can be added:\n" |
| 372 | " color descriptive epoch monotonic printable uid usec UTC year zone\n" |
| 373 | "\nSingle format verbs:\n" |
| 374 | " brief — Display priority/tag and PID of the process issuing the message.\n" |
| 375 | " long — Display all metadata fields, separate messages with blank lines.\n" |
| 376 | " process — Display PID only.\n" |
| 377 | " raw — Display the raw log message, with no other metadata fields.\n" |
| 378 | " tag — Display the priority/tag only.\n" |
Mark Salyzyn | 56ff3fa | 2017-05-15 13:40:33 -0700 | [diff] [blame] | 379 | " thread — Display priority, PID and TID of process issuing the message.\n" |
Mark Salyzyn | 604679a | 2016-10-18 11:30:11 -0700 | [diff] [blame] | 380 | " threadtime — Display the date, invocation time, priority, tag, and the PID\n" |
| 381 | " and TID of the thread issuing the message. (the default format).\n" |
| 382 | " time — Display the date, invocation time, priority/tag, and PID of the\n" |
| 383 | " process issuing the message.\n" |
| 384 | "\nAdverb modifiers can be used in combination:\n" |
| 385 | " color — Display in highlighted color to match priority. i.e. \x1B[38;5;231mVERBOSE\n" |
| 386 | " \x1B[38;5;75mDEBUG \x1B[38;5;40mINFO \x1B[38;5;166mWARNING \x1B[38;5;196mERROR FATAL\x1B[0m\n" |
| 387 | " descriptive — events logs only, descriptions from event-log-tags database.\n" |
| 388 | " epoch — Display time as seconds since Jan 1 1970.\n" |
| 389 | " monotonic — Display time as cpu seconds since last boot.\n" |
| 390 | " printable — Ensure that any binary logging content is escaped.\n" |
| 391 | " uid — If permitted, display the UID or Android ID of logged process.\n" |
| 392 | " usec — Display time down the microsecond precision.\n" |
| 393 | " UTC — Display time as UTC.\n" |
| 394 | " year — Add the year to the displayed time.\n" |
| 395 | " zone — Add the local timezone to the displayed time.\n" |
| 396 | " \"<zone>\" — Print using this public named timezone (experimental).\n\n" |
| 397 | ); |
| 398 | } |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 399 | // clang-format on |
Mark Salyzyn | 604679a | 2016-10-18 11:30:11 -0700 | [diff] [blame] | 400 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 401 | int Logcat::SetLogFormat(const char* format_string) { |
| 402 | AndroidLogPrintFormat format = android_log_formatFromString(format_string); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 403 | |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 404 | // invalid string? |
| 405 | if (format == FORMAT_OFF) return -1; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 406 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 407 | return android_log_setPrintFormat(logformat_.get(), format); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Wei Wang | 8b58417 | 2018-09-05 11:05:57 -0700 | [diff] [blame] | 410 | static std::pair<unsigned long, const char*> format_of_size(unsigned long value) { |
| 411 | static const char multipliers[][3] = {{""}, {"Ki"}, {"Mi"}, {"Gi"}}; |
| 412 | size_t i; |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 413 | for (i = 0; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 414 | (i < sizeof(multipliers) / sizeof(multipliers[0])) && (value >= 1024); |
| 415 | value /= 1024, ++i) |
| 416 | ; |
Wei Wang | 8b58417 | 2018-09-05 11:05:57 -0700 | [diff] [blame] | 417 | return std::make_pair(value, multipliers[i]); |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 420 | static char* parseTime(log_time& t, const char* cp) { |
| 421 | char* ep = t.strptime(cp, "%m-%d %H:%M:%S.%q"); |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 422 | if (ep) return ep; |
Mark Salyzyn | 4d0473f | 2015-08-31 15:53:41 -0700 | [diff] [blame] | 423 | ep = t.strptime(cp, "%Y-%m-%d %H:%M:%S.%q"); |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 424 | if (ep) return ep; |
Mark Salyzyn | 4d0473f | 2015-08-31 15:53:41 -0700 | [diff] [blame] | 425 | return t.strptime(cp, "%s.%q"); |
Mark Salyzyn | eb0456d | 2015-08-31 08:01:33 -0700 | [diff] [blame] | 426 | } |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 427 | |
Mark Salyzyn | 05b8823 | 2016-08-04 07:43:46 -0700 | [diff] [blame] | 428 | // Find last logged line in <outputFileName>, or <outputFileName>.1 |
Mark Salyzyn | 79b0a15 | 2017-03-02 15:09:41 -0800 | [diff] [blame] | 429 | static log_time lastLogTime(const char* outputFileName) { |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 430 | log_time retval(log_time::EPOCH); |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 431 | if (!outputFileName) return retval; |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 432 | |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 433 | std::string directory; |
Mark Salyzyn | 79b0a15 | 2017-03-02 15:09:41 -0800 | [diff] [blame] | 434 | const char* file = strrchr(outputFileName, '/'); |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 435 | if (!file) { |
| 436 | directory = "."; |
| 437 | file = outputFileName; |
| 438 | } else { |
Mark Salyzyn | 79b0a15 | 2017-03-02 15:09:41 -0800 | [diff] [blame] | 439 | directory = std::string(outputFileName, file - outputFileName); |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 440 | ++file; |
| 441 | } |
Mark Salyzyn | 1747573 | 2016-04-01 07:52:20 -0700 | [diff] [blame] | 442 | |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 443 | std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(directory.c_str()), |
| 444 | closedir); |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 445 | if (!dir.get()) return retval; |
Mark Salyzyn | 1747573 | 2016-04-01 07:52:20 -0700 | [diff] [blame] | 446 | |
Mark Salyzyn | 05b8823 | 2016-08-04 07:43:46 -0700 | [diff] [blame] | 447 | log_time now(android_log_clockid()); |
Mark Salyzyn | 1747573 | 2016-04-01 07:52:20 -0700 | [diff] [blame] | 448 | |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 449 | size_t len = strlen(file); |
| 450 | log_time modulo(0, NS_PER_SEC); |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 451 | struct dirent* dp; |
Mark Salyzyn | 1747573 | 2016-04-01 07:52:20 -0700 | [diff] [blame] | 452 | |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 453 | while (!!(dp = readdir(dir.get()))) { |
| 454 | if ((dp->d_type != DT_REG) || !!strncmp(dp->d_name, file, len) || |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 455 | (dp->d_name[len] && ((dp->d_name[len] != '.') || |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 456 | (strtoll(dp->d_name + 1, nullptr, 10) != 1)))) { |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 457 | continue; |
| 458 | } |
| 459 | |
| 460 | std::string file_name = directory; |
| 461 | file_name += "/"; |
| 462 | file_name += dp->d_name; |
| 463 | std::string file; |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 464 | if (!android::base::ReadFileToString(file_name, &file)) continue; |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 465 | |
| 466 | bool found = false; |
| 467 | for (const auto& line : android::base::Split(file, "\n")) { |
| 468 | log_time t(log_time::EPOCH); |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 469 | char* ep = parseTime(t, line.c_str()); |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 470 | if (!ep || (*ep != ' ')) continue; |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 471 | // determine the time precision of the logs (eg: msec or usec) |
| 472 | for (unsigned long mod = 1UL; mod < modulo.tv_nsec; mod *= 10) { |
| 473 | if (t.tv_nsec % (mod * 10)) { |
| 474 | modulo.tv_nsec = mod; |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | // We filter any times later than current as we may not have the |
| 479 | // year stored with each log entry. Also, since it is possible for |
| 480 | // entries to be recorded out of order (very rare) we select the |
| 481 | // maximum we find just in case. |
| 482 | if ((t < now) && (t > retval)) { |
| 483 | retval = t; |
| 484 | found = true; |
| 485 | } |
| 486 | } |
| 487 | // We count on the basename file to be the definitive end, so stop here. |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 488 | if (!dp->d_name[len] && found) break; |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 489 | } |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 490 | if (retval == log_time::EPOCH) return retval; |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 491 | // tail_time prints matching or higher, round up by the modulo to prevent |
| 492 | // a replay of the last entry we have just checked. |
| 493 | retval += modulo; |
| 494 | return retval; |
| 495 | } |
| 496 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 497 | void ReportErrorName(const std::string& name, bool allow_security, |
| 498 | std::vector<std::string>* errors) { |
| 499 | if (allow_security || name != "security") { |
| 500 | errors->emplace_back(name); |
Mark Salyzyn | 70cf66d | 2017-01-20 14:07:29 -0800 | [diff] [blame] | 501 | } |
Mark Salyzyn | 70cf66d | 2017-01-20 14:07:29 -0800 | [diff] [blame] | 502 | } |
Traian Schiau | 9f97860 | 2015-04-10 15:51:39 +0300 | [diff] [blame] | 503 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 504 | int Logcat::Run(int argc, char** argv) { |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 505 | bool hasSetLogFormat = false; |
Mark Salyzyn | 70cf66d | 2017-01-20 14:07:29 -0800 | [diff] [blame] | 506 | bool clearLog = false; |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 507 | bool security_buffer_selected = |
| 508 | false; // Do not report errors on the security buffer unless it is explicitly named. |
Mark Salyzyn | 70cf66d | 2017-01-20 14:07:29 -0800 | [diff] [blame] | 509 | bool getLogSize = false; |
| 510 | bool getPruneList = false; |
| 511 | bool printStatistics = false; |
| 512 | bool printDividers = false; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 513 | unsigned long setLogSize = 0; |
Mark Salyzyn | 79b0a15 | 2017-03-02 15:09:41 -0800 | [diff] [blame] | 514 | const char* setPruneList = nullptr; |
| 515 | const char* setId = nullptr; |
Mark Salyzyn | 4bdf253 | 2015-01-26 10:46:44 -0800 | [diff] [blame] | 516 | int mode = ANDROID_LOG_RDONLY; |
Mark Salyzyn | d2a03b5 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 517 | std::string forceFilters; |
Traian Schiau | 9f97860 | 2015-04-10 15:51:39 +0300 | [diff] [blame] | 518 | size_t tail_lines = 0; |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 519 | log_time tail_time(log_time::EPOCH); |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 520 | size_t pid = 0; |
Casey Dahlin | ed028f9 | 2016-03-17 14:04:52 -0700 | [diff] [blame] | 521 | bool got_t = false; |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 522 | unsigned id_mask = 0; |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 523 | |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 524 | if (argc == 2 && !strcmp(argv[1], "--help")) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 525 | show_help(); |
| 526 | return EXIT_SUCCESS; |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 527 | } |
| 528 | |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 529 | // meant to catch comma-delimited values, but cast a wider |
| 530 | // net for stability dealing with possible mistaken inputs. |
| 531 | static const char delimiters[] = ",:; \t\n\r\f"; |
| 532 | |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 533 | optind = 0; |
| 534 | while (true) { |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 535 | int option_index = 0; |
Mark Salyzyn | 1181ec0 | 2016-03-30 09:38:31 -0700 | [diff] [blame] | 536 | // list of long-argument only strings for later comparison |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 537 | static const char pid_str[] = "pid"; |
Mark Salyzyn | 1436923 | 2016-11-16 15:28:31 -0800 | [diff] [blame] | 538 | static const char debug_str[] = "debug"; |
Mark Salyzyn | 175773d | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 539 | static const char id_str[] = "id"; |
Mark Salyzyn | 712caab | 2015-11-30 13:48:56 -0800 | [diff] [blame] | 540 | static const char wrap_str[] = "wrap"; |
Mark Salyzyn | 1181ec0 | 2016-03-30 09:38:31 -0700 | [diff] [blame] | 541 | static const char print_str[] = "print"; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 542 | // clang-format off |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 543 | static const struct option long_options[] = { |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 544 | { "binary", no_argument, nullptr, 'B' }, |
| 545 | { "buffer", required_argument, nullptr, 'b' }, |
| 546 | { "buffer-size", optional_argument, nullptr, 'g' }, |
| 547 | { "clear", no_argument, nullptr, 'c' }, |
| 548 | { debug_str, no_argument, nullptr, 0 }, |
| 549 | { "dividers", no_argument, nullptr, 'D' }, |
| 550 | { "file", required_argument, nullptr, 'f' }, |
| 551 | { "format", required_argument, nullptr, 'v' }, |
Mark Salyzyn | 1747573 | 2016-04-01 07:52:20 -0700 | [diff] [blame] | 552 | // hidden and undocumented reserved alias for --regex |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 553 | { "grep", required_argument, nullptr, 'e' }, |
Mark Salyzyn | 12d8306 | 2016-03-30 09:15:09 -0700 | [diff] [blame] | 554 | // hidden and undocumented reserved alias for --max-count |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 555 | { "head", required_argument, nullptr, 'm' }, |
Mark Salyzyn | 6a3d549 | 2017-04-03 09:30:20 -0700 | [diff] [blame] | 556 | { "help", no_argument, nullptr, 'h' }, |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 557 | { id_str, required_argument, nullptr, 0 }, |
| 558 | { "last", no_argument, nullptr, 'L' }, |
| 559 | { "max-count", required_argument, nullptr, 'm' }, |
| 560 | { pid_str, required_argument, nullptr, 0 }, |
| 561 | { print_str, no_argument, nullptr, 0 }, |
| 562 | { "prune", optional_argument, nullptr, 'p' }, |
| 563 | { "regex", required_argument, nullptr, 'e' }, |
| 564 | { "rotate-count", required_argument, nullptr, 'n' }, |
| 565 | { "rotate-kbytes", required_argument, nullptr, 'r' }, |
| 566 | { "statistics", no_argument, nullptr, 'S' }, |
Mark Salyzyn | 12d8306 | 2016-03-30 09:15:09 -0700 | [diff] [blame] | 567 | // hidden and undocumented reserved alias for -t |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 568 | { "tail", required_argument, nullptr, 't' }, |
Mark Salyzyn | 712caab | 2015-11-30 13:48:56 -0800 | [diff] [blame] | 569 | // support, but ignore and do not document, the optional argument |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 570 | { wrap_str, optional_argument, nullptr, 0 }, |
| 571 | { nullptr, 0, nullptr, 0 } |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 572 | }; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 573 | // clang-format on |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 574 | |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 575 | int c = getopt_long(argc, argv, ":cdDhLt:T:gG:sQf:r:n:v:b:BSpP:m:e:", long_options, |
| 576 | &option_index); |
| 577 | if (c == -1) break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 578 | |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 579 | switch (c) { |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 580 | case 0: |
Mark Salyzyn | 175773d | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 581 | // only long options |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 582 | if (long_options[option_index].name == pid_str) { |
Steven Moreland | 36f0595 | 2019-08-02 10:13:57 -0700 | [diff] [blame] | 583 | if (pid != 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 584 | error(EXIT_FAILURE, 0, "Only one --pid argument can be provided."); |
Steven Moreland | 36f0595 | 2019-08-02 10:13:57 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 587 | if (!ParseUint(optarg, &pid) || pid < 1) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 588 | error(EXIT_FAILURE, 0, "%s %s out of range.", |
| 589 | long_options[option_index].name, optarg); |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 590 | } |
| 591 | break; |
| 592 | } |
Mark Salyzyn | 712caab | 2015-11-30 13:48:56 -0800 | [diff] [blame] | 593 | if (long_options[option_index].name == wrap_str) { |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 594 | mode |= ANDROID_LOG_WRAP | ANDROID_LOG_RDONLY | |
Mark Salyzyn | 712caab | 2015-11-30 13:48:56 -0800 | [diff] [blame] | 595 | ANDROID_LOG_NONBLOCK; |
| 596 | // ToDo: implement API that supports setting a wrap timeout |
| 597 | size_t dummy = ANDROID_LOG_WRAP_DEFAULT_TIMEOUT; |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 598 | if (optarg && (!ParseUint(optarg, &dummy) || dummy < 1)) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 599 | error(EXIT_FAILURE, 0, "%s %s out of range.", |
| 600 | long_options[option_index].name, optarg); |
Mark Salyzyn | 712caab | 2015-11-30 13:48:56 -0800 | [diff] [blame] | 601 | } |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 602 | if (dummy != ANDROID_LOG_WRAP_DEFAULT_TIMEOUT) { |
| 603 | fprintf(stderr, "WARNING: %s %u seconds, ignoring %zu\n", |
| 604 | long_options[option_index].name, ANDROID_LOG_WRAP_DEFAULT_TIMEOUT, |
| 605 | dummy); |
Mark Salyzyn | 712caab | 2015-11-30 13:48:56 -0800 | [diff] [blame] | 606 | } |
| 607 | break; |
| 608 | } |
Mark Salyzyn | 1181ec0 | 2016-03-30 09:38:31 -0700 | [diff] [blame] | 609 | if (long_options[option_index].name == print_str) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 610 | print_it_anyways_ = true; |
Mark Salyzyn | 1181ec0 | 2016-03-30 09:38:31 -0700 | [diff] [blame] | 611 | break; |
| 612 | } |
Mark Salyzyn | 1436923 | 2016-11-16 15:28:31 -0800 | [diff] [blame] | 613 | if (long_options[option_index].name == debug_str) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 614 | debug_ = true; |
Mark Salyzyn | 1436923 | 2016-11-16 15:28:31 -0800 | [diff] [blame] | 615 | break; |
| 616 | } |
Mark Salyzyn | 175773d | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 617 | if (long_options[option_index].name == id_str) { |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 618 | setId = (optarg && optarg[0]) ? optarg : nullptr; |
Mark Salyzyn | 175773d | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 619 | } |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 620 | break; |
Kristian Monsen | 694cdf6 | 2015-06-05 14:10:12 -0700 | [diff] [blame] | 621 | |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 622 | case 's': |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 623 | // default to all silent |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 624 | android_log_addFilterRule(logformat_.get(), "*:s"); |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 625 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 626 | |
| 627 | case 'c': |
Mark Salyzyn | 70cf66d | 2017-01-20 14:07:29 -0800 | [diff] [blame] | 628 | clearLog = true; |
Mark Salyzyn | 4bdf253 | 2015-01-26 10:46:44 -0800 | [diff] [blame] | 629 | mode |= ANDROID_LOG_WRONLY; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 630 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 631 | |
Mark Salyzyn | 66460fc | 2014-12-15 10:01:31 -0800 | [diff] [blame] | 632 | case 'L': |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 633 | mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_PSTORE | |
| 634 | ANDROID_LOG_NONBLOCK; |
| 635 | break; |
Mark Salyzyn | 66460fc | 2014-12-15 10:01:31 -0800 | [diff] [blame] | 636 | |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 637 | case 'd': |
Mark Salyzyn | 4bdf253 | 2015-01-26 10:46:44 -0800 | [diff] [blame] | 638 | mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 639 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 640 | |
Dan Egnor | cce2b08 | 2010-03-11 20:32:17 -0800 | [diff] [blame] | 641 | case 't': |
Casey Dahlin | ed028f9 | 2016-03-17 14:04:52 -0700 | [diff] [blame] | 642 | got_t = true; |
Mark Salyzyn | 4bdf253 | 2015-01-26 10:46:44 -0800 | [diff] [blame] | 643 | mode |= ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK; |
Chih-Hung Hsieh | 6d46142 | 2018-09-13 11:08:41 -0700 | [diff] [blame] | 644 | FALLTHROUGH_INTENDED; |
Mark Salyzyn | 2256e2f | 2013-12-09 13:47:00 -0800 | [diff] [blame] | 645 | case 'T': |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 646 | if (strspn(optarg, "0123456789") != strlen(optarg)) { |
| 647 | char* cp = parseTime(tail_time, optarg); |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 648 | if (!cp) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 649 | error(EXIT_FAILURE, 0, "-%c '%s' not in time format.", c, optarg); |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 650 | } |
| 651 | if (*cp) { |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 652 | char ch = *cp; |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 653 | *cp = '\0'; |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 654 | fprintf(stderr, "WARNING: -%c '%s' '%c%s' time truncated\n", c, optarg, ch, |
| 655 | cp + 1); |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 656 | *cp = ch; |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 657 | } |
| 658 | } else { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 659 | if (!ParseUint(optarg, &tail_lines) || tail_lines < 1) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 660 | fprintf(stderr, "WARNING: -%c %s invalid, setting to 1\n", c, optarg); |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 661 | tail_lines = 1; |
| 662 | } |
| 663 | } |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 664 | break; |
Dan Egnor | cce2b08 | 2010-03-11 20:32:17 -0800 | [diff] [blame] | 665 | |
Mark Salyzyn | 1ff1809 | 2015-01-26 13:41:33 -0800 | [diff] [blame] | 666 | case 'D': |
| 667 | printDividers = true; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 668 | break; |
Mark Salyzyn | 1ff1809 | 2015-01-26 13:41:33 -0800 | [diff] [blame] | 669 | |
Casey Dahlin | 4cf025a | 2016-03-17 16:18:55 -0700 | [diff] [blame] | 670 | case 'e': |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 671 | regex_.reset(new std::regex(optarg)); |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 672 | break; |
Casey Dahlin | 4cf025a | 2016-03-17 16:18:55 -0700 | [diff] [blame] | 673 | |
Casey Dahlin | ed028f9 | 2016-03-17 14:04:52 -0700 | [diff] [blame] | 674 | case 'm': { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 675 | if (!ParseUint(optarg, &max_count_) || max_count_ < 1) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 676 | error(EXIT_FAILURE, 0, "-%c '%s' isn't an integer greater than zero.", c, |
| 677 | optarg); |
Casey Dahlin | ed028f9 | 2016-03-17 14:04:52 -0700 | [diff] [blame] | 678 | } |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 679 | } break; |
Casey Dahlin | ed028f9 | 2016-03-17 14:04:52 -0700 | [diff] [blame] | 680 | |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 681 | case 'g': |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 682 | if (!optarg) { |
Mark Salyzyn | 70cf66d | 2017-01-20 14:07:29 -0800 | [diff] [blame] | 683 | getLogSize = true; |
Mark Salyzyn | aef4c7e | 2015-11-30 12:57:56 -0800 | [diff] [blame] | 684 | break; |
| 685 | } |
Chih-Hung Hsieh | 6d46142 | 2018-09-13 11:08:41 -0700 | [diff] [blame] | 686 | FALLTHROUGH_INTENDED; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 687 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 688 | case 'G': { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 689 | if (!ParseByteCount(optarg, &setLogSize) || setLogSize < 1) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 690 | error(EXIT_FAILURE, 0, "-G must be specified as <num><multiplier>."); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 691 | } |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 692 | } break; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 693 | |
| 694 | case 'p': |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 695 | if (!optarg) { |
Mark Salyzyn | 70cf66d | 2017-01-20 14:07:29 -0800 | [diff] [blame] | 696 | getPruneList = true; |
Mark Salyzyn | aef4c7e | 2015-11-30 12:57:56 -0800 | [diff] [blame] | 697 | break; |
| 698 | } |
Chih-Hung Hsieh | 6d46142 | 2018-09-13 11:08:41 -0700 | [diff] [blame] | 699 | FALLTHROUGH_INTENDED; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 700 | |
| 701 | case 'P': |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 702 | setPruneList = optarg; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 703 | break; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 704 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 705 | case 'b': |
| 706 | for (const auto& buffer : Split(optarg, delimiters)) { |
| 707 | if (buffer == "default") { |
| 708 | id_mask |= (1 << LOG_ID_MAIN) | (1 << LOG_ID_SYSTEM) | (1 << LOG_ID_CRASH); |
| 709 | } else if (buffer == "all") { |
| 710 | id_mask = -1; |
Mark Salyzyn | 9ca3be3 | 2016-04-11 14:03:48 -0700 | [diff] [blame] | 711 | } else { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 712 | log_id_t log_id = android_name_to_log_id(buffer.c_str()); |
| 713 | if (log_id >= LOG_ID_MAX) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 714 | error(EXIT_FAILURE, 0, "Unknown buffer '%s' listed for -b.", |
| 715 | buffer.c_str()); |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 716 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 717 | if (log_id == LOG_ID_SECURITY) { |
| 718 | security_buffer_selected = true; |
Mark Salyzyn | c969086 | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 719 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 720 | id_mask |= (1 << log_id); |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 721 | } |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 722 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 723 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 724 | |
| 725 | case 'B': |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 726 | print_binary_ = 1; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 727 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 728 | |
| 729 | case 'f': |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 730 | if ((tail_time == log_time::EPOCH) && !tail_lines) { |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 731 | tail_time = lastLogTime(optarg); |
Mark Salyzyn | 3fa657e | 2015-05-27 07:39:56 -0700 | [diff] [blame] | 732 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 733 | // redirect output to a file |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 734 | output_file_name_ = optarg; |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 735 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 736 | |
Mark Salyzyn | ff5f4b1 | 2016-06-07 13:03:10 -0700 | [diff] [blame] | 737 | case 'r': |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 738 | if (!ParseUint(optarg, &log_rotate_size_kb_) || log_rotate_size_kb_ < 1) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 739 | error(EXIT_FAILURE, 0, "Invalid parameter '%s' to -r.", optarg); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 740 | } |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 741 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 742 | |
Mark Salyzyn | ff5f4b1 | 2016-06-07 13:03:10 -0700 | [diff] [blame] | 743 | case 'n': |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 744 | if (!ParseUint(optarg, &max_rotated_logs_) || max_rotated_logs_ < 1) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 745 | error(EXIT_FAILURE, 0, "Invalid parameter '%s' to -n.", optarg); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 746 | } |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 747 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 748 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 749 | case 'v': |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 750 | if (!strcmp(optarg, "help") || !strcmp(optarg, "--help")) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 751 | show_format_help(); |
| 752 | return EXIT_SUCCESS; |
Mark Salyzyn | 604679a | 2016-10-18 11:30:11 -0700 | [diff] [blame] | 753 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 754 | for (const auto& arg : Split(optarg, delimiters)) { |
| 755 | int err = SetLogFormat(arg.c_str()); |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 756 | if (err < 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 757 | error(EXIT_FAILURE, 0, "Invalid parameter '%s' to -v.", arg.c_str()); |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 758 | } |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 759 | if (err) hasSetLogFormat = true; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 760 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 761 | break; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 762 | |
| 763 | case 'Q': |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 764 | #define LOGCAT_FILTER "androidboot.logcat=" |
| 765 | #define CONSOLE_PIPE_OPTION "androidboot.consolepipe=" |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 766 | #define CONSOLE_OPTION "androidboot.console=" |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 767 | #define QEMU_PROPERTY "ro.kernel.qemu" |
| 768 | #define QEMU_CMDLINE "qemu.cmdline" |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 769 | // This is a *hidden* option used to start a version of logcat |
| 770 | // in an emulated device only. It basically looks for |
| 771 | // androidboot.logcat= on the kernel command line. If |
| 772 | // something is found, it extracts a log filter and uses it to |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 773 | // run the program. The logcat output will go to consolepipe if |
| 774 | // androiboot.consolepipe (e.g. qemu_pipe) is given, otherwise, |
| 775 | // it goes to androidboot.console (e.g. tty) |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 776 | { |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 777 | // if not in emulator, exit quietly |
| 778 | if (false == android::base::GetBoolProperty(QEMU_PROPERTY, false)) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 779 | return EXIT_SUCCESS; |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 780 | } |
Mark Salyzyn | d2a03b5 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 781 | |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 782 | std::string cmdline = android::base::GetProperty(QEMU_CMDLINE, ""); |
| 783 | if (cmdline.empty()) { |
| 784 | android::base::ReadFileToString("/proc/cmdline", &cmdline); |
| 785 | } |
| 786 | |
| 787 | const char* logcatFilter = strstr(cmdline.c_str(), LOGCAT_FILTER); |
| 788 | // if nothing found or invalid filters, exit quietly |
| 789 | if (!logcatFilter) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 790 | return EXIT_SUCCESS; |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | const char* p = logcatFilter + strlen(LOGCAT_FILTER); |
Mark Salyzyn | d2a03b5 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 794 | const char* q = strpbrk(p, " \t\n\r"); |
| 795 | if (!q) q = p + strlen(p); |
| 796 | forceFilters = std::string(p, q); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 797 | |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 798 | // redirect our output to the emulator console pipe or console |
| 799 | const char* consolePipe = |
| 800 | strstr(cmdline.c_str(), CONSOLE_PIPE_OPTION); |
Mark Salyzyn | d2a03b5 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 801 | const char* console = |
| 802 | strstr(cmdline.c_str(), CONSOLE_OPTION); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 803 | |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 804 | if (consolePipe) { |
| 805 | p = consolePipe + strlen(CONSOLE_PIPE_OPTION); |
| 806 | } else if (console) { |
| 807 | p = console + strlen(CONSOLE_OPTION); |
| 808 | } else { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 809 | return EXIT_FAILURE; |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 810 | } |
| 811 | |
Mark Salyzyn | d2a03b5 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 812 | q = strpbrk(p, " \t\n\r"); |
| 813 | int len = q ? q - p : strlen(p); |
| 814 | std::string devname = "/dev/" + std::string(p, len); |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 815 | std::string pipePurpose("pipe:logcat"); |
| 816 | if (consolePipe) { |
| 817 | // example: "qemu_pipe,pipe:logcat" |
| 818 | // upon opening of /dev/qemu_pipe, the "pipe:logcat" |
| 819 | // string with trailing '\0' should be written to the fd |
Chih-Hung Hsieh | dd8aae6 | 2017-08-03 13:56:49 -0700 | [diff] [blame] | 820 | size_t pos = devname.find(','); |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 821 | if (pos != std::string::npos) { |
| 822 | pipePurpose = devname.substr(pos + 1); |
| 823 | devname = devname.substr(0, pos); |
| 824 | } |
| 825 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 826 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 827 | fprintf(stderr, "logcat using %s\n", devname.c_str()); |
| 828 | |
| 829 | int fd = open(devname.c_str(), O_WRONLY | O_CLOEXEC); |
| 830 | if (fd < 0) { |
| 831 | break; |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 832 | } |
Mark Salyzyn | d2a03b5 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 833 | |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 834 | if (consolePipe) { |
| 835 | // need the trailing '\0' |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 836 | if (!android::base::WriteFully(fd, pipePurpose.c_str(), |
| 837 | pipePurpose.size() + 1)) { |
| 838 | close(fd); |
| 839 | return EXIT_FAILURE; |
bohu | 2588953 | 2017-02-21 14:31:19 -0800 | [diff] [blame] | 840 | } |
| 841 | } |
Mark Salyzyn | d2a03b5 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 842 | // close output and error channels, replace with console |
Erwin Jansen | 613c7d4 | 2019-11-27 12:58:58 -0800 | [diff] [blame] | 843 | dup2(fd, output_fd_.get()); |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 844 | dup2(fd, STDERR_FILENO); |
| 845 | close(fd); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 846 | } |
| 847 | break; |
| 848 | |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 849 | case 'S': |
Mark Salyzyn | 70cf66d | 2017-01-20 14:07:29 -0800 | [diff] [blame] | 850 | printStatistics = true; |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 851 | break; |
| 852 | |
Traian Schiau | 9f97860 | 2015-04-10 15:51:39 +0300 | [diff] [blame] | 853 | case ':': |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 854 | error(EXIT_FAILURE, 0, "Option '%s' needs an argument.", argv[optind - 1]); |
| 855 | break; |
Traian Schiau | 9f97860 | 2015-04-10 15:51:39 +0300 | [diff] [blame] | 856 | |
Mark Salyzyn | 6a3d549 | 2017-04-03 09:30:20 -0700 | [diff] [blame] | 857 | case 'h': |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 858 | show_help(); |
| 859 | show_format_help(); |
| 860 | return EXIT_SUCCESS; |
Mark Salyzyn | 6a3d549 | 2017-04-03 09:30:20 -0700 | [diff] [blame] | 861 | |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 862 | case '?': |
| 863 | error(EXIT_FAILURE, 0, "Unknown option '%s'.", argv[optind - 1]); |
| 864 | break; |
| 865 | |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 866 | default: |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 867 | error(EXIT_FAILURE, 0, "Unknown getopt_long() result '%c'.", c); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 871 | if (max_count_ && got_t) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 872 | error(EXIT_FAILURE, 0, "Cannot use -m (--max-count) and -t together."); |
Casey Dahlin | ed028f9 | 2016-03-17 14:04:52 -0700 | [diff] [blame] | 873 | } |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 874 | if (print_it_anyways_ && (!regex_ || !max_count_)) { |
Mark Salyzyn | 1181ec0 | 2016-03-30 09:38:31 -0700 | [diff] [blame] | 875 | // One day it would be nice if --print -v color and --regex <expr> |
| 876 | // could play with each other and show regex highlighted content. |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 877 | fprintf(stderr, |
| 878 | "WARNING: " |
| 879 | "--print ignored, to be used in combination with\n" |
| 880 | " " |
| 881 | "--regex <expr> and --max-count <N>\n"); |
| 882 | print_it_anyways_ = false; |
Mark Salyzyn | 1181ec0 | 2016-03-30 09:38:31 -0700 | [diff] [blame] | 883 | } |
Casey Dahlin | ed028f9 | 2016-03-17 14:04:52 -0700 | [diff] [blame] | 884 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 885 | // If no buffers are specified, default to using these buffers. |
| 886 | if (id_mask == 0) { |
| 887 | id_mask = (1 << LOG_ID_MAIN) | (1 << LOG_ID_SYSTEM) | (1 << LOG_ID_CRASH) | |
| 888 | (1 << LOG_ID_KERNEL); |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 889 | } |
| 890 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 891 | if (log_rotate_size_kb_ != 0 && !output_file_name_) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 892 | error(EXIT_FAILURE, 0, "-r requires -f as well."); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 893 | } |
| 894 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 895 | if (setId != 0) { |
| 896 | if (!output_file_name_) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 897 | error(EXIT_FAILURE, 0, "--id='%s' requires -f as well.", setId); |
Mark Salyzyn | 175773d | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 900 | std::string file_name = StringPrintf("%s.id", output_file_name_); |
Mark Salyzyn | 175773d | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 901 | std::string file; |
| 902 | bool file_ok = android::base::ReadFileToString(file_name, &file); |
Mark Salyzyn | d8b454f | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 903 | android::base::WriteStringToFile(setId, file_name, S_IRUSR | S_IWUSR, |
| 904 | getuid(), getgid()); |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 905 | if (!file_ok || !file.compare(setId)) setId = nullptr; |
Mark Salyzyn | 175773d | 2016-08-03 14:20:41 -0700 | [diff] [blame] | 906 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 907 | |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 908 | if (!hasSetLogFormat) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 909 | const char* logFormat = getenv("ANDROID_PRINTF_LOG"); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 910 | |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 911 | if (!!logFormat) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 912 | for (const auto& arg : Split(logFormat, delimiters)) { |
| 913 | int err = SetLogFormat(arg.c_str()); |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 914 | // environment should not cause crash of logcat |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 915 | if (err < 0) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 916 | fprintf(stderr, "invalid format in ANDROID_PRINTF_LOG '%s'\n", arg.c_str()); |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 917 | } |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 918 | if (err > 0) hasSetLogFormat = true; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 919 | } |
Mark Salyzyn | d592002 | 2017-02-28 09:20:31 -0800 | [diff] [blame] | 920 | } |
| 921 | if (!hasSetLogFormat) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 922 | SetLogFormat("threadtime"); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
Mark Salyzyn | d2a03b5 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 926 | if (forceFilters.size()) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 927 | int err = android_log_addFilterString(logformat_.get(), forceFilters.c_str()); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 928 | if (err < 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 929 | error(EXIT_FAILURE, 0, "Invalid filter expression in logcat args."); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 930 | } |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 931 | } else if (argc == optind) { |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 932 | // Add from environment variable |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 933 | const char* env_tags_orig = getenv("ANDROID_LOG_TAGS"); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 934 | |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 935 | if (!!env_tags_orig) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 936 | int err = android_log_addFilterString(logformat_.get(), env_tags_orig); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 937 | |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 938 | if (err < 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 939 | error(EXIT_FAILURE, 0, "Invalid filter expression in ANDROID_LOG_TAGS."); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | } else { |
| 943 | // Add from commandline |
Elliott Hughes | 442d858 | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 944 | for (int i = optind ; i < argc ; i++) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 945 | int err = android_log_addFilterString(logformat_.get(), argv[i]); |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 946 | if (err < 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 947 | error(EXIT_FAILURE, 0, "Invalid filter expression '%s'.", argv[i]); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
Tom Cherry | f459c58 | 2019-11-14 08:56:39 -0800 | [diff] [blame] | 952 | if (mode & ANDROID_LOG_PSTORE) { |
Tom Cherry | eb2258a | 2019-12-04 14:37:38 -0800 | [diff] [blame] | 953 | if (output_file_name_) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 954 | error(EXIT_FAILURE, 0, "-c is ambiguous with both -f and -L specified."); |
Tom Cherry | eb2258a | 2019-12-04 14:37:38 -0800 | [diff] [blame] | 955 | } |
| 956 | if (setLogSize || getLogSize || printStatistics || getPruneList || setPruneList) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 957 | error(EXIT_FAILURE, 0, "-L is incompatible with -g/-G, -S, and -p/-P."); |
Tom Cherry | eb2258a | 2019-12-04 14:37:38 -0800 | [diff] [blame] | 958 | } |
Tom Cherry | f459c58 | 2019-11-14 08:56:39 -0800 | [diff] [blame] | 959 | if (clearLog) { |
| 960 | unlink("/sys/fs/pstore/pmsg-ramoops-0"); |
| 961 | return EXIT_SUCCESS; |
| 962 | } |
Tom Cherry | eb2258a | 2019-12-04 14:37:38 -0800 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | if (output_file_name_) { |
Tom Cherry | f459c58 | 2019-11-14 08:56:39 -0800 | [diff] [blame] | 966 | if (setLogSize || getLogSize || printStatistics || getPruneList || setPruneList) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 967 | error(EXIT_FAILURE, 0, "-f is incompatible with -g/-G, -S, and -p/-P."); |
Tom Cherry | eb2258a | 2019-12-04 14:37:38 -0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | if (clearLog || setId) { |
| 971 | int max_rotation_count_digits = |
| 972 | max_rotated_logs_ > 0 ? (int)(floor(log10(max_rotated_logs_) + 1)) : 0; |
| 973 | |
| 974 | for (int i = max_rotated_logs_; i >= 0; --i) { |
| 975 | std::string file; |
| 976 | |
| 977 | if (!i) { |
| 978 | file = output_file_name_; |
| 979 | } else { |
| 980 | file = StringPrintf("%s.%.*d", output_file_name_, max_rotation_count_digits, i); |
| 981 | } |
| 982 | |
| 983 | int err = unlink(file.c_str()); |
| 984 | |
| 985 | if (err < 0 && errno != ENOENT) { |
| 986 | fprintf(stderr, "failed to delete log file '%s': %s\n", file.c_str(), |
| 987 | strerror(errno)); |
| 988 | } |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | if (clearLog) { |
| 993 | return EXIT_SUCCESS; |
Tom Cherry | f459c58 | 2019-11-14 08:56:39 -0800 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 997 | std::unique_ptr<logger_list, decltype(&android_logger_list_free)> logger_list{ |
| 998 | nullptr, &android_logger_list_free}; |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 999 | if (tail_time != log_time::EPOCH) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1000 | logger_list.reset(android_logger_list_alloc_time(mode, tail_time, pid)); |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 1001 | } else { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1002 | logger_list.reset(android_logger_list_alloc(mode, tail_lines, pid)); |
Mark Salyzyn | 9addf59 | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 1003 | } |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1004 | // We have three orthogonal actions below to clear, set log size and |
| 1005 | // get log size. All sharing the same iteration loop. |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1006 | std::vector<std::string> open_device_failures; |
| 1007 | std::vector<std::string> clear_failures; |
| 1008 | std::vector<std::string> set_size_failures; |
| 1009 | std::vector<std::string> get_size_failures; |
| 1010 | |
| 1011 | for (int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) { |
| 1012 | if (!(id_mask & (1 << i))) continue; |
| 1013 | const char* buffer_name = android_log_id_to_name(static_cast<log_id_t>(i)); |
| 1014 | |
| 1015 | auto logger = android_logger_open(logger_list.get(), static_cast<log_id_t>(i)); |
| 1016 | if (logger == nullptr) { |
| 1017 | ReportErrorName(buffer_name, security_buffer_selected, &open_device_failures); |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1018 | continue; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1019 | } |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 1020 | |
Tom Cherry | eb2258a | 2019-12-04 14:37:38 -0800 | [diff] [blame] | 1021 | if (clearLog) { |
| 1022 | if (android_logger_clear(logger)) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1023 | ReportErrorName(buffer_name, security_buffer_selected, &clear_failures); |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 1024 | } |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 1025 | } |
| 1026 | |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1027 | if (setLogSize) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1028 | if (android_logger_set_log_size(logger, setLogSize)) { |
| 1029 | ReportErrorName(buffer_name, security_buffer_selected, &set_size_failures); |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1030 | } |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 1031 | } |
| 1032 | |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 1033 | if (getLogSize) { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1034 | long size = android_logger_get_log_size(logger); |
| 1035 | long readable = android_logger_get_log_readable_size(logger); |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 1036 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1037 | if (size < 0 || readable < 0) { |
| 1038 | ReportErrorName(buffer_name, security_buffer_selected, &get_size_failures); |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1039 | } else { |
Wei Wang | 8b58417 | 2018-09-05 11:05:57 -0700 | [diff] [blame] | 1040 | auto size_format = format_of_size(size); |
| 1041 | auto readable_format = format_of_size(readable); |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 1042 | std::string str = android::base::StringPrintf( |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1043 | "%s: ring buffer is %lu %sB (%lu %sB consumed)," |
| 1044 | " max entry is %d B, max payload is %d B\n", |
| 1045 | buffer_name, size_format.first, size_format.second, readable_format.first, |
| 1046 | readable_format.second, (int)LOGGER_ENTRY_MAX_LEN, |
| 1047 | (int)LOGGER_ENTRY_MAX_PAYLOAD); |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1048 | TEMP_FAILURE_RETRY(write(output_fd_.get(), str.data(), str.length())); |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 1049 | } |
Joe Onorato | d23b9cf | 2010-02-26 10:04:23 -0800 | [diff] [blame] | 1050 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1051 | } |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 1052 | |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1053 | // report any errors in the above loop and exit |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1054 | if (!open_device_failures.empty()) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1055 | error(EXIT_FAILURE, 0, "Unable to open log device%s '%s'.", |
| 1056 | open_device_failures.size() > 1 ? "s" : "", Join(open_device_failures, ",").c_str()); |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1057 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1058 | if (!clear_failures.empty()) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1059 | error(EXIT_FAILURE, 0, "failed to clear the '%s' log%s.", Join(clear_failures, ",").c_str(), |
| 1060 | clear_failures.size() > 1 ? "s" : ""); |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1061 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1062 | if (!set_size_failures.empty()) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1063 | error(EXIT_FAILURE, 0, "failed to set the '%s' log size%s.", |
| 1064 | Join(set_size_failures, ",").c_str(), set_size_failures.size() > 1 ? "s" : ""); |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1065 | } |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1066 | if (!get_size_failures.empty()) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1067 | error(EXIT_FAILURE, 0, "failed to get the readable '%s' log size%s.", |
| 1068 | Join(get_size_failures, ",").c_str(), get_size_failures.size() > 1 ? "s" : ""); |
Mark Salyzyn | 7ccdb90 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 1069 | } |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1070 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 1071 | if (setPruneList) { |
Traian Schiau | 9f97860 | 2015-04-10 15:51:39 +0300 | [diff] [blame] | 1072 | size_t len = strlen(setPruneList); |
Tom Cherry | c8c906e | 2019-12-06 11:01:51 -0800 | [diff] [blame] | 1073 | if (android_logger_set_prune_list(logger_list.get(), setPruneList, len)) { |
| 1074 | error(EXIT_FAILURE, 0, "Failed to set the prune list."); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 1075 | } |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1076 | return EXIT_SUCCESS; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 1077 | } |
| 1078 | |
Mark Salyzyn | c402bc7 | 2014-04-01 17:19:47 -0700 | [diff] [blame] | 1079 | if (printStatistics || getPruneList) { |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1080 | std::string buf(8192, '\0'); |
| 1081 | size_t ret_length = 0; |
| 1082 | int retry = 32; |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 1083 | |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1084 | for (; retry >= 0; --retry) { |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 1085 | if (getPruneList) { |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1086 | android_logger_get_prune_list(logger_list.get(), buf.data(), buf.size()); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 1087 | } else { |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1088 | android_logger_get_statistics(logger_list.get(), buf.data(), buf.size()); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 1089 | } |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1090 | |
| 1091 | ret_length = atol(buf.c_str()); |
| 1092 | if (ret_length < 3) { |
| 1093 | error(EXIT_FAILURE, 0, "Failed to read data."); |
| 1094 | } |
| 1095 | |
| 1096 | if (ret_length < buf.size()) { |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 1097 | break; |
| 1098 | } |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1099 | |
| 1100 | buf.resize(ret_length + 1); |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 1101 | } |
| 1102 | |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1103 | if (retry < 0) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1104 | error(EXIT_FAILURE, 0, "Failed to read data."); |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 1105 | } |
| 1106 | |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1107 | buf.resize(ret_length); |
| 1108 | if (buf.back() == '\f') { |
| 1109 | buf.pop_back(); |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
Tom Cherry | f30875b | 2019-12-06 13:33:11 -0800 | [diff] [blame] | 1112 | // Remove the byte count prefix |
| 1113 | const char* cp = buf.c_str(); |
| 1114 | while (isdigit(*cp)) ++cp; |
| 1115 | if (*cp == '\n') ++cp; |
| 1116 | |
| 1117 | size_t len = strlen(cp); |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1118 | TEMP_FAILURE_RETRY(write(output_fd_.get(), cp, len)); |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1119 | return EXIT_SUCCESS; |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 1120 | } |
| 1121 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1122 | if (getLogSize || setLogSize || clearLog) return EXIT_SUCCESS; |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1123 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1124 | SetupOutputAndSchedulingPolicy(!(mode & ANDROID_LOG_NONBLOCK)); |
The Android Open Source Project | 190995d | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1125 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1126 | while (!max_count_ || print_count_ < max_count_) { |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1127 | struct log_msg log_msg; |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1128 | int ret = android_logger_list_read(logger_list.get(), &log_msg); |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 1129 | if (!ret) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1130 | error(EXIT_FAILURE, 0, R"init(Unexpected EOF! |
Tom Cherry | a59bde4 | 2019-11-21 10:31:06 -0800 | [diff] [blame] | 1131 | |
| 1132 | This means that either logd crashed, or more likely, this instance of logcat was unable to read log |
| 1133 | messages as quickly as they were being produced. |
| 1134 | |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1135 | If you have enabled significant logging, look into using the -G option to increase log buffer sizes.)init"); |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | if (ret < 0) { |
Mark Salyzyn | e5f043c | 2017-03-01 08:30:06 -0800 | [diff] [blame] | 1139 | if (ret == -EAGAIN) break; |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1140 | |
| 1141 | if (ret == -EIO) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1142 | error(EXIT_FAILURE, 0, "Unexpected EOF!"); |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1143 | } |
| 1144 | if (ret == -EINVAL) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1145 | error(EXIT_FAILURE, 0, "Unexpected length."); |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1146 | } |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1147 | error(EXIT_FAILURE, errno, "Logcat read failure"); |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1148 | } |
| 1149 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1150 | if (log_msg.id() > LOG_ID_MAX) { |
Tom Cherry | 9684088 | 2019-12-06 10:25:37 -0800 | [diff] [blame] | 1151 | error(EXIT_FAILURE, 0, "Unexpected log id (%d) over LOG_ID_MAX (%d).", log_msg.id(), |
| 1152 | LOG_ID_MAX); |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1153 | } |
| 1154 | |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1155 | PrintDividers(log_msg.id(), printDividers); |
| 1156 | |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1157 | if (print_binary_) { |
| 1158 | TEMP_FAILURE_RETRY(write(output_fd_.get(), &log_msg, log_msg.len())); |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1159 | } else { |
Tom Cherry | fb1373a | 2019-10-29 07:05:24 -0700 | [diff] [blame] | 1160 | ProcessBuffer(&log_msg); |
Mark Salyzyn | 2a8a6aa | 2013-11-22 10:55:48 -0800 | [diff] [blame] | 1161 | } |
| 1162 | } |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1163 | return EXIT_SUCCESS; |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 1164 | } |
| 1165 | |
Tom Cherry | d8ea11f | 2019-10-30 13:51:03 -0700 | [diff] [blame] | 1166 | int main(int argc, char** argv) { |
Tom Cherry | b1cf428 | 2019-10-24 17:35:26 -0700 | [diff] [blame] | 1167 | Logcat logcat; |
| 1168 | return logcat.Run(argc, argv); |
Mark Salyzyn | 2f1a9a4 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 1169 | } |