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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2