blob: 425fb0cb7aad61f34b5ac37a807f856bf07981e6 [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
5#include "log_tool.h"
6
7#include <base/file_util.h>
8#include <base/logging.h>
9#include <base/string_split.h>
10
11#include "process_with_output.h"
12
13namespace debugd {
14
15const char *kShell = "/bin/sh";
16
17using std::string;
18using std::vector;
19
20typedef vector<string> Strings;
21
22string Run(const string& cmdline) {
23 string output;
24 ProcessWithOutput p;
Elly Jonese0518ff2012-08-13 13:22:46 -040025 string tailed_cmdline = cmdline + " | tail -c 256K";
Elly Jones03cd6d72012-06-11 13:04:28 -040026 if (!p.Init())
27 return "<not available>";
28 p.AddArg(kShell);
29 p.AddStringOption("-c", tailed_cmdline);
30 if (p.Run())
31 return "<not available>";
32 p.GetOutput(&output);
33 if (!output.size())
34 return "<empty>";
35 return output;
36}
37
38struct Log {
39 const char *name;
40 const char *command;
41};
42
Elly Jones533c7c42012-08-10 15:07:05 -040043static const Log common_logs[] = {
Elly Jones03cd6d72012-06-11 13:04:28 -040044 { "CLIENT_ID", "/bin/cat '/home/chronos/Consent To Send Stats'" },
45 { "LOGDATE", "/bin/date" },
46 { "Xorg.0.log", "/bin/cat /var/log/Xorg.0.log" },
Elly Jones03cd6d72012-06-11 13:04:28 -040047 { "bios_info", "/bin/cat /var/log/bios_info.txt" },
48 { "board-specific",
49 "/usr/share/userfeedback/scripts/get_board_specific_info" },
50 { "boot_times", "/bin/cat /tmp/boot-times-sent" },
51 { "chrome_log", "/bin/cat /home/chronos/user/log/chrome" },
52 { "chrome_system_log", "/bin/cat /var/log/chrome/chrome" },
53 { "cpu", "/usr/bin/uname -p" },
54 { "cpuinfo", "/bin/cat /proc/cpuinfo" },
Elly Jones03cd6d72012-06-11 13:04:28 -040055 { "dmesg", "/bin/dmesg" },
56 { "ec_info", "/bin/cat /var/log/ec_info.txt" },
57 { "font_info", "/usr/share/userfeedback/scripts/font_info" },
58 { "hardware_class", "/usr/bin/crossystem hwid" },
59 { "hostname", "/bin/hostname" },
60 { "hw_platform", "/usr/bin/uname -i" },
61 { "ifconfig", "/sbin/ifconfig -a" },
Elly Jones2bde94d2012-07-31 18:07:46 -040062 { "kernel-crashes", "/bin/cat /var/spool/crash/kernel.*.kcrash" },
Elly Jones03cd6d72012-06-11 13:04:28 -040063 { "login-times", "/bin/cat /home/chronos/user/login-times" },
64 { "logout-times", "/bin/cat /home/chronos/user/logout-times" },
65 { "lsmod", "lsmod" },
66 { "lspci", "/usr/sbin/lspci" },
67 { "lsusb", "lsusb" },
68 { "meminfo", "cat /proc/meminfo" },
69 { "memory_spd_info", "/bin/cat /var/log/memory_spd_info.txt" },
Elly Jones03cd6d72012-06-11 13:04:28 -040070 { "power-supply-info", "/usr/bin/power-supply-info" },
71 { "powerd.LATEST", "/bin/cat /var/log/power_manager/powerd.LATEST" },
72 { "powerd.out", "/bin/cat /var/log/power_manager/powerd.out" },
73 { "powerm.LATEST", "/bin/cat /var/log/power_manager/powerm.LATEST" },
74 { "powerm.out", "/bin/cat /var/log/power_manager/powerm.out" },
75 // Changed from 'ps ux' to 'ps aux' since we're running as debugd, not chronos
76 { "ps", "/bin/ps aux" },
77 { "syslog", "/usr/share/userfeedback/scripts/getmsgs --last '2 hours'"
Elly Jonesf8a67ee2012-06-19 13:48:38 -040078 " /var/log/messages" },
Elly Jones03cd6d72012-06-11 13:04:28 -040079 { "touchpad", "/opt/google/touchpad/tpcontrol status" },
Elly Jonesd31aee22012-07-02 11:09:10 -040080 { "touchpad_activity", "/opt/google/touchpad/generate_userfeedback alt" },
Elly Jones03cd6d72012-06-11 13:04:28 -040081 { "ui_log", "/usr/share/userfeedback/scripts/get_log /var/log/ui/ui.LATEST" },
82 { "uname", "/bin/uname -a" },
83 { "update_engine.log", "cat $(ls -1tr /var/log/update_engine | tail -5 | sed"
Elly Jonesd31aee22012-07-02 11:09:10 -040084 " s.^./var/log/update_engine/.)" },
Elly Jones03cd6d72012-06-11 13:04:28 -040085 { "verified boot", "/bin/cat /var/log/debug_vboot_noisy.log" },
86 { "vpd_2.0", "/bin/cat /var/log/vpd_2.0.txt" },
87 { "wifi_status", "/usr/bin/network_diagnostics --wifi --no-log" },
88
89 // Stuff pulled out of the original list. These need access to the running X
90 // session, which we'd rather not give to debugd, or return info specific to
91 // the current session (in the setsid(2) sense), which is not useful for
92 // debugd
93 // { "env", "set" },
94 // { "setxkbmap", "/usr/bin/setxkbmap -print -query" },
95 // { "xrandr", "/usr/bin/xrandr --verbose" }
Elly Jones533c7c42012-08-10 15:07:05 -040096 { NULL, NULL }
97};
98
99static const Log extra_logs[] = {
100 { "mm-status", "/usr/bin/modem status" },
101 { "network-devices", "/usr/bin/connectivity show devices" },
102 { "network-services", "/usr/bin/connectivity show services" },
103 { NULL, NULL }
104};
105
106static struct Log feedback_logs[] = {
107 { "mm-status", "/usr/bin/modem status-feedback" },
108 { "network-devices", "/usr/bin/connectivity show-feedback devices" },
109 { "network-services", "/usr/bin/connectivity show-feedback services" },
110 { NULL, NULL }
Elly Jones03cd6d72012-06-11 13:04:28 -0400111};
112
113LogTool::LogTool() { }
114LogTool::~LogTool() { }
115
Elly Jones533c7c42012-08-10 15:07:05 -0400116bool GetNamedLogFrom(const string& name, const struct Log* logs,
117 string* result) {
118 for (size_t i = 0; logs[i].name; i++) {
119 if (name == logs[i].name) {
120 *result = Run(logs[i].command);
121 return true;
122 }
123 }
124 *result = "<invalid log name>";
125 return false;
Elly Jones03cd6d72012-06-11 13:04:28 -0400126}
127
Elly Jones533c7c42012-08-10 15:07:05 -0400128string LogTool::GetLog(const string& name, DBus::Error& error) { // NOLINT
129 string result;
130 GetNamedLogFrom(name, common_logs, &result)
131 || GetNamedLogFrom(name, extra_logs, &result)
132 || GetNamedLogFrom(name, feedback_logs, &result);
133 return result;
134}
135
136void GetLogsFrom(const struct Log* logs, LogTool::LogMap* map) {
137 for (size_t i = 0; logs[i].name; i++)
138 (*map)[logs[i].name] = Run(logs[i].command);
139}
140
141LogTool::LogMap LogTool::GetAllLogs(DBus::Error& error) { // NOLINT
142 LogMap result;
143 GetLogsFrom(common_logs, &result);
144 GetLogsFrom(extra_logs, &result);
145 return result;
146}
147
148LogTool::LogMap LogTool::GetFeedbackLogs(DBus::Error& error) { // NOLINT
149 LogMap result;
150 GetLogsFrom(common_logs, &result);
151 GetLogsFrom(feedback_logs, &result);
Elly Jones03cd6d72012-06-11 13:04:28 -0400152 return result;
153}
154
155}; // namespace debugd