| index e04be41..4667d5b 100644 | ||
| --- a/src/plugin_netcheck.c | ||
| +++ b/src/plugin_netcheck.c | ||
| @@ -763,10 +763,19 @@ static void discover_nameservers(void) | ||
| 763 | 763 | |
| 764 | 764 | #if defined(__APPLE__) |
| 765 | 765 | /* 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 | 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 | 779 | if (f) { |
| 771 | 780 | while (fgets(line, sizeof line, f)) { |
| 772 | 781 | const char *p = strstr(line, "nameserver["); |
| index a4a7daa..92d0cc8 100644 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -387,10 +387,14 @@ grep -q 'GetAdaptersAddresses' src/plugin_netcheck.c \ | ||
| 387 | 387 | && pass "Windows uses GetAdaptersAddresses" || fail "no GetAdaptersAddresses" |
| 388 | 388 | grep -q 'getifaddrs' src/plugin_netcheck.c \ |
| 389 | 389 | && 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" | |
| 394 | 398 | grep -q 'pthread_create' src/plugin_netcheck.c \ |
| 395 | 399 | && pass "the resolver deadline runs in a thread" || fail "no resolver thread" |
| 396 | 400 | grep -q 'O_NONBLOCK' src/plugin_netcheck.c \ |
| 397 | 401 |
| index e04be41..4667d5b 100644 | index 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 is | 765 | /* 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["); |
| index a4a7daa..92d0cc8 100644 | index 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 \ |
| 397 | 401 |