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 | |
| 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 | |
| 13 | namespace debugd { |
| 14 | |
| 15 | const char *kShell = "/bin/sh"; |
| 16 | |
| 17 | using std::string; |
| 18 | using std::vector; |
| 19 | |
| 20 | typedef vector<string> Strings; |
| 21 | |
Elly Fong-Jones | 57f018c | 2012-10-08 14:22:01 -0400 | [diff] [blame^] | 22 | // TODO(ellyjones): sandbox. crosbug.com/35122 |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 23 | string Run(const string& cmdline) { |
| 24 | string output; |
| 25 | ProcessWithOutput p; |
Elly Jones | e0518ff | 2012-08-13 13:22:46 -0400 | [diff] [blame] | 26 | string tailed_cmdline = cmdline + " | tail -c 256K"; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 27 | if (!p.Init()) |
| 28 | return "<not available>"; |
| 29 | p.AddArg(kShell); |
| 30 | p.AddStringOption("-c", tailed_cmdline); |
| 31 | if (p.Run()) |
| 32 | return "<not available>"; |
| 33 | p.GetOutput(&output); |
| 34 | if (!output.size()) |
| 35 | return "<empty>"; |
| 36 | return output; |
| 37 | } |
| 38 | |
| 39 | struct Log { |
| 40 | const char *name; |
| 41 | const char *command; |
| 42 | }; |
| 43 | |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 44 | static const Log common_logs[] = { |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 45 | { "CLIENT_ID", "/bin/cat '/home/chronos/Consent To Send Stats'" }, |
| 46 | { "LOGDATE", "/bin/date" }, |
| 47 | { "Xorg.0.log", "/bin/cat /var/log/Xorg.0.log" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 48 | { "bios_info", "/bin/cat /var/log/bios_info.txt" }, |
| 49 | { "board-specific", |
| 50 | "/usr/share/userfeedback/scripts/get_board_specific_info" }, |
| 51 | { "boot_times", "/bin/cat /tmp/boot-times-sent" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 52 | { "chrome_system_log", "/bin/cat /var/log/chrome/chrome" }, |
Elly Fong-Jones | 57f018c | 2012-10-08 14:22:01 -0400 | [diff] [blame^] | 53 | { "console-ramoops", "/bin/cat /dev/pstore/console-ramoops" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 54 | { "cpu", "/usr/bin/uname -p" }, |
| 55 | { "cpuinfo", "/bin/cat /proc/cpuinfo" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 56 | { "dmesg", "/bin/dmesg" }, |
| 57 | { "ec_info", "/bin/cat /var/log/ec_info.txt" }, |
| 58 | { "font_info", "/usr/share/userfeedback/scripts/font_info" }, |
| 59 | { "hardware_class", "/usr/bin/crossystem hwid" }, |
| 60 | { "hostname", "/bin/hostname" }, |
| 61 | { "hw_platform", "/usr/bin/uname -i" }, |
| 62 | { "ifconfig", "/sbin/ifconfig -a" }, |
Elly Jones | 2bde94d | 2012-07-31 18:07:46 -0400 | [diff] [blame] | 63 | { "kernel-crashes", "/bin/cat /var/spool/crash/kernel.*.kcrash" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 64 | { "lsmod", "lsmod" }, |
| 65 | { "lspci", "/usr/sbin/lspci" }, |
| 66 | { "lsusb", "lsusb" }, |
| 67 | { "meminfo", "cat /proc/meminfo" }, |
| 68 | { "memory_spd_info", "/bin/cat /var/log/memory_spd_info.txt" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 69 | { "power-supply-info", "/usr/bin/power-supply-info" }, |
| 70 | { "powerd.LATEST", "/bin/cat /var/log/power_manager/powerd.LATEST" }, |
| 71 | { "powerd.out", "/bin/cat /var/log/power_manager/powerd.out" }, |
| 72 | { "powerm.LATEST", "/bin/cat /var/log/power_manager/powerm.LATEST" }, |
| 73 | { "powerm.out", "/bin/cat /var/log/power_manager/powerm.out" }, |
| 74 | // Changed from 'ps ux' to 'ps aux' since we're running as debugd, not chronos |
| 75 | { "ps", "/bin/ps aux" }, |
| 76 | { "syslog", "/usr/share/userfeedback/scripts/getmsgs --last '2 hours'" |
Elly Jones | f8a67ee | 2012-06-19 13:48:38 -0400 | [diff] [blame] | 77 | " /var/log/messages" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 78 | { "touchpad", "/opt/google/touchpad/tpcontrol status" }, |
Elly Jones | d31aee2 | 2012-07-02 11:09:10 -0400 | [diff] [blame] | 79 | { "touchpad_activity", "/opt/google/touchpad/generate_userfeedback alt" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 80 | { "ui_log", "/usr/share/userfeedback/scripts/get_log /var/log/ui/ui.LATEST" }, |
| 81 | { "uname", "/bin/uname -a" }, |
| 82 | { "update_engine.log", "cat $(ls -1tr /var/log/update_engine | tail -5 | sed" |
Elly Jones | d31aee2 | 2012-07-02 11:09:10 -0400 | [diff] [blame] | 83 | " s.^./var/log/update_engine/.)" }, |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 84 | { "verified boot", "/bin/cat /var/log/debug_vboot_noisy.log" }, |
| 85 | { "vpd_2.0", "/bin/cat /var/log/vpd_2.0.txt" }, |
| 86 | { "wifi_status", "/usr/bin/network_diagnostics --wifi --no-log" }, |
| 87 | |
Gaurav Shah | 6e8fd89 | 2012-10-01 11:51:08 -0700 | [diff] [blame] | 88 | |
| 89 | // Stuff pulled out of the original list because debugd is running under |
| 90 | // a VFS namespace and does not have access to later cryptohome mounts. |
| 91 | // This includes anything under /home/chronos/user/* |
| 92 | // { "chrome_log", "/bin/cat /home/chronos/user/log/chrome" }, |
| 93 | // { "login-times", "/bin/cat /home/chronos/user/login-times" }, |
| 94 | // { "logout-times", "/bin/cat /home/chronos/user/logout-times" }, |
| 95 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 96 | // Stuff pulled out of the original list. These need access to the running X |
| 97 | // session, which we'd rather not give to debugd, or return info specific to |
| 98 | // the current session (in the setsid(2) sense), which is not useful for |
| 99 | // debugd |
| 100 | // { "env", "set" }, |
| 101 | // { "setxkbmap", "/usr/bin/setxkbmap -print -query" }, |
| 102 | // { "xrandr", "/usr/bin/xrandr --verbose" } |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 103 | { NULL, NULL } |
| 104 | }; |
| 105 | |
| 106 | static const Log extra_logs[] = { |
| 107 | { "mm-status", "/usr/bin/modem status" }, |
| 108 | { "network-devices", "/usr/bin/connectivity show devices" }, |
| 109 | { "network-services", "/usr/bin/connectivity show services" }, |
| 110 | { NULL, NULL } |
| 111 | }; |
| 112 | |
| 113 | static struct Log feedback_logs[] = { |
| 114 | { "mm-status", "/usr/bin/modem status-feedback" }, |
| 115 | { "network-devices", "/usr/bin/connectivity show-feedback devices" }, |
| 116 | { "network-services", "/usr/bin/connectivity show-feedback services" }, |
| 117 | { NULL, NULL } |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | LogTool::LogTool() { } |
| 121 | LogTool::~LogTool() { } |
| 122 | |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 123 | bool GetNamedLogFrom(const string& name, const struct Log* logs, |
| 124 | string* result) { |
| 125 | for (size_t i = 0; logs[i].name; i++) { |
| 126 | if (name == logs[i].name) { |
| 127 | *result = Run(logs[i].command); |
| 128 | return true; |
| 129 | } |
| 130 | } |
| 131 | *result = "<invalid log name>"; |
| 132 | return false; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 135 | string LogTool::GetLog(const string& name, DBus::Error& error) { // NOLINT |
| 136 | string result; |
| 137 | GetNamedLogFrom(name, common_logs, &result) |
| 138 | || GetNamedLogFrom(name, extra_logs, &result) |
| 139 | || GetNamedLogFrom(name, feedback_logs, &result); |
| 140 | return result; |
| 141 | } |
| 142 | |
| 143 | void GetLogsFrom(const struct Log* logs, LogTool::LogMap* map) { |
| 144 | for (size_t i = 0; logs[i].name; i++) |
| 145 | (*map)[logs[i].name] = Run(logs[i].command); |
| 146 | } |
| 147 | |
| 148 | LogTool::LogMap LogTool::GetAllLogs(DBus::Error& error) { // NOLINT |
| 149 | LogMap result; |
| 150 | GetLogsFrom(common_logs, &result); |
| 151 | GetLogsFrom(extra_logs, &result); |
| 152 | return result; |
| 153 | } |
| 154 | |
| 155 | LogTool::LogMap LogTool::GetFeedbackLogs(DBus::Error& error) { // NOLINT |
| 156 | LogMap result; |
| 157 | GetLogsFrom(common_logs, &result); |
| 158 | GetLogsFrom(feedback_logs, &result); |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 159 | return result; |
| 160 | } |
| 161 | |
| 162 | }; // namespace debugd |