operatingsystem_solaris.cpp

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

CPP
691
字号
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// 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// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// 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: Jim Wunderlich <Jim_Wunderlich@prodigy.net>//// Modified By://///////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Time.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/Logger.h>#include "OperatingSystem.h"#include <iostream>#include <set>#include <sys/utsname.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/param.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <unistd.h>#include <time.h>#include <utmpx.h>#include <regex.h>#include <dirent.h>PEGASUS_USING_STD;#define OSP_DEBUG(X) // Logger::put(Logger::DEBUG_LOG, "Solaris OSProvider",Logger::INFORMATION, "$0", X)OperatingSystem::OperatingSystem(void){}OperatingSystem::~OperatingSystem(void){}/**   getName method of the Solaris implementation for the OS Provider   Calls uname() to get the operating system name.  */Boolean OperatingSystem::getName(String& osName){    struct utsname  unameInfo;    // Call uname and check for any errors.    if (uname(&unameInfo) < 0)    {       return false;    }    osName.assign(unameInfo.sysname);    return true;}/**   getUtilGetHostName method for the Solaris implementation of the OS Provider   Gets the name of the host system from gethostname and gethostbyname.  */static Boolean getUtilGetHostName(String& csName){     char    hostName[PEGASUS_MAXHOSTNAMELEN + 1];     struct  hostent *he;     if (gethostname(hostName, sizeof(hostName)) != 0)     {         return false;     }     hostName[sizeof(hostName)-1] = 0;     // Now get the official hostname.  If this call fails then return     // the value from gethostname().     he=gethostbyname(hostName);     if (he)     {         strncpy(hostName, he->h_name, sizeof(hostName)-1);     }     csName.assign(hostName);     return true;}Boolean OperatingSystem::getCSName(String& csName){    return getUtilGetHostName(csName);}/**   getCaption method for Solaris implementation of OS Provider   Uses uname system call and extracts information for the Caption.  */Boolean OperatingSystem::getCaption(String& caption){   struct utsname     unameInfo;   // Call uname and check for any errors.   if (uname(&unameInfo) < 0)   {       return false;   }   // append in caption the information available from uname system call.   //     system name, release, version, machine and nodename.   caption.assign(unameInfo.sysname);   caption.append(" ");   caption.append(unameInfo.release);   // caption.append(" ");   // caption.append(unameInfo.version);   // caption.append(" ");   // caption.append(unameInfo.machine);   // caption.append(" ");   // caption.append(unameInfo.nodename);   return true;}Boolean OperatingSystem::getDescription(String& description){   description.assign("This instance reflects the Operating System"        " on which the CIMOM is executing (as distinguished from instances"        " of other installed operating systems that could be run).");   return true;}/**   getInstallDate method for Solaris implementation of OS provider  */Boolean OperatingSystem::getInstallDate(CIMDateTime& installDate){// ATTN: Need to determine how to get this on SunOS   return false;}/**   getStatus method for Solaris implementation of OS provider    */Boolean OperatingSystem::getStatus(String& status){// ATTN: Need to determine how to get this on SunOS   status.assign("Unknown");   return true;}/**   getVersion method for Solaris implementation of OS provider   Uses uname system call and extracts the release and version   information (separated by a space).   Returns FALSE if uname call results in errors.   */Boolean OperatingSystem::getVersion(String& osVersion){    struct utsname  unameInfo;    // Call uname and check for any errors.    if (uname(&unameInfo) < 0)    {       return false;    }    osVersion.assign(unameInfo.release);   return true;}Boolean OperatingSystem::getOSType(Uint16& osType){    // SunOS is the OS component of the packaged    // system called Solaris so return SunOS    // osType = Solaris;    osType = SunOS;    return true;}Boolean OperatingSystem::getOtherTypeDescription(String& otherTypeDescription){    struct utsname  unameInfo;    char version[sizeof(unameInfo.release) + sizeof(unameInfo.version)];    // Call uname and check for any errors.    if (uname(&unameInfo) < 0)    {       return false;    }    sprintf(version, "%s %s", unameInfo.release, unameInfo.version);    otherTypeDescription.assign(version);    return true;}/**   getLastBootUpTime method for Solaris implementation of OS Provider   gets information from /proc/uptime file  */Boolean OperatingSystem::getLastBootUpTime(CIMDateTime& lastBootUpTime){// ATTN: need to determine how to get this on SunOSreturn false;}/**   getLocalDateTime method for Solaris implementation of OS Provider   Currently calls time to get local time, should be changed to use   the CIMOM date time and be consistent across all time properties   (e.g., LastBootUpTime + SystemUpTime = LocalDateTime)  */Boolean OperatingSystem::getLocalDateTime(CIMDateTime& localDateTime){   // Get the date and time from the system.   localDateTime = CIMDateTime::getCurrentDateTime();   return true;}/**   getCurrentTimeZone method for Solaris implementation of OS Provider   Gets information from Time::gettimeofday call and ensures sign follows   CIM standard.  */Boolean OperatingSystem::getCurrentTimeZone(Sint16& currentTimeZone){    time_t systemTime;    struct tm tmval;    // Get the time from the system.    systemTime = time(0);    localtime_r(&systemTime, &tmval);    currentTimeZone = - (Sint16) (timezone / 60);    if ((tmval.tm_isdst > 0) && daylight)    {        // ATTN: It is unclear how to determine the DST offset.  Assume 1 hour.        currentTimeZone += 60;    }    return true;}/**   getNumberOfLicensedUsers method for Solaris implementation of OS Provider   Always returns 0 for unlimited  */Boolean OperatingSystem::getNumberOfLicensedUsers(Uint32& numberOfLicensedUsers){// ATTN: need todetrmine how to get this on SunOS   // According to the MOF, if it's unlimited, use zero   numberOfLicensedUsers = 0;   return true;}/**   getNumberOfUsers method for Solaris implementation of OS Provider   Goes through the utents, counting the number of type USER_PROCESS  */Boolean OperatingSystem::getNumberOfUsers(Uint32& numberOfUsers){    struct utmpx * utmpp;    numberOfUsers = 0;    while ((utmpp = getutxent()) != NULL)    {        if (utmpp->ut_type == USER_PROCESS)        {            numberOfUsers++;        }    }    endutxent();    return true;}/**

⌨️ 快捷键说明

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