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