Steve Fung | 6c34c25 | 2015-08-20 00:27:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 16 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 17 | #ifndef CRASH_REPORTER_UDEV_COLLECTOR_H_ |
| 18 | #define CRASH_REPORTER_UDEV_COLLECTOR_H_ |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 22 | #include <base/files/file_path.h> |
Ben Chan | 895fa5d | 2014-09-02 20:58:20 -0700 | [diff] [blame] | 23 | #include <base/macros.h> |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 24 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 25 | |
Steve Fung | 129bea5 | 2015-07-23 13:11:15 -0700 | [diff] [blame] | 26 | #include "crash_collector.h" |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 27 | |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 28 | // Udev crash collector. |
| 29 | class UdevCollector : public CrashCollector { |
| 30 | public: |
| 31 | UdevCollector(); |
| 32 | |
Ben Chan | efec0b3 | 2014-08-12 08:52:11 -0700 | [diff] [blame] | 33 | ~UdevCollector() override; |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 34 | |
| 35 | // The udev event string should be formatted as follows: |
| 36 | // "ACTION=[action]:KERNEL=[name]:SUBSYSTEM=[subsystem]" |
| 37 | // The values don't have to be in any particular order. One or more of them |
| 38 | // 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] | 39 | bool HandleCrash(const std::string& udev_event); |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 40 | |
Peter Qiu | 6aa551e | 2015-03-06 11:42:04 -0800 | [diff] [blame] | 41 | protected: |
| 42 | std::string dev_coredump_directory_; |
| 43 | |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 44 | private: |
| 45 | friend class UdevCollectorTest; |
| 46 | |
Peter Qiu | 6aa551e | 2015-03-06 11:42:04 -0800 | [diff] [blame] | 47 | // Process udev crash logs, collecting log files according to the config |
| 48 | // file (crash_reporter_logs.conf). |
| 49 | bool ProcessUdevCrashLogs(const base::FilePath& crash_directory, |
| 50 | const std::string& action, |
| 51 | const std::string& kernel, |
| 52 | const std::string& subsystem); |
| 53 | // Process device coredump, collecting device coredump file. |
| 54 | // |instance_number| is the kernel number of the virtual device for the device |
| 55 | // coredump instance. |
| 56 | bool ProcessDevCoredump(const base::FilePath& crash_directory, |
| 57 | int instance_number); |
| 58 | // Copy device coredump file to crash directory, and perform necessary |
| 59 | // coredump file management. |
| 60 | bool AppendDevCoredump(const base::FilePath& crash_directory, |
| 61 | const base::FilePath& coredump_path, |
| 62 | int instance_number); |
| 63 | // Clear the device coredump file by performing a dummy write to it. |
| 64 | bool ClearDevCoredump(const base::FilePath& coredump_path); |
| 65 | // Return the driver name of the device that generates the coredump. |
| 66 | std::string GetFailingDeviceDriverName(int instance_number); |
| 67 | |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 68 | // Mutator for unit testing. |
| 69 | void set_log_config_path(const std::string& path) { |
Simon Que | 9f90aca | 2013-02-19 17:19:52 -0800 | [diff] [blame] | 70 | log_config_path_ = base::FilePath(path); |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 71 | } |
Ben Chan | 895fa5d | 2014-09-02 20:58:20 -0700 | [diff] [blame] | 72 | |
| 73 | DISALLOW_COPY_AND_ASSIGN(UdevCollector); |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 76 | #endif // CRASH_REPORTER_UDEV_COLLECTOR_H_ |