operatingsystem_solaris.cpp

来自「Pegasus is an open-source implementation」· C++ 代码 · 共 691 行 · 第 1/2 页

CPP
691
字号
   getNumberOfProcesses method for Solaris implementation of OS Provider   Counts the number of sub-directories of /proc that are of the format   to represent processes.  */Boolean OperatingSystem::getNumberOfProcesses(Uint32& numberOfProcesses){// ATTN: ned to determine how to get this on SunOS   Uint32 count;   DIR *procdir;   regex_t process_pattern_compiled;   const char process_pattern[] = "^[1-9][0-9]*$";   char buffer[sizeof(dirent) + MAXNAMELEN + 1];   struct dirent* entry = (struct dirent*)buffer;   struct dirent* result = 0;   count = 0;   if ((procdir = opendir("/proc")))   {      if (regcomp(&process_pattern_compiled, process_pattern, 0) == 0)      {         while (readdir_r(procdir, entry, &result) == 0 && result != NULL)         {#if defined (PEGASUS_PLATFORM_LINUX_GENERIC_GNU) && !defined(PEGASUS_OS_LSB)            if (entry->d_type != DT_DIR)               continue;#endif            if (regexec(&process_pattern_compiled, entry->d_name,                        0, NULL, 0) == 0)               count++;         }         regfree(&process_pattern_compiled);      }      closedir(procdir);   }   numberOfProcesses = count;   return true;}/**   getMaxNumberOfProcesses method for Solaris implementation of OS Provider   gets information from /proc/sys/kernel/threads-max  */Boolean OperatingSystem::getMaxNumberOfProcesses(Uint32& mMaxProcesses){// ATTN: Need to determine how to get this on Solaris  return false;}/**   getTotalSwapSpaceSize method for Soalris implementation of OS Provider  */Boolean OperatingSystem::getTotalSwapSpaceSize(Uint64& mTotalSwapSpaceSize){// ATTN: Need to determine ow to get this on SunOS  return false;}/** _totalVM method for Solaris implementation of OS Provider    Calculates TotalVirtualMemory as the sum of totalSwap    and totalMem.*/Uint64 OperatingSystem::_totalVM(){  Uint64 total;  Uint64 tmp;  total = 0;  if( getTotalSwapSpaceSize(tmp) )  {    total += tmp;  }  if( getTotalVisibleMemorySize(tmp))  {    total += tmp;  }  return total;}/**   getTotalVirtualMemorySize method for Soalris implementation of OS Provider   Gets information from SwapTotal in /proc/meminfo  */Boolean OperatingSystem::getTotalVirtualMemorySize(Uint64& total){    total = _totalVM();    if (total) return true;    else return false;   // possible that we had trouble with file}/**   getFreeVirtualMemorySize method for Solaris implementation of OS Provider   Gets information from SwapFree in /proc/meminfo  */Boolean OperatingSystem::getFreeVirtualMemory(Uint64& freeVirtualMemory){// ATTN: Need to determine how to get this on SunOS  return false;}/**   getFreePhysicalMemory method for Solaris implementation of OS Provider   Gets information from MemFree in /proc/meminfo  */Boolean OperatingSystem::getFreePhysicalMemory(Uint64& total){// ATTN: Need to determine how to get thison SunOS  return false;}/**   getTotalVisibleMemorySize method for Solaris implementation of OS Provider   Was returning FreePhysical - correct? diabled it.  */Boolean OperatingSystem::getTotalVisibleMemorySize(Uint64& memory){// ATTN: Need to determin how to get this on SunOS  return false;}/**   getSizeStoredInPagingFiles method for Solaris implementation of OS Provider   Was returning TotalSwap - correct? diabled it.  */Boolean OperatingSystem::getSizeStoredInPagingFiles(Uint64& total){    return false;}/**   getFreeSpaceInPagingFiles method for Solaris implementation of OS Provider   Was returning TotalVirtualMemory - correct? diabled it.  */Boolean OperatingSystem::getFreeSpaceInPagingFiles(                                              Uint64& freeSpaceInPagingFiles){    return false;}/**   getMaxProcessMemorySize method for Solaris implementation of OS Provider   Gets information from /proc/sys/vm/overcommit_memoryt or returns   TotalVirtualMemory   */Boolean OperatingSystem::getMaxProcessMemorySize(Uint64& maxProcessMemorySize){// ATTN: Need to determine how to get this for SunOS  return false;} /**   getDistributed method for Solaris implementation of OS Provider   Always sets the distributed boolean to FALSE  */Boolean OperatingSystem::getDistributed(Boolean& distributed){    distributed = false;    return true;}/**   getMaxProcsPerUser method for Solaris implementation of OS Provider   Retrieves the _SC_CHILD_MAX value from sysconf.  */Boolean OperatingSystem::getMaxProcsPerUser (Uint32& maxProcsPerUser){// ATTN: Need to determine how to get this on SunOS    return false;}/**   getSystemUpTime method for Solaris implementation of OS Provider   Gets information from /proc/uptime (already in seconds).  */Boolean OperatingSystem::getSystemUpTime(Uint64& mUpTime){// ATTN: Need to determine how to get this on SunOS   return false;}/**   getOperatingSystemCapability handles a Pegasus extension of the DMTF defined   CIM_Operating System. This attribute is defined as a string either "64 bit"   or "32 bit". On the Solaris side we will determine that by measuring   the number   of bytes allocated for pointers because this implementation will change   based on the underlying processor architecture. 32-bit 64-bit... 128-bit  */Boolean OperatingSystem::getOperatingSystemCapability(String& scapability){    char capability[80];    void *ptr;    int ptr_bits;    ptr_bits = 8*sizeof(ptr);    sprintf (capability, "%d bit", ptr_bits);    scapability.assign(capability);    return true;}/**   _reboot method for Solaris implementation of OS Provider   Finds executable in /sbin, /usr/bin, or /usr/local/sbin and invokes.   Invokes as via system system call, so have full checking of user's   authorization (already authenticated by CIMOM)   Don't we want to do some additional cleanup before actually   invoking the reboot command?  For example, we know the CIMOM is up   and running.  Perhaps set the OS state to 'Stopping' and do a   graceful shutdown of the CIMOM (at least)?   */Uint32 OperatingSystem::_reboot(){/*******************************************************ATTN: At the time of implementation the Provider Manager will not callthis function. The code is defined out becasue it is not clear that allusers would want this supportted. If it were to be supported then at aminimum the user must be athenticated or the code should run switch andrun on behalf of the caller rather than as the CIMOM and then let thesystem validate the users credentials and permissions to determine ifthe calling user has the authority to invoke a shutdown or a reboot.*******************************************************/   return false;#ifdef NOTDEF   const char *reboot[] = { "reboot", NULL };   const char *paths[] = { "/sbin", "/usr/sbin", "/usr/local/sbin", NULL };   struct stat sbuf;   String fname;   CString p;   Uint32 result;   result = 1;   for (int ii = 0; paths[ii] != NULL; ii++)   {      for (int jj = 0; reboot[jj]; jj++)      {         fname = paths[ii];         fname.append("/");         fname.append(reboot[jj]);         p = fname.getCString();         if (stat(p, &sbuf) == 0 && (sbuf.st_mode & S_IXUSR))         {            result = 2;            if (system(p) == 0)               result = 0;            return result;         }      }   }   return result;#endif // NOTDEF}/**   _shutdown method for Solaris implementation of OS Provider   Finds executable in /sbin, /usr/bin, or /usr/local/sbin and invokes.   Don't we want to add some more cleanup - especially since we know   the CIMOM is running - this could cause things to be set into a   'Stopping' state while the OS cleans up before actually invoking   the poweroff command.   */Uint32 OperatingSystem::_shutdown(){/*******************************************************ATTN: At the time of implementation the Provider Manager will not callthis function. The code is defined out becasue it is not clear that allusers would want this supportted. If it were to be supported then at aminimum the user must be athenticated or the code should run switch andrun on behalf of the caller rather than as the CIMOM and then let thesystem validate the users credentials and permissions to determine ifthe calling user has the authority to invoke a shutdown or a reboot.*******************************************************/   return false;#ifdef NOTDEF   const char *poweroff[] = { "poweroff", NULL };   const char *paths[] = { "/sbin", "/usr/sbin", "/usr/local/sbin", NULL };   struct stat sbuf;   String fname;   CString p;   Uint32 result;   result = 1;   for (int ii = 0; paths[ii] != NULL; ii++)   {      for (int jj = 0; poweroff[jj]; jj++)      {         fname = paths[ii];         fname.append("/");         fname.append(poweroff[jj]);         p = fname.getCString();         if (stat(p, &sbuf) == 0 && (sbuf.st_mode & S_IXUSR))         {            result = 2;            if (system(p) == 0)               result = 0;            return result;         }      }   }   return result;#endif //NOTDEF}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?