blob: e267b75f41697431057725dead81cb262ca9b37c [file] [log] [blame]
Steve Fung6c34c252015-08-20 00:27:30 -07001/*
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 Queacc79382012-05-04 18:10:09 -070016
Ben Chan7e776902014-06-18 13:19:51 -070017#ifndef CRASH_REPORTER_UDEV_COLLECTOR_H_
18#define CRASH_REPORTER_UDEV_COLLECTOR_H_
Simon Queacc79382012-05-04 18:10:09 -070019
20#include <string>
21
Ben Chan7e776902014-06-18 13:19:51 -070022#include <base/files/file_path.h>
Ben Chan895fa5d2014-09-02 20:58:20 -070023#include <base/macros.h>
Ben Chan7e776902014-06-18 13:19:51 -070024#include <gtest/gtest_prod.h> // for FRIEND_TEST
25
Steve Fung129bea52015-07-23 13:11:15 -070026#include "crash_collector.h"
Simon Queacc79382012-05-04 18:10:09 -070027
Simon Queacc79382012-05-04 18:10:09 -070028// Udev crash collector.
29class UdevCollector : public CrashCollector {
30 public:
31 UdevCollector();
32
Ben Chanefec0b32014-08-12 08:52:11 -070033 ~UdevCollector() override;
Simon Queacc79382012-05-04 18:10:09 -070034
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 Chan7e776902014-06-18 13:19:51 -070039 bool HandleCrash(const std::string& udev_event);
Simon Queacc79382012-05-04 18:10:09 -070040
Peter Qiu6aa551e2015-03-06 11:42:04 -080041 protected:
42 std::string dev_coredump_directory_;
43
Simon Queacc79382012-05-04 18:10:09 -070044 private:
45 friend class UdevCollectorTest;
46
Peter Qiu6aa551e2015-03-06 11:42:04 -080047 // 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 Queacc79382012-05-04 18:10:09 -070068 // Mutator for unit testing.
69 void set_log_config_path(const std::string& path) {
Simon Que9f90aca2013-02-19 17:19:52 -080070 log_config_path_ = base::FilePath(path);
Simon Queacc79382012-05-04 18:10:09 -070071 }
Ben Chan895fa5d2014-09-02 20:58:20 -070072
73 DISALLOW_COPY_AND_ASSIGN(UdevCollector);
Simon Queacc79382012-05-04 18:10:09 -070074};
75
Ben Chan7e776902014-06-18 13:19:51 -070076#endif // CRASH_REPORTER_UDEV_COLLECTOR_H_