blob: 36ec810ec1b962328e3c7553f9b7ef05552924e3 [file] [log] [blame]
Elly Jones03cd6d72012-06-11 13:04:28 -04001// 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 Vakulenko262be3f2014-07-30 15:25:50 -07005#include "debugd/src/log_tool.h"
Elly Jones03cd6d72012-06-11 13:04:28 -04006
Ben Chana0011d82014-05-13 00:19:29 -07007#include <vector>
8
Ben Chanab93abf2017-01-24 13:32:51 -08009#include <base/base64.h>
Ben Chancd8fda42014-09-05 08:21:06 -070010#include <base/files/file_util.h>
Ahmed Fakhry21140cf2016-03-04 17:15:19 -080011#include <base/json/json_writer.h>
Elly Jones03cd6d72012-06-11 13:04:28 -040012#include <base/logging.h>
Ben Chan9953a592014-02-05 23:32:00 -080013#include <base/strings/string_split.h>
14#include <base/strings/string_util.h>
Ahmed Fakhry21140cf2016-03-04 17:15:19 -080015#include <base/values.h>
Elly Jones03cd6d72012-06-11 13:04:28 -040016
Rebecca Silbersteine78af402014-10-02 10:55:04 -070017#include <chromeos/dbus/service_constants.h>
Peter Qiued45fda2015-09-09 16:52:50 -070018#include <shill/dbus_proxies/org.chromium.flimflam.Manager.h>
Rebecca Silbersteine78af402014-10-02 10:55:04 -070019
Ben Chanaf125862017-02-08 23:11:18 -080020#include "debugd/src/constants.h"
Alex Vakulenko262be3f2014-07-30 15:25:50 -070021#include "debugd/src/process_with_output.h"
Elly Jones03cd6d72012-06-11 13:04:28 -040022
23namespace debugd {
24
Elly Jones03cd6d72012-06-11 13:04:28 -040025using std::string;
Elly Jones03cd6d72012-06-11 13:04:28 -040026
Eric Caruso96d03d32017-04-25 18:01:17 -070027using Strings = std::vector<string>;
Elly Jones03cd6d72012-06-11 13:04:28 -040028
Ahmed Fakhry21140cf2016-03-04 17:15:19 -080029namespace {
30
Ben Chanaf125862017-02-08 23:11:18 -080031const char kRoot[] = "root";
32const char kShell[] = "/bin/sh";
Ahmed Fakhry21140cf2016-03-04 17:15:19 -080033
34// Minimum time in seconds needed to allow shill to test active connections.
35const int kConnectionTesterTimeoutSeconds = 5;
Ben Chanf6cd93a2012-10-14 19:37:00 -070036
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050037struct Log {
38 const char *name;
39 const char *command;
40 const char *user;
41 const char *group;
Ricky Zhou4c473ca2016-06-21 17:46:58 -070042 const char *size_cap; // passed as arg to 'tail'
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050043};
44
Ahmed Fakhry21140cf2016-03-04 17:15:19 -080045const Log common_logs[] = {
Mike Frysingerc3e835a2017-01-06 04:09:34 -050046 { "CLIENT_ID", "/usr/bin/metrics_client -i"},
Elly Jones03cd6d72012-06-11 13:04:28 -040047 { "LOGDATE", "/bin/date" },
Elly Jones03cd6d72012-06-11 13:04:28 -040048 { "bios_info", "/bin/cat /var/log/bios_info.txt" },
Vadim Bendebury64aeeed2013-09-16 13:16:49 -070049 { "bios_log",
50 "/bin/cat /sys/firmware/log "
51 "/proc/device-tree/chosen/ap-console-buffer 2> /dev/null" },
Stefan Reinauer4393fa72012-10-18 11:08:09 -070052 { "bios_times", "/bin/cat /var/log/bios_times.txt" },
Elly Jones03cd6d72012-06-11 13:04:28 -040053 { "board-specific",
Thiemo Nagela269ad22014-11-27 17:13:01 +010054 "/usr/share/userfeedback/scripts/get_board_specific_info" },
Olof Johanssone5d0fd32016-01-29 14:40:34 -080055 { "cheets_log", "/usr/bin/collect-cheets-logs 2>&1" },
Thiemo Nagela269ad22014-11-27 17:13:01 +010056 { "clobber.log", "/bin/cat /var/log/clobber.log 2> /dev/null" },
57 { "clobber-state.log", "/bin/cat /var/log/clobber-state.log 2> /dev/null" },
Elly Jones03cd6d72012-06-11 13:04:28 -040058 { "chrome_system_log", "/bin/cat /var/log/chrome/chrome" },
Stefan Reinauer48f883d2014-08-22 14:31:58 -070059 { "console-ramoops", "/bin/cat /dev/pstore/console-ramoops 2> /dev/null" },
Elly Jones03cd6d72012-06-11 13:04:28 -040060 { "cpu", "/usr/bin/uname -p" },
61 { "cpuinfo", "/bin/cat /proc/cpuinfo" },
Benson Leung1526c8f2017-01-22 20:38:04 -080062 { "cr50_version", "/bin/cat /var/cache/cr50-version" },
Eric Caruso57333f12015-09-08 12:50:32 -070063 { "cros_ec",
64 "/bin/cat /var/log/cros_ec.previous /var/log/cros_ec.log 2> /dev/null" },
Nicolas Boichat083795f2016-08-16 11:16:49 +020065 { "cros_ec_panicinfo",
Nicolas Boichatd51092b2016-09-01 10:36:46 +080066 "/bin/cat /sys/kernel/debug/cros_ec/panicinfo 2> /dev/null",
67 SandboxedProcess::kDefaultUser,
68 kDebugfsGroup
69 },
Elly Jones03cd6d72012-06-11 13:04:28 -040070 { "dmesg", "/bin/dmesg" },
71 { "ec_info", "/bin/cat /var/log/ec_info.txt" },
Stefan Reinauer4393fa72012-10-18 11:08:09 -070072 { "eventlog", "/bin/cat /var/log/eventlog.txt" },
Elly Fong-Jones215b5622013-03-20 14:32:18 -040073 {
74 "exynos_gem_objects",
Yuly Novikov13ece852013-07-11 17:19:10 -040075 "/bin/cat /sys/kernel/debug/dri/0/exynos_gem_objects 2> /dev/null",
Elly Fong-Jones215b5622013-03-20 14:32:18 -040076 SandboxedProcess::kDefaultUser,
77 kDebugfsGroup
78 },
Elly Jones03cd6d72012-06-11 13:04:28 -040079 { "font_info", "/usr/share/userfeedback/scripts/font_info" },
Daisuke Nojiridebede0e2017-02-17 14:21:28 -080080 { "sensor_info", "/usr/share/userfeedback/scripts/sensor_info" },
Elly Jones03cd6d72012-06-11 13:04:28 -040081 { "hardware_class", "/usr/bin/crossystem hwid" },
82 { "hostname", "/bin/hostname" },
83 { "hw_platform", "/usr/bin/uname -i" },
Elly Fong-Jones215b5622013-03-20 14:32:18 -040084 {
85 "i915_gem_gtt",
Yuly Novikov13ece852013-07-11 17:19:10 -040086 "/bin/cat /sys/kernel/debug/dri/0/i915_gem_gtt 2> /dev/null",
Elly Fong-Jones215b5622013-03-20 14:32:18 -040087 SandboxedProcess::kDefaultUser,
88 kDebugfsGroup
89 },
90 {
91 "i915_gem_objects",
Yuly Novikov13ece852013-07-11 17:19:10 -040092 "/bin/cat /sys/kernel/debug/dri/0/i915_gem_objects 2> /dev/null",
Elly Fong-Jones215b5622013-03-20 14:32:18 -040093 SandboxedProcess::kDefaultUser,
94 kDebugfsGroup
95 },
96 {
97 "i915_error_state",
Yuly Novikov4ac12fb2013-07-18 20:08:44 -040098 "/usr/bin/xz -c /sys/kernel/debug/dri/0/i915_error_state 2> /dev/null",
Elly Fong-Jones215b5622013-03-20 14:32:18 -040099 SandboxedProcess::kDefaultUser,
100 kDebugfsGroup,
101 },
Daniel Erat982ab4b2014-04-09 07:32:38 -0700102 { "ifconfig", "/bin/ifconfig -a" },
Stefan Reinauer48f883d2014-08-22 14:31:58 -0700103 { "kernel-crashes",
104 "/bin/cat /var/spool/crash/kernel.*.kcrash 2> /dev/null" },
Elly Jones03cd6d72012-06-11 13:04:28 -0400105 { "lsmod", "lsmod" },
106 { "lspci", "/usr/sbin/lspci" },
107 { "lsusb", "lsusb" },
Yuly Novikov13ece852013-07-11 17:19:10 -0400108 {
Thiemo Nagela269ad22014-11-27 17:13:01 +0100109 "mali_memory",
110 "/bin/cat /sys/class/misc/mali0/device/memory 2> /dev/null"
Yuly Novikov13ece852013-07-11 17:19:10 -0400111 },
Elly Jones03cd6d72012-06-11 13:04:28 -0400112 { "meminfo", "cat /proc/meminfo" },
113 { "memory_spd_info", "/bin/cat /var/log/memory_spd_info.txt" },
Kees Cooka8f3e7e2012-11-19 14:16:01 -0800114 { "mount-encrypted", "/bin/cat /var/log/mount-encrypted.log" },
Junichi Uekawa710cb4b2017-04-10 16:05:27 +0900115 { "mountinfo", "/bin/cat /proc/1/mountinfo" },
Darin Petkov54743582012-12-10 14:18:32 +0100116 { "net-diags.net.log", "/bin/cat /var/log/net-diags.net.log" },
Wade Guthrie67b672e2012-11-14 13:14:31 -0800117 { "netlog", "/usr/share/userfeedback/scripts/getmsgs --last '2 hours'"
118 " /var/log/net.log" },
henryhsufa6daa12014-09-24 13:26:30 +0800119 {
120 "nvmap_iovmm",
121 "/bin/cat /sys/kernel/debug/nvmap/iovmm/allocations 2> /dev/null",
122 SandboxedProcess::kDefaultUser,
123 kDebugfsGroup,
124 },
Vincent Palatinc64af9d2013-08-05 16:34:10 -0700125 { "platform_info", "/bin/cat /var/log/platform_info.txt" },
Daniel Erat9b58b6d2013-04-30 14:58:56 -0700126 { "power_supply_info", "/usr/bin/power_supply_info" },
Daniel Eratd8b84992017-03-13 17:30:00 -0600127 { "power_supply_sysfs", "/usr/bin/print_sysfs_power_supply_data" },
Elly Jones03cd6d72012-06-11 13:04:28 -0400128 { "powerd.LATEST", "/bin/cat /var/log/power_manager/powerd.LATEST" },
Daniel Erat546c3882013-11-22 12:46:01 -0800129 { "powerd.PREVIOUS", "/bin/cat /var/log/power_manager/powerd.PREVIOUS" },
Daniel Erat93da9a12012-12-06 14:14:17 -0800130 { "powerd.out", "/bin/cat /var/log/powerd.out" },
Thiemo Nagela269ad22014-11-27 17:13:01 +0100131 { "powerwash_count", "/bin/cat /var/log/powerwash_count 2> /dev/null" },
Elly Jones03cd6d72012-06-11 13:04:28 -0400132 // Changed from 'ps ux' to 'ps aux' since we're running as debugd, not chronos
133 { "ps", "/bin/ps aux" },
Puthikorn Voravootivat6de5e122013-12-06 11:43:13 -0800134 { "storage_info", "/bin/cat /var/log/storage_info.txt" },
Elly Jones03cd6d72012-06-11 13:04:28 -0400135 { "syslog", "/usr/share/userfeedback/scripts/getmsgs --last '2 hours'"
Elly Jonesf8a67ee2012-06-19 13:48:38 -0400136 " /var/log/messages" },
Elly Fong-Jonesb4f49c42013-02-28 13:45:26 -0500137 { "tlsdate", "/bin/cat /var/log/tlsdate.log" },
Michael Spang387567d2015-03-11 17:16:04 -0400138 { "input_devices", "/bin/cat /proc/bus/input/devices" },
Hsu-Cheng Tsaie8c31d52017-03-31 12:34:55 +0800139 { "top thread", "/usr/bin/top -Hb -n 1 | head -n 40"},
140 { "top memory", "/usr/bin/top -o \"+%MEM\" -bn 1 | head -n 57"},
Elly Jones03cd6d72012-06-11 13:04:28 -0400141 { "touchpad", "/opt/google/touchpad/tpcontrol status" },
Chung-yih Wang4b876142014-04-30 17:01:49 +0800142 { "touchpad_activity", "/opt/google/input/cmt_feedback alt" },
Andrew de los Reyesc060c342013-04-10 13:46:30 -0700143 { "touch_fw_version", "grep -E"
Charlie Mooneybb08f982016-02-04 15:35:56 -0800144 " -e 'synaptics: Touchpad model'"
145 " -e 'chromeos-[a-z]*-touch-[a-z]*-update'"
Andrew de los Reyesc060c342013-04-10 13:46:30 -0700146 " /var/log/messages | tail -n 20" },
Gwendal Grignou427d94e2016-10-25 11:34:51 -0700147 {
148 "trim",
149 "cat /var/lib/trim/stateful_trim_state /var/lib/trim/stateful_trim_data"
150 },
Elly Jones03cd6d72012-06-11 13:04:28 -0400151 { "ui_log", "/usr/share/userfeedback/scripts/get_log /var/log/ui/ui.LATEST" },
152 { "uname", "/bin/uname -a" },
153 { "update_engine.log", "cat $(ls -1tr /var/log/update_engine | tail -5 | sed"
Thiemo Nagela269ad22014-11-27 17:13:01 +0100154 " s.^./var/log/update_engine/.)" },
Elly Jones03cd6d72012-06-11 13:04:28 -0400155 { "verified boot", "/bin/cat /var/log/debug_vboot_noisy.log" },
156 { "vpd_2.0", "/bin/cat /var/log/vpd_2.0.txt" },
Samuel Tan107b6c82014-07-10 15:33:44 -0700157 { "wifi_status", "/usr/bin/network_diag --wifi-internal --no-log" },
Sonny Raoab5f9952013-07-17 14:13:53 -0700158 { "zram compressed data size",
159 "/bin/cat /sys/block/zram0/compr_data_size 2> /dev/null" },
160 { "zram original data size",
161 "/bin/cat /sys/block/zram0/orig_data_size 2> /dev/null" },
162 { "zram total memory used",
163 "/bin/cat /sys/block/zram0/mem_used_total 2> /dev/null" },
164 { "zram total reads",
165 "/bin/cat /sys/block/zram0/num_reads 2> /dev/null" },
166 { "zram total writes",
167 "/bin/cat /sys/block/zram0/num_writes 2> /dev/null" },
Gaurav Shah6e8fd892012-10-01 11:51:08 -0700168
Elly Jones03cd6d72012-06-11 13:04:28 -0400169 // Stuff pulled out of the original list. These need access to the running X
170 // session, which we'd rather not give to debugd, or return info specific to
171 // the current session (in the setsid(2) sense), which is not useful for
172 // debugd
173 // { "env", "set" },
174 // { "setxkbmap", "/usr/bin/setxkbmap -print -query" },
175 // { "xrandr", "/usr/bin/xrandr --verbose" }
Ben Chan64d19b22017-02-06 14:03:47 -0800176 { nullptr, nullptr }
Elly Jones533c7c42012-08-10 15:07:05 -0400177};
178
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800179const Log extra_logs[] = {
Ben Chan36e42282014-02-12 22:32:34 -0800180#if USE_CELLULAR
Elly Jones533c7c42012-08-10 15:07:05 -0400181 { "mm-status", "/usr/bin/modem status" },
Ben Chan36e42282014-02-12 22:32:34 -0800182#endif // USE_CELLULAR
Elly Jones533c7c42012-08-10 15:07:05 -0400183 { "network-devices", "/usr/bin/connectivity show devices" },
184 { "network-services", "/usr/bin/connectivity show services" },
Ben Chan64d19b22017-02-06 14:03:47 -0800185 { nullptr, nullptr }
Elly Jones533c7c42012-08-10 15:07:05 -0400186};
187
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800188const Log feedback_logs[] = {
Ben Chan36e42282014-02-12 22:32:34 -0800189#if USE_CELLULAR
Elly Jones533c7c42012-08-10 15:07:05 -0400190 { "mm-status", "/usr/bin/modem status-feedback" },
Ben Chan36e42282014-02-12 22:32:34 -0800191#endif // USE_CELLULAR
Elly Jones533c7c42012-08-10 15:07:05 -0400192 { "network-devices", "/usr/bin/connectivity show-feedback devices" },
193 { "network-services", "/usr/bin/connectivity show-feedback services" },
Ben Chan64d19b22017-02-06 14:03:47 -0800194 { nullptr, nullptr }
Elly Jones03cd6d72012-06-11 13:04:28 -0400195};
196
Ahmed Fakhry1498b4e2016-03-30 12:42:20 -0700197// List of log files needed to be part of the feedback report that are huge and
198// must be sent back to the client via the file descriptor using
199// LogTool::GetBigFeedbackLogs().
200const Log big_feedback_logs[] = {
Eric Carusoe3166f22016-06-10 15:36:02 -0700201 { "arc-bugreport",
Yusuke Sato874c0a82016-10-13 15:41:37 -0700202 "/bin/cat /run/arc/bugreport/pipe 2> /dev/null",
Eric Carusoe3166f22016-06-10 15:36:02 -0700203 // ARC bugreport permissions are weird. Since we're just running cat, this
204 // shouldn't cause any issues.
205 kRoot,
Ricky Zhou4c473ca2016-06-21 17:46:58 -0700206 kRoot,
207 "10M",
Eric Carusoe3166f22016-06-10 15:36:02 -0700208 },
Ben Chan64d19b22017-02-06 14:03:47 -0800209 { nullptr, nullptr }
Ahmed Fakhry1498b4e2016-03-30 12:42:20 -0700210};
211
Gaurav Shahf6c8f2a2012-10-11 17:22:43 -0700212// List of log files that must directly be collected by Chrome. This is because
213// debugd is running under a VFS namespace and does not have access to later
214// cryptohome mounts.
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800215const Log user_logs[] = {
Elly Fong-Jones6456ce52013-04-17 13:31:13 -0400216 {"chrome_user_log", "log/chrome"},
217 {"login-times", "login-times"},
218 {"logout-times", "logout-times"},
Ben Chan64d19b22017-02-06 14:03:47 -0800219 { nullptr, nullptr}
Gaurav Shahf6c8f2a2012-10-11 17:22:43 -0700220};
221
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800222class ManagerProxy : public org::chromium::flimflam::Manager_proxy,
223 public DBus::ObjectProxy {
224 public:
225 ManagerProxy(DBus::Connection* connection,
226 const char* path,
227 const char* service)
228 : DBus::ObjectProxy(*connection, path, service) {}
229 ~ManagerProxy() override = default;
Eric Caruso96d03d32017-04-25 18:01:17 -0700230 void PropertyChanged(const string&, const DBus::Variant&) override {}
231 void StateChanged(const string&) override {}
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800232};
233
234// Returns |value| if |value| is a valid UTF-8 string or a base64-encoded
235// string of |value| otherwise.
236string EnsureUTF8String(const string& value) {
237 if (base::IsStringUTF8(value))
238 return value;
239
Eric Caruso96d03d32017-04-25 18:01:17 -0700240 string encoded_value;
Ben Chanab93abf2017-01-24 13:32:51 -0800241 base::Base64Encode(value, &encoded_value);
242 return "<base64>: " + encoded_value;
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800243}
244
245// TODO(ellyjones): sandbox. crosbug.com/35122
246string Run(const Log& log) {
247 string output;
248 ProcessWithOutput p;
Eric Caruso96d03d32017-04-25 18:01:17 -0700249 string tailed_cmdline = string(log.command) + " | tail -c " +
Ahmed Fakhrye4a0b502016-09-19 18:18:49 -0700250 (log.size_cap ? log.size_cap : "512K");
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800251 if (log.user && log.group)
252 p.SandboxAs(log.user, log.group);
253 if (!p.Init())
254 return "<not available>";
255 p.AddArg(kShell);
256 p.AddStringOption("-c", tailed_cmdline);
257 if (p.Run())
258 return "<not available>";
259 p.GetOutput(&output);
260 if (!output.size())
261 return "<empty>";
262 return EnsureUTF8String(output);
263}
264
265// Fills |dictionary| with the anonymized contents of the logs in |logs|.
266void GetLogsInDictionary(const struct Log* logs,
267 AnonymizerTool* anonymizer,
268 base::DictionaryValue* dictionary) {
269 for (size_t i = 0; logs[i].name; ++i) {
270 dictionary->SetStringWithoutPathExpansion(
271 logs[i].name, anonymizer->Anonymize(Run(logs[i])));
272 }
273}
274
275// Serializes the |dictionary| into the file with the given |fd| in a JSON
276// format.
277void SerializeLogsAsJSON(const base::DictionaryValue& dictionary,
278 const DBus::FileDescriptor& fd) {
Eric Caruso96d03d32017-04-25 18:01:17 -0700279 string logs_json;
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800280 base::JSONWriter::WriteWithOptions(dictionary,
281 base::JSONWriter::OPTIONS_PRETTY_PRINT,
282 &logs_json);
283 base::WriteFileDescriptor(fd.get(), logs_json.c_str(), logs_json.size());
284}
285
Elly Jones533c7c42012-08-10 15:07:05 -0400286bool GetNamedLogFrom(const string& name, const struct Log* logs,
287 string* result) {
288 for (size_t i = 0; logs[i].name; i++) {
289 if (name == logs[i].name) {
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -0500290 *result = Run(logs[i]);
Elly Jones533c7c42012-08-10 15:07:05 -0400291 return true;
292 }
293 }
294 *result = "<invalid log name>";
295 return false;
Elly Jones03cd6d72012-06-11 13:04:28 -0400296}
297
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800298void GetLogsFrom(const struct Log* logs, LogTool::LogMap* map) {
299 for (size_t i = 0; logs[i].name; i++)
300 (*map)[logs[i].name] = Run(logs[i]);
301}
302
303} // namespace
304
Rebecca Silbersteine78af402014-10-02 10:55:04 -0700305void LogTool::CreateConnectivityReport(DBus::Connection* connection) {
306 // Perform ConnectivityTrial to report connection state in feedback log.
307 ManagerProxy shill(connection,
308 shill::kFlimflamServicePath,
309 shill::kFlimflamServiceName);
310 shill.CreateConnectivityReport();
311 // Give the connection trial time to test the connection and log the results
312 // before collecting the logs for feedback.
313 // TODO(silberst): Replace the simple approach of a single timeout with a more
314 // coordinated effort.
315 sleep(kConnectionTesterTimeoutSeconds);
316}
317
Eric Carusoc93a15c2017-04-24 16:15:12 -0700318string LogTool::GetLog(const string& name) {
Elly Jones533c7c42012-08-10 15:07:05 -0400319 string result;
320 GetNamedLogFrom(name, common_logs, &result)
321 || GetNamedLogFrom(name, extra_logs, &result)
322 || GetNamedLogFrom(name, feedback_logs, &result);
323 return result;
324}
325
Eric Carusoc93a15c2017-04-24 16:15:12 -0700326LogTool::LogMap LogTool::GetAllLogs(DBus::Connection* connection) {
Rebecca Silbersteine78af402014-10-02 10:55:04 -0700327 CreateConnectivityReport(connection);
Elly Jones533c7c42012-08-10 15:07:05 -0400328 LogMap result;
329 GetLogsFrom(common_logs, &result);
330 GetLogsFrom(extra_logs, &result);
331 return result;
332}
333
Eric Carusoc93a15c2017-04-24 16:15:12 -0700334LogTool::LogMap LogTool::GetFeedbackLogs(DBus::Connection* connection) {
Rebecca Silbersteine78af402014-10-02 10:55:04 -0700335 CreateConnectivityReport(connection);
Elly Jones533c7c42012-08-10 15:07:05 -0400336 LogMap result;
337 GetLogsFrom(common_logs, &result);
338 GetLogsFrom(feedback_logs, &result);
Darin Petkovce9b3a12013-01-10 16:38:54 +0100339 AnonymizeLogMap(&result);
Elly Jones03cd6d72012-06-11 13:04:28 -0400340 return result;
341}
342
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800343void LogTool::GetBigFeedbackLogs(DBus::Connection* connection,
Eric Carusoc93a15c2017-04-24 16:15:12 -0700344 const DBus::FileDescriptor& fd) {
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800345 CreateConnectivityReport(connection);
346 base::DictionaryValue dictionary;
347 GetLogsInDictionary(common_logs, &anonymizer_, &dictionary);
348 GetLogsInDictionary(feedback_logs, &anonymizer_, &dictionary);
Ahmed Fakhry1498b4e2016-03-30 12:42:20 -0700349 GetLogsInDictionary(big_feedback_logs, &anonymizer_, &dictionary);
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800350 SerializeLogsAsJSON(dictionary, fd);
Ahmed Fakhry1498b4e2016-03-30 12:42:20 -0700351
352 // We need to manually close the FD here to enable the client to read the
353 // contents via a pipe.
354 close(fd.get());
Ahmed Fakhry21140cf2016-03-04 17:15:19 -0800355}
356
Eric Carusoc93a15c2017-04-24 16:15:12 -0700357LogTool::LogMap LogTool::GetUserLogFiles() {
Gaurav Shahf6c8f2a2012-10-11 17:22:43 -0700358 LogMap result;
359 for (size_t i = 0; user_logs[i].name; ++i)
360 result[user_logs[i].name] = user_logs[i].command;
361 return result;
362}
363
Darin Petkovce9b3a12013-01-10 16:38:54 +0100364void LogTool::AnonymizeLogMap(LogMap* log_map) {
Ben Chane2fa3572017-02-08 22:46:18 -0800365 for (auto& entry : *log_map)
366 entry.second = anonymizer_.Anonymize(entry.second);
Darin Petkovce9b3a12013-01-10 16:38:54 +0100367}
368
Ben Chana0011d82014-05-13 00:19:29 -0700369} // namespace debugd