Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [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 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 5 | #ifndef CRASH_REPORTER_UDEV_COLLECTOR_H_ |
| 6 | #define CRASH_REPORTER_UDEV_COLLECTOR_H_ |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 10 | #include <base/files/file_path.h> |
Ben Chan | 895fa5d | 2014-09-02 20:58:20 -0700 | [diff] [blame] | 11 | #include <base/macros.h> |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 13 | |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 14 | #include "crash-reporter/crash_collector.h" |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 15 | |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 16 | // Udev crash collector. |
| 17 | class UdevCollector : public CrashCollector { |
| 18 | public: |
| 19 | UdevCollector(); |
| 20 | |
Ben Chan | efec0b3 | 2014-08-12 08:52:11 -0700 | [diff] [blame] | 21 | ~UdevCollector() override; |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 22 | |
| 23 | // The udev event string should be formatted as follows: |
| 24 | // "ACTION=[action]:KERNEL=[name]:SUBSYSTEM=[subsystem]" |
| 25 | // The values don't have to be in any particular order. One or more of them |
| 26 | // could be omitted, in which case it would be treated as a wildcard (*). |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 27 | bool HandleCrash(const std::string& udev_event); |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 28 | |
Peter Qiu | 6aa551e | 2015-03-06 11:42:04 -0800 | [diff] [blame] | 29 | protected: |
| 30 | std::string dev_coredump_directory_; |
| 31 | |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 32 | private: |
| 33 | friend class UdevCollectorTest; |
| 34 | |
Peter Qiu | 6aa551e | 2015-03-06 11:42:04 -0800 | [diff] [blame] | 35 | // Process udev crash logs, collecting log files according to the config |
| 36 | // file (crash_reporter_logs.conf). |
| 37 | bool ProcessUdevCrashLogs(const base::FilePath& crash_directory, |
| 38 | const std::string& action, |
| 39 | const std::string& kernel, |
| 40 | const std::string& subsystem); |
| 41 | // Process device coredump, collecting device coredump file. |
| 42 | // |instance_number| is the kernel number of the virtual device for the device |
| 43 | // coredump instance. |
| 44 | bool ProcessDevCoredump(const base::FilePath& crash_directory, |
| 45 | int instance_number); |
| 46 | // Copy device coredump file to crash directory, and perform necessary |
| 47 | // coredump file management. |
| 48 | bool AppendDevCoredump(const base::FilePath& crash_directory, |
| 49 | const base::FilePath& coredump_path, |
| 50 | int instance_number); |
| 51 | // Clear the device coredump file by performing a dummy write to it. |
| 52 | bool ClearDevCoredump(const base::FilePath& coredump_path); |
| 53 | // Return the driver name of the device that generates the coredump. |
| 54 | std::string GetFailingDeviceDriverName(int instance_number); |
| 55 | |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 56 | // Mutator for unit testing. |
| 57 | void set_log_config_path(const std::string& path) { |
Simon Que | 9f90aca | 2013-02-19 17:19:52 -0800 | [diff] [blame] | 58 | log_config_path_ = base::FilePath(path); |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 59 | } |
Ben Chan | 895fa5d | 2014-09-02 20:58:20 -0700 | [diff] [blame] | 60 | |
| 61 | DISALLOW_COPY_AND_ASSIGN(UdevCollector); |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 64 | #endif // CRASH_REPORTER_UDEV_COLLECTOR_H_ |