operatingsystem_hpux.cpp
来自「Pegasus is an open-source implementation」· C++ 代码 · 共 1,015 行 · 第 1/2 页
CPP
1,015 行
return true; else return false;}/** getFreeVirutalMemorySize method for HP-UX implementation of HP-UX Gets information from swapinfo -at command (the Free column) */Boolean OperatingSystem::getFreeVirtualMemory(Uint64& freeVirtualMemory){ char mline[80]; FILE * mswapInfo; Uint32 swapAvailable = 0; Uint32 swapUsed = 0; Uint32 swapFree = 0; // Initialize the return parameter in case swapinfo is not available. freeVirtualMemory = 0; // Use a pipe to invoke swapinfo. if ((mswapInfo = popen("/usr/sbin/swapinfo -at 2>/dev/null", "r")) != NULL) { // Now extract the total swap space size from the swapinfo output. while (fgets(mline, 80, mswapInfo)) { sscanf(mline, "total %u %u %u", &swapAvailable, &swapUsed, &swapFree); } // end while (void)pclose (mswapInfo); } freeVirtualMemory = swapFree; if (freeVirtualMemory != 0) return true; else return false;}/** getFreePhysicalMemory method for HP-UX implementation of HP-UX Gets information from the pstat system call (psd_free field) */Boolean OperatingSystem::getFreePhysicalMemory(Uint64& total){ struct pst_dynamic psd; struct pst_static pst; float psize; float subtotal; // Feb-25-2005: Correct value to reflect Kbytes instead of pages if (pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1) { return false; } psize = pst.page_size / 1024; if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) == -1) { return false; } subtotal = ((float)psd.psd_free * psize); total = subtotal; return true;}/** getTotalVisibleMemorySize method for HP-UX implementation of OS Provider Gets information from pstat (pst.physcial_memory adjusted for page size) */Boolean OperatingSystem::getTotalVisibleMemorySize(Uint64& memory){ float psize; float total; struct pst_static pst; if (pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1) { return false; } // Feb-25-2005: Correct value to reflect Kbytes instead of Mbytes psize = pst.page_size / 1024; total = ((float)pst.physical_memory * psize); memory = total; return true;}/** getSizeStoredInPagingFiles method for HP-UX implementation of OS Provider HP-UX doesn't have Paging Files, thus return 0 (as specified in the MOF) */Boolean OperatingSystem::getSizeStoredInPagingFiles(Uint64& total){ total = 0; return true;}/** getFreeSpaceInPagingFiles method for HP-UX implementation of OS Provider HP-UX doesn't have Paging Files, thus return 0 (as specified in the MOF) */Boolean OperatingSystem::getFreeSpaceInPagingFiles(Uint64& freeSpaceInPagingFiles){ freeSpaceInPagingFiles = 0; return true;}static Boolean getMaxProcMemViaKmtune(Boolean are32bit, Uint64& maxProcMemSize){ char mline[80]; FILE * mtuneInfo; Uint32 maxdsiz = 0; Uint32 maxssiz = 0; Uint32 maxtsiz = 0; Uint64 maxdsiz_64bit = 0; Uint64 maxssiz_64bit = 0; Uint64 maxtsiz_64bit = 0; if (are32bit) { // Use a pipe to invoke kmtune (since don't have gettune on 11.0) if ((mtuneInfo = popen("/usr/sbin/kmtune -q maxdsiz -q maxssiz " "-q maxtsiz 2>/dev/null", "r")) != NULL) { // Now extract the three values and sum them while (fgets(mline, 80, mtuneInfo)) { sscanf(mline, "maxdsiz %x", &maxdsiz); sscanf(mline, "maxssiz %x", &maxssiz); sscanf(mline, "maxtsiz %x", &maxtsiz); } // end while (void)pclose (mtuneInfo); maxProcMemSize = (maxdsiz + maxssiz + maxtsiz); return true; } // end if popen worked return false; } // end if are32bit else // are 64bit, different parameter names must be used { // Use a pipe to invoke kmtune (since don't have gettune on all OSs) if ((mtuneInfo = popen("/usr/sbin/kmtune -q maxdsiz_64bit " "-q maxssiz_64bit -q maxtsiz_64bit " "2> /dev/null","r")) != NULL) { // Now extract the three values and sum them while (fgets(mline, 80, mtuneInfo)) { sscanf(mline, "maxdsiz_64bit %llx", &maxdsiz_64bit); sscanf(mline, "maxssiz_64bit %llx", &maxssiz_64bit); sscanf(mline, "maxtsiz_64bit %llx", &maxtsiz_64bit); } // end while (void)pclose (mtuneInfo); maxProcMemSize = (maxdsiz_64bit + maxssiz_64bit + maxtsiz_64bit); return true; } // end if popen worked return false; }}static Boolean getMaxProcMemViaGettune(Boolean are32bit, Uint64& maxProcMemSize){ uint64_t maxdsiz = 0; uint64_t maxssiz = 0; uint64_t maxtsiz = 0; uint64_t maxdsiz_64bit = 0; uint64_t maxssiz_64bit = 0; uint64_t maxtsiz_64bit = 0; uint64_t total = 0; // we may be compiling on a system without gettune, but // run-time would have checked version and only be here // if we expect to have the gettune system call in libc // if handle is NULL, findsym is supposed to check currently // loaded libraries (and we know libc should be loaded) // get the procedure pointer for gettune int (*gettune_sym) (const char *, uint64_t *) = NULL; shl_t handle = NULL; if (shl_findsym(&handle, "gettune", TYPE_PROCEDURE, (void *)&gettune_sym) != 0) { return false; } if (gettune_sym == NULL) { return false; } if (are32bit) { if (gettune_sym("maxdsiz", &maxdsiz) != 0) return false; // fail if can't get info if (gettune_sym("maxssiz", &maxssiz) != 0) return false; // fail if can't get info if (gettune_sym("maxtsiz", &maxtsiz) != 0) return false; // fail if can't get info total = maxdsiz + maxtsiz + maxssiz; maxProcMemSize = total; return true; } // end if are32bit else { // are 64bit if (gettune_sym("maxdsiz_64bit", &maxdsiz_64bit) != 0) return false; // fail if can't get info if (gettune_sym("maxssiz_64bit", &maxssiz_64bit) != 0) return false; // fail if can't get info if (gettune_sym("maxtsiz_64bit", &maxtsiz_64bit) != 0) return false; // fail if can't get info total = maxdsiz_64bit + maxtsiz_64bit + maxssiz_64bit; maxProcMemSize = total; return true; }}/** getMaxProcessMemorySize method for HP-UX implementation of OS Provider Calculate values by summing kernel tunable values for max data size, max stack size, and max text size. Different names if 32-bit vs. 64-bit. NOT the pstat() pst_maxmem value; that is the amount of physical memory available to all user processes when the system first boots. Could use the gettune(2) system call on some systems, but it isn't available for 11.0. kmtune format changes in release 11.20, so will have separate paths anyway (vs. same kmtune parsing for all releases). Thus, chose to parse for 11.0, and use gettune for other releases. */Boolean OperatingSystem::getMaxProcessMemorySize(Uint64& maxProcessMemorySize){ long ret; // Initialize the return parameter in case kmtune is not available. maxProcessMemorySize = 0; ret = sysconf (_SC_KERNEL_BITS); if (ret == -1) { return false; } // First, check if we're an 11.0 system, if so, use kmtune parsing // If have many such checks, can store off Release/Version versus // getting as needed. struct utsname unameInfo; // Call uname and check for any errors. if ((uname(&unameInfo) < 0) && (errno != EOVERFLOW)) { return false; } // Need to check if 32-bit or 64-bit to use the suitable name if (ret == 32) { // we're 32 bit if (strcmp(unameInfo.release,"B.11.00")==0) { // Use kmtune on 11.0 (since don't have gettune) return (getMaxProcMemViaKmtune(true, maxProcessMemorySize)); } else { // can use gettune call 11.11 and onwards (won't be WBEM pre-11.0) return (getMaxProcMemViaGettune(true, maxProcessMemorySize)); } } // end if (ret == 32) else // so ret was 64 (only returns -1, 32, or 64) { if (strcmp(unameInfo.release,"B.11.00")==0) { // Use kmtune on 11.0 (since don't have gettune) return (getMaxProcMemViaKmtune(false, maxProcessMemorySize)); } else { // can use gettune call 11.11 and onwards (won't be WBEM pre-11.0) return (getMaxProcMemViaGettune(false, maxProcessMemorySize)); } } // end else}/** getDistributed method for HP-UX implementation of OS Provider Always sets the distributed boolean to FALSE */Boolean OperatingSystem::getDistributed(Boolean& distributed){ distributed = false; return true;}/** getMaxProcsPerUser method for HP-UX implementation of OS Provider Gets the information using kmtune. */Boolean OperatingSystem::getMaxProcsPerUser (Uint32& maxProcsPerUser){ FILE * mtuneInfo; char mline[80]; struct utsname unameInfo; uint64_t maxuprc = 0;// Call uname and check for any errors. if ((uname(&unameInfo) < 0) && (errno != EOVERFLOW)) { return false; } if (strcmp(unameInfo.release,"B.11.00")==0) {// Use a pipe to invoke kmtune (since don't have gettune on 11.0) if ((mtuneInfo = popen("/usr/sbin/kmtune" " -q maxuprc 2>/dev/null", "r")) != NULL) {// Now extract the value while (fgets(mline, 80, mtuneInfo)) { sscanf(mline, "maxuprc %d", &maxProcsPerUser); } (void)pclose (mtuneInfo); } else { return false; } } else {// we may be compiling on a system without gettune, but// run-time would have checked version and only be here// if we expect to have the gettune system call in libc// if handle is NULL, findsym is supposed to check currently// loaded libraries (and we know libc should be loaded)// get the procedure pointer for gettune int (*gettune_sym) (const char *, uint64_t *) = NULL; shl_t handle = NULL; if (shl_findsym(&handle, "gettune", TYPE_PROCEDURE, (void *)&gettune_sym) != 0) { return false; } if (gettune_sym == NULL) { return false; } if (gettune_sym("maxuprc", &maxuprc) != 0) { return false; // fail if can't get info } maxProcsPerUser = maxuprc; } return true;}/** getSystemUpTime method for HP-UX implementation of OS Provider Calculates the information from the local time and boot time. Could also consider use of uptime information. Ideally, would like to have consistency across the time-related properties (e.g., uptime = local time - Boot time). */Boolean OperatingSystem::getSystemUpTime(Uint64& mUpTime){ time_t timeval; struct pst_static pst; if (pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1) { return false; } else {// ATTN-SLC-P2-17-Apr-02: use CIMOM DateTime function & consistency, BZ#45 timeval= time((time_t *)NULL); timeval= (time_t)((long)timeval - (long)pst.boot_time); mUpTime = (long)timeval; } return true;}/** getOperatingSystemCapability method for HP-UX implementation of OS Provider Gets information from sysconf call (using _SC_KERNEL_BITS). */Boolean OperatingSystem::getOperatingSystemCapability(String& scapability){ char capability[80]; long ret; ret = sysconf (_SC_KERNEL_BITS); if (ret != -1) { sprintf (capability, "%d bit", ret); } else { return false; } scapability.assign(capability); return true;}/** _reboot method for HP-UX implementation of OS Provider Finds executable in /sbin, /usr/bin, or /usr/local/sbin and invokes. Currently disabled (as we don't want folks rebooting systems yet) Invokes as via system system call, so have full checking of user's authorization (already authenticated by CIMOM) */Uint32 OperatingSystem::_reboot(){ const char *reboot[] = { "reboot", NULL }; const char *paths[] = { "/sbin", "/usr/sbin", "/usr/local/sbin", NULL }; struct stat sbuf; String fname; CString p; Uint32 result;// ATTN-SLC-P2-17-Apr-02: this method not invoked for HP-UX (run as root) 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;}Uint32 OperatingSystem::_shutdown(){ const char *poweroff[] = { "poweroff", NULL }; const char *paths[] = { "/sbin", "/usr/sbin", "/usr/local/sbin", NULL }; struct stat sbuf; String fname; CString p; Uint32 result;// ATTN-SLC-P2-17-Apr-02: this method not invoked for HP-UX (run as root) 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;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?