* fhandler.h (fhandler_tty_slave::archetype): Make public.
(report_tty_counts): New macro. Use throughout for reporting tty use counts. * dtable.cc (dtable::vfork_child_dup): Add debugging output for usecount increment. Increment open_fhs if appropriate. (dtable::vfork_parent_restore): "Close" artificially bumped ctty. (dtable::vfork_child_fixup): Close ctty since it was bumped prior to vfork. Save open_fhs around close since the closing of these handles has no effect on the console. * fhandler_tty.cc (fhandler_tty_slave::open): Reorganize calls to allow for easier tracking of usecount modification. (fhandler_tty_slave::open): Ditto.
This commit is contained in:
		| @@ -1,3 +1,18 @@ | |||||||
|  | 2003-12-27  Christopher Faylor  <cgf@redhat.com> | ||||||
|  |  | ||||||
|  | 	* fhandler.h (fhandler_tty_slave::archetype): Make public. | ||||||
|  | 	(report_tty_counts): New macro.  Use throughout for reporting tty use | ||||||
|  | 	counts. | ||||||
|  | 	* dtable.cc (dtable::vfork_child_dup): Add debugging output for | ||||||
|  | 	usecount increment.  Increment open_fhs if appropriate. | ||||||
|  | 	(dtable::vfork_parent_restore): "Close" artificially bumped ctty. | ||||||
|  | 	(dtable::vfork_child_fixup): Close ctty since it was bumped prior to | ||||||
|  | 	vfork.  Save open_fhs around close since the closing of these handles | ||||||
|  | 	has no effect on the console. | ||||||
|  | 	* fhandler_tty.cc (fhandler_tty_slave::open): Reorganize calls to allow | ||||||
|  | 	for easier tracking of usecount modification. | ||||||
|  | 	(fhandler_tty_slave::open): Ditto. | ||||||
|  |  | ||||||
| 2003-12-26  Christopher Faylor  <cgf@redhat.com> | 2003-12-26  Christopher Faylor  <cgf@redhat.com> | ||||||
|  |  | ||||||
| 	* syscalls.cc (close_all_files): Simplify logic around closing ctty. | 	* syscalls.cc (close_all_files): Simplify logic around closing ctty. | ||||||
|   | |||||||
| @@ -215,9 +215,7 @@ cygheap_init () | |||||||
|   if (cygheap->ctty) |   if (cygheap->ctty) | ||||||
|     { |     { | ||||||
|       fhandler_console::open_fhs++; |       fhandler_console::open_fhs++; | ||||||
|       debug_printf ("tty%d, open_fhs %d, arch usecount %d", |       report_tty_counts (cygheap->ctty, "inherited", "incremented ", "unchanged "); | ||||||
| 		    cygheap->ctty->get_ttyp ()->ntty, |  | ||||||
| 		    fhandler_console::open_fhs, cygheap->ctty->usecount); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -31,6 +31,7 @@ details. */ | |||||||
| #include "dtable.h" | #include "dtable.h" | ||||||
| #include "cygheap.h" | #include "cygheap.h" | ||||||
| #include "ntdll.h" | #include "ntdll.h" | ||||||
|  | #include "tty.h" | ||||||
|  |  | ||||||
| static const NO_COPY DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, | static const NO_COPY DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, | ||||||
| 					   STD_ERROR_HANDLE}; | 					   STD_ERROR_HANDLE}; | ||||||
| @@ -701,7 +702,11 @@ dtable::vfork_child_dup () | |||||||
|   /* Remove impersonation */ |   /* Remove impersonation */ | ||||||
|   cygheap->user.deimpersonate (); |   cygheap->user.deimpersonate (); | ||||||
|   if (cygheap->ctty) |   if (cygheap->ctty) | ||||||
|     cygheap->ctty->usecount++; |     { | ||||||
|  |       cygheap->ctty->usecount++; | ||||||
|  |       fhandler_console::open_fhs++; | ||||||
|  |       report_tty_counts (cygheap->ctty, "vfork dup", "incremented ", ""); | ||||||
|  |     } | ||||||
|  |  | ||||||
|   for (size_t i = 0; i < size; i++) |   for (size_t i = 0; i < size; i++) | ||||||
|     if (not_open (i)) |     if (not_open (i)) | ||||||
| @@ -737,6 +742,9 @@ dtable::vfork_parent_restore () | |||||||
|   fds_on_hold = NULL; |   fds_on_hold = NULL; | ||||||
|   cfree (deleteme); |   cfree (deleteme); | ||||||
|  |  | ||||||
|  |   if (cygheap->ctty) | ||||||
|  |     cygheap->ctty->close (); | ||||||
|  |  | ||||||
|   ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore"); |   ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore"); | ||||||
|   return; |   return; | ||||||
| } | } | ||||||
| @@ -750,6 +758,7 @@ dtable::vfork_child_fixup () | |||||||
|   fhandler_base **saveme = fds; |   fhandler_base **saveme = fds; | ||||||
|   fds = fds_on_hold; |   fds = fds_on_hold; | ||||||
|  |  | ||||||
|  |   int old_open_fhs = fhandler_console::open_fhs; | ||||||
|   fhandler_base *fh; |   fhandler_base *fh; | ||||||
|   for (int i = 0; i < (int) size; i++) |   for (int i = 0; i < (int) size; i++) | ||||||
|     if ((fh = fds[i]) != NULL) |     if ((fh = fds[i]) != NULL) | ||||||
| @@ -764,6 +773,10 @@ dtable::vfork_child_fixup () | |||||||
| 	  } | 	  } | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  |   fhandler_console::open_fhs = old_open_fhs; | ||||||
|  |   if (cygheap->ctty) | ||||||
|  |     cygheap->ctty->close (); | ||||||
|  |  | ||||||
|   fds = saveme; |   fds = saveme; | ||||||
|   cfree (fds_on_hold); |   cfree (fds_on_hold); | ||||||
|   fds_on_hold = NULL; |   fds_on_hold = NULL; | ||||||
|   | |||||||
| @@ -122,9 +122,9 @@ class fhandler_base | |||||||
|   DWORD fs_flags; |   DWORD fs_flags; | ||||||
|   HANDLE read_state; |   HANDLE read_state; | ||||||
|   path_conv pc; |   path_conv pc; | ||||||
|   class fhandler_base *archetype; |  | ||||||
|  |  | ||||||
|  public: |  public: | ||||||
|  |   class fhandler_base *archetype; | ||||||
|   int usecount; |   int usecount; | ||||||
|  |  | ||||||
|   void set_name (path_conv &pc); |   void set_name (path_conv &pc); | ||||||
| @@ -1194,6 +1194,12 @@ struct fhandler_nodevice: public fhandler_base | |||||||
|   // int __stdcall fstat (struct __stat64 *buf, path_conv *); |   // int __stdcall fstat (struct __stat64 *buf, path_conv *); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | #define report_tty_counts(fh, call, fhs_op, use_op) \ | ||||||
|  |   termios_printf ("%s %s, %sopen_fhs %d, %susecount %d",\ | ||||||
|  | 		  fh->ttyname (), call,\ | ||||||
|  | 		  fhs_op, fhandler_console::open_fhs,\ | ||||||
|  | 		  use_op, ((fhandler_tty_slave *) fh)->archetype->usecount); | ||||||
|  |  | ||||||
| typedef union | typedef union | ||||||
| { | { | ||||||
|   char __base[sizeof (fhandler_base)]; |   char __base[sizeof (fhandler_base)]; | ||||||
|   | |||||||
| @@ -601,9 +601,8 @@ fhandler_tty_slave::open (int flags, mode_t) | |||||||
| out: | out: | ||||||
|   usecount = 0; |   usecount = 0; | ||||||
|   archetype->usecount++; |   archetype->usecount++; | ||||||
|  |   report_tty_counts (this, "opened", "incremented ", ""); | ||||||
|   myself->set_ctty (get_ttyp (), flags, arch); |   myself->set_ctty (get_ttyp (), flags, arch); | ||||||
|   termios_printf ("%s opened, incremented open_fhs %d, archetype usecount %d", |  | ||||||
| 		  pc.dev.name, fhandler_console::open_fhs, archetype->usecount); |  | ||||||
|  |  | ||||||
|   return 1; |   return 1; | ||||||
| } | } | ||||||
| @@ -613,9 +612,11 @@ fhandler_tty_slave::close () | |||||||
| { | { | ||||||
|   if (!--fhandler_console::open_fhs && myself->ctty == -1) |   if (!--fhandler_console::open_fhs && myself->ctty == -1) | ||||||
|     FreeConsole (); |     FreeConsole (); | ||||||
|   termios_printf ("decremented open_fhs %d, archetype usecount %d", |  | ||||||
| 		  fhandler_console::open_fhs, archetype->usecount); |   archetype->usecount--; | ||||||
|   if (--archetype->usecount) |   report_tty_counts (this, "closed", "decremented ", ""); | ||||||
|  |  | ||||||
|  |   if (archetype->usecount) | ||||||
|     { |     { | ||||||
| #ifdef DEBUGGING | #ifdef DEBUGGING | ||||||
|       if (archetype->usecount < 0) |       if (archetype->usecount < 0) | ||||||
| @@ -909,14 +910,13 @@ fhandler_tty_slave::read (void *ptr, size_t& len) | |||||||
| int | int | ||||||
| fhandler_tty_slave::dup (fhandler_base *child) | fhandler_tty_slave::dup (fhandler_base *child) | ||||||
| { | { | ||||||
|   fhandler_console::open_fhs++; |  | ||||||
|   fhandler_tty_slave *arch = (fhandler_tty_slave *) archetype; |   fhandler_tty_slave *arch = (fhandler_tty_slave *) archetype; | ||||||
|   *(fhandler_tty_slave *) child = *arch; |   *(fhandler_tty_slave *) child = *arch; | ||||||
|   arch->usecount++; |  | ||||||
|   child->usecount = 0; |   child->usecount = 0; | ||||||
|  |   arch->usecount++; | ||||||
|  |   fhandler_console::open_fhs++; | ||||||
|  |   report_tty_counts (child, "duped", "incremented ", ""); | ||||||
|   myself->set_ctty (get_ttyp (), openflags, arch); |   myself->set_ctty (get_ttyp (), openflags, arch); | ||||||
|   termios_printf ("incremented open_fhs %d, archetype usecount %d", |  | ||||||
| 		  fhandler_console::open_fhs, archetype->usecount); |  | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -293,8 +293,7 @@ _pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch) | |||||||
| 	    { | 	    { | ||||||
| 	      arch->usecount++; | 	      arch->usecount++; | ||||||
| 	      fhandler_console::open_fhs++; | 	      fhandler_console::open_fhs++; | ||||||
| 	      debug_printf ("tty%d, open_fhs %d, arch usecount %d", tc->ntty, | 	      report_tty_counts (cygheap->ctty, "ctty", "incremented ", ""); | ||||||
| 			    fhandler_console::open_fhs, arch->usecount); |  | ||||||
| 	    } | 	    } | ||||||
| 	} | 	} | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user