Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 5 | #include "debugd/src/log_tool.h" |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 6 | |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 7 | #include <glob.h> |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 8 | #include <grp.h> |
| 9 | #include <inttypes.h> |
Chinglin Yu | aeb4ec7 | 2018-12-10 18:53:30 +0800 | [diff] [blame] | 10 | #include <lzma.h> |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 11 | #include <pwd.h> |
| 12 | #include <stdint.h> |
| 13 | #include <sys/types.h> |
| 14 | #include <unistd.h> |
Ben Chan | 8e9f6d0 | 2017-09-26 23:04:21 -0700 | [diff] [blame] | 15 | #include <memory> |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 16 | #include <string> |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 17 | #include <utility> |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Ben Chan | ab93abf | 2017-01-24 13:32:51 -0800 | [diff] [blame] | 20 | #include <base/base64.h> |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 21 | #include <base/files/file.h> |
| 22 | #include <base/files/file_path.h> |
Ben Chan | cd8fda4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 23 | #include <base/files/file_util.h> |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 24 | #include <base/json/json_writer.h> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 25 | #include <base/logging.h> |
Ben Chan | 9953a59 | 2014-02-05 23:32:00 -0800 | [diff] [blame] | 26 | #include <base/strings/string_split.h> |
| 27 | #include <base/strings/string_util.h> |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 28 | #include <base/strings/stringprintf.h> |
| 29 | #include <base/strings/utf_string_conversion_utils.h> |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 30 | #include <base/values.h> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 31 | |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 32 | #include <chromeos/dbus/service_constants.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 33 | #include <shill/dbus-proxies.h> |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 34 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 35 | #include "debugd/src/constants.h" |
Chinglin Yu | aeb4ec7 | 2018-12-10 18:53:30 +0800 | [diff] [blame] | 36 | #include "debugd/src/perf_tool.h" |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 37 | #include "debugd/src/process_with_output.h" |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 38 | |
Ereth McKnight-MacNeil | ca3fff2 | 2021-01-21 23:31:40 -0800 | [diff] [blame] | 39 | #include <brillo/files/safe_fd.h> |
| 40 | #include <brillo/files/file_util.h> |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 41 | #include "brillo/key_value_store.h" |
| 42 | #include <brillo/osrelease_reader.h> |
mhasank | 86c46c7 | 2020-08-13 15:36:29 -0700 | [diff] [blame] | 43 | #include <brillo/cryptohome.h> |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 44 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 45 | namespace debugd { |
| 46 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 47 | using std::string; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 48 | |
Eric Caruso | 96d03d3 | 2017-04-25 18:01:17 -0700 | [diff] [blame] | 49 | using Strings = std::vector<string>; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 50 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 51 | namespace { |
| 52 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 53 | const char kRoot[] = "root"; |
| 54 | const char kShell[] = "/bin/sh"; |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 55 | constexpr char kLsbReleasePath[] = "/etc/lsb-release"; |
mhasank | 80cbe4d | 2020-04-02 22:46:08 -0700 | [diff] [blame] | 56 | constexpr char kArcBugReportBackupFileName[] = "arc-bugreport.log"; |
mhasank | d2b8488 | 2020-05-04 17:02:19 -0700 | [diff] [blame] | 57 | constexpr char kArcBugReportBackupKey[] = "arc-bugreport-backup"; |
mhasank | 80cbe4d | 2020-04-02 22:46:08 -0700 | [diff] [blame] | 58 | constexpr char kDaemonStoreBaseDir[] = "/run/daemon-store/debugd/"; |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 59 | |
| 60 | // Minimum time in seconds needed to allow shill to test active connections. |
| 61 | const int kConnectionTesterTimeoutSeconds = 5; |
Ben Chan | f6cd93a | 2012-10-14 19:37:00 -0700 | [diff] [blame] | 62 | |
Chinglin Yu | aeb4ec7 | 2018-12-10 18:53:30 +0800 | [diff] [blame] | 63 | // Default running perf for 2 seconds. |
| 64 | constexpr const int kPerfDurationSecs = 2; |
Chinglin Yu | 3c8d0a2 | 2019-02-20 11:32:52 +0800 | [diff] [blame] | 65 | // TODO(chinglinyu) Remove after crbug/934702 is fixed. |
| 66 | // The following description is added to 'perf-data' as a temporary solution |
| 67 | // before the update of feedback disclosure to users is done in crbug/934702. |
| 68 | constexpr const char kPerfDataDescription[] = |
| 69 | "perf-data contains performance profiling information about how much time " |
| 70 | "the system spends on various activities (program execution stack traces). " |
| 71 | "This might reveal some information about what system features and " |
| 72 | "resources are being used. The full detail of perf-data can be found in " |
| 73 | "the PerfDataProto protocol buffer message type in the chromium source " |
| 74 | "repository.\n"; |
Chinglin Yu | aeb4ec7 | 2018-12-10 18:53:30 +0800 | [diff] [blame] | 75 | |
Eric Caruso | a879fd9 | 2017-10-11 12:57:10 -0700 | [diff] [blame] | 76 | #define CMD_KERNEL_MODULE_PARAMS(module_name) \ |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 77 | "cd /sys/module/" #module_name "/parameters 2>/dev/null && grep -sH ^ *" |
Eric Caruso | a879fd9 | 2017-10-11 12:57:10 -0700 | [diff] [blame] | 78 | |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 79 | using Log = LogTool::Log; |
| 80 | constexpr Log::LogType kCommand = Log::kCommand; |
| 81 | constexpr Log::LogType kFile = Log::kFile; |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 82 | constexpr Log::LogType kGlob = Log::kGlob; |
mhasank | af5251d | 2020-04-29 18:53:03 -0700 | [diff] [blame] | 83 | |
| 84 | class ArcBugReportLog : public LogTool::Log { |
| 85 | public: |
| 86 | ArcBugReportLog() |
| 87 | : Log(kCommand, |
| 88 | "arc-bugreport", |
| 89 | "/usr/bin/nsenter -t1 -m /usr/sbin/android-sh -c " |
| 90 | "/system/bin/arc-bugreport", |
| 91 | kRoot, |
| 92 | kRoot, |
| 93 | 10 * 1024 * 1024 /*10 MiB*/, |
| 94 | LogTool::Encoding::kUtf8) {} |
| 95 | |
| 96 | virtual ~ArcBugReportLog() = default; |
| 97 | }; |
mhasank | 80cbe4d | 2020-04-02 22:46:08 -0700 | [diff] [blame] | 98 | |
Miriam Zimmerman | d91d8e7 | 2019-06-27 12:24:04 -0700 | [diff] [blame] | 99 | // NOTE: IF YOU ADD AN ENTRY TO THIS LIST, PLEASE: |
| 100 | // * add a row to http://go/cros-feedback-audit and fill it out |
Miriam Zimmerman | 4f142ba | 2020-06-01 14:15:21 -0700 | [diff] [blame] | 101 | // * email cros-telemetry@ |
Miriam Zimmerman | d91d8e7 | 2019-06-27 12:24:04 -0700 | [diff] [blame] | 102 | // (Eventually we'll have a better process, but for now please do this.) |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 103 | // clang-format off |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 104 | const std::vector<Log> kCommandLogs { |
Mike Frysinger | b035099 | 2018-09-14 13:45:35 -0400 | [diff] [blame] | 105 | // We need to enter init's mount namespace because it has /home/chronos |
| 106 | // mounted which is where the consent knob lives. We don't have that mount |
| 107 | // in our own mount namespace (by design). https://crbug.com/884249 |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 108 | {kCommand, "CLIENT_ID", "/usr/bin/nsenter -t1 -m /usr/bin/metrics_client -i", |
| 109 | kRoot, kDebugfsGroup}, |
| 110 | {kCommand, "LOGDATE", "/bin/date"}, |
Yusuke Sato | 27a3167 | 2019-04-29 15:26:37 -0700 | [diff] [blame] | 111 | // We need to enter init's mount namespace to access /home/root. Also, we use |
| 112 | // neither ARC container's mount namespace (with android-sh) nor |
| 113 | // /opt/google/containers/android/rootfs/android-data/ so that we can get |
| 114 | // results even when the container is down. |
| 115 | {kCommand, "android_app_storage", "/usr/bin/nsenter -t1 -m " |
| 116 | "/bin/sh -c \"/usr/bin/du -h /home/root/*/android-data/data/\"", |
| 117 | kRoot, kDebugfsGroup}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 118 | {kFile, "atrus_logs", "/var/log/atrus.log"}, |
| 119 | {kFile, "authpolicy", "/var/log/authpolicy.log"}, |
Kimiyuki Onaka | fc37289 | 2020-11-24 23:28:20 +0900 | [diff] [blame] | 120 | #if USE_ARCVM |
| 121 | {kCommand, "arcvm_console_output", "/usr/bin/vm_pstore_dump", "crosvm", |
| 122 | "crosvm", Log::kDefaultMaxBytes, LogTool::Encoding::kAutodetect, true}, |
| 123 | #endif // USE_ARCVM |
Brian Norris | afc9f63 | 2019-05-09 14:08:28 -0700 | [diff] [blame] | 124 | {kCommand, "bootstat_summary", "/usr/bin/bootstat_summary", |
| 125 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 126 | Log::kDefaultMaxBytes, LogTool::Encoding::kAutodetect, true}, |
Craig Hesling | 5c384b5 | 2019-04-20 15:18:06 -0700 | [diff] [blame] | 127 | {kFile, "bio_crypto_init.LATEST", |
| 128 | "/var/log/bio_crypto_init/bio_crypto_init.LATEST"}, |
| 129 | {kFile, "bio_crypto_init.PREVIOUS", |
| 130 | "/var/log/bio_crypto_init/bio_crypto_init.PREVIOUS"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 131 | {kFile, "biod.LATEST", "/var/log/biod/biod.LATEST"}, |
| 132 | {kFile, "biod.PREVIOUS", "/var/log/biod/biod.PREVIOUS"}, |
Craig Hesling | 4c3891e | 2019-04-20 12:53:54 -0700 | [diff] [blame] | 133 | {kFile, "bio_fw_updater.LATEST", "/var/log/biod/bio_fw_updater.LATEST"}, |
| 134 | {kFile, "bio_fw_updater.PREVIOUS", "/var/log/biod/bio_fw_updater.PREVIOUS"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 135 | {kFile, "bios_info", "/var/log/bios_info.txt"}, |
| 136 | {kCommand, "bios_log", "cat /sys/firmware/log " |
| 137 | "/proc/device-tree/chosen/ap-console-buffer 2>/dev/null"}, |
| 138 | {kFile, "bios_times", "/var/log/bios_times.txt"}, |
Anand K Mistry | ccceb1e | 2020-01-16 14:00:49 +1100 | [diff] [blame] | 139 | // Slow or non-responsive block devices could cause this command to stall. Use |
| 140 | // a timeout to prevent this command from blocking log fetching. This command |
| 141 | // is expected to take O(100ms) in the normal case. |
| 142 | {kCommand, "blkid", "timeout -s KILL 5s /sbin/blkid", kRoot, kRoot}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 143 | {kFile, "buddyinfo", "/proc/buddyinfo"}, |
| 144 | {kCommand, "cbi_info", "/usr/share/userfeedback/scripts/cbi_info", kRoot, |
| 145 | kRoot}, |
| 146 | {kFile, "cheets_log", "/var/log/arc.log"}, |
| 147 | {kFile, "clobber.log", "/var/log/clobber.log"}, |
| 148 | {kFile, "clobber-state.log", "/var/log/clobber-state.log"}, |
Sonny Rao | bd3dc00 | 2020-05-27 21:40:35 -0700 | [diff] [blame] | 149 | {kCommand, "chromeos-pgmem", "/usr/bin/chromeos-pgmem", kRoot, kRoot}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 150 | {kFile, "chrome_system_log", "/var/log/chrome/chrome"}, |
| 151 | {kFile, "chrome_system_log.PREVIOUS", "/var/log/chrome/chrome.PREVIOUS"}, |
Mike Frysinger | 32cdf3e | 2017-08-14 18:17:06 -0400 | [diff] [blame] | 152 | // There might be more than one record, so grab them all. |
| 153 | // Plus, for <linux-3.19, it's named "console-ramoops", but for newer |
| 154 | // versions, it's named "console-ramoops-#". |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 155 | {kGlob, "console-ramoops", "/sys/fs/pstore/console-ramoops*"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 156 | {kFile, "cpuinfo", "/proc/cpuinfo"}, |
| 157 | {kFile, "cr50_version", "/var/cache/cr50-version"}, |
Nicolas Boichat | f3dd82d | 2020-09-07 15:11:15 +0800 | [diff] [blame] | 158 | {kFile, "cros_ec.log", "/var/log/cros_ec.log", |
| 159 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 160 | Log::kDefaultMaxBytes, LogTool::Encoding::kUtf8}, |
| 161 | {kFile, "cros_ec.previous", "/var/log/cros_ec.previous", |
| 162 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 163 | Log::kDefaultMaxBytes, LogTool::Encoding::kUtf8}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 164 | {kFile, "cros_ec_panicinfo", "/sys/kernel/debug/cros_ec/panicinfo", |
Nicolas Boichat | 28272d7 | 2020-09-03 09:10:44 +0800 | [diff] [blame] | 165 | SandboxedProcess::kDefaultUser, kDebugfsGroup, Log::kDefaultMaxBytes, |
| 166 | LogTool::Encoding::kBase64}, |
Stephen Boyd | f00c5a0 | 2020-09-10 19:11:35 -0700 | [diff] [blame] | 167 | {kCommand, "cros_ec_pdinfo", |
| 168 | "for port in 0 1 2 3 4 5 6 7 8; do " |
| 169 | "echo \"-----------\"; " |
| 170 | // stderr output just tells us it failed |
| 171 | "ectool usbpd \"${port}\" 2>/dev/null || break; " |
| 172 | "done", kRoot, kRoot}, |
Nicolas Boichat | f3dd82d | 2020-09-07 15:11:15 +0800 | [diff] [blame] | 173 | {kFile, "cros_fp.previous", "/var/log/cros_fp.previous", |
| 174 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 175 | Log::kDefaultMaxBytes, LogTool::Encoding::kUtf8}, |
| 176 | {kFile, "cros_fp.log", "/var/log/cros_fp.log", |
| 177 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 178 | Log::kDefaultMaxBytes, LogTool::Encoding::kUtf8}, |
| 179 | {kFile, "cros_ish.previous", "/var/log/cros_ish.previous", |
| 180 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 181 | Log::kDefaultMaxBytes, LogTool::Encoding::kUtf8}, |
| 182 | {kFile, "cros_ish.log", "/var/log/cros_ish.log", |
| 183 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 184 | Log::kDefaultMaxBytes, LogTool::Encoding::kUtf8}, |
Nicolas Boichat | 579ccf3 | 2020-08-31 11:17:21 +0800 | [diff] [blame] | 185 | {kFile, "cros_scp.previous", "/var/log/cros_scp.previous", |
| 186 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 187 | 64 * 1024, LogTool::Encoding::kUtf8}, |
| 188 | {kFile, "cros_scp.log", "/var/log/cros_scp.log", |
| 189 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 190 | 64 * 1024, LogTool::Encoding::kUtf8}, |
David Munro | 0eb1ac3 | 2020-08-19 22:22:56 +1000 | [diff] [blame] | 191 | {kCommand, "crosvm.log", "nsenter -t1 -m /bin/sh -c 'tail -n+1" |
| 192 | " /run/daemon-store/crosvm/*/log/*.log.1" |
| 193 | " /run/daemon-store/crosvm/*/log/*.log'", kRoot, kRoot}, |
Steven 'Steve' Kendall | 33f7219 | 2021-02-16 16:36:16 -0500 | [diff] [blame^] | 194 | // dmesg: add full timestamps to dmesg to match other logs. |
Jorge Lucangeli Obes | af8f79c | 2020-11-13 08:54:55 -0500 | [diff] [blame] | 195 | // 'dmesg' needs CAP_SYSLOG. |
Steven 'Steve' Kendall | 33f7219 | 2021-02-16 16:36:16 -0500 | [diff] [blame^] | 196 | {kCommand, "dmesg", "TZ=UTC /bin/dmesg --time-format iso", kRoot, kRoot}, |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 197 | {kGlob, "drm_gem_objects", "/sys/kernel/debug/dri/?/gem", |
Stephen Boyd | a828716 | 2020-07-30 18:07:53 -0700 | [diff] [blame] | 198 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 199 | {kGlob, "drm_state", "/sys/kernel/debug/dri/?/state", |
Stephen Boyd | a828716 | 2020-07-30 18:07:53 -0700 | [diff] [blame] | 200 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 201 | {kFile, "ec_info", "/var/log/ec_info.txt"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 202 | {kCommand, "edid-decode", |
Stephen Boyd | af3118b | 2020-08-11 11:42:22 -0700 | [diff] [blame] | 203 | "for f in /sys/class/drm/card?-*/edid; do " |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 204 | "echo \"----------- ${f}\"; " |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 205 | // edid-decode's stderr output is redundant, so silence it. |
Jeffrey Kardatzke | 9ba9f32 | 2019-08-29 10:23:14 -0700 | [diff] [blame] | 206 | "edid-decode \"${f}\" 2>/dev/null; " |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 207 | "done"}, |
| 208 | {kFile, "eventlog", "/var/log/eventlog.txt"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 209 | {kCommand, "font_info", "/usr/share/userfeedback/scripts/font_info"}, |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 210 | {kGlob, "framebuffer", "/sys/kernel/debug/dri/?/framebuffer", |
Kuo-Hsin Yang | 95296e1 | 2020-03-06 17:52:35 +0800 | [diff] [blame] | 211 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
Daniel Campello | 9f0b2b8 | 2020-10-23 11:01:01 -0600 | [diff] [blame] | 212 | {kCommand, "fwupd_state", "/sbin/initctl emit fwupdtool-getdevices;" |
| 213 | "cat /var/lib/fwupd/state.json", kRoot, kRoot}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 214 | {kCommand, "sensor_info", "/usr/share/userfeedback/scripts/sensor_info"}, |
| 215 | {kFile, "hammerd", "/var/log/hammerd.log"}, |
| 216 | {kCommand, "hardware_class", "/usr/bin/crossystem hwid"}, |
Yong Hong | 15e4b03 | 2020-03-05 15:41:31 +0800 | [diff] [blame] | 217 | {kFile, "hardware_verification_report", |
| 218 | "/var/cache/hardware_verifier.result"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 219 | {kCommand, "hostname", "/bin/hostname"}, |
| 220 | {kFile, "i915_gem_gtt", "/sys/kernel/debug/dri/0/i915_gem_gtt", |
| 221 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
| 222 | {kFile, "i915_gem_objects", "/sys/kernel/debug/dri/0/i915_gem_objects", |
| 223 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 224 | {kCommand, "i915_error_state", |
| 225 | "/usr/bin/xz -c /sys/kernel/debug/dri/0/i915_error_state 2>/dev/null", |
| 226 | SandboxedProcess::kDefaultUser, kDebugfsGroup, Log::kDefaultMaxBytes, |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 227 | LogTool::Encoding::kBase64}, |
Evan Benn | 0e373cc | 2021-01-07 15:10:26 +1100 | [diff] [blame] | 228 | {kFile, "amdgpu_gem_info", "/sys/kernel/debug/dri/0/amdgpu_gem_info", |
| 229 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
| 230 | {kFile, "amdgpu_gtt_mm", "/sys/kernel/debug/dri/0/amdgpu_gtt_mm", |
| 231 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
| 232 | {kFile, "amdgpu_vram_mm", "/sys/kernel/debug/dri/0/amdgpu_vram_mm", |
| 233 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 234 | {kCommand, "ifconfig", "/bin/ifconfig -a"}, |
| 235 | {kFile, "input_devices", "/proc/bus/input/devices"}, |
Eric Caruso | b1820c0 | 2017-08-24 15:39:56 -0700 | [diff] [blame] | 236 | // Hardware capabilities of the wiphy device. |
Alex Levin | e1c6d57 | 2019-09-17 14:45:33 -0700 | [diff] [blame] | 237 | {kFile, "interrupts", "/proc/interrupts"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 238 | {kCommand, "iw_list", "/usr/sbin/iw list"}, |
Eric Caruso | a879fd9 | 2017-10-11 12:57:10 -0700 | [diff] [blame] | 239 | #if USE_IWLWIFI_DUMP |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 240 | {kCommand, "iwlmvm_module_params", CMD_KERNEL_MODULE_PARAMS(iwlmvm)}, |
| 241 | {kCommand, "iwlwifi_module_params", CMD_KERNEL_MODULE_PARAMS(iwlwifi)}, |
Eric Caruso | a879fd9 | 2017-10-11 12:57:10 -0700 | [diff] [blame] | 242 | #endif // USE_IWLWIFI_DUMP |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 243 | {kGlob, "kernel-crashes", "/var/spool/crash/kernel.*.kcrash", |
Mike Frysinger | 2abf7a1 | 2020-12-16 05:39:02 -0500 | [diff] [blame] | 244 | SandboxedProcess::kDefaultUser, "crash-access"}, |
Anand K Mistry | ccceb1e | 2020-01-16 14:00:49 +1100 | [diff] [blame] | 245 | {kCommand, "lsblk", "timeout -s KILL 5s lsblk -a", kRoot, kRoot, |
| 246 | Log::kDefaultMaxBytes, LogTool::Encoding::kAutodetect, true}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 247 | {kCommand, "lsmod", "lsmod"}, |
| 248 | {kCommand, "lspci", "/usr/sbin/lspci"}, |
| 249 | {kCommand, "lsusb", "lsusb && lsusb -t"}, |
Kuo-Hsin Yang | 66d8983 | 2020-02-10 17:22:28 +0800 | [diff] [blame] | 250 | {kFile, "mali_memory", "/sys/kernel/debug/mali0/gpu_memory", |
| 251 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 252 | {kFile, "memd.parameters", "/var/log/memd/memd.parameters"}, |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 253 | {kGlob, "memd clips", "/var/log/memd/memd.clip*"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 254 | {kFile, "meminfo", "/proc/meminfo"}, |
| 255 | {kCommand, "memory_spd_info", |
| 256 | // mosys may use 'i2c-dev', which may not be loaded yet. |
| 257 | "modprobe i2c-dev 2>/dev/null && mosys -l memory spd print all 2>/dev/null", |
| 258 | kRoot, kDebugfsGroup}, |
Simon Que | cb63b9c | 2017-06-19 14:53:31 -0400 | [diff] [blame] | 259 | // The sed command finds the EDID blob (starting the line after "value:") and |
| 260 | // replaces the serial number with all zeroes. |
| 261 | // |
| 262 | // The EDID is printed as a hex dump over several lines, each line containing |
| 263 | // the contents of 16 bytes. The first 16 bytes are broken down as follows: |
| 264 | // uint64_t fixed_pattern; // Always 00 FF FF FF FF FF FF 00. |
| 265 | // uint16_t manufacturer_id; // Manufacturer ID, encoded as PNP IDs. |
| 266 | // uint16_t product_code; // Manufacturer product code, little-endian. |
| 267 | // uint32_t serial_number; // Serial number, little-endian. |
| 268 | // Source: https://en.wikipedia.org/wiki/EDID#EDID_1.3_data_format |
| 269 | // |
| 270 | // The subsequent substitution command looks for the fixed pattern followed by |
| 271 | // two 32-bit fields (manufacturer + product, serial number). It replaces the |
| 272 | // latter field with 8 bytes of zeroes. |
| 273 | // |
| 274 | // TODO(crbug.com/731133): Remove the sed command once modetest itself can |
| 275 | // remove serial numbers. |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 276 | {kCommand, "modetest", |
| 277 | "(modetest; modetest -M evdi; modetest -M udl) | " |
| 278 | "sed -E '/EDID/ {:a;n;/value:/!ba;n;" |
| 279 | "s/(00f{12}00)([0-9a-f]{8})([0-9a-f]{8})/\\1\\200000000/}'", |
| 280 | kRoot, kRoot}, |
| 281 | {kFile, "mount-encrypted", "/var/log/mount-encrypted.log"}, |
| 282 | {kFile, "mountinfo", "/proc/1/mountinfo"}, |
| 283 | {kCommand, "netlog", |
Brian Norris | 7258846 | 2021-01-25 19:32:31 -0800 | [diff] [blame] | 284 | "/usr/share/userfeedback/scripts/getmsgs /var/log/net.log", |
| 285 | SandboxedProcess::kDefaultUser, SandboxedProcess::kDefaultGroup, |
| 286 | Log::kDefaultMaxBytes, LogTool::Encoding::kUtf8}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 287 | {kFile, "nvmap_iovmm", "/sys/kernel/debug/nvmap/iovmm/allocations", |
| 288 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
| 289 | {kCommand, "oemdata", "/usr/share/cros/oemdata.sh", kRoot, kRoot}, |
Kuo-Hsin Yang | a69ecc6 | 2020-03-11 17:37:11 +0800 | [diff] [blame] | 290 | {kFile, "pagetypeinfo", "/proc/pagetypeinfo", kRoot}, |
Jack Rosenthal | 3cf794a | 2020-02-19 13:32:56 -0700 | [diff] [blame] | 291 | {kFile, "platform_identity_name", |
| 292 | "/run/chromeos-config/v1/identity/platform-name"}, |
| 293 | {kFile, "platform_identity_model", "/run/chromeos-config/v1/name"}, |
| 294 | {kFile, "platform_identity_sku", "/run/chromeos-config/v1/identity/sku-id"}, |
| 295 | {kFile, "platform_identity_whitelabel_tag", |
| 296 | "/run/chromeos-config/v1/identity/whitelabel-tag"}, |
| 297 | {kFile, "platform_identity_customization_id", |
| 298 | "/run/chromeos-config/v1/identity/customization-id"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 299 | {kCommand, "power_supply_info", "/usr/bin/power_supply_info"}, |
| 300 | {kCommand, "power_supply_sysfs", "/usr/bin/print_sysfs_power_supply_data"}, |
| 301 | {kFile, "powerd.LATEST", "/var/log/power_manager/powerd.LATEST"}, |
| 302 | {kFile, "powerd.PREVIOUS", "/var/log/power_manager/powerd.PREVIOUS"}, |
| 303 | {kFile, "powerd.out", "/var/log/powerd.out"}, |
| 304 | {kFile, "powerwash_count", "/var/log/powerwash_count"}, |
Brian Norris | 4cde3d1 | 2019-04-16 10:10:34 -0700 | [diff] [blame] | 305 | {kCommand, "ps", "/bin/ps auxZ"}, |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 306 | {kGlob, "qcom_fw_info", "/sys/kernel/debug/qcom_socinfo/*/*", |
Stephen Boyd | 57779f9 | 2020-12-15 23:24:31 -0800 | [diff] [blame] | 307 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
yusukes | 34171ba | 2017-04-27 15:46:01 -0700 | [diff] [blame] | 308 | // /proc/slabinfo is owned by root and has 0400 permission. |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 309 | {kFile, "slabinfo", "/proc/slabinfo", kRoot, kRoot}, |
| 310 | {kFile, "storage_info", "/var/log/storage_info.txt"}, |
| 311 | {kCommand, "swap_info", "/usr/share/cros/init/swap.sh status 2>/dev/null", |
| 312 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
| 313 | {kCommand, "syslog", |
| 314 | "/usr/share/userfeedback/scripts/getmsgs /var/log/messages"}, |
| 315 | {kCommand, "system_log_stats", |
| 316 | "echo 'BLOCK_SIZE=1024'; " |
| 317 | "find /var/log/ -type f -exec du --block-size=1024 {} + | sort -n -r", |
| 318 | kRoot, kRoot}, |
| 319 | {kCommand, "threads", "/bin/ps -T axo pid,ppid,spid,pcpu,ni,stat,time,comm"}, |
| 320 | {kFile, "tlsdate", "/var/log/tlsdate.log"}, |
Nick Sanders | ad5dc13 | 2019-11-15 15:59:42 -0800 | [diff] [blame] | 321 | {kCommand, "top thread", "/usr/bin/top -Hbc -w128 -n 1 | head -n 40"}, |
| 322 | {kCommand, "top memory", |
| 323 | "/usr/bin/top -o \"+%MEM\" -w128 -bcn 1 | head -n 57"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 324 | {kCommand, "touch_fw_version", |
Stephen Boyd | db9eb2f | 2020-08-11 11:25:41 -0700 | [diff] [blame] | 325 | "grep -aE" |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 326 | " -e 'synaptics: Touchpad model'" |
| 327 | " -e 'chromeos-[a-z]*-touch-[a-z]*-update'" |
| 328 | " /var/log/messages | tail -n 20"}, |
| 329 | {kCommand, "tpm-firmware-updater", "/usr/share/userfeedback/scripts/getmsgs " |
| 330 | "/var/log/tpm-firmware-updater.log"}, |
Mattias Nissler | 887dce2 | 2017-07-03 14:44:35 +0200 | [diff] [blame] | 331 | // TODO(jorgelo,mnissler): Don't run this as root. |
| 332 | // On TPM 1.2 devices this will likely require adding a new user to the 'tss' |
| 333 | // group. |
| 334 | // On TPM 2.0 devices 'get_version_info' uses D-Bus and therefore can run as |
| 335 | // any user. |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 336 | {kCommand, "tpm_version", "/usr/sbin/tpm-manager get_version_info", kRoot, |
| 337 | kRoot}, |
| 338 | {kCommand, "atmel_ts_refs", |
| 339 | "/opt/google/touch/scripts/atmel_tools.sh ts r", kRoot, kRoot}, |
| 340 | {kCommand, "atmel_tp_refs", |
| 341 | "/opt/google/touch/scripts/atmel_tools.sh tp r", kRoot, kRoot}, |
| 342 | {kCommand, "atmel_ts_deltas", |
| 343 | "/opt/google/touch/scripts/atmel_tools.sh ts d", kRoot, kRoot}, |
| 344 | {kCommand, "atmel_tp_deltas", |
| 345 | "/opt/google/touch/scripts/atmel_tools.sh tp d", kRoot, kRoot}, |
| 346 | {kFile, "stateful_trim_state", "/var/lib/trim/stateful_trim_state"}, |
| 347 | {kFile, "stateful_trim_data", "/var/lib/trim/stateful_trim_data"}, |
| 348 | {kFile, "ui_log", "/var/log/ui/ui.LATEST"}, |
| 349 | {kCommand, "uname", "/bin/uname -a"}, |
| 350 | {kCommand, "update_engine.log", |
| 351 | "cat $(ls -1tr /var/log/update_engine | tail -5 | sed" |
| 352 | " s.^./var/log/update_engine/.)"}, |
Chris Morin | ca15271 | 2019-05-03 13:17:28 -0700 | [diff] [blame] | 353 | {kFile, "upstart", "/var/log/upstart.log"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 354 | {kCommand, "uptime", "/usr/bin/cut -d' ' -f1 /proc/uptime"}, |
Prashant Malani | 9704ed0 | 2021-02-10 16:19:22 -0800 | [diff] [blame] | 355 | {kCommand, "usb4 devices", "/usr/libexec/debugd/helpers/usb4_devinfo_helper", |
| 356 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 357 | {kFile, "verified boot", "/var/log/debug_vboot_noisy.log"}, |
| 358 | {kFile, "vmlog.1.LATEST", "/var/log/vmlog/vmlog.1.LATEST"}, |
| 359 | {kFile, "vmlog.1.PREVIOUS", "/var/log/vmlog/vmlog.1.PREVIOUS"}, |
| 360 | {kFile, "vmlog.LATEST", "/var/log/vmlog/vmlog.LATEST"}, |
| 361 | {kFile, "vmlog.PREVIOUS", "/var/log/vmlog/vmlog.PREVIOUS"}, |
| 362 | {kFile, "vmstat", "/proc/vmstat"}, |
| 363 | {kFile, "vpd_2.0", "/var/log/vpd_2.0.txt"}, |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 364 | {kFile, "zram compressed data size", "/sys/block/zram0/compr_data_size"}, |
| 365 | {kFile, "zram original data size", "/sys/block/zram0/orig_data_size"}, |
| 366 | {kFile, "zram total memory used", "/sys/block/zram0/mem_used_total"}, |
| 367 | {kFile, "zram total reads", "/sys/block/zram0/num_reads"}, |
| 368 | {kFile, "zram total writes", "/sys/block/zram0/num_writes"}, |
| 369 | {kCommand, "zram new stats names", |
| 370 | "echo orig_size compr_size used_total limit used_max zero_pages migrated"}, |
| 371 | {kFile, "zram new stats values", "/sys/block/zram0/mm_stat"}, |
| 372 | {kFile, "cros_tp version", "/sys/class/chromeos/cros_tp/version"}, |
| 373 | {kCommand, "cros_tp console", "/usr/sbin/ectool --name=cros_tp console", |
| 374 | kRoot, kRoot}, |
| 375 | {kCommand, "cros_tp frame", "/usr/sbin/ectool --name=cros_tp tpframeget", |
| 376 | kRoot, kRoot}, |
| 377 | {kCommand, "crostini", "/usr/bin/cicerone_client --get_info"}, |
Sean Paul | bfc5c42 | 2020-07-24 11:03:51 -0400 | [diff] [blame] | 378 | // TODO(seanpaul): Once we've finished moving over to the upstream tracefs |
| 379 | // implementation, remove drm_trace_legacy. Tracked in |
| 380 | // b/163580546. |
| 381 | {kFile, "drm_trace_legacy", "/sys/kernel/debug/dri/trace", |
| 382 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
| 383 | {kFile, "drm_trace", "/sys/kernel/debug/tracing/instances/drm/trace", |
Sean Paul | 5ce118f | 2019-12-05 08:41:32 -0500 | [diff] [blame] | 384 | SandboxedProcess::kDefaultUser, kDebugfsGroup}, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 385 | // Stuff pulled out of the original list. These need access to the running X |
| 386 | // session, which we'd rather not give to debugd, or return info specific to |
| 387 | // the current session (in the setsid(2) sense), which is not useful for |
| 388 | // debugd |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 389 | // {kCommand, "env", "set"}, |
| 390 | // {kCommand, "setxkbmap", "/usr/bin/setxkbmap -print -query"}, |
| 391 | // {kCommand, "xrandr", "/usr/bin/xrandr --verbose} |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 392 | }; |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 393 | // clang-format on |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 394 | |
Junichi Uekawa | ba686c8 | 2020-09-01 16:24:24 +0900 | [diff] [blame] | 395 | // Extra logs are logs such as netstat and logcat which should appear in |
| 396 | // chrome://system but not in feedback reports. Open sockets may have privacy |
| 397 | // implications, and logcat is already incorporated via arc-bugreport. |
| 398 | // |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 399 | // clang-format off |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 400 | const std::vector<Log> kExtraLogs { |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 401 | #if USE_CELLULAR |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 402 | {kCommand, "mm-status", "/usr/bin/modem status"}, |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 403 | #endif // USE_CELLULAR |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 404 | {kCommand, "network-devices", "/usr/bin/connectivity show devices"}, |
| 405 | {kCommand, "network-services", "/usr/bin/connectivity show services"}, |
Jeffrey Kardatzke | 36791f2 | 2019-07-11 11:53:22 -0700 | [diff] [blame] | 406 | {kCommand, "wifi_status_no_anonymize", |
| 407 | "/usr/bin/network_diag --wifi-internal --no-log"}, |
Chris Morin | 253a2b0 | 2019-04-12 16:04:25 -0700 | [diff] [blame] | 408 | // --processes requires root. |
| 409 | {kCommand, "netstat", |
| 410 | "/sbin/ss --all --query inet --numeric --processes", kRoot, kRoot}, |
Kansho Nishida | 6ae546f | 2019-08-13 17:14:58 +0900 | [diff] [blame] | 411 | {kCommand, "logcat", |
| 412 | "/usr/bin/nsenter -t1 -m /usr/sbin/android-sh -c '/system/bin/logcat -d'", |
Chris Morin | 253a2b0 | 2019-04-12 16:04:25 -0700 | [diff] [blame] | 413 | kRoot, kRoot, Log::kDefaultMaxBytes, LogTool::Encoding::kUtf8}, |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 414 | }; |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 415 | // clang-format on |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 416 | |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 417 | // clang-format off |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 418 | const std::vector<Log> kFeedbackLogs { |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 419 | #if USE_CELLULAR |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 420 | {kCommand, "mm-status", "/usr/bin/modem status-feedback"}, |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 421 | #endif // USE_CELLULAR |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 422 | {kCommand, "network-devices", |
| 423 | "/usr/bin/connectivity show-feedback devices"}, |
| 424 | {kCommand, "network-services", |
| 425 | "/usr/bin/connectivity show-feedback services"}, |
Jeffrey Kardatzke | 36791f2 | 2019-07-11 11:53:22 -0700 | [diff] [blame] | 426 | {kCommand, "wifi_status", |
| 427 | "/usr/bin/network_diag --wifi-internal --no-log --anonymize"}, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 428 | }; |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 429 | // clang-format on |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 430 | |
Jeffrey Kardatzke | e3ec6fd | 2019-08-05 12:25:17 -0700 | [diff] [blame] | 431 | // Fills |dictionary| with the contents of the logs in |logs|. |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 432 | void GetLogsInDictionary(const std::vector<Log>& logs, |
hscham | 2311cc2 | 2020-10-28 12:13:10 +0900 | [diff] [blame] | 433 | base::Value* dictionary) { |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 434 | for (const Log& log : logs) { |
hscham | 2311cc2 | 2020-10-28 12:13:10 +0900 | [diff] [blame] | 435 | dictionary->SetStringKey(log.GetName(), log.GetLogData()); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
| 439 | // Serializes the |dictionary| into the file with the given |fd| in a JSON |
| 440 | // format. |
hscham | 2311cc2 | 2020-10-28 12:13:10 +0900 | [diff] [blame] | 441 | void SerializeLogsAsJSON(const base::Value& dictionary, |
Eric Caruso | 0b24188 | 2018-04-04 13:43:46 -0700 | [diff] [blame] | 442 | const base::ScopedFD& fd) { |
Eric Caruso | 96d03d3 | 2017-04-25 18:01:17 -0700 | [diff] [blame] | 443 | string logs_json; |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 444 | base::JSONWriter::WriteWithOptions( |
| 445 | dictionary, base::JSONWriter::OPTIONS_PRETTY_PRINT, &logs_json); |
Eric Caruso | 0b24188 | 2018-04-04 13:43:46 -0700 | [diff] [blame] | 446 | base::WriteFileDescriptor(fd.get(), logs_json.c_str(), logs_json.size()); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 449 | bool GetNamedLogFrom(const string& name, |
| 450 | const std::vector<Log>& logs, |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 451 | string* result) { |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 452 | for (const Log& log : logs) { |
| 453 | if (name == log.GetName()) { |
| 454 | *result = log.GetLogData(); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 455 | return true; |
| 456 | } |
| 457 | } |
| 458 | *result = "<invalid log name>"; |
| 459 | return false; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 460 | } |
| 461 | |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 462 | void GetLogsFrom(const std::vector<Log>& logs, LogTool::LogMap* map) { |
| 463 | for (const Log& log : logs) |
| 464 | (*map)[log.GetName()] = log.GetLogData(); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 465 | } |
| 466 | |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 467 | void GetLsbReleaseInfo(LogTool::LogMap* map) { |
| 468 | const base::FilePath lsb_release(kLsbReleasePath); |
| 469 | brillo::KeyValueStore store; |
| 470 | if (!store.Load(lsb_release)) { |
| 471 | // /etc/lsb-release might not be present (cros deploying a new |
| 472 | // configuration or no fields set at all). Just print a debug |
| 473 | // message and continue. |
| 474 | DLOG(INFO) << "Could not load fields from " << lsb_release.value(); |
| 475 | } else { |
| 476 | for (const auto& key : store.GetKeys()) { |
| 477 | std::string value; |
| 478 | store.GetString(key, &value); |
| 479 | (*map)[key] = value; |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | void GetOsReleaseInfo(LogTool::LogMap* map) { |
| 485 | brillo::OsReleaseReader reader; |
| 486 | reader.Load(); |
| 487 | for (const auto& key : reader.GetKeys()) { |
| 488 | std::string value; |
| 489 | reader.GetString(key, &value); |
| 490 | (*map)["os-release " + key] = value; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | void PopulateDictionaryValue(const LogTool::LogMap& map, |
hscham | 2311cc2 | 2020-10-28 12:13:10 +0900 | [diff] [blame] | 495 | base::Value* dictionary) { |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 496 | for (const auto& kv : map) { |
hscham | 2311cc2 | 2020-10-28 12:13:10 +0900 | [diff] [blame] | 497 | dictionary->SetStringKey(kv.first, kv.second); |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Chinglin Yu | aeb4ec7 | 2018-12-10 18:53:30 +0800 | [diff] [blame] | 501 | bool CompressXzBuffer(const std::vector<uint8_t>& in_buffer, |
| 502 | std::vector<uint8_t>* out_buffer) { |
| 503 | size_t out_size = lzma_stream_buffer_bound(in_buffer.size()); |
| 504 | out_buffer->resize(out_size); |
| 505 | size_t out_pos = 0; |
| 506 | |
| 507 | lzma_ret ret = lzma_easy_buffer_encode( |
| 508 | LZMA_PRESET_DEFAULT, LZMA_CHECK_CRC64, nullptr, in_buffer.data(), |
| 509 | in_buffer.size(), out_buffer->data(), &out_pos, out_size); |
| 510 | |
| 511 | if (ret != LZMA_OK) { |
| 512 | out_buffer->clear(); |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | out_buffer->resize(out_pos); |
| 517 | return true; |
| 518 | } |
| 519 | |
| 520 | void GetPerfData(LogTool::LogMap* map) { |
| 521 | // Run perf to collect system-wide performance profile when user triggers |
| 522 | // feedback report. Perf runs at sampling frequency of ~500 hz (499 is used |
| 523 | // to avoid sampling periodic system activities), with callstack in each |
| 524 | // sample (-g). |
| 525 | std::vector<std::string> perf_args = { |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 526 | "perf", "record", "-a", "-g", "-F", "499", |
Chinglin Yu | aeb4ec7 | 2018-12-10 18:53:30 +0800 | [diff] [blame] | 527 | }; |
| 528 | std::vector<uint8_t> perf_data; |
| 529 | int32_t status; |
| 530 | |
| 531 | debugd::PerfTool perf_tool; |
| 532 | if (!perf_tool.GetPerfOutput(kPerfDurationSecs, perf_args, &perf_data, |
| 533 | nullptr, &status, nullptr)) |
| 534 | return; |
| 535 | |
| 536 | // XZ compress the profile data. |
| 537 | std::vector<uint8_t> perf_data_xz; |
| 538 | if (!CompressXzBuffer(perf_data, &perf_data_xz)) |
| 539 | return; |
| 540 | |
| 541 | // Base64 encode the compressed data. |
| 542 | std::string perf_data_str(reinterpret_cast<const char*>(perf_data_xz.data()), |
| 543 | perf_data_xz.size()); |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 544 | (*map)["perf-data"] = std::string(kPerfDataDescription) + |
| 545 | LogTool::EncodeString(std::move(perf_data_str), |
| 546 | LogTool::Encoding::kBase64); |
Chinglin Yu | aeb4ec7 | 2018-12-10 18:53:30 +0800 | [diff] [blame] | 547 | } |
| 548 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 549 | } // namespace |
| 550 | |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 551 | Log::Log(Log::LogType type, |
| 552 | std::string name, |
| 553 | std::string data, |
| 554 | std::string user, |
| 555 | std::string group, |
| 556 | int64_t max_bytes, |
Brian Norris | afc9f63 | 2019-05-09 14:08:28 -0700 | [diff] [blame] | 557 | LogTool::Encoding encoding, |
| 558 | bool access_root_mount_ns) |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 559 | : type_(type), |
| 560 | name_(name), |
| 561 | data_(data), |
| 562 | user_(user), |
| 563 | group_(group), |
| 564 | max_bytes_(max_bytes), |
Brian Norris | afc9f63 | 2019-05-09 14:08:28 -0700 | [diff] [blame] | 565 | encoding_(encoding), |
| 566 | access_root_mount_ns_(access_root_mount_ns) {} |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 567 | |
| 568 | std::string Log::GetName() const { |
| 569 | return name_; |
| 570 | } |
| 571 | |
| 572 | std::string Log::GetLogData() const { |
| 573 | // The reason this code uses a switch statement on a type enum rather than |
| 574 | // using inheritance/virtual dispatch is so that all of the Log objects can |
| 575 | // be constructed statically. Switching to heap allocated subclasses of Log |
| 576 | // makes the code that declares all of the log entries much more verbose |
| 577 | // and harder to understand. |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 578 | std::string output; |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 579 | switch (type_) { |
| 580 | case kCommand: |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 581 | output = GetCommandLogData(); |
| 582 | break; |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 583 | case kFile: |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 584 | output = GetFileLogData(); |
| 585 | break; |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 586 | case kGlob: |
| 587 | output = GetGlobLogData(); |
| 588 | break; |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 589 | default: |
Mike Frysinger | df3be7f | 2020-12-16 03:17:42 -0500 | [diff] [blame] | 590 | DCHECK(false) << "unknown log type"; |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 591 | return "<unknown log type>"; |
| 592 | } |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 593 | |
| 594 | if (output.empty()) |
| 595 | return "<empty>"; |
| 596 | |
| 597 | return LogTool::EncodeString(std::move(output), encoding_); |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | // TODO(ellyjones): sandbox. crosbug.com/35122 |
| 601 | std::string Log::GetCommandLogData() const { |
Mike Frysinger | df3be7f | 2020-12-16 03:17:42 -0500 | [diff] [blame] | 602 | DCHECK_EQ(type_, kCommand); |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 603 | if (type_ != kCommand) |
| 604 | return "<log type mismatch>"; |
| 605 | std::string tailed_cmdline = |
| 606 | base::StringPrintf("%s | tail -c %" PRId64, data_.c_str(), max_bytes_); |
| 607 | ProcessWithOutput p; |
| 608 | if (minijail_disabled_for_test_) |
| 609 | p.set_use_minijail(false); |
| 610 | if (!user_.empty() && !group_.empty()) |
| 611 | p.SandboxAs(user_, group_); |
Brian Norris | afc9f63 | 2019-05-09 14:08:28 -0700 | [diff] [blame] | 612 | if (access_root_mount_ns_) |
| 613 | p.AllowAccessRootMountNamespace(); |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 614 | if (!p.Init()) |
| 615 | return "<not available>"; |
| 616 | p.AddArg(kShell); |
| 617 | p.AddStringOption("-c", tailed_cmdline); |
| 618 | if (p.Run()) |
| 619 | return "<not available>"; |
| 620 | std::string output; |
| 621 | p.GetOutput(&output); |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 622 | return output; |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 625 | // static |
| 626 | std::string Log::GetFileData(const base::FilePath& path, |
| 627 | int64_t max_bytes, |
| 628 | const std::string& user, |
| 629 | const std::string& group) { |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 630 | uid_t old_euid = geteuid(); |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 631 | uid_t new_euid = UidForUser(user); |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 632 | gid_t old_egid = getegid(); |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 633 | gid_t new_egid = GidForGroup(group); |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 634 | |
| 635 | if (new_euid == -1 || new_egid == -1) { |
| 636 | return "<not available>"; |
| 637 | } |
| 638 | |
| 639 | // Make sure to set group first, since if we set user first we lose root |
| 640 | // and therefore the ability to set our effective gid to arbitrary gids. |
| 641 | if (setegid(new_egid)) { |
| 642 | PLOG(ERROR) << "Failed to set effective group id to " << new_egid; |
| 643 | return "<not available>"; |
| 644 | } |
| 645 | if (seteuid(new_euid)) { |
| 646 | PLOG(ERROR) << "Failed to set effective user id to " << new_euid; |
| 647 | if (setegid(old_egid)) |
| 648 | PLOG(ERROR) << "Failed to restore effective group id to " << old_egid; |
| 649 | return "<not available>"; |
| 650 | } |
| 651 | |
| 652 | std::string contents; |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 653 | // Handle special files that don't properly report length/allow lseek. |
| 654 | if (base::FilePath("/dev").IsParent(path) || |
| 655 | base::FilePath("/proc").IsParent(path) || |
| 656 | base::FilePath("/sys").IsParent(path)) { |
| 657 | if (!base::ReadFileToString(path, &contents)) |
| 658 | contents = "<not available>"; |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 659 | if (contents.size() > max_bytes) |
| 660 | contents.erase(0, contents.size() - max_bytes); |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 661 | } else { |
| 662 | base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 663 | if (!file.IsValid()) { |
| 664 | contents = "<not available>"; |
| 665 | } else { |
| 666 | int64_t length = file.GetLength(); |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 667 | if (length > max_bytes) { |
| 668 | file.Seek(base::File::FROM_END, -max_bytes); |
| 669 | length = max_bytes; |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 670 | } |
| 671 | std::vector<char> buf(length); |
| 672 | int read = file.ReadAtCurrentPos(buf.data(), buf.size()); |
| 673 | if (read < 0) { |
| 674 | PLOG(ERROR) << "Could not read from file " << path.value(); |
| 675 | } else { |
| 676 | contents = std::string(buf.begin(), buf.begin() + read); |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 681 | // Make sure we restore our old euid/egid before returning. |
| 682 | if (seteuid(old_euid)) |
| 683 | PLOG(ERROR) << "Failed to restore effective user id to " << old_euid; |
| 684 | |
| 685 | if (setegid(old_egid)) |
| 686 | PLOG(ERROR) << "Failed to restore effective group id to " << old_egid; |
| 687 | |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 688 | return contents; |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Mike Frysinger | 020c240 | 2020-12-16 05:40:53 -0500 | [diff] [blame] | 691 | std::string Log::GetFileLogData() const { |
| 692 | DCHECK_EQ(type_, kFile); |
| 693 | if (type_ != kFile) |
| 694 | return "<log type mismatch>"; |
| 695 | |
| 696 | return GetFileData(base::FilePath(data_), max_bytes_, user_, group_); |
| 697 | } |
| 698 | |
| 699 | std::string Log::GetGlobLogData() const { |
| 700 | DCHECK_EQ(type_, kGlob); |
| 701 | if (type_ != kGlob) |
| 702 | return "<log type mismatch>"; |
| 703 | |
| 704 | // NB: base::FileEnumerator requires a directory to walk, and a pattern to |
| 705 | // match against each result. Here we accept full paths with globs in them. |
| 706 | glob_t g; |
| 707 | // NB: Feel free to add GLOB_BRACE if a user comes up. |
| 708 | int gret = glob(data_.c_str(), 0, nullptr, &g); |
| 709 | if (gret == GLOB_NOMATCH) { |
| 710 | globfree(&g); |
| 711 | return "<no matches>"; |
| 712 | } else if (gret) { |
| 713 | globfree(&g); |
| 714 | PLOG(ERROR) << "glob " << data_ << " failed"; |
| 715 | return "<not available>"; |
| 716 | } |
| 717 | |
| 718 | // The results array will hold 2 entries per file: the filename, and the |
| 719 | // results of reading that file. |
| 720 | size_t output_size = 0; |
| 721 | std::vector<std::string> results; |
| 722 | results.reserve(g.gl_pathc * 2); |
| 723 | |
| 724 | for (size_t pathc = 0; pathc < g.gl_pathc; ++pathc) { |
| 725 | const base::FilePath path(g.gl_pathv[pathc]); |
| 726 | std::string contents = GetFileData(path, max_bytes_, user_, group_); |
| 727 | // NB: The 3 represents the bytes we add in the output string below. |
| 728 | output_size += path.value().size() + contents.size() + 3; |
| 729 | results.push_back(path.value()); |
| 730 | results.push_back(contents); |
| 731 | } |
| 732 | globfree(&g); |
| 733 | |
| 734 | // Combine the results into a single string. We have a header with the |
| 735 | // filename followed by that file's contents. Very basic format. |
| 736 | std::string output; |
| 737 | output.reserve(output_size); |
| 738 | for (auto iter = results.begin(); iter != results.end(); ++iter) { |
| 739 | output += *iter + ":\n"; |
| 740 | ++iter; |
| 741 | output += *iter + "\n"; |
| 742 | } |
| 743 | |
| 744 | return output; |
| 745 | } |
| 746 | |
Fletcher Woodruff | 07c2853 | 2019-01-24 11:08:53 -0700 | [diff] [blame] | 747 | void Log::DisableMinijailForTest() { |
| 748 | minijail_disabled_for_test_ = true; |
| 749 | } |
| 750 | |
| 751 | // static |
| 752 | uid_t Log::UidForUser(const std::string& user) { |
| 753 | struct passwd entry; |
| 754 | struct passwd* result; |
| 755 | std::vector<char> buf(1024); |
| 756 | getpwnam_r(user.c_str(), &entry, &buf[0], buf.size(), &result); |
| 757 | if (!result) { |
| 758 | LOG(ERROR) << "User not found: " << user; |
| 759 | return -1; |
| 760 | } |
| 761 | return entry.pw_uid; |
| 762 | } |
| 763 | |
| 764 | // static |
| 765 | gid_t Log::GidForGroup(const std::string& group) { |
| 766 | struct group entry; |
| 767 | struct group* result; |
| 768 | std::vector<char> buf(1024); |
| 769 | getgrnam_r(group.c_str(), &entry, &buf[0], buf.size(), &result); |
| 770 | if (!result) { |
| 771 | LOG(ERROR) << "Group not found: " << group; |
| 772 | return -1; |
| 773 | } |
| 774 | return entry.gr_gid; |
| 775 | } |
| 776 | |
mhasank | af5251d | 2020-04-29 18:53:03 -0700 | [diff] [blame] | 777 | LogTool::LogTool( |
| 778 | scoped_refptr<dbus::Bus> bus, |
| 779 | std::unique_ptr<org::chromium::CryptohomeInterfaceProxyInterface> |
| 780 | cryptohome_proxy, |
| 781 | std::unique_ptr<LogTool::Log> arc_bug_report_log, |
| 782 | const base::FilePath& daemon_store_base_dir) |
| 783 | : bus_(bus), |
| 784 | cryptohome_proxy_(std::move(cryptohome_proxy)), |
| 785 | arc_bug_report_log_(std::move(arc_bug_report_log)), |
| 786 | daemon_store_base_dir_(daemon_store_base_dir) {} |
mhasank | 80cbe4d | 2020-04-02 22:46:08 -0700 | [diff] [blame] | 787 | |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 788 | LogTool::LogTool(scoped_refptr<dbus::Bus> bus) |
mhasank | af5251d | 2020-04-29 18:53:03 -0700 | [diff] [blame] | 789 | : LogTool(bus, |
| 790 | std::make_unique<org::chromium::CryptohomeInterfaceProxy>(bus), |
| 791 | std::make_unique<ArcBugReportLog>(), |
| 792 | base::FilePath(kDaemonStoreBaseDir)) {} |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 793 | |
mhasank | 7186aae | 2020-09-16 20:06:00 -0700 | [diff] [blame] | 794 | bool LogTool::IsUserHashValid(const std::string& userhash) { |
| 795 | return brillo::cryptohome::home::IsSanitizedUserName(userhash) && |
| 796 | base::PathExists(daemon_store_base_dir_.Append(userhash)); |
| 797 | } |
| 798 | |
Fletcher Woodruff | 70f2723 | 2019-01-24 11:41:34 -0700 | [diff] [blame] | 799 | void LogTool::CreateConnectivityReport(bool wait_for_results) { |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 800 | // Perform ConnectivityTrial to report connection state in feedback log. |
Ben Chan | 8e9f6d0 | 2017-09-26 23:04:21 -0700 | [diff] [blame] | 801 | auto shill = std::make_unique<org::chromium::flimflam::ManagerProxy>(bus_); |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 802 | // Give the connection trial time to test the connection and log the results |
| 803 | // before collecting the logs for feedback. |
| 804 | // TODO(silberst): Replace the simple approach of a single timeout with a more |
| 805 | // coordinated effort. |
Fletcher Woodruff | 70f2723 | 2019-01-24 11:41:34 -0700 | [diff] [blame] | 806 | if (shill && shill->CreateConnectivityReport(nullptr) && wait_for_results) |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 807 | sleep(kConnectionTesterTimeoutSeconds); |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 810 | string LogTool::GetLog(const string& name) { |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 811 | string result; |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 812 | GetNamedLogFrom(name, kCommandLogs, &result) || |
| 813 | GetNamedLogFrom(name, kExtraLogs, &result) || |
| 814 | GetNamedLogFrom(name, kFeedbackLogs, &result); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 815 | return result; |
| 816 | } |
| 817 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 818 | LogTool::LogMap LogTool::GetAllLogs() { |
Fletcher Woodruff | 70f2723 | 2019-01-24 11:41:34 -0700 | [diff] [blame] | 819 | CreateConnectivityReport(false); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 820 | LogMap result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 821 | GetLogsFrom(kCommandLogs, &result); |
| 822 | GetLogsFrom(kExtraLogs, &result); |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 823 | GetLsbReleaseInfo(&result); |
| 824 | GetOsReleaseInfo(&result); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 825 | return result; |
| 826 | } |
| 827 | |
Brian Norris | ca4fc04 | 2018-04-03 00:24:26 -0700 | [diff] [blame] | 828 | LogTool::LogMap LogTool::GetAllDebugLogs() { |
Fletcher Woodruff | 70f2723 | 2019-01-24 11:41:34 -0700 | [diff] [blame] | 829 | CreateConnectivityReport(true); |
Brian Norris | ca4fc04 | 2018-04-03 00:24:26 -0700 | [diff] [blame] | 830 | LogMap result; |
| 831 | GetLogsFrom(kCommandLogs, &result); |
| 832 | GetLogsFrom(kExtraLogs, &result); |
mhasank | d2b8488 | 2020-05-04 17:02:19 -0700 | [diff] [blame] | 833 | result[arc_bug_report_log_->GetName()] = GetArcBugReport("", nullptr); |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 834 | GetLsbReleaseInfo(&result); |
| 835 | GetOsReleaseInfo(&result); |
Brian Norris | ca4fc04 | 2018-04-03 00:24:26 -0700 | [diff] [blame] | 836 | return result; |
| 837 | } |
| 838 | |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 839 | void LogTool::GetBigFeedbackLogs(const base::ScopedFD& fd, |
| 840 | const std::string& username) { |
Fletcher Woodruff | 70f2723 | 2019-01-24 11:41:34 -0700 | [diff] [blame] | 841 | CreateConnectivityReport(true); |
Chinglin Yu | aeb4ec7 | 2018-12-10 18:53:30 +0800 | [diff] [blame] | 842 | LogMap map; |
| 843 | GetPerfData(&map); |
hscham | 2311cc2 | 2020-10-28 12:13:10 +0900 | [diff] [blame] | 844 | base::Value dictionary(base::Value::Type::DICTIONARY); |
Jeffrey Kardatzke | e3ec6fd | 2019-08-05 12:25:17 -0700 | [diff] [blame] | 845 | GetLogsInDictionary(kCommandLogs, &dictionary); |
| 846 | GetLogsInDictionary(kFeedbackLogs, &dictionary); |
mhasank | d2b8488 | 2020-05-04 17:02:19 -0700 | [diff] [blame] | 847 | bool is_backup; |
| 848 | std::string arc_bug_report = GetArcBugReport(username, &is_backup); |
hscham | 2311cc2 | 2020-10-28 12:13:10 +0900 | [diff] [blame] | 849 | dictionary.SetStringKey(kArcBugReportBackupKey, |
| 850 | (is_backup ? "true" : "false")); |
| 851 | dictionary.SetStringKey(arc_bug_report_log_->GetName(), arc_bug_report); |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame] | 852 | GetLsbReleaseInfo(&map); |
| 853 | GetOsReleaseInfo(&map); |
| 854 | PopulateDictionaryValue(map, &dictionary); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 855 | SerializeLogsAsJSON(dictionary, fd); |
| 856 | } |
| 857 | |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 858 | std::string GetSanitizedUsername( |
| 859 | org::chromium::CryptohomeInterfaceProxyInterface* cryptohome_proxy, |
mhasank | af5251d | 2020-04-29 18:53:03 -0700 | [diff] [blame] | 860 | const std::string& username) { |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 861 | if (username.empty()) { |
| 862 | return std::string(); |
| 863 | } |
| 864 | |
| 865 | std::string sanitized_username; |
| 866 | brillo::ErrorPtr error; |
| 867 | if (!cryptohome_proxy->GetSanitizedUsername(username, &sanitized_username, |
| 868 | &error)) { |
| 869 | LOG(ERROR) << "Failed to call GetSanitizedUsername, error: " |
| 870 | << error->GetMessage(); |
| 871 | return std::string(); |
| 872 | } |
| 873 | |
| 874 | return sanitized_username; |
| 875 | } |
| 876 | |
mhasank | d2b8488 | 2020-05-04 17:02:19 -0700 | [diff] [blame] | 877 | std::string LogTool::GetArcBugReport(const std::string& username, |
| 878 | bool* is_backup) { |
| 879 | if (is_backup) { |
| 880 | *is_backup = true; |
| 881 | } |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 882 | std::string userhash = |
| 883 | GetSanitizedUsername(cryptohome_proxy_.get(), username); |
| 884 | |
| 885 | std::string contents; |
| 886 | if (userhash.empty() || |
| 887 | arc_bug_report_backups_.find(userhash) == arc_bug_report_backups_.end() || |
Ereth McKnight-MacNeil | ca3fff2 | 2021-01-21 23:31:40 -0800 | [diff] [blame] | 888 | !base::ReadFileToString(daemon_store_base_dir_.Append(userhash).Append( |
| 889 | kArcBugReportBackupFileName), |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 890 | &contents)) { |
| 891 | // If |userhash| was not empty, but was not found in the backup set |
| 892 | // or the file did not exist, attempt to delete the file. |
| 893 | if (!userhash.empty()) { |
mhasank | 40a8048 | 2020-09-09 17:44:24 -0700 | [diff] [blame] | 894 | DeleteArcBugReportBackup(username); |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 895 | } |
mhasank | d2b8488 | 2020-05-04 17:02:19 -0700 | [diff] [blame] | 896 | if (is_backup) { |
| 897 | *is_backup = false; |
| 898 | } |
mhasank | af5251d | 2020-04-29 18:53:03 -0700 | [diff] [blame] | 899 | contents = arc_bug_report_log_->GetLogData(); |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | return contents; |
| 903 | } |
| 904 | |
mhasank | 7186aae | 2020-09-16 20:06:00 -0700 | [diff] [blame] | 905 | void LogTool::BackupArcBugReport(const std::string& username) { |
mhasank | 80cbe4d | 2020-04-02 22:46:08 -0700 | [diff] [blame] | 906 | DLOG(INFO) << "Backing up ARC bug report"; |
| 907 | |
mhasank | 40a8048 | 2020-09-09 17:44:24 -0700 | [diff] [blame] | 908 | const std::string userhash = |
mhasank | 7186aae | 2020-09-16 20:06:00 -0700 | [diff] [blame] | 909 | GetSanitizedUsername(cryptohome_proxy_.get(), username); |
| 910 | if (!IsUserHashValid(userhash)) { |
| 911 | LOG(ERROR) << "Invalid userhash '" << userhash << "'"; |
| 912 | return; |
| 913 | } |
mhasank | 40a8048 | 2020-09-09 17:44:24 -0700 | [diff] [blame] | 914 | |
Ereth McKnight-MacNeil | ca3fff2 | 2021-01-21 23:31:40 -0800 | [diff] [blame] | 915 | brillo::SafeFD backupDir( |
| 916 | brillo::SafeFD::Root() |
| 917 | .first.OpenExistingDir(daemon_store_base_dir_.Append(userhash)) |
| 918 | .first); |
| 919 | if (!backupDir.is_valid()) { |
| 920 | LOG(ERROR) << "Failed to open ARC bug report backup dir at " |
| 921 | << daemon_store_base_dir_.Append(userhash).value(); |
| 922 | return; |
| 923 | } |
| 924 | |
| 925 | brillo::SafeFD backupFile( |
| 926 | brillo::OpenOrRemakeFile(&backupDir, kArcBugReportBackupFileName).first); |
| 927 | if (!backupFile.is_valid()) { |
| 928 | LOG(ERROR) << "Failed to open ARC bug report file at " |
| 929 | << daemon_store_base_dir_.Append(userhash) |
| 930 | .Append(kArcBugReportBackupFileName) |
| 931 | .value(); |
| 932 | return; |
| 933 | } |
| 934 | |
mhasank | af5251d | 2020-04-29 18:53:03 -0700 | [diff] [blame] | 935 | const std::string logData = arc_bug_report_log_->GetLogData(); |
Ereth McKnight-MacNeil | ca3fff2 | 2021-01-21 23:31:40 -0800 | [diff] [blame] | 936 | |
| 937 | if (backupFile.Write(logData.c_str(), logData.length()) == |
| 938 | brillo::SafeFD::Error::kNoError) { |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 939 | arc_bug_report_backups_.insert(userhash); |
| 940 | } else { |
mhasank | 7186aae | 2020-09-16 20:06:00 -0700 | [diff] [blame] | 941 | PLOG(ERROR) << "Failed to back up ARC bug report"; |
mhasank | 80cbe4d | 2020-04-02 22:46:08 -0700 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | |
mhasank | 7186aae | 2020-09-16 20:06:00 -0700 | [diff] [blame] | 945 | void LogTool::DeleteArcBugReportBackup(const std::string& username) { |
mhasank | 80cbe4d | 2020-04-02 22:46:08 -0700 | [diff] [blame] | 946 | DLOG(INFO) << "Deleting the ARC bug report backup"; |
| 947 | |
mhasank | 40a8048 | 2020-09-09 17:44:24 -0700 | [diff] [blame] | 948 | const std::string userhash = |
mhasank | 7186aae | 2020-09-16 20:06:00 -0700 | [diff] [blame] | 949 | GetSanitizedUsername(cryptohome_proxy_.get(), username); |
| 950 | if (!IsUserHashValid(userhash)) { |
| 951 | LOG(ERROR) << "Invalid userhash '" << userhash << "'"; |
| 952 | return; |
| 953 | } |
mhasank | 40a8048 | 2020-09-09 17:44:24 -0700 | [diff] [blame] | 954 | |
Ereth McKnight-MacNeil | ca3fff2 | 2021-01-21 23:31:40 -0800 | [diff] [blame] | 955 | brillo::SafeFD backupDir( |
| 956 | brillo::SafeFD::Root() |
| 957 | .first.OpenExistingDir(daemon_store_base_dir_.Append(userhash)) |
| 958 | .first); |
| 959 | if (!backupDir.is_valid()) { |
| 960 | LOG(ERROR) << "Failed to open ARC bug report backup dir at " |
| 961 | << daemon_store_base_dir_.Append(userhash).value(); |
| 962 | return; |
| 963 | } |
| 964 | |
mhasank | 4f599d3 | 2020-04-09 22:07:35 -0700 | [diff] [blame] | 965 | arc_bug_report_backups_.erase(userhash); |
Ereth McKnight-MacNeil | ca3fff2 | 2021-01-21 23:31:40 -0800 | [diff] [blame] | 966 | |
| 967 | if (backupDir.Unlink(kArcBugReportBackupFileName) != |
| 968 | brillo::SafeFD::Error::kNoError) { |
| 969 | PLOG(ERROR) << "Failed to delete ARC bug report backup at " |
| 970 | << daemon_store_base_dir_.Append(userhash) |
| 971 | .Append(kArcBugReportBackupFileName) |
| 972 | .value(); |
mhasank | 80cbe4d | 2020-04-02 22:46:08 -0700 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Jeffrey Kardatzke | e3ec6fd | 2019-08-05 12:25:17 -0700 | [diff] [blame] | 976 | void LogTool::GetJournalLog(const base::ScopedFD& fd) { |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 977 | Log journal(kCommand, "journal.export", "journalctl -n 10000 -o export", |
| 978 | "syslog", "syslog", 10 * 1024 * 1024, LogTool::Encoding::kBinary); |
Jeffrey Kardatzke | e3ec6fd | 2019-08-05 12:25:17 -0700 | [diff] [blame] | 979 | std::string output = journal.GetLogData(); |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 980 | base::WriteFileDescriptor(fd.get(), output.data(), output.size()); |
| 981 | } |
| 982 | |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 983 | // static |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 984 | string LogTool::EncodeString(string value, LogTool::Encoding source_encoding) { |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 985 | if (source_encoding == LogTool::Encoding::kBinary) |
| 986 | return value; |
| 987 | |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 988 | if (source_encoding == LogTool::Encoding::kAutodetect) { |
| 989 | if (base::IsStringUTF8(value)) |
| 990 | return value; |
Chris Morin | 790fd26 | 2019-04-03 20:29:36 -0700 | [diff] [blame] | 991 | source_encoding = LogTool::Encoding::kBase64; |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | if (source_encoding == LogTool::Encoding::kUtf8) { |
| 995 | string output; |
| 996 | const char* src = value.data(); |
| 997 | int32_t src_len = static_cast<int32_t>(value.length()); |
| 998 | |
| 999 | output.reserve(value.size()); |
| 1000 | for (int32_t char_index = 0; char_index < src_len; char_index++) { |
| 1001 | uint32_t code_point; |
| 1002 | if (!base::ReadUnicodeCharacter(src, src_len, &char_index, &code_point) || |
| 1003 | !base::IsValidCharacter(code_point)) { |
| 1004 | // Replace invalid characters with U+FFFD REPLACEMENT CHARACTER. |
| 1005 | code_point = 0xFFFD; |
| 1006 | } |
| 1007 | base::WriteUnicodeCharacter(code_point, &output); |
| 1008 | } |
| 1009 | return output; |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 1010 | } |
Chris Morin | 853d344 | 2019-04-01 21:35:13 -0700 | [diff] [blame] | 1011 | |
| 1012 | base::Base64Encode(value, &value); |
| 1013 | return "<base64>: " + value; |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 1016 | } // namespace debugd |