Planeshift
|
00001 // Copyright (c) 2012 Google Inc. 00002 // All rights reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without 00005 // modification, are permitted provided that the following conditions are 00006 // met: 00007 // 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above 00011 // copyright notice, this list of conditions and the following disclaimer 00012 // in the documentation and/or other materials provided with the 00013 // distribution. 00014 // * Neither the name of Google Inc. nor the names of its 00015 // contributors may be used to endorse or promote products derived from 00016 // this software without specific prior written permission. 00017 // 00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 00030 #ifndef CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ 00031 #define CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ 00032 00033 #include <assert.h> 00034 #include <sys/types.h> 00035 00036 #include <string> 00037 00038 #include "common/using_std_string.h" 00039 00040 // The MinidumpDescriptor describes how to access a minidump: it can contain 00041 // either a file descriptor or a path. 00042 // Note that when using files, it is created with the path to a directory. 00043 // The actual path where the minidump is generated is created by this class. 00044 namespace google_breakpad { 00045 00046 class MinidumpDescriptor { 00047 public: 00048 MinidumpDescriptor() : fd_(-1), size_limit_(-1) {} 00049 00050 explicit MinidumpDescriptor(const string& directory) 00051 : fd_(-1), 00052 directory_(directory), 00053 c_path_(NULL), 00054 size_limit_(-1) { 00055 assert(!directory.empty()); 00056 } 00057 00058 explicit MinidumpDescriptor(int fd) 00059 : fd_(fd), 00060 c_path_(NULL), 00061 size_limit_(-1) { 00062 assert(fd != -1); 00063 } 00064 00065 explicit MinidumpDescriptor(const MinidumpDescriptor& descriptor); 00066 MinidumpDescriptor& operator=(const MinidumpDescriptor& descriptor); 00067 00068 bool IsFD() const { return fd_ != -1; } 00069 00070 int fd() const { return fd_; } 00071 00072 string directory() const { return directory_; } 00073 00074 const char* path() const { return c_path_; } 00075 00076 // Updates the path so it is unique. 00077 // Should be called from a normal context: this methods uses the heap. 00078 void UpdatePath(); 00079 00080 off_t size_limit() const { return size_limit_; } 00081 void set_size_limit(off_t limit) { size_limit_ = limit; } 00082 00083 private: 00084 // The file descriptor where the minidump is generated. 00085 int fd_; 00086 00087 // The directory where the minidump should be generated. 00088 string directory_; 00089 // The full path to the generated minidump. 00090 string path_; 00091 // The C string of |path_|. Precomputed so it can be access from a compromised 00092 // context. 00093 const char* c_path_; 00094 00095 off_t size_limit_; 00096 }; 00097 00098 } // namespace google_breakpad 00099 00100 #endif // CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_