diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 3aee9dfd4..075960f0d 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,13 @@ +Thu Oct 19 23:31:41 2000 Christopher Faylor + + * external.cc (fillout_pinfo): Pass PID_NOREDIR flag to pinfo init to + avoid finding execed processes twice. + * signal.cc (kill_pgrp): Ditto. + * spawn.cc (spawn_guts): Avoid passing first argument to CreateProcess + when running a windows shell so that CreateProcess will locate the + shell. Reorganize so that correct error is returned when CreateProcess + fails. + Thu Oct 19 13:55:31 2000 Christopher Faylor * dcrt0.cc (sigthread::init): Correct overzealous ifdef. diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index 3a04453ed..0623911d5 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -44,7 +44,7 @@ fillout_pinfo (pid_t pid, int winpid) DWORD thispid = pids[i++]; if (!thispid) continue; - pinfo p (thispid); + pinfo p (thispid, PID_NOREDIR); if (!p) { diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index ce1ebe52f..e1a195c7b 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -163,7 +163,6 @@ pinfo::init (pid_t n, DWORD create, HANDLE in_h) } else if (!create) { - /* CGF FIXME -- deal with inheritance after an exec */ h = OpenFileMappingA (FILE_MAP_READ | FILE_MAP_WRITE, FALSE, mapname); created = 0; } @@ -185,6 +184,13 @@ pinfo::init (pid_t n, DWORD create, HANDLE in_h) procinfo = (_pinfo *) MapViewOfFile (h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); ProtectHandle1 (h, pinfo_shared_handle); + if ((procinfo->process_state & PID_INITIALIZING) && (create & PID_NOREDIR)) + { + release (); + set_errno (ENOENT); + return; + } + if (procinfo->process_state & PID_EXECED) { assert (!i); @@ -232,6 +238,7 @@ pinfo::release () if (((DWORD) procinfo & 0x77000000) == 0x61000000) try_to_debug (); #endif UnmapViewOfFile (procinfo); + procinfo = NULL; ForceCloseHandle1 (h, pinfo_shared_handle); h = NULL; } diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc index afed39d6b..7ed6e4df2 100644 --- a/winsup/cygwin/signal.cc +++ b/winsup/cygwin/signal.cc @@ -193,7 +193,7 @@ kill_pgrp (pid_t pid, int sig) winpids pids; for (unsigned i = 0; i < pids.npids; i++) { - pinfo p (pids[i]); + pinfo p (pids[i], PID_NOREDIR); if (!proc_exists (p)) continue; diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 74f01fcd4..fcd21b7a9 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -175,9 +175,7 @@ public: size_t ix; char *buf; size_t alloced; - linebuf () : ix (0), buf (NULL), alloced (0) - { - } + linebuf () : ix (0), buf (NULL), alloced (0) {} ~linebuf () {/* if (buf) free (buf);*/} void add (const char *what, int len); void add (const char *what) {add (what, strlen (what));} @@ -349,15 +347,21 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv, av newargv (ac, argv); + int null_app_name = 0; if (ac == 3 && argv[1][0] == '/' && argv[1][1] == 'c' && (iscmd (argv[0], "command.com") || iscmd (argv[0], "cmd.exe"))) { - one_line.add (argv[0]); + real_path.check (prog_arg); + if (!real_path.error) + one_line.add (real_path); + else + one_line.add (argv[0]); one_line.add (" "); one_line.add (argv[1]); one_line.add (" "); one_line.add (argv[2]); strcpy (real_path, argv[0]); + null_app_name = 1; goto skip_arg_parsing; } @@ -525,8 +529,6 @@ skip_arg_parsing: si.hStdError = handle (2, 1); /* Get output handle */ si.cb = sizeof (si); - syscall_printf ("spawn_guts (%s, %.132s)", (char *) real_path, one_line.buf); - int flags = CREATE_DEFAULT_ERROR_MODE | GetPriorityClass (hMainProc); if (mode == _P_DETACH || !set_console_state_for_spawn ()) @@ -550,11 +552,15 @@ skip_arg_parsing: if (!hToken && myself->token != INVALID_HANDLE_VALUE) hToken = myself->token; -cygbench ("spawn-guts"); + const char *runpath = null_app_name ? NULL : (const char *) real_path; + + syscall_printf ("spawn_guts null_app_name %d (%s, %.132s)", null_app_name, runpath, one_line.buf); + + cygbench ("spawn-guts"); if (!hToken) { ciresrv.moreinfo->uid = getuid (); - rc = CreateProcess (real_path, /* image name - with full path */ + rc = CreateProcess (runpath, /* image name - with full path */ one_line.buf, /* what was passed to exec */ /* process security attrs */ allow_ntsec ? sec_user (sa_buf) : &sec_all_nih, @@ -612,7 +618,7 @@ cygbench ("spawn-guts"); load_registry_hive (sid); rc = CreateProcessAsUser (hToken, - real_path, /* image name - with full path */ + runpath, /* image name - with full path */ one_line.buf, /* what was passed to exec */ sec_attribs, /* process security attrs */ sec_attribs, /* thread security attrs */ @@ -639,10 +645,10 @@ cygbench ("spawn-guts"); messages]. */ if (!rc) { - if (spr) - ForceCloseHandle (spr); __seterrno (); syscall_printf ("CreateProcess failed, %E"); + if (spr) + ForceCloseHandle (spr); return -1; }