Planeshift
minidump_descriptor.h
Go to the documentation of this file.
1 // Copyright (c) 2012 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #ifndef CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_
31 #define CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_
32 
33 #include <assert.h>
34 #include <sys/types.h>
35 
36 #include <string>
37 
39 
40 // The MinidumpDescriptor describes how to access a minidump: it can contain
41 // either a file descriptor or a path.
42 // Note that when using files, it is created with the path to a directory.
43 // The actual path where the minidump is generated is created by this class.
44 namespace google_breakpad {
45 
47  public:
48  MinidumpDescriptor() : fd_(-1), size_limit_(-1) {}
49 
50  explicit MinidumpDescriptor(const string& directory)
51  : fd_(-1),
52  directory_(directory),
53  c_path_(NULL),
54  size_limit_(-1) {
55  assert(!directory.empty());
56  }
57 
58  explicit MinidumpDescriptor(int fd)
59  : fd_(fd),
60  c_path_(NULL),
61  size_limit_(-1) {
62  assert(fd != -1);
63  }
64 
65  explicit MinidumpDescriptor(const MinidumpDescriptor& descriptor);
67 
68  bool IsFD() const { return fd_ != -1; }
69 
70  int fd() const { return fd_; }
71 
72  string directory() const { return directory_; }
73 
74  const char* path() const { return c_path_; }
75 
76  // Updates the path so it is unique.
77  // Should be called from a normal context: this methods uses the heap.
78  void UpdatePath();
79 
80  off_t size_limit() const { return size_limit_; }
81  void set_size_limit(off_t limit) { size_limit_ = limit; }
82 
83  private:
84  // The file descriptor where the minidump is generated.
85  int fd_;
86 
87  // The directory where the minidump should be generated.
88  string directory_;
89  // The full path to the generated minidump.
90  string path_;
91  // The C string of |path_|. Precomputed so it can be access from a compromised
92  // context.
93  const char* c_path_;
94 
95  off_t size_limit_;
96 };
97 
98 } // namespace google_breakpad
99 
100 #endif // CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_
MinidumpDescriptor & operator=(const MinidumpDescriptor &descriptor)
MinidumpDescriptor(const string &directory)