* syscalls.cc (setsid): Detach process from its console if the current

controlling tty is the console and already closed.
* dtable.h (class dtable): Add members to count descriptors referring to the
console.
* dtable.cc (dtable::dec_console_fds): New function to detach process from its
console.
(dtable::release): Decrement the counter of console descriptors.
(dtable::build_fhandler): Increment it.
* exception.cc (ctrl_c_handler): Send SIGTERM to myself when catch
CTRL_SHUTDOWN_EVENT.
This commit is contained in:
Christopher Faylor 2001-07-26 00:10:52 +00:00
parent 811bf2902d
commit 0cc642a5f1
5 changed files with 51 additions and 10 deletions

View File

@ -1,3 +1,16 @@
2001-07-25 Kazuhiro Fujieda <fujieda@jaist.ac.jp>
* syscalls.cc (setsid): Detach process from its console if the current
controlling tty is the console and already closed.
* dtable.h (class dtable): Add members to count descriptors referring
to the console.
* dtable.cc (dtable::dec_console_fds): New function to detach process
from its console.
(dtable::release): Decrement the counter of console descriptors.
(dtable::build_fhandler): Increment it.
* exception.cc (ctrl_c_handler): Send SIGTERM to myself when catch
CTRL_SHUTDOWN_EVENT.
Tue 24 Jul 2001 02:28:00 PM Trevor Forbes <t4bs@hotmail.com> Tue 24 Jul 2001 02:28:00 PM Trevor Forbes <t4bs@hotmail.com>
* thread.cc (verifyable_object_isvalid): Don't validate * thread.cc (verifyable_object_isvalid): Don't validate

View File

@ -1,6 +1,6 @@
/* dtable.cc: file descriptor support. /* dtable.cc: file descriptor support.
Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions. Copyright 1996, 1997, 1998, 1999, 2000, 2001 Cygnus Solutions.
This file is part of Cygwin. This file is part of Cygwin.
@ -51,6 +51,13 @@ set_std_handle (int fd)
SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_output_handle ()); SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_output_handle ());
} }
void
dtable::dec_console_fds ()
{
if (console_fds > 0 && !--console_fds && myself->ctty != TTY_CONSOLE)
FreeConsole ();
}
int int
dtable::extend (int howmuch) dtable::extend (int howmuch)
{ {
@ -146,8 +153,13 @@ dtable::release (int fd)
{ {
if (!not_open (fd)) if (!not_open (fd))
{ {
if ((fds[fd]->get_device () & FH_DEVMASK) == FH_SOCKET) switch (fds[fd]->get_device ())
{
case FH_SOCKET:
dec_need_fixup_before (); dec_need_fixup_before ();
case FH_CONSOLE:
dec_console_fds ();
}
delete fds[fd]; delete fds[fd];
fds[fd] = NULL; fds[fd] = NULL;
} }
@ -261,6 +273,7 @@ dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit)
case FH_CONIN: case FH_CONIN:
case FH_CONOUT: case FH_CONOUT:
fh = new (buf) fhandler_console (name); fh = new (buf) fhandler_console (name);
inc_console_fds ();
break; break;
case FH_PTYM: case FH_PTYM:
fh = new (buf) fhandler_pty_master (name); fh = new (buf) fhandler_pty_master (name);

View File

@ -1,6 +1,6 @@
/* dtable.h: fd table definition. /* dtable.h: fd table definition.
Copyright 2000 Red Hat, Inc. Copyright 2000, 2001 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -19,19 +19,26 @@ class dtable
fhandler_base **fds_on_hold; fhandler_base **fds_on_hold;
int first_fd_for_open; int first_fd_for_open;
int cnt_need_fixup_before; int cnt_need_fixup_before;
int console_fds;
public: public:
size_t size; size_t size;
dtable () : first_fd_for_open(3), cnt_need_fixup_before(0) {} dtable () : first_fd_for_open(3), cnt_need_fixup_before(0), console_fds(0) {}
void init () {first_fd_for_open = 3;} void init () {first_fd_for_open = 3;}
void dec_need_fixup_before () void dec_need_fixup_before ()
{ if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; } { if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; }
void inc_need_fixup_before () void inc_need_fixup_before ()
{ ++cnt_need_fixup_before; } { cnt_need_fixup_before++; }
BOOL need_fixup_before () BOOL need_fixup_before ()
{ return cnt_need_fixup_before > 0; } { return cnt_need_fixup_before > 0; }
void dec_console_fds ();
void inc_console_fds ()
{ console_fds++; }
BOOL has_console_fds ()
{ return console_fds > 0; }
int vfork_child_dup (); int vfork_child_dup ();
void vfork_parent_restore (); void vfork_parent_restore ();
void vfork_child_fixup (); void vfork_child_fixup ();

View File

@ -895,14 +895,20 @@ ctrl_c_handler (DWORD type)
if (type == CTRL_LOGOFF_EVENT) if (type == CTRL_LOGOFF_EVENT)
return TRUE; return TRUE;
if ((type == CTRL_CLOSE_EVENT) || (type == CTRL_SHUTDOWN_EVENT))
/* Return FALSE to prevent an "End task" dialog box from appearing /* Return FALSE to prevent an "End task" dialog box from appearing
for each Cygwin process window that's open when the computer for each Cygwin process window that's open when the computer
is shut down or console window is closed. */ is shut down or console window is closed. */
if (type == CTRL_SHUTDOWN_EVENT)
{
sig_send (NULL, SIGTERM);
return FALSE;
}
if (type == CTRL_CLOSE_EVENT)
{ {
sig_send (NULL, SIGHUP); sig_send (NULL, SIGHUP);
return FALSE; return FALSE;
} }
tty_min *t = cygwin_shared->tty.get_tty (myself->ctty); tty_min *t = cygwin_shared->tty.get_tty (myself->ctty);
/* Ignore this if we're not the process group lead since it should be handled /* Ignore this if we're not the process group lead since it should be handled
*by* the process group leader. */ *by* the process group leader. */

View File

@ -240,6 +240,8 @@ setsid (void)
/* FIXME: for now */ /* FIXME: for now */
if (myself->pgid != _getpid ()) if (myself->pgid != _getpid ())
{ {
if (myself->ctty == TTY_CONSOLE && !cygheap->fdtab.has_console_fds ())
FreeConsole ();
myself->ctty = -1; myself->ctty = -1;
myself->sid = _getpid (); myself->sid = _getpid ();
myself->pgid = _getpid (); myself->pgid = _getpid ();