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 | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
Ben Chan | ab93abf | 2017-01-24 13:32:51 -0800 | [diff] [blame] | 9 | #include <base/base64.h> |
Ben Chan | cd8fda4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 10 | #include <base/files/file_util.h> |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 11 | #include <base/json/json_writer.h> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 12 | #include <base/logging.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 13 | #include <base/memory/ptr_util.h> |
Ben Chan | 9953a59 | 2014-02-05 23:32:00 -0800 | [diff] [blame] | 14 | #include <base/strings/string_split.h> |
| 15 | #include <base/strings/string_util.h> |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 16 | #include <base/values.h> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 17 | |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 18 | #include <chromeos/dbus/service_constants.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 19 | #include <shill/dbus-proxies.h> |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 20 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 21 | #include "debugd/src/constants.h" |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 22 | #include "debugd/src/process_with_output.h" |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 23 | |
| 24 | namespace debugd { |
| 25 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 26 | using std::string; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 27 | |
Eric Caruso | 96d03d3 | 2017-04-25 18:01:17 -0700 | [diff] [blame] | 28 | using Strings = std::vector<string>; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 29 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 30 | namespace { |
| 31 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 32 | const char kRoot[] = "root"; |
| 33 | const char kShell[] = "/bin/sh"; |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 34 | |
| 35 | // Minimum time in seconds needed to allow shill to test active connections. |
| 36 | const int kConnectionTesterTimeoutSeconds = 5; |
Ben Chan | f6cd93a | 2012-10-14 19:37:00 -0700 | [diff] [blame] | 37 | |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 38 | struct Log { |
| 39 | const char *name; |
| 40 | const char *command; |
| 41 | const char *user; |
| 42 | const char *group; |
Ricky Zhou | 4c473ca | 2016-06-21 17:46:58 -0700 | [diff] [blame] | 43 | const char *size_cap; // passed as arg to 'tail' |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 44 | }; |
| 45 | |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 46 | const Log kCommandLogs[] = { |
Mike Frysinger | c3e835a | 2017-01-06 04:09:34 -0500 | [diff] [blame] | 47 | { "CLIENT_ID", "/usr/bin/metrics_client -i"}, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 48 | { "LOGDATE", "/bin/date" }, |
Ahmed Fakhry | b7d12cd | 2017-05-03 11:05:13 -0700 | [diff] [blame] | 49 | { "atrus_logs", "/bin/cat /var/log/atrus.log 2> /dev/null" }, |
Lutz Justen | c226566 | 2017-06-27 10:13:23 +0200 | [diff] [blame] | 50 | { "authpolicy", "/bin/cat /var/log/authpolicy.log" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 51 | { "bios_info", "/bin/cat /var/log/bios_info.txt" }, |
Vadim Bendebury | 64aeeed | 2013-09-16 13:16:49 -0700 | [diff] [blame] | 52 | { "bios_log", |
| 53 | "/bin/cat /sys/firmware/log " |
| 54 | "/proc/device-tree/chosen/ap-console-buffer 2> /dev/null" }, |
Stefan Reinauer | 4393fa7 | 2012-10-18 11:08:09 -0700 | [diff] [blame] | 55 | { "bios_times", "/bin/cat /var/log/bios_times.txt" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 56 | { "board-specific", |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 57 | "/usr/share/userfeedback/scripts/get_board_specific_info" }, |
Olof Johansson | e5d0fd3 | 2016-01-29 14:40:34 -0800 | [diff] [blame] | 58 | { "cheets_log", "/usr/bin/collect-cheets-logs 2>&1" }, |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 59 | { "clobber.log", "/bin/cat /var/log/clobber.log 2> /dev/null" }, |
| 60 | { "clobber-state.log", "/bin/cat /var/log/clobber-state.log 2> /dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 61 | { "chrome_system_log", "/bin/cat /var/log/chrome/chrome" }, |
Mike Frysinger | 32cdf3e | 2017-08-14 18:17:06 -0400 | [diff] [blame^] | 62 | // There might be more than one record, so grab them all. |
| 63 | // Plus, for <linux-3.19, it's named "console-ramoops", but for newer |
| 64 | // versions, it's named "console-ramoops-#". |
| 65 | { "console-ramoops", "/bin/cat /dev/pstore/console-ramoops* 2> /dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 66 | { "cpu", "/usr/bin/uname -p" }, |
| 67 | { "cpuinfo", "/bin/cat /proc/cpuinfo" }, |
Benson Leung | 1526c8f | 2017-01-22 20:38:04 -0800 | [diff] [blame] | 68 | { "cr50_version", "/bin/cat /var/cache/cr50-version" }, |
Eric Caruso | 57333f1 | 2015-09-08 12:50:32 -0700 | [diff] [blame] | 69 | { "cros_ec", |
| 70 | "/bin/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] | 71 | { "cros_ec_panicinfo", |
Nicolas Boichat | d51092b | 2016-09-01 10:36:46 +0800 | [diff] [blame] | 72 | "/bin/cat /sys/kernel/debug/cros_ec/panicinfo 2> /dev/null", |
| 73 | SandboxedProcess::kDefaultUser, |
| 74 | kDebugfsGroup |
| 75 | }, |
Shawn Nematbakhsh | 6081373 | 2017-07-13 10:46:23 -0700 | [diff] [blame] | 76 | { "cros_ec_pdinfo", |
| 77 | "/bin/cat /sys/kernel/debug/cros_ec/pdinfo 2> /dev/null", |
| 78 | SandboxedProcess::kDefaultUser, |
| 79 | kDebugfsGroup |
| 80 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 81 | { "dmesg", "/bin/dmesg" }, |
| 82 | { "ec_info", "/bin/cat /var/log/ec_info.txt" }, |
Stefan Reinauer | 4393fa7 | 2012-10-18 11:08:09 -0700 | [diff] [blame] | 83 | { "eventlog", "/bin/cat /var/log/eventlog.txt" }, |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 84 | { |
| 85 | "exynos_gem_objects", |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 86 | "/bin/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] | 87 | SandboxedProcess::kDefaultUser, |
| 88 | kDebugfsGroup |
| 89 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 90 | { "font_info", "/usr/share/userfeedback/scripts/font_info" }, |
Daisuke Nojiri | debede0e | 2017-02-17 14:21:28 -0800 | [diff] [blame] | 91 | { "sensor_info", "/usr/share/userfeedback/scripts/sensor_info" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 92 | { "hardware_class", "/usr/bin/crossystem hwid" }, |
| 93 | { "hostname", "/bin/hostname" }, |
| 94 | { "hw_platform", "/usr/bin/uname -i" }, |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 95 | { |
| 96 | "i915_gem_gtt", |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 97 | "/bin/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] | 98 | SandboxedProcess::kDefaultUser, |
| 99 | kDebugfsGroup |
| 100 | }, |
| 101 | { |
| 102 | "i915_gem_objects", |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 103 | "/bin/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] | 104 | SandboxedProcess::kDefaultUser, |
| 105 | kDebugfsGroup |
| 106 | }, |
| 107 | { |
| 108 | "i915_error_state", |
Yuly Novikov | 4ac12fb | 2013-07-18 20:08:44 -0400 | [diff] [blame] | 109 | "/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] | 110 | SandboxedProcess::kDefaultUser, |
| 111 | kDebugfsGroup, |
| 112 | }, |
Daniel Erat | 982ab4b | 2014-04-09 07:32:38 -0700 | [diff] [blame] | 113 | { "ifconfig", "/bin/ifconfig -a" }, |
Lutz Justen | c226566 | 2017-06-27 10:13:23 +0200 | [diff] [blame] | 114 | { "input_devices", "/bin/cat /proc/bus/input/devices" }, |
Stefan Reinauer | 48f883d | 2014-08-22 14:31:58 -0700 | [diff] [blame] | 115 | { "kernel-crashes", |
| 116 | "/bin/cat /var/spool/crash/kernel.*.kcrash 2> /dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 117 | { "lsmod", "lsmod" }, |
| 118 | { "lspci", "/usr/sbin/lspci" }, |
Simon Que | 41c88b5 | 2017-06-19 14:05:07 -0400 | [diff] [blame] | 119 | { "lsusb", "lsusb && lsusb -t" }, |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 120 | { |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 121 | "mali_memory", |
| 122 | "/bin/cat /sys/class/misc/mali0/device/memory 2> /dev/null" |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 123 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 124 | { "meminfo", "cat /proc/meminfo" }, |
| 125 | { "memory_spd_info", "/bin/cat /var/log/memory_spd_info.txt" }, |
Simon Que | cb63b9c | 2017-06-19 14:53:31 -0400 | [diff] [blame] | 126 | // The sed command finds the EDID blob (starting the line after "value:") and |
| 127 | // replaces the serial number with all zeroes. |
| 128 | // |
| 129 | // The EDID is printed as a hex dump over several lines, each line containing |
| 130 | // the contents of 16 bytes. The first 16 bytes are broken down as follows: |
| 131 | // uint64_t fixed_pattern; // Always 00 FF FF FF FF FF FF 00. |
| 132 | // uint16_t manufacturer_id; // Manufacturer ID, encoded as PNP IDs. |
| 133 | // uint16_t product_code; // Manufacturer product code, little-endian. |
| 134 | // uint32_t serial_number; // Serial number, little-endian. |
| 135 | // Source: https://en.wikipedia.org/wiki/EDID#EDID_1.3_data_format |
| 136 | // |
| 137 | // The subsequent substitution command looks for the fixed pattern followed by |
| 138 | // two 32-bit fields (manufacturer + product, serial number). It replaces the |
| 139 | // latter field with 8 bytes of zeroes. |
| 140 | // |
| 141 | // TODO(crbug.com/731133): Remove the sed command once modetest itself can |
| 142 | // remove serial numbers. |
| 143 | { |
| 144 | "modetest", |
| 145 | "(modetest; modetest -M evdi; modetest -M udl) | " |
| 146 | "sed -E '/EDID/ {:a;n;/value:/!ba;n;" |
| 147 | "s/(00f{12}00)([0-9a-f]{8})([0-9a-f]{8})/\\1\\200000000/}'", |
| 148 | kRoot, |
| 149 | kRoot, |
| 150 | }, |
Kees Cook | a8f3e7e | 2012-11-19 14:16:01 -0800 | [diff] [blame] | 151 | { "mount-encrypted", "/bin/cat /var/log/mount-encrypted.log" }, |
Junichi Uekawa | 710cb4b | 2017-04-10 16:05:27 +0900 | [diff] [blame] | 152 | { "mountinfo", "/bin/cat /proc/1/mountinfo" }, |
Darin Petkov | 5474358 | 2012-12-10 14:18:32 +0100 | [diff] [blame] | 153 | { "net-diags.net.log", "/bin/cat /var/log/net-diags.net.log" }, |
Nicolas Boichat | 0230b0b | 2017-08-17 11:20:19 +0800 | [diff] [blame] | 154 | { "netlog", "/usr/share/userfeedback/scripts/getmsgs /var/log/net.log" }, |
henryhsu | fa6daa1 | 2014-09-24 13:26:30 +0800 | [diff] [blame] | 155 | { |
| 156 | "nvmap_iovmm", |
| 157 | "/bin/cat /sys/kernel/debug/nvmap/iovmm/allocations 2> /dev/null", |
| 158 | SandboxedProcess::kDefaultUser, |
| 159 | kDebugfsGroup, |
| 160 | }, |
Vincent Palatin | c64af9d | 2013-08-05 16:34:10 -0700 | [diff] [blame] | 161 | { "platform_info", "/bin/cat /var/log/platform_info.txt" }, |
Daniel Erat | 9b58b6d | 2013-04-30 14:58:56 -0700 | [diff] [blame] | 162 | { "power_supply_info", "/usr/bin/power_supply_info" }, |
Daniel Erat | d8b8499 | 2017-03-13 17:30:00 -0600 | [diff] [blame] | 163 | { "power_supply_sysfs", "/usr/bin/print_sysfs_power_supply_data" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 164 | { "powerd.LATEST", "/bin/cat /var/log/power_manager/powerd.LATEST" }, |
Daniel Erat | 546c388 | 2013-11-22 12:46:01 -0800 | [diff] [blame] | 165 | { "powerd.PREVIOUS", "/bin/cat /var/log/power_manager/powerd.PREVIOUS" }, |
Daniel Erat | 93da9a1 | 2012-12-06 14:14:17 -0800 | [diff] [blame] | 166 | { "powerd.out", "/bin/cat /var/log/powerd.out" }, |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 167 | { "powerwash_count", "/bin/cat /var/log/powerwash_count 2> /dev/null" }, |
Mattias Nissler | 887dce2 | 2017-07-03 14:44:35 +0200 | [diff] [blame] | 168 | // Changed from 'ps ux' to 'ps aux' since we're running as debugd, |
| 169 | // not chronos. |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 170 | { "ps", "/bin/ps aux" }, |
yusukes | 34171ba | 2017-04-27 15:46:01 -0700 | [diff] [blame] | 171 | // /proc/slabinfo is owned by root and has 0400 permission. |
| 172 | { "slabinfo", "/bin/cat /proc/slabinfo", kRoot, kRoot, }, |
Puthikorn Voravootivat | 6de5e12 | 2013-12-06 11:43:13 -0800 | [diff] [blame] | 173 | { "storage_info", "/bin/cat /var/log/storage_info.txt" }, |
Nicolas Boichat | 0230b0b | 2017-08-17 11:20:19 +0800 | [diff] [blame] | 174 | { "syslog", "/usr/share/userfeedback/scripts/getmsgs /var/log/messages" }, |
Brandon Mayer | e24c7a2 | 2017-08-04 13:58:48 -0400 | [diff] [blame] | 175 | { "system_log_stats", "echo 'BLOCK_SIZE=1024'; " |
| 176 | "find /var/log/ -type f -exec du --block-size=1024 {} + | sort -n -r", |
| 177 | kRoot, kRoot}, |
Elly Fong-Jones | b4f49c4 | 2013-02-28 13:45:26 -0500 | [diff] [blame] | 178 | { "tlsdate", "/bin/cat /var/log/tlsdate.log" }, |
Hsu-Cheng Tsai | e8c31d5 | 2017-03-31 12:34:55 +0800 | [diff] [blame] | 179 | { "top thread", "/usr/bin/top -Hb -n 1 | head -n 40"}, |
| 180 | { "top memory", "/usr/bin/top -o \"+%MEM\" -bn 1 | head -n 57"}, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 181 | { "touchpad", "/opt/google/touchpad/tpcontrol status" }, |
Chung-yih Wang | 4b87614 | 2014-04-30 17:01:49 +0800 | [diff] [blame] | 182 | { "touchpad_activity", "/opt/google/input/cmt_feedback alt" }, |
Andrew de los Reyes | c060c34 | 2013-04-10 13:46:30 -0700 | [diff] [blame] | 183 | { "touch_fw_version", "grep -E" |
Charlie Mooney | bb08f98 | 2016-02-04 15:35:56 -0800 | [diff] [blame] | 184 | " -e 'synaptics: Touchpad model'" |
| 185 | " -e 'chromeos-[a-z]*-touch-[a-z]*-update'" |
Andrew de los Reyes | c060c34 | 2013-04-10 13:46:30 -0700 | [diff] [blame] | 186 | " /var/log/messages | tail -n 20" }, |
Mattias Nissler | 887dce2 | 2017-07-03 14:44:35 +0200 | [diff] [blame] | 187 | // TODO(jorgelo,mnissler): Don't run this as root. |
| 188 | // On TPM 1.2 devices this will likely require adding a new user to the 'tss' |
| 189 | // group. |
| 190 | // On TPM 2.0 devices 'get_version_info' uses D-Bus and therefore can run as |
| 191 | // any user. |
| 192 | { "tpm_version", "/usr/sbin/tpm-manager get_version_info", kRoot, kRoot }, |
Charlie Mooney | 69f5670 | 2017-05-02 14:55:41 -0700 | [diff] [blame] | 193 | { "atmel_ts_refs", "/opt/google/touch/scripts/atmel_tools.sh ts r", |
| 194 | kRoot, kRoot}, |
| 195 | { "atmel_tp_refs", "/opt/google/touch/scripts/atmel_tools.sh tp r", |
| 196 | kRoot, kRoot}, |
| 197 | { "atmel_ts_deltas", "/opt/google/touch/scripts/atmel_tools.sh ts d", |
| 198 | kRoot, kRoot}, |
| 199 | { "atmel_tp_deltas", "/opt/google/touch/scripts/atmel_tools.sh tp d", |
| 200 | kRoot, kRoot}, |
Gwendal Grignou | 427d94e | 2016-10-25 11:34:51 -0700 | [diff] [blame] | 201 | { |
| 202 | "trim", |
| 203 | "cat /var/lib/trim/stateful_trim_state /var/lib/trim/stateful_trim_data" |
| 204 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 205 | { "ui_log", "/usr/share/userfeedback/scripts/get_log /var/log/ui/ui.LATEST" }, |
| 206 | { "uname", "/bin/uname -a" }, |
| 207 | { "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] | 208 | " s.^./var/log/update_engine/.)" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 209 | { "verified boot", "/bin/cat /var/log/debug_vboot_noisy.log" }, |
Justin TerAvest | bf921a3 | 2017-05-11 14:31:44 -0600 | [diff] [blame] | 210 | { "vmlog.1.LATEST", "/bin/cat /var/log/vmlog/vmlog.1.LATEST" }, |
| 211 | { "vmlog.1.PREVIOUS", "/bin/cat /var/log/vmlog/vmlog.1.PREVIOUS" }, |
| 212 | { "vmlog.LATEST", "/bin/cat /var/log/vmlog/vmlog.LATEST" }, |
| 213 | { "vmlog.PREVIOUS", "/bin/cat /var/log/vmlog/vmlog.PREVIOUS" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 214 | { "vpd_2.0", "/bin/cat /var/log/vpd_2.0.txt" }, |
Samuel Tan | 107b6c8 | 2014-07-10 15:33:44 -0700 | [diff] [blame] | 215 | { "wifi_status", "/usr/bin/network_diag --wifi-internal --no-log" }, |
Sonny Rao | ab5f995 | 2013-07-17 14:13:53 -0700 | [diff] [blame] | 216 | { "zram compressed data size", |
| 217 | "/bin/cat /sys/block/zram0/compr_data_size 2> /dev/null" }, |
| 218 | { "zram original data size", |
| 219 | "/bin/cat /sys/block/zram0/orig_data_size 2> /dev/null" }, |
| 220 | { "zram total memory used", |
| 221 | "/bin/cat /sys/block/zram0/mem_used_total 2> /dev/null" }, |
| 222 | { "zram total reads", |
| 223 | "/bin/cat /sys/block/zram0/num_reads 2> /dev/null" }, |
| 224 | { "zram total writes", |
| 225 | "/bin/cat /sys/block/zram0/num_writes 2> /dev/null" }, |
Luigi Semenzato | 0253b14 | 2017-07-07 15:59:48 -0700 | [diff] [blame] | 226 | { "zram new stats names", "/bin/echo orig_size compr_size used_total limit " |
Luigi Semenzato | 4164de4 | 2017-07-06 10:42:54 -0700 | [diff] [blame] | 227 | "used_max zero_pages migrated" }, |
Luigi Semenzato | 0253b14 | 2017-07-07 15:59:48 -0700 | [diff] [blame] | 228 | { "zram new stats values", "/bin/cat /sys/block/zram0/mm_stat 2> /dev/null" }, |
Wei-Ning Huang | 230b7d8 | 2017-07-14 16:19:13 +0800 | [diff] [blame] | 229 | { "cros_tp version", "/bin/cat /sys/class/chromeos/cros_tp/version" }, |
| 230 | { "cros_tp console", "/usr/sbin/ectool --name=cros_tp console", |
| 231 | kRoot, kRoot }, |
Wei-Ning Huang | 23ffdcf | 2017-08-04 11:30:39 +0800 | [diff] [blame] | 232 | { "cros_tp frame", "/usr/sbin/ectool --name=cros_tp tpframeget", |
| 233 | kRoot, kRoot }, |
Gaurav Shah | 6e8fd89 | 2012-10-01 11:51:08 -0700 | [diff] [blame] | 234 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 235 | // Stuff pulled out of the original list. These need access to the running X |
| 236 | // session, which we'd rather not give to debugd, or return info specific to |
| 237 | // the current session (in the setsid(2) sense), which is not useful for |
| 238 | // debugd |
| 239 | // { "env", "set" }, |
| 240 | // { "setxkbmap", "/usr/bin/setxkbmap -print -query" }, |
| 241 | // { "xrandr", "/usr/bin/xrandr --verbose" } |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 242 | { nullptr, nullptr } |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 243 | }; |
| 244 | |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 245 | const Log kExtraLogs[] = { |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 246 | #if USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 247 | { "mm-status", "/usr/bin/modem status" }, |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 248 | #endif // USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 249 | { "network-devices", "/usr/bin/connectivity show devices" }, |
| 250 | { "network-services", "/usr/bin/connectivity show services" }, |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 251 | { nullptr, nullptr } |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 252 | }; |
| 253 | |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 254 | const Log kFeedbackLogs[] = { |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 255 | #if USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 256 | { "mm-status", "/usr/bin/modem status-feedback" }, |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 257 | #endif // USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 258 | { "network-devices", "/usr/bin/connectivity show-feedback devices" }, |
| 259 | { "network-services", "/usr/bin/connectivity show-feedback services" }, |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 260 | { nullptr, nullptr } |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 261 | }; |
| 262 | |
Ahmed Fakhry | 1498b4e | 2016-03-30 12:42:20 -0700 | [diff] [blame] | 263 | // List of log files needed to be part of the feedback report that are huge and |
| 264 | // must be sent back to the client via the file descriptor using |
| 265 | // LogTool::GetBigFeedbackLogs(). |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 266 | const Log kBigFeedbackLogs[] = { |
Eric Caruso | e3166f2 | 2016-06-10 15:36:02 -0700 | [diff] [blame] | 267 | { "arc-bugreport", |
Yusuke Sato | 874c0a8 | 2016-10-13 15:41:37 -0700 | [diff] [blame] | 268 | "/bin/cat /run/arc/bugreport/pipe 2> /dev/null", |
Eric Caruso | e3166f2 | 2016-06-10 15:36:02 -0700 | [diff] [blame] | 269 | // ARC bugreport permissions are weird. Since we're just running cat, this |
| 270 | // shouldn't cause any issues. |
| 271 | kRoot, |
Ricky Zhou | 4c473ca | 2016-06-21 17:46:58 -0700 | [diff] [blame] | 272 | kRoot, |
| 273 | "10M", |
Eric Caruso | e3166f2 | 2016-06-10 15:36:02 -0700 | [diff] [blame] | 274 | }, |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 275 | { nullptr, nullptr } |
Ahmed Fakhry | 1498b4e | 2016-03-30 12:42:20 -0700 | [diff] [blame] | 276 | }; |
| 277 | |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 278 | // List of log files that must directly be collected by Chrome. This is because |
| 279 | // debugd is running under a VFS namespace and does not have access to later |
| 280 | // cryptohome mounts. |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 281 | const Log kUserLogs[] = { |
Elly Fong-Jones | 6456ce5 | 2013-04-17 13:31:13 -0400 | [diff] [blame] | 282 | {"chrome_user_log", "log/chrome"}, |
| 283 | {"login-times", "login-times"}, |
| 284 | {"logout-times", "logout-times"}, |
Ben Chan | 64d19b2 | 2017-02-06 14:03:47 -0800 | [diff] [blame] | 285 | { nullptr, nullptr} |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 288 | // Returns |value| if |value| is a valid UTF-8 string or a base64-encoded |
| 289 | // string of |value| otherwise. |
| 290 | string EnsureUTF8String(const string& value) { |
| 291 | if (base::IsStringUTF8(value)) |
| 292 | return value; |
| 293 | |
Eric Caruso | 96d03d3 | 2017-04-25 18:01:17 -0700 | [diff] [blame] | 294 | string encoded_value; |
Ben Chan | ab93abf | 2017-01-24 13:32:51 -0800 | [diff] [blame] | 295 | base::Base64Encode(value, &encoded_value); |
| 296 | return "<base64>: " + encoded_value; |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | // TODO(ellyjones): sandbox. crosbug.com/35122 |
| 300 | string Run(const Log& log) { |
| 301 | string output; |
| 302 | ProcessWithOutput p; |
Eric Caruso | 96d03d3 | 2017-04-25 18:01:17 -0700 | [diff] [blame] | 303 | string tailed_cmdline = string(log.command) + " | tail -c " + |
Ahmed Fakhry | e4a0b50 | 2016-09-19 18:18:49 -0700 | [diff] [blame] | 304 | (log.size_cap ? log.size_cap : "512K"); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 305 | if (log.user && log.group) |
| 306 | p.SandboxAs(log.user, log.group); |
| 307 | if (!p.Init()) |
| 308 | return "<not available>"; |
| 309 | p.AddArg(kShell); |
| 310 | p.AddStringOption("-c", tailed_cmdline); |
| 311 | if (p.Run()) |
| 312 | return "<not available>"; |
| 313 | p.GetOutput(&output); |
| 314 | if (!output.size()) |
| 315 | return "<empty>"; |
| 316 | return EnsureUTF8String(output); |
| 317 | } |
| 318 | |
| 319 | // Fills |dictionary| with the anonymized contents of the logs in |logs|. |
| 320 | void GetLogsInDictionary(const struct Log* logs, |
| 321 | AnonymizerTool* anonymizer, |
| 322 | base::DictionaryValue* dictionary) { |
| 323 | for (size_t i = 0; logs[i].name; ++i) { |
| 324 | dictionary->SetStringWithoutPathExpansion( |
| 325 | logs[i].name, anonymizer->Anonymize(Run(logs[i]))); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Serializes the |dictionary| into the file with the given |fd| in a JSON |
| 330 | // format. |
| 331 | void SerializeLogsAsJSON(const base::DictionaryValue& dictionary, |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 332 | const dbus::FileDescriptor& fd) { |
Eric Caruso | 96d03d3 | 2017-04-25 18:01:17 -0700 | [diff] [blame] | 333 | string logs_json; |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 334 | base::JSONWriter::WriteWithOptions(dictionary, |
| 335 | base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 336 | &logs_json); |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 337 | base::WriteFileDescriptor(fd.value(), logs_json.c_str(), logs_json.size()); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 340 | bool GetNamedLogFrom(const string& name, const struct Log* logs, |
| 341 | string* result) { |
| 342 | for (size_t i = 0; logs[i].name; i++) { |
| 343 | if (name == logs[i].name) { |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 344 | *result = Run(logs[i]); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 345 | return true; |
| 346 | } |
| 347 | } |
| 348 | *result = "<invalid log name>"; |
| 349 | return false; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 352 | void GetLogsFrom(const struct Log* logs, LogTool::LogMap* map) { |
| 353 | for (size_t i = 0; logs[i].name; i++) |
| 354 | (*map)[logs[i].name] = Run(logs[i]); |
| 355 | } |
| 356 | |
| 357 | } // namespace |
| 358 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 359 | void LogTool::CreateConnectivityReport() { |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 360 | // Perform ConnectivityTrial to report connection state in feedback log. |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 361 | auto shill = base::MakeUnique<org::chromium::flimflam::ManagerProxy>(bus_); |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 362 | // Give the connection trial time to test the connection and log the results |
| 363 | // before collecting the logs for feedback. |
| 364 | // TODO(silberst): Replace the simple approach of a single timeout with a more |
| 365 | // coordinated effort. |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 366 | if (shill && shill->CreateConnectivityReport(nullptr)) |
| 367 | sleep(kConnectionTesterTimeoutSeconds); |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 370 | string LogTool::GetLog(const string& name) { |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 371 | string result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 372 | GetNamedLogFrom(name, kCommandLogs, &result) |
| 373 | || GetNamedLogFrom(name, kExtraLogs, &result) |
| 374 | || GetNamedLogFrom(name, kFeedbackLogs, &result); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 375 | return result; |
| 376 | } |
| 377 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 378 | LogTool::LogMap LogTool::GetAllLogs() { |
| 379 | CreateConnectivityReport(); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 380 | LogMap result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 381 | GetLogsFrom(kCommandLogs, &result); |
| 382 | GetLogsFrom(kExtraLogs, &result); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 383 | return result; |
| 384 | } |
| 385 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 386 | LogTool::LogMap LogTool::GetFeedbackLogs() { |
| 387 | CreateConnectivityReport(); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 388 | LogMap result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 389 | GetLogsFrom(kCommandLogs, &result); |
| 390 | GetLogsFrom(kFeedbackLogs, &result); |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 391 | AnonymizeLogMap(&result); |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 392 | return result; |
| 393 | } |
| 394 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 395 | void LogTool::GetBigFeedbackLogs(const dbus::FileDescriptor& fd) { |
| 396 | CreateConnectivityReport(); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 397 | base::DictionaryValue dictionary; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 398 | GetLogsInDictionary(kCommandLogs, &anonymizer_, &dictionary); |
| 399 | GetLogsInDictionary(kFeedbackLogs, &anonymizer_, &dictionary); |
| 400 | GetLogsInDictionary(kBigFeedbackLogs, &anonymizer_, &dictionary); |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 401 | SerializeLogsAsJSON(dictionary, fd); |
| 402 | } |
| 403 | |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 404 | LogTool::LogMap LogTool::GetUserLogFiles() { |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 405 | LogMap result; |
Ben Chan | cf7d641 | 2017-08-10 22:30:09 -0700 | [diff] [blame] | 406 | for (size_t i = 0; kUserLogs[i].name; ++i) |
| 407 | result[kUserLogs[i].name] = kUserLogs[i].command; |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 408 | return result; |
| 409 | } |
| 410 | |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 411 | void LogTool::AnonymizeLogMap(LogMap* log_map) { |
Ben Chan | e2fa357 | 2017-02-08 22:46:18 -0800 | [diff] [blame] | 412 | for (auto& entry : *log_map) |
| 413 | entry.second = anonymizer_.Anonymize(entry.second); |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 414 | } |
| 415 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 416 | } // namespace debugd |