On Thu, Sep 24, 2026 at 10:24:20PM +0200, Enrico Forestieri wrote:
> > We should probaly get rid of the whole probe machinery later once this 
> > patchset
> > lands? One less compsec consumer. I can prepare patch for testing if you'd 
> > like.
> 
> Sure, no problem.

Would you review/commit the patch then?

Thanks, Pavel
>From a5918ffe2b43eddf57f206b180205d512863536b Mon Sep 17 00:00:00 2001
Date: Thu, 1 Oct 2026 00:56:32 +0200
Subject: [PATCH] Drop the cygdrive probe

LyX asked an installed Cygwin where it maps the Windows drives, by
running its mount.exe through the command interpreter at startup. The
answer was only ever used when writing posix style paths into LaTeX
files, i.e. when a native Windows LyX drives a Cygwin TeX.

The probe was also close to untestable. Its fallback is the default
prefix that virtually everyone has, so a failing probe is invisible
unless the user changed the prefix with mount --change-cygdrive-prefix.
Keeping the default as a constant loses nothing for anybody else.

With it goes runComspec(), the copy of the old runCommand() Windows
branch that the previous patch moved here for this one caller.

Tier 01 DiD / argv 09: one COMSPEC caller less on Windows

Assisted-by: Claude Opus 5
---
 src/support/os_win32.cpp | 149 ++-------------------------------------
 1 file changed, 7 insertions(+), 142 deletions(-)

diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp
index bacb905b52..2947b33f1f 100644
--- a/src/support/os_win32.cpp
+++ b/src/support/os_win32.cpp
@@ -32,21 +32,17 @@
 
 #include "support/lassert.h"
 
-#include <cstdio>
 #include <cstdlib>
-#include <cstring> // memset
 #include <iostream>
 #include <vector>
 
 #include <QString>
 
 #include <io.h>
-#include <fcntl.h>  // _O_RDONLY
 #include <direct.h> // _getdrive
 #include <fileapi.h> // GetFinalPathNameByHandle
 #include <shlobj.h>  // SHGetFolderPath
 #include <windef.h>
-#include <windows.h>
 #include <shellapi.h>
 #include <shlwapi.h>
 
@@ -91,102 +87,15 @@ wchar_t ** argv_ = 0;
 
 bool windows_style_tex_paths_ = true;
 
-string cygdrive = "/cygdrive";
+// The prefix a Cygwin installation maps the Windows drives under. Used
+// when writing posix style paths into LaTeX files for a Cygwin TeX.
+// LyX used to ask an installed Cygwin for it, but that only mattered
+// for someone who had changed it with mount --change-cygdrive-prefix,
+// and native LyX driving a Cygwin TeX is not a combination anybody
+// runs any more now that we ship a Cygwin build needing no X server.
+string const cygdrive = "/cygdrive";
 
 
-// Run cmd through COMSPEC and return its standard output in result,
-// the return value tells whether the command exited successfully.
-//
-// Relic of the former cross-platform support::runCommand() and it spawns
-// a shell, so you need be extra careful about safety of the arguments. 
-// Preferably do not add new callers of this function - we have generic 
-// Systemcall and this is used only in init() before QCoreApplication
-// kicks in.
-bool runComspec(string const & cmd, string & result)
-{
-	result.clear();
-
-	if (verbose)
-		lyxerr << "\nRunning: " << cmd << endl;
-	else
-		LYXERR(Debug::INFO,"Running: " << cmd);
-
-	STARTUPINFO startup;
-	PROCESS_INFORMATION process;
-	SECURITY_ATTRIBUTES security;
-	HANDLE in, out;
-	FILE * inf = 0;
-	bool err2out = false;
-	string command;
-	string const infile = trim(split(cmd, command, '<'), " \"");
-	command = rtrim(command);
-	if (suffixIs(command, "2>&1")) {
-		command = rtrim(command, "2>&1");
-		err2out = true;
-	}
-	string const cmdarg = "/d /c \"" + command + "\"";
-	string const comspec = getEnv("COMSPEC");
-
-	security.nLength = sizeof(SECURITY_ATTRIBUTES);
-	security.bInheritHandle = TRUE;
-	security.lpSecurityDescriptor = NULL;
-
-	if (CreatePipe(&in, &out, &security, 0)) {
-		memset(&startup, 0, sizeof(STARTUPINFO));
-		memset(&process, 0, sizeof(PROCESS_INFORMATION));
-
-		startup.cb = sizeof(STARTUPINFO);
-		startup.dwFlags = STARTF_USESTDHANDLES;
-
-		startup.hStdError = err2out ? out : GetStdHandle(STD_ERROR_HANDLE);
-		startup.hStdInput = infile.empty()
-			? GetStdHandle(STD_INPUT_HANDLE)
-			: CreateFile(infile.c_str(), GENERIC_READ,
-				FILE_SHARE_READ, &security, OPEN_EXISTING,
-				FILE_ATTRIBUTE_NORMAL, NULL);
-		startup.hStdOutput = out;
-
-		if (startup.hStdInput != INVALID_HANDLE_VALUE &&
-			CreateProcess(comspec.c_str(), (LPTSTR)cmdarg.c_str(),
-				&security, &security, TRUE, CREATE_NO_WINDOW,
-				0, 0, &startup, &process)) {
-
-			CloseHandle(process.hThread);
-			int fno = _open_osfhandle((intptr_t)in, _O_RDONLY);
-			CloseHandle(out);
-			inf = _fdopen(fno, "r");
-		}
-	}
-
-	if (!inf) {
-		lyxerr << "RunCommand: could not start child process" << endl;
-		return false;
-	}
-
-	int c = fgetc(inf);
-	while (c != EOF) {
-		result += static_cast<char>(c);
-		c = fgetc(inf);
-	}
-
-	WaitForSingleObject(process.hProcess, INFINITE);
-	DWORD pret;
-	BOOL success = GetExitCodeProcess(process.hProcess, &pret);
-	bool valid = (pret == 0) && success;
-	if (!success)
-		pret = -1;
-	if (!infile.empty())
-		CloseHandle(startup.hStdInput);
-	CloseHandle(process.hProcess);
-	if (fclose(inf) != 0)
-		pret = -1;
-
-	if (pret == -1)
-		perror("RunCommand: could not terminate child process");
-
-	return valid;
-}
-
 BOOL terminate_handler(DWORD event)
 {
 	if (event == CTRL_CLOSE_EVENT
@@ -290,50 +199,6 @@ void init(int argc, char ** argv[])
 #endif
 	LATTEST(argc == argc_);
 
-	// If Cygwin is detected, query the cygdrive prefix.
-	// The cygdrive prefix is needed for translating windows style paths
-	// to posix style paths in LaTeX files when the Cygwin teTeX is used.
-	int i;
-	HKEY hkey;
-	char buf[MAX_PATH];
-	DWORD bufsize = sizeof(buf);
-	LONG retval = ERROR_FILE_NOT_FOUND;
-	HKEY const mainkey[2] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER };
-	char const * const subkey[2] = {
-		"Software\\Cygwin\\setup",                         // Cygwin 1.7
-		"Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/" // Prev. ver.
-	};
-	char const * const valuename[2] = {
-		"rootdir", // Cygwin 1.7 or later
-		"native"   // Previous versions
-	};
-	// Check for newer Cygwin versions first, then older ones
-	for (i = 0; i < 2 && retval != ERROR_SUCCESS; ++i) {
-		for (int k = 0; k < 2 && retval != ERROR_SUCCESS; ++k)
-			retval = RegOpenKey(mainkey[k], subkey[i], &hkey);
-	}
-	if (retval == ERROR_SUCCESS) {
-		// Query the Cygwin root directory
-		retval = RegQueryValueEx(hkey, valuename[i - 1],
-				NULL, NULL, (LPBYTE) buf, &bufsize);
-		RegCloseKey(hkey);
-		string const mount = string(buf) + "\\bin\\mount.exe";
-		if (retval == ERROR_SUCCESS && FileName(mount).exists()) {
-			string result;
-			bool const valid = runComspec(
-				mount + " --show-cygdrive-prefix", result);
-			// The output of the mount command is as follows:
-			// Prefix              Type         Flags
-			// /cygdrive           system       binmode
-			// So, we use the inner split to pass the second line
-			// to the outer split which sets cygdrive with its
-			// contents until the first blank, discarding the
-			// unneeded return value.
-			if (valid && prefixIs(result, "Prefix"))
-				split(split(result, '\n'), cygdrive, ' ');
-		}
-	}
-
 	// Catch shutdown events.
 	SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, TRUE);
 }
-- 
2.39.5

-- 
lyx-devel mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to