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