windows: resolve the login CLI before popen so cli_present is honest
cmd.exe returns 1 for a missing program, indistinguishable from the program's own failure, so a Windows node without SCORPIOX CODE reported cli_present:true and 'start failed' where it should say cli_unavailable. bin_available() now resolves an explicit path with GetFileAttributesA and a bare name with SearchPathA before run_capture() ever opens a pipe. Measured on a real Windows box (.214): with CLAUDE_LOGIN_BIN set to a nonexistent path, status now reports cli_present:false.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-12 15:42:12
Commitbca1c198
Parentsf99e9db3
Changed files
src/plugin_claudecode_login.c+25−0■■■■■
1 file+25−0
Diff
src/plugin_claudecode_login.c+25−0■■■■■
index c7bad2c..3cf63a5 100644
--- a/src/plugin_claudecode_login.c
+++ b/src/plugin_claudecode_login.c
@@ -706,6 +706,30 @@ static void shell_quote_into(const char *in, char *out, size_t outsz)
706706 #endif
707707 }
708708
709+/* Is <bin> resolvable on this node? POSIX answers through popen's own 127
710+ * ("command not found"). cmd.exe returns 1 for a missing program, which is
711+ * indistinguishable from the program's own failure - so on Windows the path is
712+ * resolved BEFORE popen with SearchPathA. Without this, a Windows node with no
713+ * SCORPIOX CODE reported cli_present:true and "start failed" instead of
714+ * cli_unavailable (measured on a real Windows box). */
715+static int bin_available(const char *bin)
716+{
717+ if (!bin || !*bin) return 0;
718+#if defined(_WIN32)
719+ {
720+ char full[MAX_PATH];
721+ DWORD n;
722+ /* An explicit path is checked directly; a bare name is searched on PATH. */
723+ if (strchr(bin, '\\') || strchr(bin, '/') || strchr(bin, ':'))
724+ return file_exists(bin);
725+ n = SearchPathA(NULL, bin, ".exe", (DWORD)sizeof(full), full, NULL);
726+ return n > 0 && n < (DWORD)sizeof(full);
727+ }
728+#else
729+ return 1; /* decided by run_capture's own 127 check */
730+#endif
731+}
732+
709733 /* Run `<bin> <args>` and capture stdout.
710734 * Returns 1 when the process ran,
711735 * 0 when popen() itself failed,
@@ -724,6 +748,7 @@ static int run_capture(const char *bin, const char *args, buf_t *out)
724748 int rc;
725749
726750 if (!bin || !*bin) return 0;
751+ if (!bin_available(bin)) return -1;
727752 shell_quote_into(bin, qbin, sizeof(qbin));
728753 #if defined(_WIN32)
729754 if (args && *args) snprintf(cmd, sizeof(cmd), "%s %s 2>NUL", qbin, args);
730755
src/plugin_claudecode_login.c+25−0■■■■■
index c7bad2c..3cf63a5 100644index c7bad2c..3cf63a5 100644
--- a/src/plugin_claudecode_login.c--- a/src/plugin_claudecode_login.c
+++ b/src/plugin_claudecode_login.c+++ b/src/plugin_claudecode_login.c
@@ -706,6 +706,30 @@ static void shell_quote_into(const char *in, char *out, size_t outsz)@@ -706,6 +706,30 @@ static void shell_quote_into(const char *in, char *out, size_t outsz)
706 #endif706 #endif
707 }707 }
708 708
709+/* Is <bin> resolvable on this node? POSIX answers through popen's own 127
710+ * ("command not found"). cmd.exe returns 1 for a missing program, which is
711+ * indistinguishable from the program's own failure - so on Windows the path is
712+ * resolved BEFORE popen with SearchPathA. Without this, a Windows node with no
713+ * SCORPIOX CODE reported cli_present:true and "start failed" instead of
714+ * cli_unavailable (measured on a real Windows box). */
715+static int bin_available(const char *bin)
716+{
717+ if (!bin || !*bin) return 0;
718+#if defined(_WIN32)
719+ {
720+ char full[MAX_PATH];
721+ DWORD n;
722+ /* An explicit path is checked directly; a bare name is searched on PATH. */
723+ if (strchr(bin, '\\') || strchr(bin, '/') || strchr(bin, ':'))
724+ return file_exists(bin);
725+ n = SearchPathA(NULL, bin, ".exe", (DWORD)sizeof(full), full, NULL);
726+ return n > 0 && n < (DWORD)sizeof(full);
727+ }
728+#else
729+ return 1; /* decided by run_capture's own 127 check */
730+#endif
731+}
732+
709 /* Run `<bin> <args>` and capture stdout.733 /* Run `<bin> <args>` and capture stdout.
710 * Returns 1 when the process ran,734 * Returns 1 when the process ran,
711 * 0 when popen() itself failed,735 * 0 when popen() itself failed,
@@ -724,6 +748,7 @@ static int run_capture(const char *bin, const char *args, buf_t *out)@@ -724,6 +748,7 @@ static int run_capture(const char *bin, const char *args, buf_t *out)
724 int rc;748 int rc;
725 749
726 if (!bin || !*bin) return 0;750 if (!bin || !*bin) return 0;
751+ if (!bin_available(bin)) return -1;
727 shell_quote_into(bin, qbin, sizeof(qbin));752 shell_quote_into(bin, qbin, sizeof(qbin));
728 #if defined(_WIN32)753 #if defined(_WIN32)
729 if (args && *args) snprintf(cmd, sizeof(cmd), "%s %s 2>NUL", qbin, args);754 if (args && *args) snprintf(cmd, sizeof(cmd), "%s %s 2>NUL", qbin, args);
730755