1 mike 1.2 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)
33 //
34 // Modified By: Amit K Arora, IBM (amita@in.ibm.com) for Bug#1527
35 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
36 // David Dillard, VERITAS Software Corp.
37 // (david.dillard@veritas.com)
38 //
39 //%/////////////////////////////////////////////////////////////////////////////
40
41 #if defined(PEGASUS_OS_VMS)
42 # include <fcntl.h>
43 mike 1.2 #endif
44 #include <Pegasus/Common/Logger.h>
45 #include <Pegasus/Common/System.h>
46 #include <Pegasus/Common/TraceFileHandler.h>
47 #include <Pegasus/Common/Mutex.h>
48
49 PEGASUS_USING_STD;
50
|
55 mike 1.2
56 ///////////////////////////////////////////////////////////////////////////////
57 // Writes message to file. Locks the file before writing to it
58 // Implementation of this function is platform specific
59 ///////////////////////////////////////////////////////////////////////////////
60
61 #if defined(PEGASUS_OS_VMS)
62
63 void TraceFileHandler::handleMessage(
64 const char *message,
65 const char *fmt, va_list argList)
66 {
67 Sint32 retCode;
68 Sint32 fileDesc;
69
70 // Do not add Trace calls in the Critical section
71 // ---- BEGIN CRITICAL SECTION
72
73 // Check if the file has been deleted, if so re-open the file and
74 // continue
75 if (!System::exists(_fileName))
76 mike 1.2 {
77 if (_fileHandle == 0)
78 {
79 _fileHandle = fopen(_fileName, "a+", "shr=get,put,upd");
80 // _fileHandle = fopen(_fileName,"a","shr=get");
81 }
82 else
83 {
84 _fileHandle =
85 freopen(_fileName, "a+", _fileHandle, "shr=get,put,upd");
86 // _fileHandle = freopen(_fileName,"a",_fileHandle,"shr=get");
87 }
88 if (!_fileHandle)
89 {
90 // Unable to re-open file, log a message
91
92 Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER,
93 Logger::WARNING,
94 "Common.TraceFileHandlerVms.FAILED_TO_OPEN_FILE",
95 "Failed to open File $0", _fileName);
96 return;
97 mike 1.2 }
98
99 // Set permissions on the trace file to 0400
100
101 if (!FileSystem::
102 changeFilePermissions(String(_fileName), (S_IRUSR | S_IWUSR)))
103 {
104 Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING,
105 "Common.TraceFileHandlerVms.FAILED_TO_SET_FILE_PERMISSIONS",
106 "Failed to set permissions on file $0", _fileName);
107 return;
108 }
109 }
110
111 // Seek to the end of File
112
113 retCode = fseek(_fileHandle, 0, SEEK_END);
114
115 // Write the message to the file
116
117 retCode = fprintf(_fileHandle, "%s", message);
118 mike 1.2 retCode = vfprintf(_fileHandle, fmt, argList);
119 retCode = fprintf(_fileHandle, "\n");
120 retCode = fflush(_fileHandle);
121 fileDesc = fileno(_fileHandle);
122 retCode = fsync(fileDesc);
123 _wroteToLog = false;
124 // retCode = fclose(_fileHandle);
125 // _fileHandle = 0;
126
127 // ---- END CRITICAL SECTION
128
129 return;
130 }
131
132 #else /* PEGASUS_OS_VMS */
133
134 void TraceFileHandler::handleMessage(
135 const char *message,
136 const char *fmt, va_list argList)
137 {
138 if (!_fileHandle)
139 mike 1.2 {
140 // The trace file is not open, which means an earlier fopen() was
141 // unsuccessful. Stop now to avoid logging duplicate error messages.
142 return;
143 }
144
145 // Do not add Trace calls in the Critical section
146 // ---- BEGIN CRITICAL SECTION
147 AutoMutex writeLock(writeMutex);
148
149 // If the file has been deleted, re-open it and continue
150 if (!System::exists(_fileName))
151 {
152 fclose(_fileHandle);
153 _fileHandle = _openFile(_fileName);
154 if (!_fileHandle)
155 {
156 return;
157 }
158 }
159
160 mike 1.2 // Got the Lock on the File. Seek to the end of File
161 fseek(_fileHandle, 0, SEEK_END);
162 # ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU
163 long pos = ftell(_fileHandle);
164 // Check if the file size is approaching 2GB - which is the
165 // maximum size a file on 32 bit Linux can grow (ofcourse if
166 // not using large-files option). If this is not checked, the
167 // cimserver may get a SIGXFSZ signal and shutdown. See Bug#1527.
168 if (pos >= 0x7ff00000)
169 {
170 // If the file size is almost 2 GB in size, close this trace
171 // file and open a new trace file which would have _fileCount
172 // as the suffix. So, if "cimserver.trc" is the trace file that
173 // approaches 2GB, the next file which gets created would be
174 // named "cimserver.trc.1" and so on ...
175 fclose(_fileHandle);
176 sprintf(_fileName, "%s.%u", _baseFileName, ++_fileCount);
177 _fileHandle = fopen(_fileName, "a+");
178 if (!_fileHandle)
179 {
180 // Unable to open file, log a message
181 mike 1.2 if (!_wroteToLog)
182 {
183 Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING,
184 "Common.TraceFileHandler.FAILED_TO_OPEN_FILE",
185 "Failed to open File $0", _fileName);
186 _wroteToLog = true;
187 }
188 return;
189 }
190 }
191 # endif
192
193 // Write the message to the file
194 fprintf(_fileHandle, "%s", message);
195 vfprintf(_fileHandle, fmt, argList);
196 fprintf(_fileHandle, "\n");
197 fflush(_fileHandle);
198 }
199
200 #endif /* !PEGASUS_OS_VMS */
201
202 mike 1.2 PEGASUS_NAMESPACE_END
|