From 247ac234f46c038e1c23094172a6151efc17c6f0 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 21 Dec 2005 17:14:34 +0000 Subject: [PATCH] * cygheap.cc (init_cygheap::manage_console_count): Revert previous change. Handle this a different way. * external.cc (cygwin_internal): Accommodate extra hook_or_detect_cygwin argument. * hookapi.cc (cygwin_internal): Fill in subsys variable with the subsystem of the executable. * spawn.cc (av::iscui): New variable. (spawn_guts): Hide window when we don't have a console and this isn't NT/XP/2003. (av::fixup): Set iscui flag. * winsup.h (hook_or_detect_cygwin): Accommodate extra argument. --- winsup/cygwin/ChangeLog | 14 ++++++++++++++ winsup/cygwin/cygheap.cc | 3 +-- winsup/cygwin/external.cc | 3 ++- winsup/cygwin/hookapi.cc | 4 +++- winsup/cygwin/spawn.cc | 14 +++++++++++--- winsup/cygwin/winsup.h | 2 +- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index dce26a8c4..2a3c6d4f4 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,17 @@ +2005-12-21 Christopher Faylor + + * cygheap.cc (init_cygheap::manage_console_count): Revert previous + change. Handle this a different way. + * external.cc (cygwin_internal): Accommodate extra + hook_or_detect_cygwin argument. + * hookapi.cc (cygwin_internal): Fill in subsys variable with the + subsystem of the executable. + * spawn.cc (av::iscui): New variable. + (spawn_guts): Hide window when we don't have a console and this isn't + NT/XP/2003. + (av::fixup): Set iscui flag. + * winsup.h (hook_or_detect_cygwin): Accommodate extra argument. + 2005-12-21 Christopher Faylor * cygheap.cc (init_cygheap::manage_console_count): Don't call diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 819de8fe7..122e6207a 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -96,8 +96,7 @@ init_cygheap::manage_console_count (const char *something, int amount, bool avoi console_count += amount; debug_printf ("%s: console_count %d, amount %d, %s, avoid_freeing_console %d", something, console_count, amount, myctty (), avoid_freeing_console); - if (wincap.pty_needs_alloc_console () && !avoid_freeing_console && amount <= 0 - && !console_count && myself->ctty == -1) + if (!avoid_freeing_console && amount <= 0 && !console_count && myself->ctty == -1) { FreeConsole (); debug_printf ("freed console"); diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index 2a6badad2..b51c58b84 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -295,7 +295,8 @@ cygwin_internal (cygwin_getinfo_types t, ...) { const char *name = va_arg (arg, const char *); const void *hookfn = va_arg (arg, const void *); - return (unsigned long) hook_or_detect_cygwin (name, hookfn); + WORD subsys; + return (unsigned long) hook_or_detect_cygwin (name, hookfn, subsys); } case CW_ARGV: { diff --git a/winsup/cygwin/hookapi.cc b/winsup/cygwin/hookapi.cc index 26aff5165..2ef1eea47 100644 --- a/winsup/cygwin/hookapi.cc +++ b/winsup/cygwin/hookapi.cc @@ -151,7 +151,7 @@ makename (const char *name, char *&buf, int& i, int inc) // Top level routine to find the EXE's imports, and redirect them void * -hook_or_detect_cygwin (const char *name, const void *fn) +hook_or_detect_cygwin (const char *name, const void *fn, WORD& subsys) { HMODULE hm = fn ? GetModuleHandle (NULL) : (HMODULE) name; PIMAGE_NT_HEADERS pExeNTHdr = PEHeaderFromHModule (hm); @@ -159,6 +159,8 @@ hook_or_detect_cygwin (const char *name, const void *fn) if (!pExeNTHdr) return false; + subsys = pExeNTHdr->OptionalHeader.Subsystem; + DWORD importRVA = pExeNTHdr->OptionalHeader.DataDirectory [IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; if (!importRVA) diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index ba16ef743..b5997ff86 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -294,8 +294,9 @@ class av public: int argc; bool win16_exe; - av (): argv (NULL) {} - av (int ac_in, const char * const *av_in) : calloced (0), argc (ac_in), win16_exe (false) + bool iscui; + av (): argv (NULL), iscui (false) {} + av (int ac_in, const char * const *av_in) : calloced (0), argc (ac_in), win16_exe (false), iscui (false) { argv = (char **) cmalloc (HEAP_1_ARGV, (argc + 5) * sizeof (char *)); memcpy (argv, av_in, (argc + 1) * sizeof (char *)); @@ -578,6 +579,11 @@ spawn_guts (const char * prog_arg, const char *const *argv, si.hStdOutput = handle (1, 1); /* Get output handle */ si.hStdError = handle (2, 1); /* Get output handle */ si.cb = sizeof (si); + if (!wincap.pty_needs_alloc_console () && newargv.iscui && !GetConsoleCP ()) + { + si.dwFlags |= STARTF_USESHOWWINDOW; + si.wShowWindow = SW_HIDE; + } int flags = GetPriorityClass (hMainProc); sigproc_printf ("priority class %d", flags); @@ -1060,11 +1066,13 @@ av::fixup (child_info_types chtype, const char *prog_arg, path_conv& real_path, } if (buf[0] == 'M' && buf[1] == 'Z') { + WORD subsys; unsigned off = (unsigned char) buf[0x18] | (((unsigned char) buf[0x19]) << 8); win16_exe = off < sizeof (IMAGE_DOS_HEADER); if (!win16_exe) - real_path.set_cygexec (!!hook_or_detect_cygwin (buf, NULL)); + real_path.set_cygexec (!!hook_or_detect_cygwin (buf, NULL, subsys)); UnmapViewOfFile (buf); + iscui = subsys == IMAGE_SUBSYSTEM_WINDOWS_CUI; break; } } diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 3a24d8d1a..2e40adeaf 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -250,7 +250,7 @@ extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribu extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3))); extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2))); -void *hook_or_detect_cygwin (const char *, const void *) __attribute__ ((regparm (2))); +void *hook_or_detect_cygwin (const char *, const void *, WORD&) __attribute__ ((regparm (3))); /* Time related */ void __stdcall totimeval (struct timeval *, FILETIME *, int, int);