This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Make Cygwin damons easier to use on Win9x.


>>> On Wed, 27 Jun 2001 22:04:32 +1000
>>> "Robert Collins" <robert.collins@itdomain.com.au> said:

> perhaps a combination? If the last console handle closes and setsid() has
> already been called, || if setsid has been called and then the last console
> handle is closed.

like the following?

2001-06-27  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_LOGOFF_EVENT.

Index: syscalls.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/syscalls.cc,v
retrieving revision 1.125
diff -u -p -r1.125 syscalls.cc
--- syscalls.cc	2001/06/26 21:03:08	1.125
+++ syscalls.cc	2001/06/27 14:39:30
@@ -236,6 +236,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 ();
Index: dtable.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dtable.h,v
retrieving revision 1.9
diff -u -p -r1.9 dtable.h
--- dtable.h	2001/06/24 22:26:50	1.9
+++ dtable.h	2001/06/27 14:39:30
@@ -19,10 +19,11 @@ 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 ()
@@ -31,6 +32,12 @@ public:
     { ++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 ();
Index: dtable.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dtable.cc,v
retrieving revision 1.40
diff -u -p -r1.40 dtable.cc
--- dtable.cc	2001/06/24 22:26:50	1.40
+++ dtable.cc	2001/06/27 14:39:30
@@ -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 de
       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: exceptions.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/exceptions.cc,v
retrieving revision 1.90
diff -u -p -r1.90 exceptions.cc
--- exceptions.cc	2001/06/24 22:26:50	1.90
+++ exceptions.cc	2001/06/27 14:39:30
@@ -893,7 +893,10 @@ static BOOL WINAPI
 ctrl_c_handler (DWORD type)
 {
   if (type == CTRL_LOGOFF_EVENT)
-    return TRUE;
+    {
+      sig_send (NULL, SIGTERM);
+      return FALSE;
+    }
 
   if ((type == CTRL_CLOSE_EVENT) || (type == CTRL_SHUTDOWN_EVENT))
     /* Return FALSE to prevent an "End task" dialog box from appearing

____
  | AIST      Kazuhiro Fujieda <fujieda@jaist.ac.jp>
  | HOKURIKU  School of Information Science
o_/ 1990      Japan Advanced Institute of Science and Technology


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]