Skip to content

Commit cf0d96a

Browse files
tyan0dscho
authored andcommitted
Cygwin: termios: Handle app execution alias in is_console_app()
After the commit f74dc93, WSL cannot start by distribution name such as debian.exe, which has '.exe' extention but actually is an app execution alias. This is because the commit f74dc93 disabled to follow windows reparse point by adding PC_SYM_NOFOLLOW_REP flag in spawn.cc, that path is used for sapwning a process. As a result, the path, that is_console_app () received, had been the reparse point of app execution alias, then it returned false for the the path due to open-failure because CreateFileW() cannot open an app execution alias, while it can open normal reparse point. If is_console_app() returns false, standard handles for console app (such as WSL) would not be setup. This causes that the console input cannot be transfered to the non-cygwin app. This patch fixes the issue by locally converting the path, which is a path to the app execution alias, once again using PC_SYM_FOLLOW (without PC_SYM_NOFOLLOW_REP) option path_conv for using inside of is_console_app() to resolve the reparse point here, if the path is an app execution alias. Fixes: f74dc93 ("fix native symlink spawn passing wrong arg0") Reviewed-by: Johannes Schindelin <[email protected]> Signed-off-by: Takashi Yano <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 284feb0 commit cf0d96a

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

winsup/cygwin/fhandler/termios.cc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,26 @@ fhandler_termios::fstat (struct stat *buf)
702702
}
703703

704704
static bool
705-
is_console_app (const WCHAR *filename)
705+
is_console_app (path_conv &pc)
706706
{
707-
wchar_t *e = wcsrchr (filename, L'.');
707+
tmp_pathbuf tp;
708+
WCHAR *native_path = tp.w_get ();
709+
pc.get_wide_win32_path (native_path);
710+
711+
wchar_t *e = wcsrchr (native_path, L'.');
708712
if (e && (wcscasecmp (e, L".bat") == 0 || wcscasecmp (e, L".cmd") == 0))
709713
return true;
714+
715+
if (pc.is_app_execution_alias ())
716+
{
717+
UNICODE_STRING upath;
718+
RtlInitUnicodeString (&upath, native_path);
719+
path_conv target (&upath, PC_SYM_FOLLOW);
720+
target.get_wide_win32_path (native_path);
721+
}
722+
710723
HANDLE h;
711-
h = CreateFileW (filename, GENERIC_READ, FILE_SHARE_READ,
724+
h = CreateFileW (native_path, GENERIC_READ, FILE_SHARE_READ,
712725
NULL, OPEN_EXISTING, 0, NULL);
713726
if (h == INVALID_HANDLE_VALUE)
714727
return true;
@@ -761,7 +774,7 @@ fhandler_termios::ioctl (unsigned int cmd, void *varg)
761774

762775
void
763776
fhandler_termios::spawn_worker::setup (bool iscygwin, HANDLE h_stdin,
764-
const WCHAR *runpath, bool nopcon,
777+
path_conv &pc, bool nopcon,
765778
bool reset_sendsig,
766779
const WCHAR *envblock)
767780
{
@@ -800,7 +813,7 @@ fhandler_termios::spawn_worker::setup (bool iscygwin, HANDLE h_stdin,
800813
ptys->setup_locale ();
801814
}
802815
}
803-
if (!iscygwin && ptys_primary && is_console_app (runpath))
816+
if (!iscygwin && ptys_primary && is_console_app (pc))
804817
{
805818
if (h_stdin == ptys_primary->get_handle_nat ())
806819
stdin_is_ptys = true;

winsup/cygwin/local_includes/fhandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ class fhandler_termios: public fhandler_base
20352035
spawn_worker () :
20362036
ptys_need_cleanup (false), cons_need_cleanup (false),
20372037
stdin_is_ptys (false), ptys_ttyp (NULL) {}
2038-
void setup (bool iscygwin, HANDLE h_stdin, const WCHAR *runpath,
2038+
void setup (bool iscygwin, HANDLE h_stdin, path_conv &pc,
20392039
bool nopcon, bool reset_sendsig, const WCHAR *envblock);
20402040
bool need_cleanup () { return ptys_need_cleanup || cons_need_cleanup; }
20412041
void cleanup ();

winsup/cygwin/spawn.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
579579

580580
bool no_pcon = mode != _P_OVERLAY && mode != _P_WAIT;
581581
term_spawn_worker.setup (iscygwin (), handle (fileno_stdin, false),
582-
runpath, no_pcon, reset_sendsig, envblock);
582+
real_path, no_pcon, reset_sendsig, envblock);
583583

584584
/* Set up needed handles for stdio */
585585
si.dwFlags = STARTF_USESTDHANDLES;

0 commit comments

Comments
 (0)