(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 kumpf 1.5 PEGASUS_NAMESPACE_BEGIN
 52           
 53           static Mutex writeMutex;
 54           PEGASUS_FORK_SAFE_MUTEX(writeMutex)
 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 yi.zhou 1.6             Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, 
105             			  Logger::WARNING,
106 mike    1.2                           "Common.TraceFileHandlerVms.FAILED_TO_SET_FILE_PERMISSIONS",
107                                       "Failed to set permissions on file $0", _fileName);
108                         return;
109                     }
110                 }
111             
112                 // Seek to the end of File
113             
114                 retCode = fseek(_fileHandle, 0, SEEK_END);
115             
116                 // Write the message to the file
117             
118                 retCode = fprintf(_fileHandle, "%s", message);
119                 retCode = vfprintf(_fileHandle, fmt, argList);
120                 retCode = fprintf(_fileHandle, "\n");
121                 retCode = fflush(_fileHandle);
122                 fileDesc = fileno(_fileHandle);
123                 retCode = fsync(fileDesc);
124                 _wroteToLog = false;
125                 // retCode = fclose(_fileHandle);
126                 // _fileHandle = 0;
127 mike    1.2 
128                 // ---- END CRITICAL SECTION
129             
130                 return;
131             }
132             
133             #else /* PEGASUS_OS_VMS */
134             
135             void TraceFileHandler::handleMessage(
136                 const char *message,
137                 const char *fmt, va_list argList)
138             {
139                 if (!_fileHandle)
140                 {
141                     // The trace file is not open, which means an earlier fopen() was
142                     // unsuccessful.  Stop now to avoid logging duplicate error messages.
143                     return;
144                 }
145             
146                 // Do not add Trace calls in the Critical section
147                 // ---- BEGIN CRITICAL SECTION
148 mike    1.2     AutoMutex writeLock(writeMutex);
149             
150                 // If the file has been deleted, re-open it and continue
151                 if (!System::exists(_fileName))
152                 {
153                     fclose(_fileHandle);
154                     _fileHandle = _openFile(_fileName);
155                     if (!_fileHandle)
156                     {
157                         return;
158                     }
159                 }
160             
161                 // Got the Lock on the File. Seek to the end of File
162                 fseek(_fileHandle, 0, SEEK_END);
163             # ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU
164                 long pos = ftell(_fileHandle);
165                 // Check if the file size is approaching 2GB - which is the
166                 // maximum size a file on 32 bit Linux can grow (ofcourse if
167                 // not using large-files option). If this is not checked, the
168                 // cimserver may get a SIGXFSZ signal and shutdown. See Bug#1527.
169 mike    1.2     if (pos >= 0x7ff00000)
170                 {
171                     // If the file size is almost 2 GB in size, close this trace
172                     // file and open a new trace file which would have _fileCount
173                     // as the suffix. So, if "cimserver.trc" is the trace file that
174                     // approaches 2GB, the next file which gets created would be
175                     // named "cimserver.trc.1" and so on ...
176                     fclose(_fileHandle);
177                     sprintf(_fileName, "%s.%u", _baseFileName, ++_fileCount);
178                     _fileHandle = fopen(_fileName, "a+");
179                     if (!_fileHandle)
180                     {
181                         // Unable to open file, log a message
182                         if (!_wroteToLog)
183                         {
184 yi.zhou 1.6                 Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, 
185             			      Logger::WARNING,
186 mike    1.2                               "Common.TraceFileHandler.FAILED_TO_OPEN_FILE",
187                                           "Failed to open File $0", _fileName);
188                             _wroteToLog = true;
189                         }
190                         return;
191                     }
192                 }
193             # endif
194             
195                 // Write the message to the file
196                 fprintf(_fileHandle, "%s", message);
197                 vfprintf(_fileHandle, fmt, argList);
198                 fprintf(_fileHandle, "\n");
199                 fflush(_fileHandle);
200             }
201             
202             #endif /* !PEGASUS_OS_VMS */
203             
204             PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2