fix(macos): scutil lives in /usr/sbin, not /usr/bin - try both absolute paths
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-12 11:56:18
Commit06e8ea17
Parents1e64f08f
Changed files
src/plugin_netcheck.c+11−2■■■■■
tests/run.sh+8−4■■■■■
2 files+19−6
Diff
src/plugin_netcheck.c+11−2■■■■■
index e04be41..4667d5b 100644
--- a/src/plugin_netcheck.c
+++ b/src/plugin_netcheck.c
@@ -763,10 +763,19 @@ static void discover_nameservers(void)
763763
764764 #if defined(__APPLE__)
765765 /* macOS keeps /etc/resolv.conf as a symlink to a rotating stub; scutil is
766- * the authoritative source. Fixed argv - no user input reaches the shell. */
766+ * the authoritative source. Fixed argv - no user input reaches the shell.
767+ * scutil lives in /usr/sbin on macOS (measured on the MacBook builder), so
768+ * both absolute spellings are tried rather than trusting one. */
767769 {
768- FILE *f = sx_popen("/usr/bin/scutil --dns", "r");
770+ static const char *SCUTIL_PATHS[] = {"/usr/sbin/scutil", "/usr/bin/scutil"};
771+ FILE *f = NULL;
769772 char line[MAX_LINE];
773+ int si;
774+ for (si = 0; si < 2 && !f; si++) {
775+ char cmd[64];
776+ snprintf(cmd, sizeof cmd, "%s --dns", SCUTIL_PATHS[si]);
777+ f = sx_popen(cmd, "r");
778+ }
770779 if (f) {
771780 while (fgets(line, sizeof line, f)) {
772781 const char *p = strstr(line, "nameserver[");
tests/run.sh+8−4■■■■■
index a4a7daa..92d0cc8 100644
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -387,10 +387,14 @@ grep -q 'GetAdaptersAddresses' src/plugin_netcheck.c \
387387 && pass "Windows uses GetAdaptersAddresses" || fail "no GetAdaptersAddresses"
388388 grep -q 'getifaddrs' src/plugin_netcheck.c \
389389 && pass "POSIX uses getifaddrs" || fail "no getifaddrs"
390-grep -q 'scutil --dns' src/plugin_netcheck.c \
391- && pass "macOS reads nameservers from scutil by absolute path" || fail "no scutil path"
392-grep -q '/usr/bin/scutil' src/plugin_netcheck.c \
393- && pass "the scutil path is absolute" || fail "scutil path not absolute"
390+grep -q -- '--dns' src/plugin_netcheck.c \
391+ && pass "macOS queries the dns state through scutil" || fail "no scutil --dns call"
392+grep -q 'snprintf(cmd, sizeof cmd, "%s --dns"' src/plugin_netcheck.c \
393+ && pass "the scutil argv is built from a fixed path, never from PATH" || fail "scutil argv not fixed"
394+grep -q '/usr/sbin/scutil' src/plugin_netcheck.c \
395+ && pass "scutil is tried at its real macOS path (/usr/sbin)" || fail "no /usr/sbin/scutil"
396+grep -q 'SCUTIL_PATHS' src/plugin_netcheck.c \
397+ && pass "both absolute scutil spellings are tried" || fail "no scutil path list"
394398 grep -q 'pthread_create' src/plugin_netcheck.c \
395399 && pass "the resolver deadline runs in a thread" || fail "no resolver thread"
396400 grep -q 'O_NONBLOCK' src/plugin_netcheck.c \
397401
src/plugin_netcheck.c+11−2■■■■■
index e04be41..4667d5b 100644index e04be41..4667d5b 100644
--- a/src/plugin_netcheck.c--- a/src/plugin_netcheck.c
+++ b/src/plugin_netcheck.c+++ b/src/plugin_netcheck.c
@@ -763,10 +763,19 @@ static void discover_nameservers(void)@@ -763,10 +763,19 @@ static void discover_nameservers(void)
763 763
764 #if defined(__APPLE__)764 #if defined(__APPLE__)
765 /* macOS keeps /etc/resolv.conf as a symlink to a rotating stub; scutil is765 /* macOS keeps /etc/resolv.conf as a symlink to a rotating stub; scutil is
766- * the authoritative source. Fixed argv - no user input reaches the shell. */766+ * the authoritative source. Fixed argv - no user input reaches the shell.
767+ * scutil lives in /usr/sbin on macOS (measured on the MacBook builder), so
768+ * both absolute spellings are tried rather than trusting one. */
767 {769 {
768- FILE *f = sx_popen("/usr/bin/scutil --dns", "r");770+ static const char *SCUTIL_PATHS[] = {"/usr/sbin/scutil", "/usr/bin/scutil"};
771+ FILE *f = NULL;
769 char line[MAX_LINE];772 char line[MAX_LINE];
773+ int si;
774+ for (si = 0; si < 2 && !f; si++) {
775+ char cmd[64];
776+ snprintf(cmd, sizeof cmd, "%s --dns", SCUTIL_PATHS[si]);
777+ f = sx_popen(cmd, "r");
778+ }
770 if (f) {779 if (f) {
771 while (fgets(line, sizeof line, f)) {780 while (fgets(line, sizeof line, f)) {
772 const char *p = strstr(line, "nameserver[");781 const char *p = strstr(line, "nameserver[");
tests/run.sh+8−4■■■■■
index a4a7daa..92d0cc8 100644index a4a7daa..92d0cc8 100644
--- a/tests/run.sh--- a/tests/run.sh
+++ b/tests/run.sh+++ b/tests/run.sh
@@ -387,10 +387,14 @@ grep -q 'GetAdaptersAddresses' src/plugin_netcheck.c \@@ -387,10 +387,14 @@ grep -q 'GetAdaptersAddresses' src/plugin_netcheck.c \
387 && pass "Windows uses GetAdaptersAddresses" || fail "no GetAdaptersAddresses"387 && pass "Windows uses GetAdaptersAddresses" || fail "no GetAdaptersAddresses"
388 grep -q 'getifaddrs' src/plugin_netcheck.c \388 grep -q 'getifaddrs' src/plugin_netcheck.c \
389 && pass "POSIX uses getifaddrs" || fail "no getifaddrs"389 && pass "POSIX uses getifaddrs" || fail "no getifaddrs"
390-grep -q 'scutil --dns' src/plugin_netcheck.c \390+grep -q -- '--dns' src/plugin_netcheck.c \
391- && pass "macOS reads nameservers from scutil by absolute path" || fail "no scutil path"391+ && pass "macOS queries the dns state through scutil" || fail "no scutil --dns call"
392-grep -q '/usr/bin/scutil' src/plugin_netcheck.c \392+grep -q 'snprintf(cmd, sizeof cmd, "%s --dns"' src/plugin_netcheck.c \
393- && pass "the scutil path is absolute" || fail "scutil path not absolute"393+ && pass "the scutil argv is built from a fixed path, never from PATH" || fail "scutil argv not fixed"
394+grep -q '/usr/sbin/scutil' src/plugin_netcheck.c \
395+ && pass "scutil is tried at its real macOS path (/usr/sbin)" || fail "no /usr/sbin/scutil"
396+grep -q 'SCUTIL_PATHS' src/plugin_netcheck.c \
397+ && pass "both absolute scutil spellings are tried" || fail "no scutil path list"
394 grep -q 'pthread_create' src/plugin_netcheck.c \398 grep -q 'pthread_create' src/plugin_netcheck.c \
395 && pass "the resolver deadline runs in a thread" || fail "no resolver thread"399 && pass "the resolver deadline runs in a thread" || fail "no resolver thread"
396 grep -q 'O_NONBLOCK' src/plugin_netcheck.c \400 grep -q 'O_NONBLOCK' src/plugin_netcheck.c \
397401