operatingsystem_vms.cpp

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

CPP
2,080
字号
//%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: Ray Boucher, Hewlett-Packard Company <ray.boucher@hp.com>//// Modified By://// Sean Keenan, Hewlett-Packard Company <sean.keenan@hp.com>////%////////////////////////////////////////////////////////////////////////////////  PTR 73-51-32//  Modified getNumberOfUsers() function to return the //  number of interactive user names for number of users//  property ////  PTR 73-51-30 and PTR 73-51-2//  Changes made to address review comments in PTR 73-51-2//  Replacing sys$specific:[000000] with wbem_tmp: logical//  as first argument to tempnam() in //  in getNumberOfLicensedUsers() and getInstallDate() functions.////  PTR 73-51-27//  Changed getNumberOfLicensedUsers() to return number of licensed users //  as 0 (unlimited licensed users) in case of I64 as the base O/S license on //  IA64 (FOE) provides unlimited number of users////  PTR 73-51-22 21-Jul-2006//  Changed the getTotalSwapSpaceSize(),getFreeSpaceInPagingFiles(),//  getSizeStoredInPagingFiles(), getTotalVisibleMemorySize() and//  getFreePhysicalMemory() functions to get teh pagesize using the //  sys$getsyiw() call using item code SYI$_PAGE_SIZE////  PTR 73-51-28 12-Jul-2006//  changed obtaining of TotalVirtualMemorySize from current process PGFLQUOTA//  to the sum of TotalVisibleMemorySize and SizeStoredInPagingFiles.//  changed obtaining of FreeVirtualMemory from current process PAGFILCNT//  to the sum of FreePhysicalMemory and FreeSpaceInPagingFiles////  PTR 73-51-19 and PTR 73-51-20 11-Jul-2006//  The installDate and NumberOfLicensedUsers are not displayed in the wbemexec//  enumerate instance output. The same was seen as appearing fine, when//  CIMserver is running interactively.//  The function getInstallDate() and getNumberOfLicensedUsers() is modifled as below://  The first argument of tempname() call is changed from NULL to "SYS$SPECIFIC:[000000]"//  as tempnam() would take a default of "SYS$SCRATCH:" directory, if first argument is not specified.////  PTR 73-51-21 10-Jul-06.//  changed The checking for define PEGASUS_PLATFORM_VMS_IPF_DECCXX//  to PEGASUS_PLATFORM_VMS_IA64_DECCXX, as the later was being used//  in the /define directive during compilation.//  The FreePhysicalMemory is retrived properly, after changing this define.////  PTR 73-51-2 28-Jun-06.//  Made changes to get the coreect OS verison.//  Removed the display of uname.release information from getversion()////  PTR 73-51-15. Removed include of <pegasus/common/system.h>//  and <pegasus/common/logger.h> as it was giving compiler warning////%////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include "OperatingSystem.h"#include <time.h>#include <timers.h>#include <dirent.h>#include <utsname.h>#include <netdb.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <descrip.h>#include <syidef.h>#include <jpidef.h>#include <pscandef.h>#include <lib$routines.h>#include <starlet.h>#include <stsdef.h>#include <ssdef.h>#include <libdtdef.h>#include <lnmdef.h>#define MAXHOSTNAMELEN  256#define MAXUSERNAME 512extern "C"{#if defined (PEGASUS_PLATFORM_VMS_ALPHA_DECCXX)  extern const long SCH$GL_FREECNT;#elif defined (PEGASUS_PLATFORM_VMS_IA64_DECCXX)  extern const long SCH$GI_FREECNT;#endif}PEGASUS_USING_STD;OperatingSystem::OperatingSystem(void){}OperatingSystem::~OperatingSystem(void){}//// ================================================================================// NAME              : getUtilGetHostName// DESCRIPTION       : Gets the name of the host system from gethostname//                      and gethostbyname.// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//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)  {      csName.assign(he->h_name);  }  else  {      csName.assign(hostName);  }  return true;}//// ================================================================================// NAME              : convertToCIMDateString// DESCRIPTION       : Converts a tm struct to a CIMDateTime formatted//                      char *.// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//int convertToCIMDateString(struct tm *t, char *time){  // Format the date.  sprintf(time, "%04d%02d%02d%02d%02d%02d.000000%c%03d",	  t->tm_year + 1900,	  t->tm_mon + 1,	  t->tm_mday,	  t->tm_hour,	  t->tm_min,	  t->tm_sec,	  (timezone > 0) ? '-' : '+',	  timezone / 60 - (t->tm_isdst ? 60 : 0));  return 1;}//// ================================================================================// NAME              : get_time// DESCRIPTION       : Returns a tm structure, which contains the current time.// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//struct tm *get_time(){  struct tm *local;  struct timespec since_epoch;  if (getclock(TIMEOFDAY, &since_epoch) != 0)  {    return (NULL);		/*getclock error */  }  else  {    if ((local = localtime(&since_epoch.tv_sec)) == (struct tm *) NULL)    {      return (NULL);		/*localtime error */    }    else    {      return local;    }  }}//// ================================================================================// NAME              : GetFreeMem// DESCRIPTION       : kernel routine - link/sysexe to pick up SCH$GL_FREECNT// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//int GetFreeMem(long *pFreeMem){#if defined (PEGASUS_PLATFORM_VMS_ALPHA_DECCXX)  *pFreeMem = SCH$GL_FREECNT;#elif defined (PEGASUS_PLATFORM_VMS_IA64_DECCXX)  *pFreeMem = SCH$GI_FREECNT;#endif  return (SS$_NORMAL);}//// ================================================================================// NAME              : getCSName// DESCRIPTION       :// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//Boolean OperatingSystem::getCSName(String & csName){  return getUtilGetHostName(csName);}//// ================================================================================// NAME              : getName// DESCRIPTION       : Calls uname() to get the operating system name.// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//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;}//// ================================================================================// NAME              : getCaption// DESCRIPTION       : Return a string constant for the caption.// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//Boolean OperatingSystem::getCaption(String & caption){  caption.assign("The current Operating System");  return true;}//// ================================================================================// NAME              : getDescription// DESCRIPTION       : Return a string constant for the description.// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//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;}//// ================================================================================// NAME              : getInstallDate// DESCRIPTION       : Get the date that the OS was installed. Requires//                      VMS SYSLCK priviledge.// ASSUMPTIONS       : None// PRE-CONDITIONS    :// POST-CONDITIONS   :// NOTES             :// ================================================================================//Boolean OperatingSystem::getInstallDate(CIMDateTime & installDate){  Boolean bStatus;  int status,    istr;  char record1[512],   *rptr1 = 0;  char *HistFile = 0;  char  cmd[512];  FILE *fptr1 = 0;  unsigned __int64 bintime = 0;  unsigned short int timbuf[7],    val = 0;  char cimtime[80] = "";  struct tm timetm;  struct tm *ptimetm = &timetm;  time_t tme = 0,    tme1 = 0;  char t_string[24] = "",    libdst;  unsigned int retlen;  unsigned long libop,    libdayweek,    libdayear;  long dst_desc[2];  char log_string[] = "SYS$TIMEZONE_DAYLIGHT_SAVING";  struct dsc$descriptor_s sysinfo;  static $DESCRIPTOR(lnm_tbl, "LNM$SYSTEM");  struct  {    unsigned short wLength;    unsigned short wCode;    void *pBuffer;    unsigned int *pRetLen;    int term;  }  item_list;  // A temp file is used to avoid a filename collision when two users  // call OsInfo at the same time.  // Note: The prefix string is limited to 5 chars.  //       P3 = 0 returns unix format \sys$sratch\hist_acca.out  //       P3 = 1 returns vms format. sys$scratch:hist_acca.out  HistFile = tempnam("wbem_tmp:", "hist_", 1);  if (!HistFile) {    bStatus = false;    goto done;  }  strcat(HistFile, ".out");  sysinfo.dsc$b_dtype = DSC$K_DTYPE_T;  sysinfo.dsc$b_class = DSC$K_CLASS_S;  sysinfo.dsc$w_length = sizeof (t_string);  sysinfo.dsc$a_pointer = t_string;  // "pipe product show history openvms |   //       search/nolog/nowarn/out=history.out sys$input install");  strcpy(cmd, "pipe product show history openvms | search/nolog/nowarn/out=");  strcat(cmd, HistFile);  strcat(cmd, " sys$input install");// Note: The format of this string has changed from 8.2 to 8.3. Now it has//       just the date, no time.// OpenVMS 8.2// $ product sho history openvms// ----------------------------------- ----------- ----------- --------------------// PRODUCT                             KIT TYPE    OPERATION   DATE AND TIME// ----------------------------------- ----------- ----------- --------------------// HP I64VMS OPENVMS V8.2              Platform    Install     25-JAN-2005 10:26:24// HP I64VMS OPENVMS X8.2-ALQ          Platform    Remove      25-JAN-2005 10:26:24//// VI::_TNA37:> product sho history openvms// ------------------------------------ ----------- ----------- --- -----------// PRODUCT                              KIT TYPE    OPERATION   VAL DATE// ------------------------------------ ----------- ----------- --- -----------// HP I64VMS OPENVMS X8.3-B49           Platform    Install     (U) 09-JAN-2006// HP I64VMS OPENVMS X8.3-B3K           Platform    Remove       -  09-JAN-2006//  status = system(cmd);  if (!$VMS_STATUS_SUCCESS(status))  {    bStatus = false;  }  // "if (f$search(\"history.out\") .nes. \"\") then delete history.out;*"  strcpy(cmd, "if (f$search(\"");  strcat(cmd, HistFile);  strcat(cmd, "\") .nes. \"\") then delete ");  strcat(cmd, HistFile);  strcat(cmd, ";*");  if (fptr1 = fopen(HistFile, "r"))  {    while (fgets(record1, sizeof (record1), fptr1))    {      for (istr = 0; istr <= (sizeof (record1) - 4); istr++)      {	if ((rptr1 = strstr(record1 + istr, "-")) && !strncmp(rptr1 + 4, "-", 1))	{	  break;	}	rptr1 = 0;      }      if (rptr1)      {	time(&tme);	tme1 = mktime(ptimetm);	/* get timezone */	strcpy(t_string, rptr1 - 2);        if (t_string[11] == 10) {          // a <cr>.           // When the date; but not the time is provided, fill in zeros.          t_string[11] = ' ';          t_string[12] = '0';          t_string[13] = '0';          t_string[14] = ':';          t_string[15] = '0';          t_string[16] = '0';          t_string[17] = ':';          t_string[18] = '0';          t_string[19] = '0';        }	t_string[20] = '.';	t_string[21] = '0';	t_string[22] = '0';	t_string[23] = '0';	status = sys$bintim(&sysinfo, &bintime);	if (!$VMS_STATUS_SUCCESS(status))	{	  bStatus = false;          goto done;	}	libop = LIB$K_DAY_OF_WEEK;	status = lib$cvt_from_internal_time(&libop, &libdayweek, &bintime);	if (!$VMS_STATUS_SUCCESS(status))	{	  bStatus = false;          goto done;	}	libop = LIB$K_DAY_OF_YEAR;	status = lib$cvt_from_internal_time(&libop, &libdayear, &bintime);	if (!$VMS_STATUS_SUCCESS(status))	{	  bStatus = false;          goto done;	}	dst_desc[0] = strlen(log_string);	dst_desc[1] = (long) log_string;	item_list.wLength = 1;	item_list.wCode = LNM$_STRING;	item_list.pBuffer = &libdst;	item_list.pRetLen = &retlen;	item_list.term = 0;	status = sys$trnlnm(0, &lnm_tbl, &dst_desc, 0, &item_list);	if (!$VMS_STATUS_SUCCESS(status))	{	  bStatus = false;          goto done;	}	status = sys$numtim(timbuf, &bintime);	if (!$VMS_STATUS_SUCCESS(status))	{

⌨️ 快捷键说明

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