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

  1 karl  1.6 //%2003////////////////////////////////////////////////////////////////////////
  2 mike  1.2 //
  3 karl  1.6 // 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 mike  1.2 //
  8           // Permission is hereby granted, free of charge, to any person obtaining a copy
  9           // of this software and associated documentation files (the "Software"), to
 10           // deal in the Software without restriction, including without limitation the
 11           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 12           // sell copies of the Software, and to permit persons to whom the Software is
 13           // furnished to do so, subject to the following conditions:
 14 kumpf 1.3 // 
 15 mike  1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 17           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 18           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 19           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 20           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 21           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23           //
 24           //==============================================================================
 25           //
 26           // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)
 27           //
 28           // Modified By:
 29           //
 30           //%/////////////////////////////////////////////////////////////////////////////
 31           
 32           
 33           #include <fcntl.h>
 34           #include <Pegasus/Common/Logger.h>
 35           #include <Pegasus/Common/System.h>
 36 mike  1.2 #include <Pegasus/Common/TraceFileHandler.h>
 37           
 38           PEGASUS_USING_STD;
 39           
 40           PEGASUS_NAMESPACE_BEGIN
 41           
 42           /////////////////////////////////////////////////////////////////////////////// 
 43           //  Writes message to file. Locks the file before writing to it
 44           //  Implementation of this function is platform specific
 45           ///////////////////////////////////////////////////////////////////////////////
 46           void TraceFileHandler::handleMessage(
 47               const char* message,
 48               const char* fmt,
 49               va_list argList) 
 50           {
 51               struct flock lock;
 52               Sint32 retCode;
 53           
 54               lock.l_type = F_WRLCK;
 55               lock.l_whence = SEEK_SET;
 56               lock.l_start = 0;
 57 mike  1.2     lock.l_len = 1;
 58           
 59               // Try to lock the file. If the lock is busy, wait for it to be free.
 60               // Do not add Trace calls in the Critical section
 61               // ---- BEGIN CRITICAL SECTION
 62           
 63               // Check if the file has been deleted, if so re-open the file and continue
 64               if (!System::exists(_fileName))
 65               {
 66           	freopen(_fileName,"a+",_fileHandle);
 67                   if (!_fileHandle)
 68                   {
 69                       // Unable to re-open file, log a message
 70 humberto 1.5             //l10n
 71                          //Logger::put(Logger::DEBUG_LOG,System::CIMSERVER,Logger::WARNING,
 72                              //"Failed to open File $0",_fileName);
 73                          Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,Logger::WARNING,
 74                          	"Common.TraceFileHandlerUnix.FAILED_TO_OPEN_FILE",
 75 mike     1.2                 "Failed to open File $0",_fileName);
 76                          return; 
 77                      } 	
 78                  }
 79                  retCode = fcntl(fileno(_fileHandle), F_SETLKW, &lock);
 80              
 81                  if (retCode != -1)
 82                  {
 83              	// Got the Lock on the File. Seek to the end of File
 84              	fseek(_fileHandle,0,SEEK_END);
 85              
 86              	// Write the message to the file
 87                      fprintf (_fileHandle, "%s",message);
 88              	retCode = vfprintf(_fileHandle,fmt,argList);
 89              	fprintf(_fileHandle,"\n");
 90              	fflush(_fileHandle);
 91              	
 92              	// Free the Lock on the File
 93                      lock.l_type = F_UNLCK;
 94                      retCode = fcntl(fileno(_fileHandle), F_SETLK, &lock);
 95              
 96 mike     1.2 	if (retCode == -1)
 97              	{
 98              	    // Failed to release lock on file. Log message and return
 99 humberto 1.5 	    //l10n
100              	    //Logger::put(Logger::DEBUG_LOG,System::CIMSERVER,Logger::WARNING,
101              		//"Failed to release write lock on File $0",_fileName);
102              		Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,Logger::WARNING,
103              			"Common.TraceFileHandlerUnix.FAILED_TO_RELEASE_WRITE_LOCK",
104              			"Failed to release write lock on File $0",_fileName);
105 mike     1.2         }
106              	_wroteToLog = false;
107                  }
108                  else
109                  {
110              	// Unable to Lock the file for writing
111              	// Log message and return
112              	// Check if message is already logged, so as to not to flood log file
113              	if (!_wroteToLog)
114 humberto 1.5 	{ 
115              		//l10n
116              	    //Logger::put(Logger::DEBUG_LOG,System::CIMSERVER,Logger::WARNING,
117              		//"Failed to obtain write lock on File $0",_fileName);
118              		Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,Logger::WARNING,
119              			"Common.TraceFileHandlerUnix.FAILED_TO_OBTAIN_WRITE_LOCK",
120              			"Failed to obtain write lock on File $0",_fileName);
121 mike     1.2             _wroteToLog = true;
122              	}
123                  }
124                  // ---- END CRITICAL SECTION
125              
126                  return;
127              } 
128              
129              PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2