(file) Return to TraceFileHandlerPOSIX.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  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           
 51           PEGASUS_NAMESPACE_BEGIN static Mutex writeMutex;
 52           
 53           ///////////////////////////////////////////////////////////////////////////////
 54           //  Writes message to file. Locks the file before writing to it
 55           //  Implementation of this function is platform specific
 56           ///////////////////////////////////////////////////////////////////////////////
 57           
 58           #if defined(PEGASUS_OS_VMS)
 59           
 60           void TraceFileHandler::handleMessage(
 61               const char *message,
 62               const char *fmt, va_list argList)
 63           {
 64 mike  1.2     Sint32 retCode;
 65               Sint32 fileDesc;
 66           
 67               // Do not add Trace calls in the Critical section
 68               // ---- BEGIN CRITICAL SECTION
 69           
 70               // Check if the file has been deleted, if so re-open the file and
 71               // continue
 72               if (!System::exists(_fileName))
 73               {
 74                   if (_fileHandle == 0)
 75                   {
 76                       _fileHandle = fopen(_fileName, "a+", "shr=get,put,upd");
 77                       // _fileHandle = fopen(_fileName,"a","shr=get");
 78                   }
 79                   else
 80                   {
 81                       _fileHandle =
 82                           freopen(_fileName, "a+", _fileHandle, "shr=get,put,upd");
 83                       // _fileHandle = freopen(_fileName,"a",_fileHandle,"shr=get");
 84                   }
 85 mike  1.2         if (!_fileHandle)
 86                   {
 87                       // Unable to re-open file, log a message
 88           
 89                       Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER,
 90                                     Logger::WARNING,
 91                                     "Common.TraceFileHandlerVms.FAILED_TO_OPEN_FILE",
 92                                     "Failed to open File $0", _fileName);
 93                       return;
 94                   }
 95           
 96                   // Set permissions on the trace file to 0400
 97           
 98                   if (!FileSystem::
 99                       changeFilePermissions(String(_fileName), (S_IRUSR | S_IWUSR)))
100                   {
101                       Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING,
102                                     "Common.TraceFileHandlerVms.FAILED_TO_SET_FILE_PERMISSIONS",
103                                     "Failed to set permissions on file $0", _fileName);
104                       return;
105                   }
106 mike  1.2     }
107           
108               // Seek to the end of File
109           
110               retCode = fseek(_fileHandle, 0, SEEK_END);
111           
112               // Write the message to the file
113           
114               retCode = fprintf(_fileHandle, "%s", message);
115               retCode = vfprintf(_fileHandle, fmt, argList);
116               retCode = fprintf(_fileHandle, "\n");
117               retCode = fflush(_fileHandle);
118               fileDesc = fileno(_fileHandle);
119               retCode = fsync(fileDesc);
120               _wroteToLog = false;
121               // retCode = fclose(_fileHandle);
122               // _fileHandle = 0;
123           
124               // ---- END CRITICAL SECTION
125           
126               return;
127 mike  1.2 }
128           
129           #else /* PEGASUS_OS_VMS */
130           
131           void TraceFileHandler::handleMessage(
132               const char *message,
133               const char *fmt, va_list argList)
134           {
135               if (!_fileHandle)
136               {
137                   // The trace file is not open, which means an earlier fopen() was
138                   // unsuccessful.  Stop now to avoid logging duplicate error messages.
139                   return;
140               }
141           
142               // Do not add Trace calls in the Critical section
143               // ---- BEGIN CRITICAL SECTION
144               AutoMutex writeLock(writeMutex);
145           
146               // If the file has been deleted, re-open it and continue
147               if (!System::exists(_fileName))
148 mike  1.2     {
149                   fclose(_fileHandle);
150                   _fileHandle = _openFile(_fileName);
151                   if (!_fileHandle)
152                   {
153                       return;
154                   }
155               }
156           
157               // Got the Lock on the File. Seek to the end of File
158               fseek(_fileHandle, 0, SEEK_END);
159           # ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU
160               long pos = ftell(_fileHandle);
161               // Check if the file size is approaching 2GB - which is the
162               // maximum size a file on 32 bit Linux can grow (ofcourse if
163               // not using large-files option). If this is not checked, the
164               // cimserver may get a SIGXFSZ signal and shutdown. See Bug#1527.
165               if (pos >= 0x7ff00000)
166               {
167                   // If the file size is almost 2 GB in size, close this trace
168                   // file and open a new trace file which would have _fileCount
169 mike  1.2         // as the suffix. So, if "cimserver.trc" is the trace file that
170                   // approaches 2GB, the next file which gets created would be
171                   // named "cimserver.trc.1" and so on ...
172                   fclose(_fileHandle);
173                   sprintf(_fileName, "%s.%u", _baseFileName, ++_fileCount);
174                   _fileHandle = fopen(_fileName, "a+");
175                   if (!_fileHandle)
176                   {
177                       // Unable to open file, log a message
178                       if (!_wroteToLog)
179                       {
180                           Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING,
181                                         "Common.TraceFileHandler.FAILED_TO_OPEN_FILE",
182                                         "Failed to open File $0", _fileName);
183                           _wroteToLog = true;
184                       }
185                       return;
186                   }
187               }
188           # endif
189           
190 mike  1.2     // Write the message to the file
191               fprintf(_fileHandle, "%s", message);
192               vfprintf(_fileHandle, fmt, argList);
193               fprintf(_fileHandle, "\n");
194               fflush(_fileHandle);
195           }
196           
197           #endif /* !PEGASUS_OS_VMS */
198           
199           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2