]> sourceware.org Git - newlib-cygwin.git/commitdiff
* syscalls.cc (setsid): Detach process from its console if the current
authorChristopher Faylor <me@cgf.cx>
Thu, 26 Jul 2001 00:10:52 +0000 (00:10 +0000)
committerChristopher Faylor <me@cgf.cx>
Thu, 26 Jul 2001 00:10:52 +0000 (00:10 +0000)
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.

winsup/cygwin/ChangeLog
winsup/cygwin/dtable.cc
winsup/cygwin/dtable.h
winsup/cygwin/exceptions.cc
winsup/cygwin/syscalls.cc

index 385f9e4d03b27b5eaee79c29884f5082783f7e7b..5c555adcdd2d77a3328079829b910861563446bf 100644 (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>
 
        * thread.cc (verifyable_object_isvalid): Don't validate
index a5477eb9864b19a066a0f6ae465dfde81f75d834..cc16fdada4b4c95636d058f625b462a17714a2c6 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -51,6 +51,13 @@ set_std_handle (int fd)
     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
 dtable::extend (int howmuch)
 {
@@ -146,8 +153,13 @@ dtable::release (int fd)
 {
   if (!not_open (fd))
     {
-      if ((fds[fd]->get_device () & FH_DEVMASK) == FH_SOCKET)
-        dec_need_fixup_before ();
+      switch (fds[fd]->get_device ())
+       {
+       case FH_SOCKET:
+         dec_need_fixup_before ();
+       case FH_CONSOLE:
+         dec_console_fds ();
+       }
       delete fds[fd];
       fds[fd] = NULL;
     }
@@ -261,6 +273,7 @@ dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit)
       case FH_CONIN:
       case FH_CONOUT:
        fh = new (buf) fhandler_console (name);
+       inc_console_fds ();
        break;
       case FH_PTYM:
        fh = new (buf) fhandler_pty_master (name);
index f81d916b7e5d8da66818b2a07e5ebd384070b0fd..bfeffa36bf03c654972ce6efb83a57d2f659ba89 100644 (file)
@@ -1,6 +1,6 @@
 /* dtable.h: fd table definition.
 
-   Copyright 2000 Red Hat, Inc.
+   Copyright 2000, 2001 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -19,19 +19,26 @@ class dtable
   fhandler_base **fds_on_hold;
   int first_fd_for_open;
   int cnt_need_fixup_before;
+  int console_fds;
 public:
   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 dec_need_fixup_before ()
     { if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; }
   void inc_need_fixup_before ()
-    { ++cnt_need_fixup_before; }
+    { cnt_need_fixup_before++; }
   BOOL need_fixup_before ()
     { 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 ();
   void vfork_parent_restore ();
   void vfork_child_fixup ();
index 3c91984753a9a65ea68945fa70d7d8f2a8b6d84e..7a2061aa5a0f108742092ea1453c10c6f9ae458d 100644 (file)
@@ -895,14 +895,20 @@ ctrl_c_handler (DWORD type)
   if (type == CTRL_LOGOFF_EVENT)
     return TRUE;
 
-  if ((type == CTRL_CLOSE_EVENT) || (type == CTRL_SHUTDOWN_EVENT))
-    /* Return FALSE to prevent an "End task" dialog box from appearing
-       for each Cygwin process window that's open when the computer
-       is shut down or console window is closed. */
+  /* Return FALSE to prevent an "End task" dialog box from appearing
+     for each Cygwin process window that's open when the computer
+     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);
       return FALSE;
     }
+
   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
      *by* the process group leader. */
index c8b9cb406c27361b2ae7f35fbfd57a2780d3af37..7e37278da62c672aa966cfc490d5e1fefccb3d99 100644 (file)
@@ -240,6 +240,8 @@ setsid (void)
   /* FIXME: for now */
   if (myself->pgid != _getpid ())
     {
+      if (myself->ctty == TTY_CONSOLE && !cygheap->fdtab.has_console_fds ())
+       FreeConsole ();
       myself->ctty = -1;
       myself->sid = _getpid ();
       myself->pgid = _getpid ();
This page took 0.042493 seconds and 5 git commands to generate.