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 | f6cd93a | 2012-10-14 19:37:00 -0700 | [diff] [blame] | 9 | #include <glib.h> |
| 10 | |
Ben Chan | cd8fda4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 11 | #include <base/files/file_util.h> |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 12 | #include <base/json/json_writer.h> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 13 | #include <base/logging.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> |
Peter Qiu | ed45fda | 2015-09-09 16:52:50 -0700 | [diff] [blame] | 19 | #include <shill/dbus_proxies/org.chromium.flimflam.Manager.h> |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 20 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 21 | #include "debugd/src/process_with_output.h" |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 22 | |
| 23 | namespace debugd { |
| 24 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 25 | using std::string; |
| 26 | using std::vector; |
| 27 | |
| 28 | typedef vector<string> Strings; |
| 29 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 30 | const char *kDebugfsGroup = "debugfs-access"; |
Ben Chan | f6cd93a | 2012-10-14 19:37:00 -0700 | [diff] [blame] | 31 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 32 | namespace { |
| 33 | |
| 34 | const char *kShell = "/bin/sh"; |
| 35 | |
| 36 | // Minimum time in seconds needed to allow shill to test active connections. |
| 37 | const int kConnectionTesterTimeoutSeconds = 5; |
Ben Chan | f6cd93a | 2012-10-14 19:37:00 -0700 | [diff] [blame] | 38 | |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 39 | struct Log { |
| 40 | const char *name; |
| 41 | const char *command; |
| 42 | const char *user; |
| 43 | const char *group; |
| 44 | }; |
| 45 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 46 | const Log common_logs[] = { |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 47 | { "CLIENT_ID", "/bin/cat '/home/chronos/Consent To Send Stats'" }, |
| 48 | { "LOGDATE", "/bin/date" }, |
| 49 | { "Xorg.0.log", "/bin/cat /var/log/Xorg.0.log" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 50 | { "bios_info", "/bin/cat /var/log/bios_info.txt" }, |
Vadim Bendebury | 64aeeed | 2013-09-16 13:16:49 -0700 | [diff] [blame] | 51 | { "bios_log", |
| 52 | "/bin/cat /sys/firmware/log " |
| 53 | "/proc/device-tree/chosen/ap-console-buffer 2> /dev/null" }, |
Stefan Reinauer | 4393fa7 | 2012-10-18 11:08:09 -0700 | [diff] [blame] | 54 | { "bios_times", "/bin/cat /var/log/bios_times.txt" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 55 | { "board-specific", |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 56 | "/usr/share/userfeedback/scripts/get_board_specific_info" }, |
Olof Johansson | e5d0fd3 | 2016-01-29 14:40:34 -0800 | [diff] [blame] | 57 | { "cheets_log", "/usr/bin/collect-cheets-logs 2>&1" }, |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 58 | { "clobber.log", "/bin/cat /var/log/clobber.log 2> /dev/null" }, |
| 59 | { "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] | 60 | { "chrome_system_log", "/bin/cat /var/log/chrome/chrome" }, |
Stefan Reinauer | 48f883d | 2014-08-22 14:31:58 -0700 | [diff] [blame] | 61 | { "console-ramoops", "/bin/cat /dev/pstore/console-ramoops 2> /dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 62 | { "cpu", "/usr/bin/uname -p" }, |
| 63 | { "cpuinfo", "/bin/cat /proc/cpuinfo" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 64 | { "dmesg", "/bin/dmesg" }, |
| 65 | { "ec_info", "/bin/cat /var/log/ec_info.txt" }, |
Stefan Reinauer | 4393fa7 | 2012-10-18 11:08:09 -0700 | [diff] [blame] | 66 | { "eventlog", "/bin/cat /var/log/eventlog.txt" }, |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 67 | { |
| 68 | "exynos_gem_objects", |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 69 | "/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] | 70 | SandboxedProcess::kDefaultUser, |
| 71 | kDebugfsGroup |
| 72 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 73 | { "font_info", "/usr/share/userfeedback/scripts/font_info" }, |
| 74 | { "hardware_class", "/usr/bin/crossystem hwid" }, |
| 75 | { "hostname", "/bin/hostname" }, |
| 76 | { "hw_platform", "/usr/bin/uname -i" }, |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 77 | { |
| 78 | "i915_gem_gtt", |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 79 | "/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] | 80 | SandboxedProcess::kDefaultUser, |
| 81 | kDebugfsGroup |
| 82 | }, |
| 83 | { |
| 84 | "i915_gem_objects", |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 85 | "/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] | 86 | SandboxedProcess::kDefaultUser, |
| 87 | kDebugfsGroup |
| 88 | }, |
| 89 | { |
| 90 | "i915_error_state", |
Yuly Novikov | 4ac12fb | 2013-07-18 20:08:44 -0400 | [diff] [blame] | 91 | "/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] | 92 | SandboxedProcess::kDefaultUser, |
| 93 | kDebugfsGroup, |
| 94 | }, |
Daniel Erat | 982ab4b | 2014-04-09 07:32:38 -0700 | [diff] [blame] | 95 | { "ifconfig", "/bin/ifconfig -a" }, |
Stefan Reinauer | 48f883d | 2014-08-22 14:31:58 -0700 | [diff] [blame] | 96 | { "kernel-crashes", |
| 97 | "/bin/cat /var/spool/crash/kernel.*.kcrash 2> /dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 98 | { "lsmod", "lsmod" }, |
| 99 | { "lspci", "/usr/sbin/lspci" }, |
| 100 | { "lsusb", "lsusb" }, |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 101 | { |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 102 | "mali_memory", |
| 103 | "/bin/cat /sys/class/misc/mali0/device/memory 2> /dev/null" |
Yuly Novikov | 13ece85 | 2013-07-11 17:19:10 -0400 | [diff] [blame] | 104 | }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 105 | { "meminfo", "cat /proc/meminfo" }, |
| 106 | { "memory_spd_info", "/bin/cat /var/log/memory_spd_info.txt" }, |
Kees Cook | a8f3e7e | 2012-11-19 14:16:01 -0800 | [diff] [blame] | 107 | { "mount-encrypted", "/bin/cat /var/log/mount-encrypted.log" }, |
Darin Petkov | 5474358 | 2012-12-10 14:18:32 +0100 | [diff] [blame] | 108 | { "net-diags.net.log", "/bin/cat /var/log/net-diags.net.log" }, |
Wade Guthrie | 67b672e | 2012-11-14 13:14:31 -0800 | [diff] [blame] | 109 | { "netlog", "/usr/share/userfeedback/scripts/getmsgs --last '2 hours'" |
| 110 | " /var/log/net.log" }, |
henryhsu | fa6daa1 | 2014-09-24 13:26:30 +0800 | [diff] [blame] | 111 | { |
| 112 | "nvmap_iovmm", |
| 113 | "/bin/cat /sys/kernel/debug/nvmap/iovmm/allocations 2> /dev/null", |
| 114 | SandboxedProcess::kDefaultUser, |
| 115 | kDebugfsGroup, |
| 116 | }, |
Vincent Palatin | c64af9d | 2013-08-05 16:34:10 -0700 | [diff] [blame] | 117 | { "platform_info", "/bin/cat /var/log/platform_info.txt" }, |
Daniel Erat | 9b58b6d | 2013-04-30 14:58:56 -0700 | [diff] [blame] | 118 | { "power_supply_info", "/usr/bin/power_supply_info" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 119 | { "powerd.LATEST", "/bin/cat /var/log/power_manager/powerd.LATEST" }, |
Daniel Erat | 546c388 | 2013-11-22 12:46:01 -0800 | [diff] [blame] | 120 | { "powerd.PREVIOUS", "/bin/cat /var/log/power_manager/powerd.PREVIOUS" }, |
Daniel Erat | 93da9a1 | 2012-12-06 14:14:17 -0800 | [diff] [blame] | 121 | { "powerd.out", "/bin/cat /var/log/powerd.out" }, |
Thiemo Nagel | a269ad2 | 2014-11-27 17:13:01 +0100 | [diff] [blame] | 122 | { "powerwash_count", "/bin/cat /var/log/powerwash_count 2> /dev/null" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 123 | // Changed from 'ps ux' to 'ps aux' since we're running as debugd, not chronos |
| 124 | { "ps", "/bin/ps aux" }, |
Puthikorn Voravootivat | 6de5e12 | 2013-12-06 11:43:13 -0800 | [diff] [blame] | 125 | { "storage_info", "/bin/cat /var/log/storage_info.txt" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 126 | { "syslog", "/usr/share/userfeedback/scripts/getmsgs --last '2 hours'" |
Elly Jones | f8a67ee | 2012-06-19 13:48:38 -0400 | [diff] [blame] | 127 | " /var/log/messages" }, |
Elly Fong-Jones | b4f49c4 | 2013-02-28 13:45:26 -0500 | [diff] [blame] | 128 | { "tlsdate", "/bin/cat /var/log/tlsdate.log" }, |
Michael Spang | 387567d | 2015-03-11 17:16:04 -0400 | [diff] [blame] | 129 | { "input_devices", "/bin/cat /proc/bus/input/devices" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 130 | { "touchpad", "/opt/google/touchpad/tpcontrol status" }, |
Chung-yih Wang | 4b87614 | 2014-04-30 17:01:49 +0800 | [diff] [blame] | 131 | { "touchpad_activity", "/opt/google/input/cmt_feedback alt" }, |
Andrew de los Reyes | c060c34 | 2013-04-10 13:46:30 -0700 | [diff] [blame] | 132 | { "touch_fw_version", "grep -E" |
Charlie Mooney | bb08f98 | 2016-02-04 15:35:56 -0800 | [diff] [blame] | 133 | " -e 'synaptics: Touchpad model'" |
| 134 | " -e 'chromeos-[a-z]*-touch-[a-z]*-update'" |
Andrew de los Reyes | c060c34 | 2013-04-10 13:46:30 -0700 | [diff] [blame] | 135 | " /var/log/messages | tail -n 20" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 136 | { "ui_log", "/usr/share/userfeedback/scripts/get_log /var/log/ui/ui.LATEST" }, |
| 137 | { "uname", "/bin/uname -a" }, |
| 138 | { "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] | 139 | " s.^./var/log/update_engine/.)" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 140 | { "verified boot", "/bin/cat /var/log/debug_vboot_noisy.log" }, |
| 141 | { "vpd_2.0", "/bin/cat /var/log/vpd_2.0.txt" }, |
Samuel Tan | 107b6c8 | 2014-07-10 15:33:44 -0700 | [diff] [blame] | 142 | { "wifi_status", "/usr/bin/network_diag --wifi-internal --no-log" }, |
Sonny Rao | ab5f995 | 2013-07-17 14:13:53 -0700 | [diff] [blame] | 143 | { "zram compressed data size", |
| 144 | "/bin/cat /sys/block/zram0/compr_data_size 2> /dev/null" }, |
| 145 | { "zram original data size", |
| 146 | "/bin/cat /sys/block/zram0/orig_data_size 2> /dev/null" }, |
| 147 | { "zram total memory used", |
| 148 | "/bin/cat /sys/block/zram0/mem_used_total 2> /dev/null" }, |
| 149 | { "zram total reads", |
| 150 | "/bin/cat /sys/block/zram0/num_reads 2> /dev/null" }, |
| 151 | { "zram total writes", |
| 152 | "/bin/cat /sys/block/zram0/num_writes 2> /dev/null" }, |
Gaurav Shah | 6e8fd89 | 2012-10-01 11:51:08 -0700 | [diff] [blame] | 153 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 154 | // Stuff pulled out of the original list. These need access to the running X |
| 155 | // session, which we'd rather not give to debugd, or return info specific to |
| 156 | // the current session (in the setsid(2) sense), which is not useful for |
| 157 | // debugd |
| 158 | // { "env", "set" }, |
| 159 | // { "setxkbmap", "/usr/bin/setxkbmap -print -query" }, |
| 160 | // { "xrandr", "/usr/bin/xrandr --verbose" } |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 161 | { NULL, NULL } |
| 162 | }; |
| 163 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 164 | const Log extra_logs[] = { |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 165 | #if USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 166 | { "mm-status", "/usr/bin/modem status" }, |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 167 | #endif // USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 168 | { "network-devices", "/usr/bin/connectivity show devices" }, |
| 169 | { "network-services", "/usr/bin/connectivity show services" }, |
| 170 | { NULL, NULL } |
| 171 | }; |
| 172 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 173 | const Log feedback_logs[] = { |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 174 | #if USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 175 | { "mm-status", "/usr/bin/modem status-feedback" }, |
Ben Chan | 36e4228 | 2014-02-12 22:32:34 -0800 | [diff] [blame] | 176 | #endif // USE_CELLULAR |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 177 | { "network-devices", "/usr/bin/connectivity show-feedback devices" }, |
| 178 | { "network-services", "/usr/bin/connectivity show-feedback services" }, |
| 179 | { NULL, NULL } |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 180 | }; |
| 181 | |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 182 | // List of log files that must directly be collected by Chrome. This is because |
| 183 | // debugd is running under a VFS namespace and does not have access to later |
| 184 | // cryptohome mounts. |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 185 | const Log user_logs[] = { |
Elly Fong-Jones | 6456ce5 | 2013-04-17 13:31:13 -0400 | [diff] [blame] | 186 | {"chrome_user_log", "log/chrome"}, |
| 187 | {"login-times", "login-times"}, |
| 188 | {"logout-times", "logout-times"}, |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 189 | { NULL, NULL} |
| 190 | }; |
| 191 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 192 | class ManagerProxy : public org::chromium::flimflam::Manager_proxy, |
| 193 | public DBus::ObjectProxy { |
| 194 | public: |
| 195 | ManagerProxy(DBus::Connection* connection, |
| 196 | const char* path, |
| 197 | const char* service) |
| 198 | : DBus::ObjectProxy(*connection, path, service) {} |
| 199 | ~ManagerProxy() override = default; |
| 200 | void PropertyChanged(const std::string&, const DBus::Variant&) override {} |
| 201 | void StateChanged(const std::string&) override {} |
| 202 | }; |
| 203 | |
| 204 | // Returns |value| if |value| is a valid UTF-8 string or a base64-encoded |
| 205 | // string of |value| otherwise. |
| 206 | string EnsureUTF8String(const string& value) { |
| 207 | if (base::IsStringUTF8(value)) |
| 208 | return value; |
| 209 | |
| 210 | gchar* base64_value = g_base64_encode( |
| 211 | reinterpret_cast<const guchar*>(value.c_str()), value.length()); |
| 212 | if (base64_value) { |
| 213 | string encoded_value = "<base64>: "; |
| 214 | encoded_value += base64_value; |
| 215 | g_free(base64_value); |
| 216 | return encoded_value; |
| 217 | } |
| 218 | return "<invalid>"; |
| 219 | } |
| 220 | |
| 221 | // TODO(ellyjones): sandbox. crosbug.com/35122 |
| 222 | string Run(const Log& log) { |
| 223 | string output; |
| 224 | ProcessWithOutput p; |
| 225 | string tailed_cmdline = std::string(log.command) + " | tail -c 256K"; |
| 226 | if (log.user && log.group) |
| 227 | p.SandboxAs(log.user, log.group); |
| 228 | if (!p.Init()) |
| 229 | return "<not available>"; |
| 230 | p.AddArg(kShell); |
| 231 | p.AddStringOption("-c", tailed_cmdline); |
| 232 | if (p.Run()) |
| 233 | return "<not available>"; |
| 234 | p.GetOutput(&output); |
| 235 | if (!output.size()) |
| 236 | return "<empty>"; |
| 237 | return EnsureUTF8String(output); |
| 238 | } |
| 239 | |
| 240 | // Fills |dictionary| with the anonymized contents of the logs in |logs|. |
| 241 | void GetLogsInDictionary(const struct Log* logs, |
| 242 | AnonymizerTool* anonymizer, |
| 243 | base::DictionaryValue* dictionary) { |
| 244 | for (size_t i = 0; logs[i].name; ++i) { |
| 245 | dictionary->SetStringWithoutPathExpansion( |
| 246 | logs[i].name, anonymizer->Anonymize(Run(logs[i]))); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // Serializes the |dictionary| into the file with the given |fd| in a JSON |
| 251 | // format. |
| 252 | void SerializeLogsAsJSON(const base::DictionaryValue& dictionary, |
| 253 | const DBus::FileDescriptor& fd) { |
| 254 | std::string logs_json; |
| 255 | base::JSONWriter::WriteWithOptions(dictionary, |
| 256 | base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 257 | &logs_json); |
| 258 | base::WriteFileDescriptor(fd.get(), logs_json.c_str(), logs_json.size()); |
| 259 | } |
| 260 | |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 261 | bool GetNamedLogFrom(const string& name, const struct Log* logs, |
| 262 | string* result) { |
| 263 | for (size_t i = 0; logs[i].name; i++) { |
| 264 | if (name == logs[i].name) { |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 265 | *result = Run(logs[i]); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 266 | return true; |
| 267 | } |
| 268 | } |
| 269 | *result = "<invalid log name>"; |
| 270 | return false; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 273 | void GetLogsFrom(const struct Log* logs, LogTool::LogMap* map) { |
| 274 | for (size_t i = 0; logs[i].name; i++) |
| 275 | (*map)[logs[i].name] = Run(logs[i]); |
| 276 | } |
| 277 | |
| 278 | } // namespace |
| 279 | |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 280 | void LogTool::CreateConnectivityReport(DBus::Connection* connection) { |
| 281 | // Perform ConnectivityTrial to report connection state in feedback log. |
| 282 | ManagerProxy shill(connection, |
| 283 | shill::kFlimflamServicePath, |
| 284 | shill::kFlimflamServiceName); |
| 285 | shill.CreateConnectivityReport(); |
| 286 | // Give the connection trial time to test the connection and log the results |
| 287 | // before collecting the logs for feedback. |
| 288 | // TODO(silberst): Replace the simple approach of a single timeout with a more |
| 289 | // coordinated effort. |
| 290 | sleep(kConnectionTesterTimeoutSeconds); |
| 291 | } |
| 292 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 293 | string LogTool::GetLog(const string& name, DBus::Error* error) { |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 294 | string result; |
| 295 | GetNamedLogFrom(name, common_logs, &result) |
| 296 | || GetNamedLogFrom(name, extra_logs, &result) |
| 297 | || GetNamedLogFrom(name, feedback_logs, &result); |
| 298 | return result; |
| 299 | } |
| 300 | |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 301 | LogTool::LogMap LogTool::GetAllLogs(DBus::Connection* connection, |
| 302 | DBus::Error* error) { |
| 303 | CreateConnectivityReport(connection); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 304 | LogMap result; |
| 305 | GetLogsFrom(common_logs, &result); |
| 306 | GetLogsFrom(extra_logs, &result); |
| 307 | return result; |
| 308 | } |
| 309 | |
Rebecca Silberstein | e78af40 | 2014-10-02 10:55:04 -0700 | [diff] [blame] | 310 | LogTool::LogMap LogTool::GetFeedbackLogs(DBus::Connection* connection, |
| 311 | DBus::Error* error) { |
| 312 | CreateConnectivityReport(connection); |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 313 | LogMap result; |
| 314 | GetLogsFrom(common_logs, &result); |
| 315 | GetLogsFrom(feedback_logs, &result); |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 316 | AnonymizeLogMap(&result); |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 317 | return result; |
| 318 | } |
| 319 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 320 | void LogTool::GetBigFeedbackLogs(DBus::Connection* connection, |
| 321 | const DBus::FileDescriptor& fd, |
| 322 | DBus::Error* error) { |
| 323 | CreateConnectivityReport(connection); |
| 324 | base::DictionaryValue dictionary; |
| 325 | GetLogsInDictionary(common_logs, &anonymizer_, &dictionary); |
| 326 | GetLogsInDictionary(feedback_logs, &anonymizer_, &dictionary); |
| 327 | SerializeLogsAsJSON(dictionary, fd); |
| 328 | } |
| 329 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 330 | LogTool::LogMap LogTool::GetUserLogFiles(DBus::Error* error) { |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 331 | LogMap result; |
| 332 | for (size_t i = 0; user_logs[i].name; ++i) |
| 333 | result[user_logs[i].name] = user_logs[i].command; |
| 334 | return result; |
| 335 | } |
| 336 | |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 337 | void LogTool::AnonymizeLogMap(LogMap* log_map) { |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 338 | for (LogMap::iterator it = log_map->begin(); |
| 339 | it != log_map->end(); ++it) { |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame^] | 340 | it->second = anonymizer_.Anonymize(it->second); |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 344 | } // namespace debugd |