blob: 1689dd3952313cd4d28579e89d94bdb8d9454440 [file] [log] [blame]
Simon Queacc79382012-05-04 18:10:09 -07001// 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 Chan7e776902014-06-18 13:19:51 -07005#ifndef CRASH_REPORTER_UDEV_COLLECTOR_H_
6#define CRASH_REPORTER_UDEV_COLLECTOR_H_
Simon Queacc79382012-05-04 18:10:09 -07007
8#include <string>
9
Ben Chan7e776902014-06-18 13:19:51 -070010#include <base/files/file_path.h>
Ben Chan895fa5d2014-09-02 20:58:20 -070011#include <base/macros.h>
Ben Chan7e776902014-06-18 13:19:51 -070012#include <gtest/gtest_prod.h> // for FRIEND_TEST
13
Simon Queacc79382012-05-04 18:10:09 -070014#include "crash-reporter/crash_collector.h"
Simon Queacc79382012-05-04 18:10:09 -070015
Simon Queacc79382012-05-04 18:10:09 -070016// Udev crash collector.
17class UdevCollector : public CrashCollector {
18 public:
19 UdevCollector();
20
Ben Chanefec0b32014-08-12 08:52:11 -070021 ~UdevCollector() override;
Simon Queacc79382012-05-04 18:10:09 -070022
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 Chan7e776902014-06-18 13:19:51 -070027 bool HandleCrash(const std::string& udev_event);
Simon Queacc79382012-05-04 18:10:09 -070028
Peter Qiu6aa551e2015-03-06 11:42:04 -080029 protected:
30 std::string dev_coredump_directory_;
31
Simon Queacc79382012-05-04 18:10:09 -070032 private:
33 friend class UdevCollectorTest;
34
Peter Qiu6aa551e2015-03-06 11:42:04 -080035 // 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 Queacc79382012-05-04 18:10:09 -070056 // Mutator for unit testing.
57 void set_log_config_path(const std::string& path) {
Simon Que9f90aca2013-02-19 17:19:52 -080058 log_config_path_ = base::FilePath(path);
Simon Queacc79382012-05-04 18:10:09 -070059 }
Ben Chan895fa5d2014-09-02 20:58:20 -070060
61 DISALLOW_COPY_AND_ASSIGN(UdevCollector);
Simon Queacc79382012-05-04 18:10:09 -070062};
63
Ben Chan7e776902014-06-18 13:19:51 -070064#endif // CRASH_REPORTER_UDEV_COLLECTOR_H_