Line data Source code
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 : #include <stdio.h>
31 :
32 : #include "linux/handler/guid_generator.h"
33 : #include "linux/handler/minidump_descriptor.h"
34 :
35 : namespace google_breakpad {
36 :
37 : //static
38 : const MinidumpDescriptor::MicrodumpOnConsole
39 : MinidumpDescriptor::kMicrodumpOnConsole = {};
40 :
41 0 : MinidumpDescriptor::MinidumpDescriptor(const MinidumpDescriptor& descriptor)
42 0 : : mode_(descriptor.mode_),
43 0 : fd_(descriptor.fd_),
44 : directory_(descriptor.directory_),
45 : c_path_(NULL),
46 0 : size_limit_(descriptor.size_limit_),
47 0 : microdump_extra_info_(descriptor.microdump_extra_info_) {
48 : // The copy constructor is not allowed to be called on a MinidumpDescriptor
49 : // with a valid path_, as getting its c_path_ would require the heap which
50 : // can cause problems in compromised environments.
51 0 : assert(descriptor.path_.empty());
52 0 : }
53 :
54 0 : MinidumpDescriptor& MinidumpDescriptor::operator=(
55 : const MinidumpDescriptor& descriptor) {
56 0 : assert(descriptor.path_.empty());
57 :
58 0 : mode_ = descriptor.mode_;
59 0 : fd_ = descriptor.fd_;
60 0 : directory_ = descriptor.directory_;
61 0 : path_.clear();
62 0 : if (c_path_) {
63 : // This descriptor already had a path set, so generate a new one.
64 0 : c_path_ = NULL;
65 0 : UpdatePath();
66 : }
67 0 : size_limit_ = descriptor.size_limit_;
68 0 : microdump_extra_info_ = descriptor.microdump_extra_info_;
69 0 : return *this;
70 : }
71 :
72 0 : void MinidumpDescriptor::UpdatePath() {
73 0 : assert(mode_ == kWriteMinidumpToFile && !directory_.empty());
74 :
75 : GUID guid;
76 : char guid_str[kGUIDStringLength + 1];
77 0 : if (!CreateGUID(&guid) || !GUIDToString(&guid, guid_str, sizeof(guid_str))) {
78 0 : assert(false);
79 : }
80 :
81 0 : path_.clear();
82 0 : path_ = directory_ + "/" + guid_str + ".dmp";
83 0 : c_path_ = path_.c_str();
84 0 : }
85 :
86 : } // namespace google_breakpad
|