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 | |
| 22 | string Run(const string& cmdline) { |
| 23 | string output; |
| 24 | ProcessWithOutput p; |
| 25 | string tailed_cmdline = cmdline + " | tail -c 32768"; |
| 26 | 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 | |
| 38 | struct Log { |
| 39 | const char *name; |
| 40 | const char *command; |
| 41 | }; |
| 42 | |
| 43 | static struct Log logs[] = { |
| 44 | { "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" }, |
| 47 | { "alsa_controls", "/usr/bin/amixer -c0 contents" }, |
| 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" }, |
| 52 | { "chrome_log", "/bin/cat /home/chronos/user/log/chrome" }, |
| 53 | { "chrome_system_log", "/bin/cat /var/log/chrome/chrome" }, |
| 54 | { "cpu", "/usr/bin/uname -p" }, |
| 55 | { "cpuinfo", "/bin/cat /proc/cpuinfo" }, |
| 56 | { "cras", "/usr/bin/cras_test_client --dump_server_info" }, |
| 57 | { "dmesg", "/bin/dmesg" }, |
| 58 | { "ec_info", "/bin/cat /var/log/ec_info.txt" }, |
| 59 | { "font_info", "/usr/share/userfeedback/scripts/font_info" }, |
| 60 | { "hardware_class", "/usr/bin/crossystem hwid" }, |
| 61 | { "hostname", "/bin/hostname" }, |
| 62 | { "hw_platform", "/usr/bin/uname -i" }, |
| 63 | { "ifconfig", "/sbin/ifconfig -a" }, |
| 64 | { "login-times", "/bin/cat /home/chronos/user/login-times" }, |
| 65 | { "logout-times", "/bin/cat /home/chronos/user/logout-times" }, |
| 66 | { "lsmod", "lsmod" }, |
| 67 | { "lspci", "/usr/sbin/lspci" }, |
| 68 | { "lsusb", "lsusb" }, |
| 69 | { "meminfo", "cat /proc/meminfo" }, |
| 70 | { "memory_spd_info", "/bin/cat /var/log/memory_spd_info.txt" }, |
| 71 | { "mm-status", "/usr/share/userfeedback/scripts/mm-status" }, |
| 72 | { "network-devices", "/usr/bin/connectivity show devices" }, |
| 73 | { "network-services", "/usr/bin/connectivity show services" }, |
| 74 | { "power-supply-info", "/usr/bin/power-supply-info" }, |
| 75 | { "powerd.LATEST", "/bin/cat /var/log/power_manager/powerd.LATEST" }, |
| 76 | { "powerd.out", "/bin/cat /var/log/power_manager/powerd.out" }, |
| 77 | { "powerm.LATEST", "/bin/cat /var/log/power_manager/powerm.LATEST" }, |
| 78 | { "powerm.out", "/bin/cat /var/log/power_manager/powerm.out" }, |
| 79 | // Changed from 'ps ux' to 'ps aux' since we're running as debugd, not chronos |
| 80 | { "ps", "/bin/ps aux" }, |
| 81 | { "syslog", "/usr/share/userfeedback/scripts/getmsgs --last '2 hours'" |
| 82 | "/var/log/messages" }, |
| 83 | { "touchpad", "/opt/google/touchpad/tpcontrol status" }, |
| 84 | { "touchpad_activity", "/opt/google/touchpad/generate_userfeedback" }, |
| 85 | { "ui_log", "/usr/share/userfeedback/scripts/get_log /var/log/ui/ui.LATEST" }, |
| 86 | { "uname", "/bin/uname -a" }, |
| 87 | { "update_engine.log", "cat $(ls -1tr /var/log/update_engine | tail -5 | sed" |
| 88 | "s.^./var/log/update_engine/.)" }, |
| 89 | { "verified boot", "/bin/cat /var/log/debug_vboot_noisy.log" }, |
| 90 | { "vpd_2.0", "/bin/cat /var/log/vpd_2.0.txt" }, |
| 91 | { "wifi_status", "/usr/bin/network_diagnostics --wifi --no-log" }, |
| 92 | |
| 93 | // Stuff pulled out of the original list. These need access to the running X |
| 94 | // session, which we'd rather not give to debugd, or return info specific to |
| 95 | // the current session (in the setsid(2) sense), which is not useful for |
| 96 | // debugd |
| 97 | // { "env", "set" }, |
| 98 | // { "setxkbmap", "/usr/bin/setxkbmap -print -query" }, |
| 99 | // { "xrandr", "/usr/bin/xrandr --verbose" } |
| 100 | }; |
| 101 | |
| 102 | LogTool::LogTool() { } |
| 103 | LogTool::~LogTool() { } |
| 104 | |
| 105 | string LogTool::GetLog(const string& name, DBus::Error& error) { // NOLINT |
| 106 | for (unsigned int i = 0; i < arraysize(logs); i++) |
| 107 | if (!strcmp(name.c_str(), logs[i].name)) |
| 108 | return Run(logs[i].command); |
| 109 | return "<invalid log name>"; |
| 110 | } |
| 111 | |
| 112 | std::map<string, string> LogTool::GetAllLogs(DBus::Error& error) { // NOLINT |
| 113 | std::map<string, string> result; |
| 114 | for (unsigned int i = 0; i < arraysize(logs); i++) |
| 115 | result[logs[i].name] = Run(logs[i].command); |
| 116 | return result; |
| 117 | } |
| 118 | |
| 119 | }; // namespace debugd |