operatingsystem_vms.cpp
来自「Pegasus is an open-source implementation」· C++ 代码 · 共 2,080 行 · 第 1/4 页
CPP
2,080 行
bStatus = false; goto done; } timetm.tm_sec = timbuf[5]; timetm.tm_min = timbuf[4]; timetm.tm_hour = timbuf[3]; timetm.tm_mday = timbuf[2]; timetm.tm_mon = timbuf[1] - 1; timetm.tm_year = timbuf[0] - 1900; timetm.tm_wday = libdayweek - 1; timetm.tm_yday = libdayear - 1; if (libdst != 48) timetm.tm_isdst = 1; status = convertToCIMDateString(ptimetm, cimtime); if (!$VMS_STATUS_SUCCESS(status)) { bStatus = false; goto done; } installDate.clear(); installDate.set(cimtime); bStatus = true; goto done; } // end if (rptr1 = strstr(record1,"Install")) } bStatus = false; goto done; } // end if (fptr1 = fopen(HistFile, "r")) else { bStatus = false; goto done; }done:if (fptr1) { fclose(fptr1); fptr1 = 0;}status = system(cmd);if (HistFile) { free(HistFile); HistFile = 0;}return bStatus;}//// ================================================================================// NAME : getStatus// DESCRIPTION : Since the OS is up and running, we'll return unknown here.// ASSUMPTIONS : None// PRE-CONDITIONS :// POST-CONDITIONS :// NOTES :// ================================================================================//Boolean OperatingSystem::getStatus(String & status){ status.assign("Unknown"); return true;}//// ================================================================================// NAME : getVersion// DESCRIPTION : Uses uname system call to extract the release and version.// ASSUMPTIONS : None// PRE-CONDITIONS :// POST-CONDITIONS :// NOTES :// ================================================================================//Boolean OperatingSystem::getVersion(String & osVersion){ struct utsname unameInfo; // Changed to fix PTR -73-51-2 char version[sizeof (unameInfo.version)]; // Call uname and check for any errors. if (uname(&unameInfo) < 0) { return false; } // Changed to fix PTR -73-51-2 sprintf(version, "%s", unameInfo.version); osVersion.assign(version); return true;}//// ================================================================================// NAME : getOSType// DESCRIPTION : Return OSType value for OpenVms.// ASSUMPTIONS : None// PRE-CONDITIONS :// POST-CONDITIONS :// NOTES :// ================================================================================//Boolean OperatingSystem::getOSType(Uint16 & osType){ osType = OpenVMS; return true;}//// ================================================================================// NAME : getOtherTypeDescription// DESCRIPTION : Return NULL since we have an OSType.// ASSUMPTIONS : None// PRE-CONDITIONS :// POST-CONDITIONS :// NOTES :// ================================================================================//Boolean OperatingSystem::getOtherTypeDescription(String & otherTypeDescription){otherTypeDescription = String::EMPTY; return true;}//// ================================================================================// NAME : getLastBootUpTime// DESCRIPTION : Get the time the OS was last booted.// ASSUMPTIONS : None// PRE-CONDITIONS :// POST-CONDITIONS :// NOTES :// ================================================================================//Boolean OperatingSystem::getLastBootUpTime(CIMDateTime & lastBootUpTime){ long status, item = SYI$_BOOTTIME, dst_desc[2]; char t_string[24] = ""; char cimtime[80] = ""; char log_string[] = "SYS$TIMEZONE_DAYLIGHT_SAVING"; char libdst; time_t tme = 0, tme1 = 0; unsigned __int64 bintime = 0; unsigned short int timbuf[7], val = 0; unsigned long libop, libdayweek, libdayear; unsigned int retlen; struct tm timetm; struct tm *ptimetm = &timetm; 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; 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; status = lib$getsyi(&item, 0, &sysinfo, &val, 0, 0); if (!$VMS_STATUS_SUCCESS(status)) { return false; } status = sys$bintim(&sysinfo, &bintime); if (!$VMS_STATUS_SUCCESS(status)) { return false; } libop = LIB$K_DAY_OF_WEEK; status = lib$cvt_from_internal_time(&libop, &libdayweek, &bintime); if (!$VMS_STATUS_SUCCESS(status)) { return false; } libop = LIB$K_DAY_OF_YEAR; status = lib$cvt_from_internal_time(&libop, &libdayear, &bintime); if (!$VMS_STATUS_SUCCESS(status)) { return false; } 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)) { return false; } status = sys$numtim(timbuf, &bintime); if (!$VMS_STATUS_SUCCESS(status)) { return false; } timetm.tm_sec = timbuf[5]; timetm.tm_min = timbuf[4]; timetm.tm_hour = timbuf[3]; timetm.tm_mday = timbuf[2]; timetm.tm_mon = timbuf[1] - 1; timetm.tm_year = timbuf[0] - 1900; timetm.tm_wday = libdayweek - 1; timetm.tm_yday = libdayear - 1; timetm.tm_isdst = 0; if (libdst != 48) timetm.tm_isdst = 1; if (convertToCIMDateString(ptimetm, cimtime) != -1) { lastBootUpTime.clear(); lastBootUpTime.set(cimtime); return true; } else { return false; }}//// ================================================================================// NAME : getLocalDateTime// DESCRIPTION : Get the local date and time.// ASSUMPTIONS : None// PRE-CONDITIONS :// POST-CONDITIONS :// NOTES :// ================================================================================//Boolean OperatingSystem::getLocalDateTime(CIMDateTime & localDateTime){ struct tm *local; char date[80]; if ((local = get_time()) == NULL) { return false; } if (convertToCIMDateString(local, date) != -1) { localDateTime.clear(); localDateTime.set(date); return true; } return false;}//// ================================================================================// NAME : getCurrentTimeZone// DESCRIPTION : Get the number of minutes that OS is offset from GMT.// ASSUMPTIONS : None// PRE-CONDITIONS :// POST-CONDITIONS :// NOTES :// ================================================================================//Boolean OperatingSystem::getCurrentTimeZone(Sint16 & currentTimeZone){ struct tm *tz; if ((tz = get_time()) == NULL) { return false; } if (timezone > 0) { currentTimeZone = -(timezone / 60 - (tz->tm_isdst ? 60 : 0)); } else { currentTimeZone = timezone / 60 - (tz->tm_isdst ? 60 : 0); } return true;}//// ================================================================================// NAME : getNumberOfLicensedUsers// DESCRIPTION : Get the number of user licenses for the OS.// ASSUMPTIONS : None// PRE-CONDITIONS :// POST-CONDITIONS :// NOTES :// ================================================================================////PTR 73-51-27 - Changed to return 0 for number of licensed users on I64.Boolean OperatingSystem::getNumberOfLicensedUsers(Uint32 & numberOfLicensedUsers){ Boolean bStatus = false; int status, loaded_units, req_units; char record1[512], record2[512], *rptr1 = 0, *rptr2 = 0, *rptr3 = 0; char *UsageFile = 0; char *UnitsFile = 0; char usage_cmd[512]; char units_cmd[512]; FILE *fptr1 = 0, *fptr2 = 0; // 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\usageacca.out // P3 = 1 returns vms format. sys$scratch:usageacca.out UsageFile = tempnam("wbem_tmp:", "usage", 1); if (!UsageFile) { bStatus = false; goto done; } strcat(UsageFile, ".out"); UnitsFile = tempnam("wbem_tmp:", "units", 1); if (!UnitsFile) { bStatus = false; goto done; } strcat(UnitsFile, ".out");// Note: This code may not work on non-English versions of OpenVMS...//// Alpha// $ sho lic/usage//// View of loaded licenses from node WALNUT 20-JAN-2006 11:57:02.12//// ------- Product ID -------- ---- Unit usage information ----// Product Producer Loaded Allocated Available// ACMS DEC Unlimited license, no usage information// ADA DEC Unlimited license, no usage information// ...// OPENVMS-ALPHA DEC Unlimited license, no usage information// OPENVMS-ALPHA-USER DEC Unlimited license, no usage information// OPENVMS-GALAXY DEC Unlimited license, no usage information//// I64// $ sho lic/usage//// View of loaded licenses from node RED 20-JAN-2006 11:54:54.12//// ------- Product ID -------- ---- Unit usage information ----------------// Product Producer Loaded Allocated Available Compliance// ACMS HP 50 14 36 Yes// BASIC HP 50 14 36 Yes// ...// OPENVMS-I64-EOE HP 50 14 36 Yes// OPENVMS-I64-FOE HP 50 14 36 Yes// OPENVMS-I64-MCOE HP 50 14 36 Yes// strcpy(usage_cmd, "show license/usage/nowarning_interval/out="); strcat(usage_cmd, UsageFile);#ifdef PEGASUS_PLATFORM_VMS_ALPHA_DECCXX strcat(usage_cmd, " openvms-alpha");#endif#ifdef PEGASUS_PLATFORM_VMS_IA64_DECCXX// Which of these to use for IA64?// When a machine has more than one of these installed, this will// find the first one. strcat(usage_cmd, " openvms-i64-*");// strcat(usage_cmd, " openvms-i64-EOE");// strcat(usage_cmd, " openvms-i64-FOE");// strcat(usage_cmd, " openvms-i64-MCOE");#endif status = system(usage_cmd); if (!$VMS_STATUS_SUCCESS(status)) { bStatus = false; goto done; }// Alpha // $ sho lic/units/nowarn// VMS/LMF Charge Information for node WALNUT// This is a COMPAQ AlphaServer DS20E 666 MHz, hardware model type 1940// Type: A, Units Required: 75 (VAX/VMS Capacity or OpenVMS Unlimited or Base)// Type: B, * Not Permitted * (VAX/VMS F&A Server)// Type: C, * Not Permitted * (VAX/VMS Concurrent User)// Type: D, * Not Permitted * (VAX/VMS Workstation)// Type: E, * Not Permitted * (VAX/VMS System Integrated Products)// Type: F, * Not Permitted * (VAX Layered Products)// Type: G, * Not Permitted * (Reserved)// Type: H, Units Required: 1050 (Alpha Layered Products)// Type: I, Units Required: 1050 (Layered Products)//// I64// $ sho lic/units/nowarn// OpenVMS I64/LMF Charge Information for node RED// This is an HP rx4640 (1.50GHz/6.0MB), with 4 CPUs active, 4 socket(s)// Type: PPL, Units Required: 4 (I64 Per Processor)// strcpy(units_cmd, "show license/units/nowarning_interval/out="); strcat(units_cmd, UnitsFile); status = system(units_cmd); if (!$VMS_STATUS_SUCCESS(status)) { bStatus = false; goto done; } if (fptr1 = fopen(UsageFile, "r")) { while (fgets(record1, sizeof (record1), fptr1)) {#ifdef PEGASUS_PLATFORM_VMS_IA64_DECCXX// The base O/S license on IA64 (FOE) provides unlimited number// of users - PTR 73-51-27 if (rptr1 = strstr(record1, "HP ")) { // either FOE,EOE or MCOE license is existing on the system // Return Unlimited number of users numberOfLicensedUsers = 0; bStatus = true; goto done; }#endif#ifdef PEGASUS_PLATFORM_VMS_ALPHA_DECCXX if (rptr1 = strstr(record1, "DEC ")) { rptr2 = strstr(rptr1 + 3, "Unlimited license"); if (rptr2) { numberOfLicensedUsers = 0; bStatus = true; goto done; } else { rptr2 = strtok(rptr1 + 3, " "); loaded_units = strtol(rptr2, NULL, 10); if (fptr2 = fopen(UnitsFile, "r")) { while (fgets(record2, sizeof (record2), fptr2)) { if (rptr1 = strstr(record2, "Type: A, Units Required:")) { rptr3 = strtok(rptr1 + 25, " "); req_units = strtol(rptr3, NULL, 10); if (req_units != 0) { numberOfLicensedUsers = loaded_units / req_units; bStatus = true; goto done; } else { bStatus = false; goto done; } } } // end while (fgets(record2, sizeof(record2), fptr2)) if (!fptr2 == 0) { fclose(fptr2); fptr2 = 0; } } // end if (fptr2 = fopen(UnitsFile, "r")) else { bStatus = false; goto done; } } // end if (rptr2) } // end if (rptr1 = strstr(record1,"DEC "))
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?