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

  1 karl  1.17 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.12 // 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 karl  1.6  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.12 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.14 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.17 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.2  //
 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 karl  1.17 // 
 21 mike  1.2  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // 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 a.arora 1.11 // Modified By: Amit K Arora, IBM (amita@in.ibm.com) for Bug#1527
 35 kumpf   1.13 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 36 david.dillard 1.15 //              David Dillard, VERITAS Software Corp.
 37                    //                  (david.dillard@veritas.com)
 38 mike          1.2  //
 39                    //%/////////////////////////////////////////////////////////////////////////////
 40                    
 41                    
 42                    #include <Pegasus/Common/Logger.h>
 43                    #include <Pegasus/Common/System.h>
 44 david.dillard 1.15 #include <Pegasus/Common/IPC.h>
 45 mike          1.2  #include <Pegasus/Common/TraceFileHandler.h>
 46                    
 47                    PEGASUS_USING_STD;
 48                    
 49                    PEGASUS_NAMESPACE_BEGIN
 50                    
 51 david.dillard 1.15 static Mutex writeMutex;
 52                    
 53                    ///////////////////////////////////////////////////////////////////////////////
 54 mike          1.2  //  Writes message to file. Locks the file before writing to it
 55                    //  Implementation of this function is platform specific
 56                    ///////////////////////////////////////////////////////////////////////////////
 57                    void TraceFileHandler::handleMessage(
 58                        const char* message,
 59                        const char* fmt,
 60 david.dillard 1.15     va_list argList)
 61 mike          1.2  {
 62 kumpf         1.13     if (!_fileHandle)
 63                        {
 64                            // The trace file is not open, which means an earlier fopen() was
 65                            // unsuccessful.  Stop now to avoid logging duplicate error messages.
 66                            return;
 67                        }
 68 mike          1.2  
 69                        // Do not add Trace calls in the Critical section
 70                        // ---- BEGIN CRITICAL SECTION
 71 chip          1.16     AutoMutex writeLock(writeMutex);
 72 mike          1.2  
 73 kumpf         1.13     // If the file has been deleted, re-open it and continue
 74 mike          1.2      if (!System::exists(_fileName))
 75                        {
 76 kumpf         1.13         fclose(_fileHandle);
 77                            _fileHandle = _openFile(_fileName);
 78 mike          1.2          if (!_fileHandle)
 79                            {
 80 david.dillard 1.15             return;
 81                            }
 82 kumpf         1.13     }
 83 kumpf         1.7  
 84 david.dillard 1.15     // Got the Lock on the File. Seek to the end of File
 85                        fseek(_fileHandle,0,SEEK_END);
 86                    #ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU
 87                        long pos = ftell(_fileHandle);
 88                        // Check if the file size is approaching 2GB - which is the
 89                        // maximum size a file on 32 bit Linux can grow (ofcourse if
 90                        // not using large-files option). If this is not checked, the
 91                        // cimserver may get a SIGXFSZ signal and shutdown. See Bug#1527.
 92                        if(pos >= 0x7ff00000)
 93 mike          1.2      {
 94 david.dillard 1.15         // If the file size is almost 2 GB in size, close this trace
 95                            // file and open a new trace file which would have _fileCount
 96                            // as the suffix. So, if "cimserver.trc" is the trace file that
 97                            // approaches 2GB, the next file which gets created would be
 98                            // named "cimserver.trc.1" and so on ...
 99                            fclose(_fileHandle);
100                            sprintf(_fileName,"%s.%u",_baseFileName,++_fileCount);
101                            _fileHandle = fopen(_fileName,"a+");
102                            if (!_fileHandle)
103 a.arora       1.11         {
104 david.dillard 1.15             // Unable to open file, log a message
105                                if (!_wroteToLog)
106 a.arora       1.11             {
107 david.dillard 1.15                 Logger::put_l(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,
108                                            "Common.TraceFileHandler.FAILED_TO_OPEN_FILE",
109                                            "Failed to open File $0",_fileName);
110                                    _wroteToLog = true;
111 a.arora       1.11             }
112 david.dillard 1.15             return;
113 a.arora       1.11         }
114 david.dillard 1.15     }
115 a.arora       1.11 #endif
116 mike          1.2  
117 david.dillard 1.15     // Write the message to the file
118                        fprintf (_fileHandle, "%s",message);
119                        vfprintf(_fileHandle,fmt,argList);
120                        fprintf(_fileHandle,"\n");
121                        fflush(_fileHandle);
122                    }
123 mike          1.2  
124                    PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2