Skip to content

Commit bddf4ef

Browse files
committed
is_Cygwin: avoid execing anything
The `is_Cygwin` function is used, among other things, to determine how executables are discovered in the `PATH` list by the `_which` function. We are about to change the behavior of the `_which` function on Windows (but not Cygwin): On Windows, we want it to ignore empty elements of the `PATH` instead of treating them as referring to the current directory (which is a "legacy feature" according to https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03, but apparently not explicitly deprecated, the POSIX documentation is quite unclear on that even if the Cygwin project itself considers it to be deprecated: cygwin/cygwin@fc74dbf22f5c). This is important because on Windows, `exec` does something very unsafe by default (unless we're running a Cygwin version of Tcl, which follows Unix semantics). However, we try to `exec` something _inside_ `is_Cygwin` to determine whether we're running within Cygwin or not, i.e. before we determined whether we need to handle `PATH` specially or not. That's a Catch-22. Therefore, and because it is much cleaner anyway, use the `$::tcl_platform(os)` value which is guaranteed to start with `CYGWIN_` when running a Cygwin variant of Tcl/Tk, instead of executing `cygpath --windir`. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 857abe6 commit bddf4ef

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

git-gui.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,8 @@ proc is_Windows {} {
269269
proc is_Cygwin {} {
270270
global _iscygwin
271271
if {$_iscygwin eq {}} {
272-
if {$::tcl_platform(platform) eq {windows}} {
273-
if {[catch {set p [exec cygpath --windir]} err]} {
274-
set _iscygwin 0
275-
} else {
276-
set _iscygwin 1
277-
# Handle MSys2 which is only cygwin when MSYSTEM is MSYS.
278-
if {[info exists ::env(MSYSTEM)] && $::env(MSYSTEM) ne "MSYS"} {
279-
set _iscygwin 0
280-
}
281-
}
272+
if {[string match "CYGWIN_*" $::tcl_platform(os)]} {
273+
set _iscygwin 1
282274
} else {
283275
set _iscygwin 0
284276
}

0 commit comments

Comments
 (0)