From 72955c29c21c889dbb03ec2c7f490d27cc5abd1d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 14 Nov 2012 01:06:03 +0100 Subject: [PATCH 1/3] windows: map WSAESHUTDOWN to UV_EPIPE This is a back-port of commit 483043b from the master branch. --- src/win/error.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win/error.c b/src/win/error.c index e5fb76a1..1d2d2513 100644 --- a/src/win/error.c +++ b/src/win/error.c @@ -144,6 +144,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) { case ERROR_BAD_PIPE: return UV_EPIPE; case ERROR_NO_DATA: return UV_EPIPE; case ERROR_PIPE_NOT_CONNECTED: return UV_EPIPE; + case WSAESHUTDOWN: return UV_EPIPE; case ERROR_PIPE_BUSY: return UV_EBUSY; case ERROR_SEM_TIMEOUT: return UV_ETIMEDOUT; case WSAETIMEDOUT: return UV_ETIMEDOUT; From 5639b2f1f904893987cf3bdc965bc24c66b4c6e2 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 20 Oct 2012 23:58:22 +0200 Subject: [PATCH 2/3] linux: use /proc/cpuinfo for CPU frequency Obtain the CPU frequency from /proc/cpuinfo because there may not be any cpufreq info available in /sys. This also means that the reported CPU speed from now on is the *maximum* speed, not the *actual* speed the CPU runs at. This change only applies to x86 because ARM and MIPS don't report that information in /proc/cpuinfo. Fixes #588. This is a back-port of commit 775064a from the master branch. --- src/unix/linux/linux-core.c | 48 ++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/unix/linux/linux-core.c b/src/unix/linux/linux-core.c index e26656e1..4259d171 100644 --- a/src/unix/linux/linux-core.c +++ b/src/unix/linux/linux-core.c @@ -325,10 +325,13 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { if (ci == NULL) return uv__new_sys_error(ENOMEM); - read_speeds(numcpus, ci); read_models(numcpus, ci); read_times(numcpus, ci); + /* read_models() on x86 also reads the CPU speed from /proc/cpuinfo */ + if (ci[0].speed == 0) + read_speeds(numcpus, ci); + *cpu_infos = ci; *count = numcpus; @@ -344,18 +347,26 @@ static void read_speeds(unsigned int numcpus, uv_cpu_info_t* ci) { } +/* Also reads the CPU frequency on x86. The other architectures only have + * a BogoMIPS field, which may not be very accurate. + */ static void read_models(unsigned int numcpus, uv_cpu_info_t* ci) { #if defined(__i386__) || defined(__x86_64__) - static const char marker[] = "model name\t: "; + static const char model_marker[] = "model name\t: "; + static const char speed_marker[] = "cpu MHz\t\t: "; #elif defined(__arm__) - static const char marker[] = "Processor\t: "; + static const char model_marker[] = "Processor\t: "; + static const char speed_marker[] = ""; #elif defined(__mips__) - static const char marker[] = "cpu model\t\t: "; + static const char model_marker[] = "cpu model\t\t: "; + static const char speed_marker[] = ""; #else # warning uv_cpu_info() is not supported on this architecture. - static const char marker[] = "(dummy)"; + static const char model_marker[] = ""; + static const char speed_marker[] = ""; #endif - unsigned int num; + unsigned int model_idx; + unsigned int speed_idx; char buf[1024]; char* model; FILE* fp; @@ -364,18 +375,27 @@ static void read_models(unsigned int numcpus, uv_cpu_info_t* ci) { if (fp == NULL) return; - num = 0; + model_idx = 0; + speed_idx = 0; while (fgets(buf, sizeof(buf), fp)) { - if (num >= numcpus) - break; - - if (strncmp(buf, marker, sizeof(marker) - 1)) + if (model_marker[0] != '\0' && + model_idx < numcpus && + strncmp(buf, model_marker, sizeof(model_marker) - 1) == 0) + { + model = buf + sizeof(model_marker) - 1; + model = strndup(model, strlen(model) - 1); /* strip newline */ + ci[model_idx++].model = model; continue; + } - model = buf + sizeof(marker) - 1; - model = strndup(model, strlen(model) - 1); /* strip newline */ - ci[num++].model = model; + if (speed_marker[0] != '\0' && + speed_idx < numcpus && + strncmp(buf, speed_marker, sizeof(speed_marker) - 1) == 0) + { + ci[speed_idx++].speed = atoi(buf + sizeof(speed_marker) - 1); + continue; + } } fclose(fp); } From deb1c34774e19272cfed683697c6961726582555 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 29 Nov 2012 23:24:25 +0100 Subject: [PATCH 3/3] sunos: fix uv_getaddrinfo() NULL pointer dereference --- src/unix/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/unix/core.c b/src/unix/core.c index 9f20d04b..f3636e28 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -291,7 +291,12 @@ static int uv_getaddrinfo_done(eio_req* req_) { uv_getaddrinfo_t* req = req_->data; struct addrinfo *res = req->res; #if __sun - size_t hostlen = strlen(req->hostname); + size_t hostlen; + + if (req->hostname) + hostlen = strlen(req->hostname); + else + hostlen = 0; #endif req->res = NULL;