diff --git a/checkin_notes b/checkin_notes index 630164cec4..0ba9ba1a95 100755 --- a/checkin_notes +++ b/checkin_notes @@ -5249,3 +5249,9 @@ Janus 23 May 2007 torrent.php (new) illegalargumentexception.php (new) +David 23 May 2007 + - client: unscrambled some of the #ifdefs in hostinfo_unix.C + In Linux case, if measured RAM size is negative, print some info. + + client/ + hostinfo_unix.C diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C index 8f6287ff59..5c764b862d 100644 --- a/client/hostinfo_unix.C +++ b/client/hostinfo_unix.C @@ -76,11 +76,11 @@ #include "str_util.h" #include "client_state.h" #include "hostinfo_network.h" +#include "client_msgs.h" using std::string; #ifdef __APPLE__ -#include "client_msgs.h" #include #include #ifdef __cplusplus @@ -247,7 +247,7 @@ bool HOST_INFO::host_is_running_on_batteries() { // Unfortunately the format of /proc/cpuinfo is not standardized. // See http://people.nl.linux.org/~hch/cpuinfo/ for some examples. // -void parse_cpuinfo(HOST_INFO& host) { +static void parse_cpuinfo_linux(HOST_INFO& host) { char buf[256], features[1024], model_buf[1024]; bool vendor_found=false, model_found=false; bool cache_found=false, features_found=false; @@ -422,31 +422,88 @@ void parse_cpuinfo(HOST_INFO& host) { strlcpy(host.p_model, model_buf, sizeof(host.p_model)); fclose(f); } - #endif // linux -// get all relevant host information +#ifdef __APPLE__ +static void get_cpuinfo_macosx(HOST_INFO& host) { + int p_model_size = sizeof(p_model); +#ifdef __i386__ + char brand_string[256]; + int family, stepping, model; + + len = sizeof(p_vendor); + sysctlbyname("machdep.cpu.vendor", p_vendor, &len, NULL, 0); + + len = sizeof(brand_string); + sysctlbyname("machdep.cpu.brand_string", brand_string, &len, NULL, 0); + + len = sizeof(family); + sysctlbyname("machdep.cpu.family", &family, &len, NULL, 0); + + len = sizeof(model); + sysctlbyname("machdep.cpu.model", &model, &len, NULL, 0); + + len = sizeof(stepping); + sysctlbyname("machdep.cpu.stepping", &stepping, &len, NULL, 0); + + len = sizeof(p_features); + sysctlbyname("machdep.cpu.features", p_features, &len, NULL, 0); + + snprintf( + p_model, sizeof(p_model), + "%s [x86 Family %d Model %d Stepping %d]", + brand_string, family, model, stepping + ); +#else // PowerPC + char capabilities[256], model[256]; + int response = 0; + int retval; + len = sizeof(response); + safe_strcpy(p_vendor, "Power Macintosh"); + retval = sysctlbyname("hw.optional.altivec", &response, &len, NULL, 0); + if (response && (!retval)) { + safe_strcpy(capabilities, "AltiVec"); + } + + len = sizeof(model); + sysctlbyname("hw.model", model, &len, NULL, 0); + + snprintf(p_model, p_model_size, "%s [%s Model %s] [%s]", p_vendor, p_vendor, model, capabilities); + +#endif + + p_model[p_model_size-1] = 0; + char *in = p_model + 1; + char *out = in; + // Strip out runs of multiple spaces + do { + if ((!isspace(*(in-1))) || (!isspace(*in))) { + *out++ = *in; + } + } while (*in++); +} +#endif + +// Rules: +// - Keep code in the right place +// - only one level of #if // int HOST_INFO::get_host_info() { get_filesystem_info(d_total, d_free); +///////////// p_vendor, p_model, p_features ///////////////// + #ifdef linux - parse_cpuinfo(*this); + parse_cpuinfo_linux(*this); +#elif defined( __APPLE__) + get_cpu_info_maxosx(*this); #elif defined(__EMX__) - int mib[2]; - unsigned int mem_size; - size_t len; CPU_INFO_t cpuInfo; strcpy( p_vendor, cpuInfo.vendor.company); strcpy( p_model, cpuInfo.name.fromID); -#else -#if HAVE_SYS_SYSCTL_H +#elif defined(HAVE_SYS_SYSCTL_H) int mib[2]; size_t len; -#ifdef __APPLE__ - long mem_size; -#else - unsigned int mem_size; // Get machine mib[0] = CTL_HW; @@ -459,12 +516,9 @@ int HOST_INFO::get_host_info() { mib[1] = HW_MODEL; len = sizeof(p_model); sysctl(mib, 2, &p_model, &len, NULL, 0); -#endif // ! __APPLE__ -#else -// Tru64 UNIX. -// 2005-12-26 SMS. -#ifdef __osf__ - int mem_size; +#elif defined(__osf__) + // Tru64 UNIX. + // 2005-12-26 SMS. long cpu_type; char *cpu_type_name; @@ -474,9 +528,22 @@ int HOST_INFO::get_host_info() { CPU_TYPE_TO_TEXT( (cpu_type& 0xffffffff), cpu_type_name); strncpy( p_model, "Alpha ", sizeof( p_model)); strncat( p_model, cpu_type_name, (sizeof( p_model)- strlen( p_model)- 1)); +#elif defined(HAVE_SYS_SYSTEMINFO_H) + sysinfo(SI_PLATFORM, p_vendor, sizeof(p_vendor)); + sysinfo(SI_ISALIST, p_model, sizeof(p_model)); + for (unsigned int i=0; i 2GB. The Gestalt selector // gestaltPhysicalRAMSizeInMegabytes is available starting with OS 10.3.0. - if (Gestalt(gestaltPhysicalRAMSizeInMegabytes, &mem_size)) - msg_printf(NULL, MSG_INTERNAL_ERROR, "Couldn't determine physical RAM size"); + long mem_size; + if (Gestalt(gestaltPhysicalRAMSizeInMegabytes, &mem_size)) { + msg_printf(NULL, MSG_INTERNAL_ERROR, + "Couldn't determine physical RAM size" + ); + } m_nbytes = (1024. * 1024.) * (double)mem_size; -#elif defined(HAVE_SYS_SYSCTL_H) && defined(CTL_HW) && defined(HW_PHYSMEM) -#error This code does not properly report physical RAM size > 2GB (see comment above for __APPLE__) - mib[0] = CTL_HW; - mib[1] = HW_PHYSMEM; - len = sizeof(mem_size); - sysctl(mib, 2, &mem_size, &len, NULL, 0); // Mac OS X - m_nbytes = mem_size; #elif defined(_HPUX_SOURCE) struct pst_static pst; pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0); @@ -537,10 +606,11 @@ int HOST_INFO::get_host_info() { #elif defined(__osf__) // Tru64 UNIX. // 2005-12-26 SMS. + int mem_size; getsysinfo( GSI_PHYSMEM, (caddr_t) &mem_size, sizeof( mem_size)); m_nbytes = 1024.* (double)mem_size; #else -#error Need to specify a sysconf() define to obtain memory size +#error Need to specify a method to get memory size #endif #if defined(HAVE_SYS_SWAP_H) && defined(SC_GETNSWP) @@ -623,93 +693,15 @@ int HOST_INFO::get_host_info() { pstat_getvminfo(&vminfo, sizeof(vminfo), (size_t)1, 0); m_swap = (vminfo.psv_swapspc_max * pst.page_size); #else +//#error Need to specify a method to obtain swap space #endif -#if defined(HAVE_SYS_SYSTEMINFO_H) -#if defined(SI_HW_SERIAL) - sysinfo(SI_HW_SERIAL, serialnum, sizeof(serialnum)); -#else -//#error Need to specify a method to obtain serial num -#endif -#ifdef SI_PLATFORM - sysinfo(SI_PLATFORM, p_vendor, sizeof(p_vendor)); -#endif - -#ifdef SI_ISALIST - sysinfo(SI_ISALIST, p_model, sizeof(p_model)); - for (unsigned int i=0; i