aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2024-12-03 00:31:06 +0100
committerGitHub <noreply@github.com>2024-12-03 00:31:06 +0100
commitc431bc39c396ce644b47367d415a2c869ee81941 (patch)
tree01bb67e5052aef9a8ba8dddf8ac2355ab3c67f1f
parent14644080c8adf10e460b90c51774531390aebe3c (diff)
downloadlibuv-c431bc39c396ce644b47367d415a2c869ee81941.tar.gz
libuv-c431bc39c396ce644b47367d415a2c869ee81941.zip
linux: fix uv_cpu_info() arm cpu model detection (#4633)
Libuv looks for "Processor" in /proc/cpuinfo but it's been reported that on at least some Raspberry Pi models, it's called "model name". Look for both. Fixes: https://github.com/nodejs/node/issues/56105
-rw-r--r--src/unix/linux.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/unix/linux.c b/src/unix/linux.c
index 857a4ef8..0fa565b7 100644
--- a/src/unix/linux.c
+++ b/src/unix/linux.c
@@ -1713,16 +1713,22 @@ int uv_uptime(double* uptime) {
int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
#if defined(__PPC__)
static const char model_marker[] = "cpu\t\t: ";
+ static const char model_marker2[] = "";
#elif defined(__arm__)
- static const char model_marker[] = "Processor\t: ";
+ static const char model_marker[] = "model name\t: ";
+ static const char model_marker2[] = "Processor\t: ";
#elif defined(__aarch64__)
static const char model_marker[] = "CPU part\t: ";
+ static const char model_marker2[] = "";
#elif defined(__mips__)
static const char model_marker[] = "cpu model\t\t: ";
+ static const char model_marker2[] = "";
#elif defined(__loongarch__)
static const char model_marker[] = "cpu family\t\t: ";
+ static const char model_marker2[] = "";
#else
static const char model_marker[] = "model name\t: ";
+ static const char model_marker2[] = "";
#endif
static const char parts[] =
#ifdef __aarch64__
@@ -1821,14 +1827,22 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
if (1 != fscanf(fp, "processor\t: %u\n", &cpu))
break; /* Parse error. */
- found = 0;
- while (!found && fgets(buf, sizeof(buf), fp))
- found = !strncmp(buf, model_marker, sizeof(model_marker) - 1);
+ while (fgets(buf, sizeof(buf), fp)) {
+ if (!strncmp(buf, model_marker, sizeof(model_marker) - 1)) {
+ p = buf + sizeof(model_marker) - 1;
+ goto parts;
+ }
+ if (!*model_marker2)
+ continue;
+ if (!strncmp(buf, model_marker2, sizeof(model_marker2) - 1)) {
+ p = buf + sizeof(model_marker2) - 1;
+ goto parts;
+ }
+ }
- if (!found)
- goto next;
+ goto next; /* Not found. */
- p = buf + sizeof(model_marker) - 1;
+parts:
n = (int) strcspn(p, "\n");
/* arm64: translate CPU part code to model name. */