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

Diff for /pegasus/src/Pegasus/Common/TraceFileHandler.cpp between version 1.22 and 1.34

version 1.22, 2005/02/19 02:46:42 version 1.34, 2008/05/15 17:24:34
Line 1 
Line 1 
 //%2005////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
Line 8 
Line 8 
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 // EMC Corporation; VERITAS Software Corporation; The Open Group. // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 27 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)  
 //  
 // Modified By: Rudy Schuet (rudy.schuet@compaq.com) 11/12/01  
 //              added nsk platform support  
 //              Amit K Arora, IBM (amita@in.ibm.com) for Bug#1527  
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)  
 //              Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <fstream>  
 #include <iostream>  
 #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/FileSystem.h>
 #include <Pegasus/Common/TraceFileHandler.h> #include <Pegasus/Common/TraceFileHandler.h>
  
 #if defined(PEGASUS_OS_TYPE_WINDOWS) #if defined(PEGASUS_OS_TYPE_WINDOWS)
 # include <Pegasus/Common/TraceFileHandlerWindows.cpp> # include <Pegasus/Common/TraceFileHandlerWindows.cpp>
 #elif defined(PEGASUS_OS_TYPE_UNIX)  #elif defined(PEGASUS_OS_TYPE_UNIX) || defined(PEGASUS_OS_VMS)
 # include <Pegasus/Common/TraceFileHandlerUnix.cpp>  # include <Pegasus/Common/TraceFileHandlerPOSIX.cpp>
 #elif defined(PEGASUS_OS_TYPE_NSK)  
 # include <Pegasus/Common/TraceFileHandlerNsk.cpp>  
 #elif defined(PEGASUS_OS_VMS)  
 # include <Pegasus/Common/TraceFileHandlerVms.cpp>  
 #else #else
 # error "Unsupported platform" # error "Unsupported platform"
 #endif #endif
Line 85 
Line 73 
     {     {
         fclose(_fileHandle);         fclose(_fileHandle);
     }     }
     if (_fileName)  
     {  
         delete []_fileName;         delete []_fileName;
     }  
 #ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU #ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU
     if (_baseFileName)  
     {  
         delete []_baseFileName;         delete []_baseFileName;
     }  
 #endif #endif
 } }
  
Line 102 
Line 84 
 //  mode //  mode
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
  
 Uint32 TraceFileHandler::setFileName(const char* fileName)  Uint32 TraceFileHandler::setMessageDestination(const char* fileName)
 { {
     // If a file is already open, close it     // If a file is already open, close it
     if (_fileHandle)     if (_fileHandle)
Line 118 
Line 100 
     _baseFileName = 0;     _baseFileName = 0;
 #endif #endif
  
     if (!isValidFilePath(fileName))      if (!isValidMessageDestination(fileName))
     {     {
         return 1;         return 1;
     }     }
   
     _fileHandle = _openFile(fileName);     _fileHandle = _openFile(fileName);
     if (!_fileHandle)     if (!_fileHandle)
     {     {
Line 141 
Line 122 
  
 FILE* TraceFileHandler::_openFile(const char* fileName) FILE* TraceFileHandler::_openFile(const char* fileName)
 { {
   #ifdef PEGASUS_OS_VMS
   //    FILE* fileHandle = fopen(fileName,"a+", "shr=get,put,upd");
       FILE* fileHandle = fopen(fileName,"w", "shr=get,put,upd");
   #else
     FILE* fileHandle = fopen(fileName,"a+");     FILE* fileHandle = fopen(fileName,"a+");
   #endif
     if (!fileHandle)     if (!fileHandle)
     {     {
         // Unable to open file, log a message         // Unable to open file, log a message
         Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING,          Logger::put_l(
               Logger::ERROR_LOG,
               System::CIMSERVER,
               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",
               fileName);
           return 0;
       }
   
       //
       // Verify that the file has the correct owner
       //
       if (!System::verifyFileOwnership(fileName))
       {
           Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
              "Common.TraceFileHandler.UNEXPECTED_FILE_OWNER",
              "File $0 is not owned by user $1.", fileName,
              System::getEffectiveUserName());
           fclose(fileHandle);
         return 0;         return 0;
     }     }
  
Line 162 
Line 165 
             String(fileName), (_S_IREAD|_S_IWRITE)) )             String(fileName), (_S_IREAD|_S_IWRITE)) )
 #endif #endif
     {     {
         Logger::put_l(Logger::DEBUG_LOG, "Tracer", Logger::WARNING,          Logger::put_l(
               Logger::ERROR_LOG,
               System::CIMSERVER,
               Logger::WARNING,
            "Common.TraceFileHandler.FAILED_TO_SET_FILE_PERMISSIONS",            "Common.TraceFileHandler.FAILED_TO_SET_FILE_PERMISSIONS",
            "Failed to set permissions on file $0", fileName);             "Failed to set permissions on file $0",
         fclose(fileHandle);              fileName);
         return 0;  
     }  
   
     //  
     // Verify that the file has the correct owner  
     //  
     if (!System::verifyFileOwnership(fileName))  
     {  
         Logger::put_l(Logger::ERROR_LOG, "Tracer", Logger::WARNING,  
            "Common.TraceFileHandler.UNEXPECTED_FILE_OWNER",  
            "File $0 is not owned by user $1.", fileName,  
            System::getEffectiveUserName());  
         fclose(fileHandle);         fclose(fileHandle);
         return 0;         return 0;
     }     }
Line 185 
Line 179 
     return fileHandle;     return fileHandle;
 } }
  
 Boolean TraceFileHandler::isValidFilePath(const char* filePath)  Boolean TraceFileHandler::isValidMessageDestination(const char* filePath)
 { {
     String fileName = String(filePath);     String fileName = String(filePath);
  
Line 193 
Line 187 
     FileSystem::translateSlashes(fileName);     FileSystem::translateSlashes(fileName);
     if (FileSystem::isDirectory(fileName))     if (FileSystem::isDirectory(fileName))
     {     {
         return 0;          return false;
     }     }
  
     // Check if the file exists and is writable     // Check if the file exists and is writable
     if (FileSystem::exists(fileName))     if (FileSystem::exists(fileName))
     {     {
         if (!FileSystem::canWrite(fileName))          return FileSystem::canWrite(fileName);
         {  
             return 0;  
         }  
         else  
         {  
             return 1;  
         }         }
     }  
     else  
     {  
         // Check if directory is writable         // Check if directory is writable
         Uint32 index = fileName.reverseFind('/');         Uint32 index = fileName.reverseFind('/');
  
         if (index != PEG_NOT_FOUND)         if (index != PEG_NOT_FOUND)
         {         {
             String dirName = fileName.subString(0,index);             String dirName = fileName.subString(0,index);
             if (!FileSystem::isDirectory(dirName))  
           if (dirName.size() == 0)
             {             {
                 return 0;              dirName = "/";
             }             }
             if (!FileSystem::canWrite(dirName) )  
             {          if (!FileSystem::isDirectory(dirName))
                 return 0;  
             }  
             else  
             {             {
                 return 1;              return false;
             }             }
   
           return FileSystem::canWrite(dirName);
         }         }
         else  
         {  
             String currentDir;             String currentDir;
  
             // Check if there is permission to write in the             // Check if there is permission to write in the
             // current working directory             // current working directory
             FileSystem::getCurrentDirectory(currentDir);             FileSystem::getCurrentDirectory(currentDir);
  
             if (!FileSystem::canWrite(currentDir))      return FileSystem::canWrite(currentDir);
             {  
                 return 0;  
             }  
             else  
             {  
                 return 1;  
             }  
         }  
     }  
     PEGASUS_UNREACHABLE(return 1;)  
 } }
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.22  
changed lines
  Added in v.1.34

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2