* fhandler.h (fhandler_console): Remove tcsetpgrp.

* fhandler_console.cc (fhandler_console::tcsetpgrp): Eliminate.
* fork.cc (fork_parent): Avoid returning same pid twice in a row regardless of
OS.
* pinfo.cc (pinfo::init): Rename create argument to flags and treat it as such.
* signal.cc (set_sigcatchers): New function.
(signal): Use set_sigcatchers to increment or decrement sigcatcher tracker.
(sigaction): Ditto.  Add debugging output.
* spawn.cc (spawn_guts): Always quote first argv[0] argument when it's a
COMSPEC shell.
This commit is contained in:
Christopher Faylor 2000-10-21 04:53:49 +00:00
parent e9921bcbaa
commit b0de2aa284
8 changed files with 57 additions and 36 deletions

View File

@ -1,3 +1,18 @@
Sat Oct 21 00:46:36 2000 Christopher Faylor <cgf@cygnus.com>
* fhandler.h (fhandler_console): Remove tcsetpgrp.
* fhandler_console.cc (fhandler_console::tcsetpgrp): Eliminate.
* fork.cc (fork_parent): Avoid returning same pid twice in a row
regardless of OS.
* pinfo.cc (pinfo::init): Rename create argument to flags and treat it
as such.
* signal.cc (set_sigcatchers): New function.
(signal): Use set_sigcatchers to increment or decrement sigcatcher
tracker.
(sigaction): Ditto. Add debugging output.
* spawn.cc (spawn_guts): Always quote first argv[0] argument when it's
a COMSPEC shell.
2000-10-20 DJ Delorie <dj@redhat.com>
* times.cc (to_time_t): pass zero time as epoch

View File

@ -607,8 +607,6 @@ public:
int tcsetattr (int a, const struct termios *t);
int tcgetattr (struct termios *t);
int tcsetpgrp (const pid_t pid);
/* Special dup as we must dup two handles */
int dup (fhandler_base *child);

View File

@ -188,8 +188,8 @@ fhandler_console::read (void *pv, size_t buflen)
if (!ReadConsoleInput (h, &input_rec, 1, &nread))
{
syscall_printf ("ReadConsoleInput failed, %E");
__seterrno ();
syscall_printf ("ReadConsoleInput failed, %E");
return -1; /* seems to be failure */
}
@ -252,13 +252,6 @@ fhandler_console::read (void *pv, size_t buflen)
return copied_chars;
}
int
fhandler_console::tcsetpgrp (pid_t pid)
{
tc->pgid = pid;
return 0;
}
void
fhandler_console::set_input_state ()
{

View File

@ -293,9 +293,6 @@ fhandler_termios::line_edit (const char *rptr, int nread, int always_accept)
if (!iscanon || always_accept)
set_input_done (ralen > 0);
/* FIXME: It's not clear that this code will ever do anything.
Currently, it doesn't look like accept_input will ever return
a negative number. */
if (input_done)
(void) accept_input ();

View File

@ -443,14 +443,17 @@ fork_parent (void *stack_here, HANDLE& hParent, dll *&first_dll, bool& load_dlls
/* Protect the handle but name it similarly to the way it will
be called in subproc handling. */
ProtectHandle1 (pi.hProcess, childhProc);
if (os_being_run != winNT)
{
if (last_fork_proc)
CloseHandle (last_fork_proc);
if (!DuplicateHandle (hMainProc, pi.hProcess, hMainProc, &last_fork_proc,
0, FALSE, DUPLICATE_SAME_ACCESS))
system_printf ("couldn't create last_fork_proc, %E");
}
/* Keep a handle to the current forked process sitting around to prevent
Windows from reusing the same pid twice in a row. Having the same pid
twice in a row confuses bash. So, after every CreateProcess, we can safely
remove the old pid and save a handle to the newly created process. Keeping
a handle open will stop windows from reusing the same pid. */
if (last_fork_proc)
CloseHandle (last_fork_proc);
if (!DuplicateHandle (hMainProc, pi.hProcess, hMainProc, &last_fork_proc,
0, FALSE, DUPLICATE_SAME_ACCESS))
system_printf ("couldn't create last_fork_proc, %E");
/* Fill in fields in the child's process table entry. */
forked->ppid = myself->pid;

View File

@ -134,7 +134,7 @@ _pinfo::exit (UINT n, bool norecord)
}
void
pinfo::init (pid_t n, DWORD create, HANDLE in_h)
pinfo::init (pid_t n, DWORD flag, HANDLE in_h)
{
if (n == myself->pid)
{
@ -144,6 +144,7 @@ pinfo::init (pid_t n, DWORD create, HANDLE in_h)
return;
}
int createit = flag & PID_IN_USE;
for (int i = 0; i < 10; i++)
{
int created;
@ -151,7 +152,7 @@ pinfo::init (pid_t n, DWORD create, HANDLE in_h)
__small_sprintf (mapname, "cygpid.%x", n);
int mapsize;
if (create & PID_EXECED)
if (flag & PID_EXECED)
mapsize = PINFO_REDIR_SIZE;
else
mapsize = sizeof (_pinfo);
@ -161,7 +162,7 @@ pinfo::init (pid_t n, DWORD create, HANDLE in_h)
h = in_h;
created = 0;
}
else if (!create)
else if (!createit)
{
h = OpenFileMappingA (FILE_MAP_READ | FILE_MAP_WRITE, FALSE, mapname);
created = 0;
@ -175,7 +176,7 @@ pinfo::init (pid_t n, DWORD create, HANDLE in_h)
if (!h)
{
if (create)
if (createit)
__seterrno ();
procinfo = NULL;
return;
@ -184,7 +185,7 @@ 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))
if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR))
{
release ();
set_errno (ENOENT);
@ -208,7 +209,7 @@ pinfo::init (pid_t n, DWORD create, HANDLE in_h)
should only be a brief occurrence, so rather than introduce some kind
of locking mechanism, just loop. FIXME: I'm sure I'll regret doing it
this way at some point. */
if (i < 9 && !created && create && (procinfo->process_state & PID_EXITED))
if (i < 9 && !created && createit && (procinfo->process_state & PID_EXITED))
{
Sleep (5);
release ();
@ -217,7 +218,7 @@ pinfo::init (pid_t n, DWORD create, HANDLE in_h)
if (!created)
/* nothing */;
else if (!(create & PID_EXECED))
else if (!(flag & PID_EXECED))
procinfo->pid = n;
else
{

View File

@ -23,6 +23,23 @@ int sigcatchers; /* FIXME: Not thread safe. */
#define sigtrapped(func) ((func) != SIG_IGN && (func) != SIG_DFL)
static inline void
set_sigcatchers (void (*oldsig) (int), void (*cursig) (int))
{
#ifdef DEBUGGING
int last_sigcatchers = sigcatchers;
#endif
if (!sigtrapped (oldsig) && sigtrapped (cursig))
sigcatchers++;
else if (sigtrapped (oldsig) && !sigtrapped (cursig))
sigcatchers--;
#ifdef DEBUGGING
if (last_sigcatchers != sigcatchers)
sigproc_printf ("last %d, old %d, cur %p, cur %p", last_sigcatchers,
sigcatchers, oldsig, cursig);
#endif
}
extern "C" _sig_func_ptr
signal (int sig, _sig_func_ptr func)
{
@ -39,10 +56,7 @@ signal (int sig, _sig_func_ptr func)
prev = myself->getsig (sig).sa_handler;
myself->getsig (sig).sa_handler = func;
myself->getsig (sig).sa_mask = 0;
if (!sigtrapped (prev) && sigtrapped (func))
sigcatchers++;
else if (sigtrapped (prev) && !sigtrapped (func))
sigcatchers--;
set_sigcatchers (prev, func);
syscall_printf ("%p = signal (%d, %p)", prev, sig, func);
return prev;
@ -235,6 +249,7 @@ killpg (int pgrp, int sig)
extern "C" int
sigaction (int sig, const struct sigaction *newact, struct sigaction *oldact)
{
sigproc_printf ("sig %d, newact %p, oldact %p", sig, newact, oldact);
/* check that sig is in right range */
if (sig < 0 || sig >= NSIG)
{
@ -257,10 +272,7 @@ sigaction (int sig, const struct sigaction *newact, struct sigaction *oldact)
sig_clear (sig);
if (newact->sa_handler == SIG_DFL && sig == SIGCHLD)
sig_clear (sig);
if (!sigtrapped (oa.sa_handler) && sigtrapped (newact->sa_handler))
sigcatchers++;
else if (sigtrapped (oa.sa_handler) && !sigtrapped (newact->sa_handler))
sigcatchers--;
set_sigcatchers (oa.sa_handler, newact->sa_handler);
}
if (oldact)

View File

@ -352,10 +352,12 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
(iscmd (argv[0], "command.com") || iscmd (argv[0], "cmd.exe")))
{
real_path.check (prog_arg);
one_line.add ("\"");
if (!real_path.error)
one_line.add (real_path);
else
one_line.add (argv[0]);
one_line.add ("\"");
one_line.add (" ");
one_line.add (argv[1]);
one_line.add (" ");