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 | |
Ben Chan | 8e9f6d0 | 2017-09-26 23:04:21 -0700 | [diff] [blame] | 7 | #include <memory> |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 8 | #include <string> |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Ben Chan | ab93abf | 2017-01-24 13:32:51 -0800 | [diff] [blame] | 11 | #include <base/base64.h> |
Ben Chan | cd8fda4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 12 | #include <base/files/file_util.h> |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 13 | #include <base/json/json_writer.h> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 14 | #include <base/logging.h> |
Ben Chan | 9953a59 | 2014-02-05 23:32:00 -0800 | [diff] [blame] | 15 | #include <base/strings/string_split.h> |
| 16 | #include <base/strings/string_util.h> |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 17 | #include <base/strings/stringprintf.h> |
| 18 | #include <base/strings/utf_string_conversion_utils.h> |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 19 | #include <base/values.h> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 20 | |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 21 | #include <chromeos/dbus/service_constants.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 22 | #include <shill/dbus-proxies.h> |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 23 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 24 | #include "debugd/src/constants.h" |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 25 | #include "debugd/src/process_with_output.h" |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 26 | |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame^] | 27 | #include "brillo/key_value_store.h" |
| 28 | #include <brillo/osrelease_reader.h> |
| 29 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 30 | namespace debugd { |
| 31 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 32 | using std::string; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 33 | |
Eric Caruso | 96d03d3 | 2017-04-25 18:01:17 -0700 | [diff] [blame] | 34 | using Strings = std::vector<string>; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 35 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 36 | namespace { |
| 37 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 38 | const char kRoot[] = "root"; |
| 39 | const char kShell[] = "/bin/sh"; |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame^] | 40 | constexpr char kLsbReleasePath[] = "/etc/lsb-release"; |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 41 | |
| 42 | // Minimum time in seconds needed to allow shill to test active connections. |
| 43 | const int kConnectionTesterTimeoutSeconds = 5; |
Ben Chan | f6cd93a | 2012-10-14 19:37:00 -0700 | [diff] [blame] | 44 | |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 45 | // Default maximum size of a log entry. |
| 46 | constexpr const char kDefaultSizeCap[] = "512K"; |
| 47 | |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 48 | struct Log { |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 49 | const char* name; |
| 50 | const char* command; |
| 51 | const char* user = nullptr; |
| 52 | const char* group = nullptr; |
| 53 | const char* size_cap = kDefaultSizeCap; // passed as arg to 'tail -c' |
| 54 | LogTool::Encoding encoding = LogTool::Encoding::kAutodetect; |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 55 | }; |
| 56 | |
Eric Caruso | a879fd9 | 2017-10-11 12:57:10 -0700 | [diff] [blame] | 57 | #define CMD_KERNEL_MODULE_PARAMS(module_name) \ |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 58 | "cd /sys/module/" #module_name "/parameters 2>/dev/null && grep -sH ^ *" |
Eric Caruso | a879fd9 | 2017-10-11 12:57:10 -0700 | [diff] [blame] | 59 | |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 60 | const Log kCommandLogs[] = { |
Mike Frysinger | b035099 | 2018-09-14 13:45:35 -0400 | [diff] [blame] | 61 | // We need to enter init's mount namespace because it has /home/chronos |
| 62 | // mounted which is where the consent knob lives. We don't have that mount |
| 63 | // in our own mount namespace (by design). https://crbug.com/884249 |
| 64 | { "CLIENT_ID", "/usr/bin/nsenter -t1 -m /usr/bin/metrics_client -i", |
| 65 | kRoot, |
| 66 | kDebugfsGroup, |
| 67 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 68 | { "LOGDATE", "/bin/date" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 69 | { "atrus_logs", "cat /var/log/atrus.log 2>/dev/null" }, |
| 70 | { "authpolicy", "cat /var/log/authpolicy.log" }, |
Nicolas Norvez | d573ff6 | 2018-08-08 18:30:13 -0700 | [diff] [blame] | 71 | { "biod.LATEST", "cat /var/log/biod/biod.LATEST" }, |
| 72 | { "biod.PREVIOUS", "cat /var/log/biod/biod.PREVIOUS" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 73 | { "bios_info", "cat /var/log/bios_info.txt" }, |
Vadim Bendebury | 64aeeed | 2013-09-16 13:16:49 -0700 | [diff] [blame] | 74 | { "bios_log", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 75 | "cat /sys/firmware/log " |
| 76 | "/proc/device-tree/chosen/ap-console-buffer 2>/dev/null" }, |
| 77 | { "bios_times", "cat /var/log/bios_times.txt" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 78 | { "board-specific", |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 79 | "/usr/share/userfeedback/scripts/get_board_specific_info" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 80 | { "buddyinfo", "cat /proc/buddyinfo" }, |
Daisuke Nojiri | 3d832ee | 2017-02-17 14:21:28 -0800 | [diff] [blame] | 81 | { "cbi_info", "/usr/share/userfeedback/scripts/cbi_info", kRoot, }, |
Olof Johansson | e5d0fd3 | 2016-01-29 14:40:34 -0800 | [diff] [blame] | 82 | { "cheets_log", "/usr/bin/collect-cheets-logs 2>&1" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 83 | { "clobber.log", "cat /var/log/clobber.log 2>/dev/null" }, |
| 84 | { "clobber-state.log", "cat /var/log/clobber-state.log 2>/dev/null" }, |
| 85 | { "chrome_system_log", "cat /var/log/chrome/chrome" }, |
Dariusz Marcinkiewicz | a059706 | 2018-09-11 10:53:53 +0200 | [diff] [blame] | 86 | { "chrome_system_log.PREVIOUS", "cat /var/log/chrome/chrome.PREVIOUS" }, |
Mike Frysinger | 32cdf3e | 2017-08-14 18:17:06 -0400 | [diff] [blame] | 87 | // There might be more than one record, so grab them all. |
| 88 | // Plus, for <linux-3.19, it's named "console-ramoops", but for newer |
| 89 | // versions, it's named "console-ramoops-#". |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 90 | { "console-ramoops", "cat /sys/fs/pstore/console-ramoops* 2>/dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 91 | { "cpu", "/usr/bin/uname -p" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 92 | { "cpuinfo", "cat /proc/cpuinfo" }, |
| 93 | { "cr50_version", "cat /var/cache/cr50-version" }, |
Eric Caruso | 57333f1 | 2015-09-08 12:50:32 -0700 | [diff] [blame] | 94 | { "cros_ec", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 95 | "cat /var/log/cros_ec.previous /var/log/cros_ec.log 2>/dev/null" }, |
Nicolas Boichat | 083795f | 2016-08-16 11:16:49 +0200 | [diff] [blame] | 96 | { "cros_ec_panicinfo", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 97 | "cat /sys/kernel/debug/cros_ec/panicinfo 2>/dev/null", |
Nicolas Boichat | d51092b | 2016-09-01 10:36:46 +0800 | [diff] [blame] | 98 | SandboxedProcess::kDefaultUser, |
| 99 | kDebugfsGroup |
| 100 | }, |
Shawn Nematbakhsh | 6081373 | 2017-07-13 10:46:23 -0700 | [diff] [blame] | 101 | { "cros_ec_pdinfo", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 102 | "cat /sys/kernel/debug/cros_ec/pdinfo 2>/dev/null", |
Shawn Nematbakhsh | 6081373 | 2017-07-13 10:46:23 -0700 | [diff] [blame] | 103 | SandboxedProcess::kDefaultUser, |
| 104 | kDebugfsGroup |
| 105 | }, |
Vincent Palatin | e358804 | 2018-04-04 17:02:38 +0200 | [diff] [blame] | 106 | { "cros_fp", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 107 | "cat /var/log/cros_fp.previous /var/log/cros_fp.log 2>/dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 108 | { "dmesg", "/bin/dmesg" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 109 | { "ec_info", "cat /var/log/ec_info.txt" }, |
Miguel Casas | 8d4e54f | 2018-03-29 09:42:52 -0400 | [diff] [blame] | 110 | // The sed command replaces the EDID serial number (4 bytes at position 12) |
| 111 | // with zeroes. See https://en.wikipedia.org/wiki/EDID#EDID_1.4_data_format. |
| 112 | { "edid-decode", |
Miguel Casas | 55b7c84 | 2018-08-15 13:10:10 -0400 | [diff] [blame] | 113 | "for f in /sys/class/drm/card0-*/edid; do " |
Miguel Casas | 8d4e54f | 2018-03-29 09:42:52 -0400 | [diff] [blame] | 114 | "echo \"----------- ${f}\"; " |
Miguel Casas | 1b8d279 | 2018-08-17 20:00:52 -0400 | [diff] [blame] | 115 | "sed -E 's/^(.{11}).{4}/\\1\\x0\\x0\\x0\\x0/' \"${f}\" | " |
| 116 | // edid-decode's stderr output is redundant, so silence it. |
| 117 | "edid-decode 2>/dev/null; " |
Miguel Casas | 8d4e54f | 2018-03-29 09:42:52 -0400 | [diff] [blame] | 118 | "done" |
| 119 | }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 120 | { "eventlog", "cat /var/log/eventlog.txt" }, |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 121 | { |
| 122 | "exynos_gem_objects", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 123 | "cat /sys/kernel/debug/dri/0/exynos_gem_objects 2>/dev/null", |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 124 | SandboxedProcess::kDefaultUser, |
| 125 | kDebugfsGroup |
| 126 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 127 | { "font_info", "/usr/share/userfeedback/scripts/font_info" }, |
Daisuke Nojiri | debede0e | 2017-02-17 14:21:28 -0800 | [diff] [blame] | 128 | { "sensor_info", "/usr/share/userfeedback/scripts/sensor_info" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 129 | { "hardware_class", "/usr/bin/crossystem hwid" }, |
| 130 | { "hostname", "/bin/hostname" }, |
| 131 | { "hw_platform", "/usr/bin/uname -i" }, |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 132 | { |
| 133 | "i915_gem_gtt", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 134 | "cat /sys/kernel/debug/dri/0/i915_gem_gtt 2>/dev/null", |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 135 | SandboxedProcess::kDefaultUser, |
| 136 | kDebugfsGroup |
| 137 | }, |
| 138 | { |
| 139 | "i915_gem_objects", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 140 | "cat /sys/kernel/debug/dri/0/i915_gem_objects 2>/dev/null", |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 141 | SandboxedProcess::kDefaultUser, |
| 142 | kDebugfsGroup |
| 143 | }, |
| 144 | { |
| 145 | "i915_error_state", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 146 | "/usr/bin/xz -c /sys/kernel/debug/dri/0/i915_error_state 2>/dev/null", |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 147 | SandboxedProcess::kDefaultUser, |
| 148 | kDebugfsGroup, |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 149 | kDefaultSizeCap, |
| 150 | LogTool::Encoding::kBinary, |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 151 | }, |
Daniel Erat | 982ab4b | 2014-04-09 07:32:38 -0700 | [diff] [blame] | 152 | { "ifconfig", "/bin/ifconfig -a" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 153 | { "input_devices", "cat /proc/bus/input/devices" }, |
Eric Caruso | b1820c0 | 2017-08-24 15:39:56 -0700 | [diff] [blame] | 154 | // Information about the wiphy device, such as current channel. |
| 155 | { "iw_dev", "/usr/sbin/iw dev" }, |
| 156 | // Hardware capabilities of the wiphy device. |
| 157 | { "iw_list", "/usr/sbin/iw list" }, |
Eric Caruso | a879fd9 | 2017-10-11 12:57:10 -0700 | [diff] [blame] | 158 | #if USE_IWLWIFI_DUMP |
| 159 | { "iwlmvm_module_params", CMD_KERNEL_MODULE_PARAMS(iwlmvm) }, |
| 160 | { "iwlwifi_module_params", CMD_KERNEL_MODULE_PARAMS(iwlwifi) }, |
| 161 | #endif // USE_IWLWIFI_DUMP |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 162 | { "kernel-crashes", "cat /var/spool/crash/kernel.*.kcrash 2>/dev/null" }, |
| 163 | { "logcat", |
| 164 | "/usr/sbin/android-sh -c '/system/bin/logcat -d'", |
Kevin Cernekee | 143e2af | 2018-03-20 13:28:20 -0700 | [diff] [blame] | 165 | kRoot, |
| 166 | kRoot, |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 167 | kDefaultSizeCap, |
| 168 | LogTool::Encoding::kUtf8, |
Kevin Cernekee | 143e2af | 2018-03-20 13:28:20 -0700 | [diff] [blame] | 169 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 170 | { "lsmod", "lsmod" }, |
| 171 | { "lspci", "/usr/sbin/lspci" }, |
Simon Que | 41c88b5 | 2017-06-19 14:05:07 -0400 | [diff] [blame] | 172 | { "lsusb", "lsusb && lsusb -t" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 173 | { "mali_memory", "cat /sys/class/misc/mali0/device/memory 2>/dev/null" }, |
Luigi Semenzato | 7f00dfb | 2018-06-26 11:34:02 -0700 | [diff] [blame] | 174 | { "memd.parameters", "cat /var/log/memd/memd.parameters 2>/dev/null" }, |
| 175 | { "memd clips", "cat /var/log/memd/memd.clip* 2>/dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 176 | { "meminfo", "cat /proc/meminfo" }, |
Mike Frysinger | 8fd2eee | 2017-11-03 14:35:26 -0400 | [diff] [blame] | 177 | { |
| 178 | "memory_spd_info", |
| 179 | // mosys may use 'i2c-dev', which may not be loaded yet. |
| 180 | "modprobe i2c-dev 2>/dev/null && " |
| 181 | "mosys -l memory spd print all 2>/dev/null", |
| 182 | kRoot, |
| 183 | kDebugfsGroup, |
| 184 | }, |
Simon Que | cb63b9c | 2017-06-19 14:53:31 -0400 | [diff] [blame] | 185 | // The sed command finds the EDID blob (starting the line after "value:") and |
| 186 | // replaces the serial number with all zeroes. |
| 187 | // |
| 188 | // The EDID is printed as a hex dump over several lines, each line containing |
| 189 | // the contents of 16 bytes. The first 16 bytes are broken down as follows: |
| 190 | // uint64_t fixed_pattern; // Always 00 FF FF FF FF FF FF 00. |
| 191 | // uint16_t manufacturer_id; // Manufacturer ID, encoded as PNP IDs. |
| 192 | // uint16_t product_code; // Manufacturer product code, little-endian. |
| 193 | // uint32_t serial_number; // Serial number, little-endian. |
| 194 | // Source: https://en.wikipedia.org/wiki/EDID#EDID_1.3_data_format |
| 195 | // |
| 196 | // The subsequent substitution command looks for the fixed pattern followed by |
| 197 | // two 32-bit fields (manufacturer + product, serial number). It replaces the |
| 198 | // latter field with 8 bytes of zeroes. |
| 199 | // |
| 200 | // TODO(crbug.com/731133): Remove the sed command once modetest itself can |
| 201 | // remove serial numbers. |
| 202 | { |
| 203 | "modetest", |
| 204 | "(modetest; modetest -M evdi; modetest -M udl) | " |
| 205 | "sed -E '/EDID/ {:a;n;/value:/!ba;n;" |
| 206 | "s/(00f{12}00)([0-9a-f]{8})([0-9a-f]{8})/\\1\\200000000/}'", |
| 207 | kRoot, |
| 208 | kRoot, |
| 209 | }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 210 | { "mount-encrypted", "cat /var/log/mount-encrypted.log" }, |
| 211 | { "mountinfo", "cat /proc/1/mountinfo" }, |
Nicolas Boichat | 0230b0b | 2017-08-17 11:20:19 +0800 | [diff] [blame] | 212 | { "netlog", "/usr/share/userfeedback/scripts/getmsgs /var/log/net.log" }, |
Kevin Cernekee | 143e2af | 2018-03-20 13:28:20 -0700 | [diff] [blame] | 213 | // --processes requires root. |
| 214 | { "netstat", "/sbin/ss --all --query inet --numeric --processes", |
| 215 | kRoot, |
| 216 | kRoot, |
| 217 | }, |
henryhsu | fa6daa1 | 2014-09-24 13:26:30 +0800 | [diff] [blame] | 218 | { |
| 219 | "nvmap_iovmm", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 220 | "cat /sys/kernel/debug/nvmap/iovmm/allocations 2>/dev/null", |
henryhsu | fa6daa1 | 2014-09-24 13:26:30 +0800 | [diff] [blame] | 221 | SandboxedProcess::kDefaultUser, |
| 222 | kDebugfsGroup, |
| 223 | }, |
Todd Broch | a0c1376 | 2018-05-03 11:31:25 -0700 | [diff] [blame] | 224 | { "oemdata", "/usr/share/cros/oemdata.sh", kRoot, kRoot, }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 225 | { "pagetypeinfo", "cat /proc/pagetypeinfo" }, |
Mike Frysinger | 8fd2eee | 2017-11-03 14:35:26 -0400 | [diff] [blame] | 226 | { |
| 227 | "platform_info", |
| 228 | // mosys may use 'i2c-dev', which may not be loaded yet. |
| 229 | "modprobe i2c-dev 2>/dev/null && " |
| 230 | "for param in " |
| 231 | "vendor " |
| 232 | "name " |
| 233 | "version " |
| 234 | "family " |
| 235 | "model " |
| 236 | "sku " |
| 237 | "customization " |
| 238 | "; do " |
| 239 | "mosys -l platform \"${param}\" 2>/dev/null; " |
| 240 | "done", |
| 241 | kRoot, |
| 242 | kDebugfsGroup, |
| 243 | }, |
Daniel Erat | 9b58b6d | 2013-04-30 14:58:56 -0700 | [diff] [blame] | 244 | { "power_supply_info", "/usr/bin/power_supply_info" }, |
Daniel Erat | d8b8499 | 2017-03-13 17:30:00 -0600 | [diff] [blame] | 245 | { "power_supply_sysfs", "/usr/bin/print_sysfs_power_supply_data" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 246 | { "powerd.LATEST", "cat /var/log/power_manager/powerd.LATEST" }, |
| 247 | { "powerd.PREVIOUS", "cat /var/log/power_manager/powerd.PREVIOUS" }, |
| 248 | { "powerd.out", "cat /var/log/powerd.out" }, |
| 249 | { "powerwash_count", "cat /var/log/powerwash_count 2>/dev/null" }, |
Mattias Nissler | 887dce2 | 2017-07-03 14:44:35 +0200 | [diff] [blame] | 250 | // Changed from 'ps ux' to 'ps aux' since we're running as debugd, |
| 251 | // not chronos. |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 252 | { "ps", "/bin/ps aux" }, |
yusukes | 34171ba | 2017-04-27 15:46:01 -0700 | [diff] [blame] | 253 | // /proc/slabinfo is owned by root and has 0400 permission. |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 254 | { "slabinfo", "cat /proc/slabinfo", kRoot, kRoot, }, |
| 255 | { "storage_info", "cat /var/log/storage_info.txt" }, |
Alexis Savery | bbb8513 | 2018-05-18 17:41:10 -0700 | [diff] [blame] | 256 | { "swap_info", |
| 257 | "/usr/share/cros/init/swap.sh status 2>/dev/null", |
| 258 | SandboxedProcess::kDefaultUser, |
| 259 | kDebugfsGroup |
| 260 | }, |
Nicolas Boichat | 0230b0b | 2017-08-17 11:20:19 +0800 | [diff] [blame] | 261 | { "syslog", "/usr/share/userfeedback/scripts/getmsgs /var/log/messages" }, |
Brandon Mayer | e24c7a2 | 2017-08-04 13:58:48 -0400 | [diff] [blame] | 262 | { "system_log_stats", "echo 'BLOCK_SIZE=1024'; " |
| 263 | "find /var/log/ -type f -exec du --block-size=1024 {} + | sort -n -r", |
| 264 | kRoot, kRoot}, |
Kuo-Hsin Yang | 379846b | 2018-06-04 11:16:55 +0800 | [diff] [blame] | 265 | { "threads", "/bin/ps -T axo pid,ppid,spid,pcpu,ni,stat,time,comm" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 266 | { "tlsdate", "cat /var/log/tlsdate.log" }, |
Hsu-Cheng Tsai | e8c31d5 | 2017-03-31 12:34:55 +0800 | [diff] [blame] | 267 | { "top thread", "/usr/bin/top -Hb -n 1 | head -n 40"}, |
| 268 | { "top memory", "/usr/bin/top -o \"+%MEM\" -bn 1 | head -n 57"}, |
Andrew de los Reyes | c060c34 | 2013-04-10 13:46:30 -0700 | [diff] [blame] | 269 | { "touch_fw_version", "grep -E" |
Charlie Mooney | bb08f98 | 2016-02-04 15:35:56 -0800 | [diff] [blame] | 270 | " -e 'synaptics: Touchpad model'" |
| 271 | " -e 'chromeos-[a-z]*-touch-[a-z]*-update'" |
Andrew de los Reyes | c060c34 | 2013-04-10 13:46:30 -0700 | [diff] [blame] | 272 | " /var/log/messages | tail -n 20" }, |
Mattias Nissler | 483d76f | 2017-08-23 16:53:36 +0200 | [diff] [blame] | 273 | { |
| 274 | "tpm-firmware-updater", |
| 275 | "/usr/share/userfeedback/scripts/getmsgs /var/log/tpm-firmware-updater.log" |
| 276 | }, |
Mattias Nissler | 887dce2 | 2017-07-03 14:44:35 +0200 | [diff] [blame] | 277 | // TODO(jorgelo,mnissler): Don't run this as root. |
| 278 | // On TPM 1.2 devices this will likely require adding a new user to the 'tss' |
| 279 | // group. |
| 280 | // On TPM 2.0 devices 'get_version_info' uses D-Bus and therefore can run as |
| 281 | // any user. |
| 282 | { "tpm_version", "/usr/sbin/tpm-manager get_version_info", kRoot, kRoot }, |
Charlie Mooney | 69f5670 | 2017-05-02 14:55:41 -0700 | [diff] [blame] | 283 | { "atmel_ts_refs", "/opt/google/touch/scripts/atmel_tools.sh ts r", |
| 284 | kRoot, kRoot}, |
| 285 | { "atmel_tp_refs", "/opt/google/touch/scripts/atmel_tools.sh tp r", |
| 286 | kRoot, kRoot}, |
| 287 | { "atmel_ts_deltas", "/opt/google/touch/scripts/atmel_tools.sh ts d", |
| 288 | kRoot, kRoot}, |
| 289 | { "atmel_tp_deltas", "/opt/google/touch/scripts/atmel_tools.sh tp d", |
| 290 | kRoot, kRoot}, |
Gwendal Grignou | 427d94e | 2016-10-25 11:34:51 -0700 | [diff] [blame] | 291 | { |
| 292 | "trim", |
| 293 | "cat /var/lib/trim/stateful_trim_state /var/lib/trim/stateful_trim_data" |
| 294 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 295 | { "ui_log", "/usr/share/userfeedback/scripts/get_log /var/log/ui/ui.LATEST" }, |
| 296 | { "uname", "/bin/uname -a" }, |
| 297 | { "update_engine.log", "cat $(ls -1tr /var/log/update_engine | tail -5 | sed" |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 298 | " s.^./var/log/update_engine/.)" }, |
Dariusz Marcinkiewicz | c412688 | 2017-10-13 16:07:36 +0200 | [diff] [blame] | 299 | { "uptime", "/usr/bin/cut -d' ' -f1 /proc/uptime" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 300 | { "verified boot", "cat /var/log/debug_vboot_noisy.log" }, |
| 301 | { "vmlog.1.LATEST", "cat /var/log/vmlog/vmlog.1.LATEST" }, |
| 302 | { "vmlog.1.PREVIOUS", "cat /var/log/vmlog/vmlog.1.PREVIOUS" }, |
| 303 | { "vmlog.LATEST", "cat /var/log/vmlog/vmlog.LATEST" }, |
| 304 | { "vmlog.PREVIOUS", "cat /var/log/vmlog/vmlog.PREVIOUS" }, |
| 305 | { "vmstat", "cat /proc/vmstat" }, |
| 306 | { "vpd_2.0", "cat /var/log/vpd_2.0.txt" }, |
Samuel Tan | 107b6c8 | 2014-07-10 15:33:44 -0700 | [diff] [blame] | 307 | { "wifi_status", "/usr/bin/network_diag --wifi-internal --no-log" }, |
Sonny Rao | ab5f995 | 2013-07-17 14:13:53 -0700 | [diff] [blame] | 308 | { "zram compressed data size", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 309 | "cat /sys/block/zram0/compr_data_size 2>/dev/null" }, |
Sonny Rao | ab5f995 | 2013-07-17 14:13:53 -0700 | [diff] [blame] | 310 | { "zram original data size", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 311 | "cat /sys/block/zram0/orig_data_size 2>/dev/null" }, |
Sonny Rao | ab5f995 | 2013-07-17 14:13:53 -0700 | [diff] [blame] | 312 | { "zram total memory used", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 313 | "cat /sys/block/zram0/mem_used_total 2>/dev/null" }, |
Sonny Rao | ab5f995 | 2013-07-17 14:13:53 -0700 | [diff] [blame] | 314 | { "zram total reads", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 315 | "cat /sys/block/zram0/num_reads 2>/dev/null" }, |
Sonny Rao | ab5f995 | 2013-07-17 14:13:53 -0700 | [diff] [blame] | 316 | { "zram total writes", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 317 | "cat /sys/block/zram0/num_writes 2>/dev/null" }, |
| 318 | { "zram new stats names", |
| 319 | "echo orig_size compr_size used_total limit " |
Luigi Semenzato | 4164de4 | 2017-07-06 10:42:54 -0700 | [diff] [blame] | 320 | "used_max zero_pages migrated" }, |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 321 | { "zram new stats values", "cat /sys/block/zram0/mm_stat 2>/dev/null" }, |
| 322 | { "cros_tp version", "cat /sys/class/chromeos/cros_tp/version" }, |
Wei-Ning Huang | 230b7d8 | 2017-07-14 16:19:13 +0800 | [diff] [blame] | 323 | { "cros_tp console", "/usr/sbin/ectool --name=cros_tp console", |
| 324 | kRoot, kRoot }, |
Wei-Ning Huang | 23ffdcf | 2017-08-04 11:30:39 +0800 | [diff] [blame] | 325 | { "cros_tp frame", "/usr/sbin/ectool --name=cros_tp tpframeget", |
| 326 | kRoot, kRoot }, |
Zach Reizner | 7eab48b | 2018-06-22 19:26:48 -0700 | [diff] [blame] | 327 | { "crostini", "/usr/bin/cicerone_client --get_info" }, |
Gaurav Shah | 6e8fd89 | 2012-10-01 11:51:08 -0700 | [diff] [blame] | 328 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 329 | // Stuff pulled out of the original list. These need access to the running X |
| 330 | // session, which we'd rather not give to debugd, or return info specific to |
| 331 | // the current session (in the setsid(2) sense), which is not useful for |
| 332 | // debugd |
| 333 | // { "env", "set" }, |
| 334 | // { "setxkbmap", "/usr/bin/setxkbmap -print -query" }, |
| 335 | // { "xrandr", "/usr/bin/xrandr --verbose" } |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 336 | { nullptr, nullptr } |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 337 | }; |
| 338 | |
Kevin Cernekee | 143e2af | 2018-03-20 13:28:20 -0700 | [diff] [blame] | 339 | // netstat and logcat should appear in chrome://system but not in feedback |
| 340 | // reports. Open sockets may have privacy implications, and logcat is |
| 341 | // already incorporated via arc-bugreport. |
| 342 | const std::vector<string> kCommandLogsExclude = {"netstat", "logcat"}; |
| 343 | |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 344 | const Log kExtraLogs[] = { |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 345 | #if USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 346 | { "mm-status", "/usr/bin/modem status" }, |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 347 | #endif // USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 348 | { "network-devices", "/usr/bin/connectivity show devices" }, |
| 349 | { "network-services", "/usr/bin/connectivity show services" }, |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 350 | { nullptr, nullptr } |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 351 | }; |
| 352 | |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 353 | const Log kFeedbackLogs[] = { |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 354 | #if USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 355 | { "mm-status", "/usr/bin/modem status-feedback" }, |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 356 | #endif // USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 357 | { "network-devices", "/usr/bin/connectivity show-feedback devices" }, |
| 358 | { "network-services", "/usr/bin/connectivity show-feedback services" }, |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 359 | { nullptr, nullptr } |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 360 | }; |
| 361 | |
Ahmed Fakhry | 1498b4e | 2016-03-30 12:42:20 -0700 | [diff] [blame] | 362 | // List of log files needed to be part of the feedback report that are huge and |
| 363 | // must be sent back to the client via the file descriptor using |
| 364 | // LogTool::GetBigFeedbackLogs(). |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 365 | const Log kBigFeedbackLogs[] = { |
Eric Caruso | e3166f2 | 2016-06-10 15:36:02 -0700 | [diff] [blame] | 366 | { "arc-bugreport", |
Luigi Semenzato | 7e2c08f | 2018-06-26 14:58:49 -0700 | [diff] [blame] | 367 | "cat /run/arc/bugreport/pipe 2>/dev/null", |
Eric Caruso | e3166f2 | 2016-06-10 15:36:02 -0700 | [diff] [blame] | 368 | // ARC bugreport permissions are weird. Since we're just running cat, this |
| 369 | // shouldn't cause any issues. |
| 370 | kRoot, |
Ricky Zhou | 4c473ca | 2016-06-21 17:46:58 -0700 | [diff] [blame] | 371 | kRoot, |
| 372 | "10M", |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 373 | LogTool::Encoding::kUtf8, |
Eric Caruso | e3166f2 | 2016-06-10 15:36:02 -0700 | [diff] [blame] | 374 | }, |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 375 | { nullptr, nullptr } |
Ahmed Fakhry | 1498b4e | 2016-03-30 12:42:20 -0700 | [diff] [blame] | 376 | }; |
| 377 | |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 378 | // List of log files that must directly be collected by Chrome. This is because |
| 379 | // debugd is running under a VFS namespace and does not have access to later |
| 380 | // cryptohome mounts. |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 381 | const Log kUserLogs[] = { |
Elly Fong-Jones | 6456ce5 | 2013-04-17 13:31:13 -0400 | [diff] [blame] | 382 | {"chrome_user_log", "log/chrome"}, |
Xiaohui Chen | 32b171d | 2018-08-27 17:18:44 -0700 | [diff] [blame] | 383 | {"libassistant_user_log", "log/libassistant.log"}, |
Elly Fong-Jones | 6456ce5 | 2013-04-17 13:31:13 -0400 | [diff] [blame] | 384 | {"login-times", "login-times"}, |
| 385 | {"logout-times", "logout-times"}, |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 386 | { nullptr, nullptr} |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 387 | }; |
| 388 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 389 | // TODO(ellyjones): sandbox. crosbug.com/35122 |
| 390 | string Run(const Log& log) { |
| 391 | string output; |
| 392 | ProcessWithOutput p; |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 393 | string tailed_cmdline = |
| 394 | base::StringPrintf("%s | tail -c %s", log.command, log.size_cap); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 395 | if (log.user && log.group) |
| 396 | p.SandboxAs(log.user, log.group); |
| 397 | if (!p.Init()) |
| 398 | return "<not available>"; |
| 399 | p.AddArg(kShell); |
| 400 | p.AddStringOption("-c", tailed_cmdline); |
| 401 | if (p.Run()) |
| 402 | return "<not available>"; |
| 403 | p.GetOutput(&output); |
| 404 | if (!output.size()) |
| 405 | return "<empty>"; |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 406 | return LogTool::EnsureUTF8String(output, log.encoding); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | // Fills |dictionary| with the anonymized contents of the logs in |logs|. |
| 410 | void GetLogsInDictionary(const struct Log* logs, |
| 411 | AnonymizerTool* anonymizer, |
| 412 | base::DictionaryValue* dictionary) { |
| 413 | for (size_t i = 0; logs[i].name; ++i) { |
| 414 | dictionary->SetStringWithoutPathExpansion( |
| 415 | logs[i].name, anonymizer->Anonymize(Run(logs[i]))); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | // Serializes the |dictionary| into the file with the given |fd| in a JSON |
| 420 | // format. |
| 421 | void SerializeLogsAsJSON(const base::DictionaryValue& dictionary, |
Eric Caruso | 0b24188 | 2018-04-04 13:43:46 -0700 | [diff] [blame] | 422 | const base::ScopedFD& fd) { |
Eric Caruso | 96d03d3 | 2017-04-25 18:01:17 -0700 | [diff] [blame] | 423 | string logs_json; |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 424 | base::JSONWriter::WriteWithOptions(dictionary, |
| 425 | base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 426 | &logs_json); |
Eric Caruso | 0b24188 | 2018-04-04 13:43:46 -0700 | [diff] [blame] | 427 | base::WriteFileDescriptor(fd.get(), logs_json.c_str(), logs_json.size()); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 430 | bool GetNamedLogFrom(const string& name, const struct Log* logs, |
| 431 | string* result) { |
| 432 | for (size_t i = 0; logs[i].name; i++) { |
| 433 | if (name == logs[i].name) { |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 434 | *result = Run(logs[i]); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 435 | return true; |
| 436 | } |
| 437 | } |
| 438 | *result = "<invalid log name>"; |
| 439 | return false; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 440 | } |
| 441 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 442 | void GetLogsFrom(const struct Log* logs, LogTool::LogMap* map) { |
| 443 | for (size_t i = 0; logs[i].name; i++) |
| 444 | (*map)[logs[i].name] = Run(logs[i]); |
| 445 | } |
| 446 | |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame^] | 447 | void GetLsbReleaseInfo(LogTool::LogMap* map) { |
| 448 | const base::FilePath lsb_release(kLsbReleasePath); |
| 449 | brillo::KeyValueStore store; |
| 450 | if (!store.Load(lsb_release)) { |
| 451 | // /etc/lsb-release might not be present (cros deploying a new |
| 452 | // configuration or no fields set at all). Just print a debug |
| 453 | // message and continue. |
| 454 | DLOG(INFO) << "Could not load fields from " << lsb_release.value(); |
| 455 | } else { |
| 456 | for (const auto& key : store.GetKeys()) { |
| 457 | std::string value; |
| 458 | store.GetString(key, &value); |
| 459 | (*map)[key] = value; |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | void GetOsReleaseInfo(LogTool::LogMap* map) { |
| 465 | brillo::OsReleaseReader reader; |
| 466 | reader.Load(); |
| 467 | for (const auto& key : reader.GetKeys()) { |
| 468 | std::string value; |
| 469 | reader.GetString(key, &value); |
| 470 | (*map)["os-release " + key] = value; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | void PopulateDictionaryValue(const LogTool::LogMap& map, |
| 475 | base::DictionaryValue* dictionary) { |
| 476 | for (const auto& kv : map) { |
| 477 | dictionary->SetString(kv.first, kv.second); |
| 478 | } |
| 479 | } |
| 480 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 481 | } // namespace |
| 482 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 483 | void LogTool::CreateConnectivityReport() { |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 484 | // Perform ConnectivityTrial to report connection state in feedback log. |
Ben Chan | 8e9f6d0 | 2017-09-26 23:04:21 -0700 | [diff] [blame] | 485 | auto shill = std::make_unique<org::chromium::flimflam::ManagerProxy>(bus_); |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 486 | // Give the connection trial time to test the connection and log the results |
| 487 | // before collecting the logs for feedback. |
| 488 | // TODO(silberst): Replace the simple approach of a single timeout with a more |
| 489 | // coordinated effort. |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 490 | if (shill && shill->CreateConnectivityReport(nullptr)) |
| 491 | sleep(kConnectionTesterTimeoutSeconds); |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 494 | string LogTool::GetLog(const string& name) { |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 495 | string result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 496 | GetNamedLogFrom(name, kCommandLogs, &result) |
| 497 | || GetNamedLogFrom(name, kExtraLogs, &result) |
| 498 | || GetNamedLogFrom(name, kFeedbackLogs, &result); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 499 | return result; |
| 500 | } |
| 501 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 502 | LogTool::LogMap LogTool::GetAllLogs() { |
| 503 | CreateConnectivityReport(); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 504 | LogMap result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 505 | GetLogsFrom(kCommandLogs, &result); |
| 506 | GetLogsFrom(kExtraLogs, &result); |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame^] | 507 | GetLsbReleaseInfo(&result); |
| 508 | GetOsReleaseInfo(&result); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 509 | return result; |
| 510 | } |
| 511 | |
Brian Norris | ca4fc04 | 2018-04-03 00:24:26 -0700 | [diff] [blame] | 512 | LogTool::LogMap LogTool::GetAllDebugLogs() { |
| 513 | CreateConnectivityReport(); |
| 514 | LogMap result; |
| 515 | GetLogsFrom(kCommandLogs, &result); |
| 516 | GetLogsFrom(kExtraLogs, &result); |
| 517 | GetLogsFrom(kBigFeedbackLogs, &result); |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame^] | 518 | GetLsbReleaseInfo(&result); |
| 519 | GetOsReleaseInfo(&result); |
Brian Norris | ca4fc04 | 2018-04-03 00:24:26 -0700 | [diff] [blame] | 520 | return result; |
| 521 | } |
| 522 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 523 | LogTool::LogMap LogTool::GetFeedbackLogs() { |
| 524 | CreateConnectivityReport(); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 525 | LogMap result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 526 | GetLogsFrom(kCommandLogs, &result); |
Kevin Cernekee | 143e2af | 2018-03-20 13:28:20 -0700 | [diff] [blame] | 527 | for (const auto& key : kCommandLogsExclude) { |
| 528 | result.erase(key); |
| 529 | } |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 530 | GetLogsFrom(kFeedbackLogs, &result); |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame^] | 531 | GetLsbReleaseInfo(&result); |
| 532 | GetOsReleaseInfo(&result); |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 533 | AnonymizeLogMap(&result); |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 534 | return result; |
| 535 | } |
| 536 | |
Eric Caruso | 0b24188 | 2018-04-04 13:43:46 -0700 | [diff] [blame] | 537 | void LogTool::GetBigFeedbackLogs(const base::ScopedFD& fd) { |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 538 | CreateConnectivityReport(); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 539 | base::DictionaryValue dictionary; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 540 | GetLogsInDictionary(kCommandLogs, &anonymizer_, &dictionary); |
Kevin Cernekee | 143e2af | 2018-03-20 13:28:20 -0700 | [diff] [blame] | 541 | for (const auto& key : kCommandLogsExclude) { |
| 542 | dictionary.Remove(key, nullptr); |
| 543 | } |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 544 | GetLogsInDictionary(kFeedbackLogs, &anonymizer_, &dictionary); |
| 545 | GetLogsInDictionary(kBigFeedbackLogs, &anonymizer_, &dictionary); |
Kartik Hegde | 1c4b97b | 2018-09-09 19:09:34 -0600 | [diff] [blame^] | 546 | LogMap map; |
| 547 | GetLsbReleaseInfo(&map); |
| 548 | GetOsReleaseInfo(&map); |
| 549 | PopulateDictionaryValue(map, &dictionary); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 550 | SerializeLogsAsJSON(dictionary, fd); |
| 551 | } |
| 552 | |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 553 | LogTool::LogMap LogTool::GetUserLogFiles() { |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 554 | LogMap result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 555 | for (size_t i = 0; kUserLogs[i].name; ++i) |
| 556 | result[kUserLogs[i].name] = kUserLogs[i].command; |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 557 | return result; |
| 558 | } |
| 559 | |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame] | 560 | // static |
| 561 | string LogTool::EnsureUTF8String(const string& value, |
| 562 | LogTool::Encoding source_encoding) { |
| 563 | if (source_encoding == LogTool::Encoding::kAutodetect) { |
| 564 | if (base::IsStringUTF8(value)) |
| 565 | return value; |
| 566 | source_encoding = LogTool::Encoding::kBinary; |
| 567 | } |
| 568 | |
| 569 | if (source_encoding == LogTool::Encoding::kUtf8) { |
| 570 | string output; |
| 571 | const char* src = value.data(); |
| 572 | int32_t src_len = static_cast<int32_t>(value.length()); |
| 573 | |
| 574 | output.reserve(value.size()); |
| 575 | for (int32_t char_index = 0; char_index < src_len; char_index++) { |
| 576 | uint32_t code_point; |
| 577 | if (!base::ReadUnicodeCharacter(src, src_len, &char_index, &code_point) || |
| 578 | !base::IsValidCharacter(code_point)) { |
| 579 | // Replace invalid characters with U+FFFD REPLACEMENT CHARACTER. |
| 580 | code_point = 0xFFFD; |
| 581 | } |
| 582 | base::WriteUnicodeCharacter(code_point, &output); |
| 583 | } |
| 584 | return output; |
| 585 | } else { |
| 586 | string encoded_value; |
| 587 | base::Base64Encode(value, &encoded_value); |
| 588 | return "<base64>: " + encoded_value; |
| 589 | } |
| 590 | } |
| 591 | |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 592 | void LogTool::AnonymizeLogMap(LogMap* log_map) { |
Ben Chan | e2fa357 | 2017-02-08 22:46:18 -0800 | [diff] [blame] | 593 | for (auto& entry : *log_map) |
| 594 | entry.second = anonymizer_.Anonymize(entry.second); |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 595 | } |
| 596 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 597 | } // namespace debugd |