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

Diff for /pegasus/src/Pegasus/Common/TraceFileHandlerPOSIX.cpp between version 1.3 and 1.18

version 1.3, 2006/09/22 18:58:22 version 1.18, 2009/01/21 19:52:04
Line 1 
Line 1 
 //%2006////////////////////////////////////////////////////////////////////////  //%LICENSE////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development  // Licensed to The Open Group (TOG) under one or more contributor license
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.  // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;  // this work for additional information regarding copyright ownership.
 // IBM Corp.; EMC Corporation, The Open Group.  // Each contributor licenses this file to you under the OpenPegasus Open
 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;  // Source License; you may not use this file except in compliance with the
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.  // License.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;  //
 // EMC Corporation; VERITAS Software Corporation; The Open Group.  // Permission is hereby granted, free of charge, to any person obtaining a
 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;  // copy of this software and associated documentation files (the "Software"),
 // EMC Corporation; Symantec Corporation; The Open Group.  // to deal in the Software without restriction, including without limitation
 //  // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 // Permission is hereby granted, free of charge, to any person obtaining a copy  // and/or sell copies of the Software, and to permit persons to whom the
 // of this software and associated documentation files (the "Software"), to  // Software is furnished to do so, subject to the following conditions:
 // deal in the Software without restriction, including without limitation the  //
 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  // The above copyright notice and this permission notice shall be included
 // sell copies of the Software, and to permit persons to whom the Software is  // in all copies or substantial portions of the Software.
 // furnished to do so, subject to the following conditions:  //
 //  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT  // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR  // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN  // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION  //
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  //////////////////////////////////////////////////////////////////////////
 //  
 //==============================================================================  
 //  
 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)  
 //  
 // Modified By: Amit K Arora, IBM (amita@in.ibm.com) for Bug#1527  
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)  
 //              David Dillard, VERITAS Software Corp.  
 //                  (david.dillard@veritas.com)  
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #if defined(PEGASUS_OS_VMS) #if defined(PEGASUS_OS_VMS)
 # include <fcntl.h> # include <fcntl.h>
 #endif #endif
 #include <Pegasus/Common/Logger.h>  
 #include <Pegasus/Common/System.h> #include <Pegasus/Common/System.h>
 #include <Pegasus/Common/TraceFileHandler.h> #include <Pegasus/Common/TraceFileHandler.h>
 #include <Pegasus/Common/Mutex.h> #include <Pegasus/Common/Mutex.h>
Line 51 
Line 41 
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 static Mutex writeMutex; static Mutex writeMutex;
 PEGASUS_FORK_SAFE_MUTEX(writeMutex);  PEGASUS_FORK_SAFE_MUTEX(writeMutex)
  
 /////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
 //  Writes message to file. Locks the file before writing to it //  Writes message to file. Locks the file before writing to it
 //  Implementation of this function is platform specific //  Implementation of this function is platform specific
 /////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
  
 #if defined(PEGASUS_OS_VMS)  void TraceFileHandler::prepareFileHandle(void)
   
 void TraceFileHandler::handleMessage(  
     const char *message,  
     const char *fmt, va_list argList)  
 {  
     Sint32 retCode;  
     Sint32 fileDesc;  
   
     // Do not add Trace calls in the Critical section  
     // ---- BEGIN CRITICAL SECTION  
   
     // Check if the file has been deleted, if so re-open the file and  
     // continue  
     if (!System::exists(_fileName))  
     {  
         if (_fileHandle == 0)  
         {  
             _fileHandle = fopen(_fileName, "a+", "shr=get,put,upd");  
             // _fileHandle = fopen(_fileName,"a","shr=get");  
         }  
         else  
         {  
             _fileHandle =  
                 freopen(_fileName, "a+", _fileHandle, "shr=get,put,upd");  
             // _fileHandle = freopen(_fileName,"a",_fileHandle,"shr=get");  
         }  
         if (!_fileHandle)  
         {  
             // Unable to re-open file, log a message  
   
             Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER,  
                           Logger::WARNING,  
                           "Common.TraceFileHandlerVms.FAILED_TO_OPEN_FILE",  
                           "Failed to open File $0", _fileName);  
             return;  
         }  
   
         // Set permissions on the trace file to 0400  
   
         if (!FileSystem::  
             changeFilePermissions(String(_fileName), (S_IRUSR | S_IWUSR)))  
         {  
             Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING,  
                           "Common.TraceFileHandlerVms.FAILED_TO_SET_FILE_PERMISSIONS",  
                           "Failed to set permissions on file $0", _fileName);  
             return;  
         }  
     }  
   
     // Seek to the end of File  
   
     retCode = fseek(_fileHandle, 0, SEEK_END);  
   
     // Write the message to the file  
   
     retCode = fprintf(_fileHandle, "%s", message);  
     retCode = vfprintf(_fileHandle, fmt, argList);  
     retCode = fprintf(_fileHandle, "\n");  
     retCode = fflush(_fileHandle);  
     fileDesc = fileno(_fileHandle);  
     retCode = fsync(fileDesc);  
     _wroteToLog = false;  
     // retCode = fclose(_fileHandle);  
     // _fileHandle = 0;  
   
     // ---- END CRITICAL SECTION  
   
     return;  
 }  
   
 #else /* PEGASUS_OS_VMS */  
   
 void TraceFileHandler::handleMessage(  
     const char *message,  
     const char *fmt, va_list argList)  
 {  
     if (!_fileHandle)  
     {     {
         // The trace file is not open, which means an earlier fopen() was  
         // unsuccessful.  Stop now to avoid logging duplicate error messages.  
         return;  
     }  
   
     // Do not add Trace calls in the Critical section  
     // ---- BEGIN CRITICAL SECTION  
     AutoMutex writeLock(writeMutex);  
   
     // If the file has been deleted, re-open it and continue     // If the file has been deleted, re-open it and continue
     if (!System::exists(_fileName))     if (!System::exists(_fileName))
     {     {
Line 178 
Line 82 
         if (!_fileHandle)         if (!_fileHandle)
         {         {
             // Unable to open file, log a message             // Unable to open file, log a message
             if (!_wroteToLog)              MessageLoaderParms parm(
             {  
                 Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING,  
                               "Common.TraceFileHandler.FAILED_TO_OPEN_FILE",                               "Common.TraceFileHandler.FAILED_TO_OPEN_FILE",
                               "Failed to open File $0", _fileName);                  "Failed to open File $0",
                 _wroteToLog = true;                  _fileName);
             }              _logError(TRCFH_FAILED_TO_OPEN_FILE_SYSMSG,parm);
             return;             return;
         }         }
     }     }
 # endif # endif
   }
   
   void TraceFileHandler::handleMessage(
       const char *message,
       Uint32 msgLen,
       const char *fmt, va_list argList)
   {
       if (_configHasChanged)
       {
           _reConfigure();
       }
   
       if (!_fileHandle)
       {
           // The trace file is not open, which means an earlier fopen() was
           // unsuccessful.  Stop now to avoid logging duplicate error messages.
           return;
       }
   
       // Do not add Trace calls in the Critical section
       // ---- BEGIN CRITICAL SECTION
       AutoMutex writeLock(writeMutex);
  
       prepareFileHandle();
     // Write the message to the file     // Write the message to the file
     fprintf(_fileHandle, "%s", message);     fprintf(_fileHandle, "%s", message);
     vfprintf(_fileHandle, fmt, argList);     vfprintf(_fileHandle, fmt, argList);
     fprintf(_fileHandle, "\n");     fprintf(_fileHandle, "\n");
     fflush(_fileHandle);      if (0 == fflush(_fileHandle))
       {
           // trace message successful written, reset error log messages
           // thus allow writing of errors to log again
           _logErrorBitField = 0;
       }
   
       // ---- END CRITICAL SECTION
   }
   
   void TraceFileHandler::handleMessage(const char *message, Uint32 msgLen)
   {
       if (_configHasChanged)
       {
           _reConfigure();
       }
   
       if (!_fileHandle)
       {
           // The trace file is not open, which means an earlier fopen() was
           // unsuccessful.  Stop now to avoid logging duplicate error messages.
           return;
 } }
  
 #endif /* !PEGASUS_OS_VMS */      // Do not add Trace calls in the Critical section
       // ---- BEGIN CRITICAL SECTION
       AutoMutex writeLock(writeMutex);
   
       prepareFileHandle();
       // Write the message to the file
       fprintf(_fileHandle, "%s\n", message);
       if (0 == fflush(_fileHandle))
       {
           // trace message successful written, reset error log messages
           // thus allow writing of errors to log again
           _logErrorBitField = 0;
       }
       // ---- END CRITICAL SECTION
   }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.3  
changed lines
  Added in v.1.18

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2