diff --git a/src/node_os.cc b/src/node_os.cc index ad7b71a80e..5019df75ee 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -7,8 +7,8 @@ #include #include // gethostname, sysconf -#include // sysctl -#include // sysctl +#include +#include namespace node { @@ -28,12 +28,11 @@ static Handle GetHostname(const Arguments& args) { static Handle GetOSType(const Arguments& args) { HandleScope scope; char type[256]; - static int which[] = {CTL_KERN, KERN_OSTYPE}; - size_t size = sizeof(type); + struct utsname info; - if (sysctl(which, 2, &type, &size, NULL, 0) < 0) { - return Undefined(); - } + uname(&info); + strncpy(type, info.sysname, strlen(info.sysname)); + type[strlen(info.sysname)] = 0; return scope.Close(String::New(type)); } @@ -41,12 +40,11 @@ static Handle GetOSType(const Arguments& args) { static Handle GetOSRelease(const Arguments& args) { HandleScope scope; char release[256]; - static int which[] = {CTL_KERN, KERN_OSRELEASE}; - size_t size = sizeof(release); + struct utsname info; - if (sysctl(which, 2, &release, &size, NULL, 0) < 0) { - return Undefined(); - } + uname(&info); + strncpy(release, info.release, strlen(info.release)); + release[strlen(info.release)] = 0; return scope.Close(String::New(release)); } diff --git a/src/platform_cygwin.cc b/src/platform_cygwin.cc index de0a3ba5ed..6a601aeb1d 100644 --- a/src/platform_cygwin.cc +++ b/src/platform_cygwin.cc @@ -4,7 +4,6 @@ #include #include // for MAXPATHLEN -#include #include #include // getpagesize, sysconf #include // sscanf, snprintf @@ -290,8 +289,8 @@ int Platform::GetCPUInfo(Local *cpus) { continue; else if (strncmp(line, "intr ", 5) == 0) break; - sscanf(line, "%*s %llu %llu %llu %llu %*llu %llu", - &ticks_user, &ticks_nice, &ticks_sys, &ticks_idle, &ticks_intr); + sscanf(line, "%*s %llu %llu %llu %llu", + &ticks_user, &ticks_nice, &ticks_sys, &ticks_idle); snprintf(speedPath, sizeof(speedPath), "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_max_freq", i); fpSpeed = fopen(speedPath, "r"); @@ -308,7 +307,7 @@ int Platform::GetCPUInfo(Local *cpus) { cputimes->Set(String::New("nice"), Number::New(ticks_nice * multiplier)); cputimes->Set(String::New("sys"), Number::New(ticks_sys * multiplier)); cputimes->Set(String::New("idle"), Number::New(ticks_idle * multiplier)); - cputimes->Set(String::New("irq"), Number::New(ticks_intr * multiplier)); + cputimes->Set(String::New("irq"), Number::New(0)); cpuinfo->Set(String::New("model"), String::New(model)); cpuinfo->Set(String::New("speed"), Number::New(cpuspeed)); @@ -337,26 +336,23 @@ double Platform::GetTotalMemory() { } double Platform::GetUptime() { - struct sysinfo info; + double amount; + char line[512]; + FILE *fpUptime = fopen("/proc/uptime", "r"); - if (sysinfo(&info) < 0) { - return -1; + if (fpUptime) { + if (fgets(line, 511, fpUptime) != NULL) { + sscanf(line, "%lf %*lf", &amount); + } + fclose(fpUptime); } - return static_cast(info.uptime); + return amount; } int Platform::GetLoadAvg(Local *loads) { - struct sysinfo info; - - if (sysinfo(&info) < 0) { - return -1; - } - (*loads)->Set(0, Number::New(static_cast(info.loads[0]) / 65536.0)); - (*loads)->Set(1, Number::New(static_cast(info.loads[1]) / 65536.0)); - (*loads)->Set(2, Number::New(static_cast(info.loads[2]) / 65536.0)); - - return 0; + // Unsupported as of cygwin 1.7.7 + return -1; } } // namespace node