From ed4d903e696d5a239fcc09ac8e853056537fb8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 2 Apr 2026 20:05:47 +0800 Subject: [PATCH] Sysctl (OpenBSD): improves error messages --- src/common/impl/sysctl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/impl/sysctl.c b/src/common/impl/sysctl.c index 10801a473..62268754a 100644 --- a/src/common/impl/sysctl.c +++ b/src/common/impl/sysctl.c @@ -6,15 +6,16 @@ const char* ffSysctlGetString(int mib1, int mib2, FFstrbuf* result) { size_t neededLength; if (sysctl((int[]) { mib1, mib2 }, 2, NULL, &neededLength, NULL, 0) != 0 || neededLength == 1) { // neededLength is 1 for empty strings, because of the null terminator - return "sysctlbyname() failed"; + return "sysctl() length query failed"; } ffStrbufEnsureFree(result, (uint32_t) neededLength - 1); - if (sysctl((int[]) { mib1, mib2 }, 2, result->chars + result->length, &neededLength, NULL, 0) == 0) { - result->length += (uint32_t) neededLength - 1; + if (sysctl((int[]) { mib1, mib2 }, 2, result->chars + result->length, &neededLength, NULL, 0) != 0) { + return "sysctl() failed to retrieve string data"; } + result->length += (uint32_t) neededLength - 1; result->chars[result->length] = '\0'; return NULL;