* dtable.cc (dtable::delete_archetype): Improve debugging output.
(dtable::init_std_file_from_handle): Close console handle early, before initialization. Build up openflags for passing to open_setup, just to be safe. (last_tty_dev): New variable. (fh_last_tty_dev): New macro. (fh_alloc): Try again to keep track of previously opened tty, this time by just saving the device and using that to potentially open an archetype. Avoid setting the "/dev/tty" name if the creation of the fhandler failed. (build_fh_pc): Remove unused second argument. Reorganize how and where the name is set. Set last_tty_dev as appropriate. Avoid a NULL dereference in a debug printf. * dtable.h (build_fh_pc): Reflect removal of second parameter. * fhandler.cc (fhandler_base::reset): Use new '<<' operator to copy pc since it preserves any potentially previously set name. (fhandler_base::set_name): Ditto. * fhandler.h (fhandler_*::clone): Throughout use ccalloc to allocate new fhandler, primarily to make sure that pc field is properly zeroed. (fhandler_termios::last): Eliminate. (fhandler_termios): Remove setting of last. (fhandler_base::~fhandler_termios): Ditto. * fhandler_console.cc (fhandler_console::open): Don't make decisions about opening close-on-exec handles here since it makes no sense for archetypes. (fhandler_console::init): Assume that input handle has already been opened. * fhandler_termios.cc (fhandler_termios::last): Delete. * path.h (path_conv::eq_worker): New function. Move bulk of operator = here. (operator <<): New function. (operator =): Use eq_worker to perform old functionality.
This commit is contained in:
		| @@ -1,3 +1,38 @@ | ||||
| 2011-10-21  Christopher Faylor  <me.cygwin2011@cgf.cx> | ||||
|  | ||||
| 	* dtable.cc (dtable::delete_archetype): Improve debugging output. | ||||
| 	(dtable::init_std_file_from_handle): Close console handle early, before | ||||
| 	initialization.  Build up openflags for passing to open_setup, just to | ||||
| 	be safe. | ||||
| 	(last_tty_dev): New variable. | ||||
| 	(fh_last_tty_dev): New macro. | ||||
| 	(fh_alloc): Try again to keep track of previously opened tty, this time | ||||
| 	by just saving the device and using that to potentially open an | ||||
| 	archetype.  Avoid setting the "/dev/tty" name if the creation of the | ||||
| 	fhandler failed. | ||||
| 	(build_fh_pc): Remove unused second argument.  Reorganize how and where | ||||
| 	the name is set.  Set last_tty_dev as appropriate.  Avoid a NULL | ||||
| 	dereference in a debug printf. | ||||
| 	* dtable.h (build_fh_pc): Reflect removal of second parameter. | ||||
| 	* fhandler.cc (fhandler_base::reset): Use new '<<' operator to copy pc | ||||
| 	since it preserves any potentially previously set name. | ||||
| 	(fhandler_base::set_name): Ditto. | ||||
| 	* fhandler.h (fhandler_*::clone): Throughout use ccalloc to allocate | ||||
| 	new fhandler, primarily to make sure that pc field is properly zeroed. | ||||
| 	(fhandler_termios::last): Eliminate. | ||||
| 	(fhandler_termios): Remove setting of last. | ||||
| 	(fhandler_base::~fhandler_termios): Ditto. | ||||
| 	* fhandler_console.cc (fhandler_console::open): Don't make decisions | ||||
| 	about opening close-on-exec handles here since it makes no sense for | ||||
| 	archetypes. | ||||
| 	(fhandler_console::init): Assume that input handle has already been | ||||
| 	opened. | ||||
| 	* fhandler_termios.cc (fhandler_termios::last): Delete. | ||||
| 	* path.h (path_conv::eq_worker): New function.  Move bulk of operator = | ||||
| 	here. | ||||
| 	(operator <<): New function. | ||||
| 	(operator =): Use eq_worker to perform old functionality. | ||||
|  | ||||
| 2011-10-21  Corinna Vinschen  <corinna@vinschen.de> | ||||
|  | ||||
| 	* fhandler_disk_file.cc (fhandler_disk_file::rmdir): Check invalid | ||||
|   | ||||
| @@ -40,6 +40,8 @@ enum child_status | ||||
| /* Change this value if you get a message indicating that it is out-of-sync. */ | ||||
| #define CURR_CHILD_INFO_MAGIC 0x29afd207U | ||||
|  | ||||
| #define NPROCS	256 | ||||
|  | ||||
| /* NOTE: Do not make gratuitous changes to the names or organization of the | ||||
|    below class.  The layout is checksummed to determine compatibility between | ||||
|    different cygwin versions. */ | ||||
| @@ -54,6 +56,8 @@ public: | ||||
|   HANDLE subproc_ready;	// used for synchronization with parent | ||||
|   HANDLE user_h; | ||||
|   HANDLE parent; | ||||
|   int nprocs; | ||||
|   pid_t children[NPROCS]; | ||||
|   init_cygheap *cygheap; | ||||
|   void *cygheap_max; | ||||
|   DWORD cygheap_reserve_sz; | ||||
|   | ||||
| @@ -217,7 +217,8 @@ dtable::delete_archetype (fhandler_base *fh) | ||||
|   for (unsigned i = 0; i < farchetype; i++) | ||||
|     if (fh == archetypes[i]) | ||||
|       { | ||||
| 	debug_printf ("deleting element %d for %s", i, fh->get_name ()); | ||||
| 	debug_printf ("deleting element %d for %s(%d/%d)", i, fh->get_name (), | ||||
| 		      fh->dev ().get_major (), fh->dev ().get_minor ()); | ||||
| 	if (i < --farchetype) | ||||
| 	  archetypes[i] = archetypes[farchetype]; | ||||
| 	break; | ||||
| @@ -314,7 +315,11 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) | ||||
|       if (myself->ctty > 0) | ||||
| 	dev.parse (myself->ctty); | ||||
|       else | ||||
| 	dev.parse (FH_CONSOLE); | ||||
| 	{ | ||||
| 	  dev.parse (FH_CONSOLE); | ||||
| 	  CloseHandle (handle); | ||||
| 	  handle = INVALID_HANDLE_VALUE; | ||||
| 	} | ||||
|     } | ||||
|   else if (GetCommState (handle, &dcb)) | ||||
|     /* FIXME: Not right - assumes ttyS0 */ | ||||
| @@ -347,48 +352,48 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) | ||||
|  | ||||
|       IO_STATUS_BLOCK io; | ||||
|       FILE_ACCESS_INFORMATION fai; | ||||
|       int openflags = O_BINARY; | ||||
|  | ||||
|       /* Console windows are not kernel objects, so the access mask returned | ||||
| 	 by NtQueryInformationFile is meaningless.  CMD always hands down | ||||
| 	 stdin handles as R/O handles, but our tty slave sides are R/W. */ | ||||
|       if (dev == FH_TTY || iscons_dev (dev) || dev.get_major () == DEV_PTYS_MAJOR) | ||||
| 	access |= GENERIC_READ | GENERIC_WRITE; | ||||
|       else if (NT_SUCCESS (NtQueryInformationFile (handle, &io, &fai, | ||||
| 						   sizeof fai, | ||||
| 						   FileAccessInformation))) | ||||
|       if (!iscons_dev (dev) && fh->is_tty ()) | ||||
| 	{ | ||||
| 	  openflags |= O_RDWR; | ||||
| 	  access |= GENERIC_READ | GENERIC_WRITE; | ||||
| 	} | ||||
|       else if (!iscons_dev (dev) | ||||
| 	       && NT_SUCCESS (NtQueryInformationFile (handle, &io, &fai, | ||||
| 						      sizeof fai, | ||||
| 						      FileAccessInformation))) | ||||
| 	{ | ||||
| 	  if (fai.AccessFlags & FILE_READ_DATA) | ||||
| 	    access |= GENERIC_READ; | ||||
| 	  if (fai.AccessFlags & FILE_WRITE_DATA) | ||||
| 	    access |= GENERIC_WRITE; | ||||
| 	    { | ||||
| 	      openflags |= O_WRONLY; | ||||
| 	      access |= GENERIC_WRITE; | ||||
| 	    } | ||||
| 	  if (fai.AccessFlags & FILE_READ_DATA) | ||||
| 	    { | ||||
| 	      openflags |= openflags & O_WRONLY ? O_RDWR : O_RDONLY; | ||||
| 	      access |= GENERIC_READ; | ||||
| 	    } | ||||
| 	} | ||||
|       else if (fd == 0) | ||||
| 	access |= GENERIC_READ; | ||||
| 	{ | ||||
| 	  openflags |= O_RDONLY; | ||||
| 	  access |= GENERIC_READ; | ||||
| 	} | ||||
|       else | ||||
| 	access |= GENERIC_WRITE;  /* Should be rdwr for stderr but not sure that's | ||||
| 				    possible for some versions of handles */ | ||||
|       /* FIXME: Workaround Windows 7 issue.  If the parent process of | ||||
| 	 the process tree closes the original handles to the console window, | ||||
| 	 strange problems occur when starting child processes later on if | ||||
| 	 stdio redirection is used. | ||||
|  | ||||
| 	 CV 2009-08-08:  It looks like this problem has been fixed only | ||||
| 	 half-heartedly in RTM.  Unfortunately the new implementation | ||||
| 	 has still a problem which now also occurs on the 32 bit release | ||||
| 	 of Windows 7.  It's still not quite clear what happens but it's | ||||
| 	 easily reproducible.  Just start X via the start menu entry. | ||||
| 	 This opens an xterm window with a shell.  Exit from the shell, | ||||
| 	 and you get a Windows error box reporting a crash in the | ||||
| 	 Console Window Host application (conhost.exe) due to an access | ||||
| 	 violation. | ||||
|  | ||||
| 	 This needs further investigation but the workaround not to close | ||||
| 	 the handles will have a marginal hit of three extra handles per | ||||
| 	 process at most. */ | ||||
|       if (!fh->init (iscons_dev (dev) && wincap.has_console_handle_problem () | ||||
| 		     ? INVALID_HANDLE_VALUE : handle, access, bin)) | ||||
| 	{ | ||||
| 	  openflags |= O_WRONLY; | ||||
| 	  access |= GENERIC_WRITE;  /* Should be rdwr for stderr but not sure that's | ||||
| 				       possible for some versions of handles */ | ||||
| 	} | ||||
|       if (!fh->init (handle, access, bin)) | ||||
| 	api_fatal ("couldn't initialize fd %d for %s", fd, fh->get_name ()); | ||||
|  | ||||
|       fh->open_setup (openflags); | ||||
|       fh->usecount = 0; | ||||
|       cygheap->fdtab[fd] = fh; | ||||
|       set_std_handle (fd); | ||||
|       paranoid_printf ("fd %d, handle %p", fd, handle); | ||||
| @@ -435,6 +440,8 @@ build_fh_dev (const device& dev, const char *unix_name) | ||||
| } | ||||
|  | ||||
| #define fh_unset ((fhandler_base *) 1) | ||||
| static device last_tty_dev; | ||||
| #define fh_last_tty_dev ((fhandler_termios *) cygheap->fdtab.find_archetype (last_tty_dev)) | ||||
|  | ||||
| static fhandler_base * | ||||
| fh_alloc (path_conv& pc) | ||||
| @@ -555,17 +562,22 @@ fh_alloc (path_conv& pc) | ||||
| 	  break; | ||||
| 	case FH_TTY: | ||||
| 	  if (!pc.isopen ()) | ||||
| 	    fhraw = cnew_no_ctor (fhandler_console, -1);  | ||||
| 	  else if (myself->ctty <= 0 | ||||
| 		   && !myself->set_ctty (fhandler_termios::last, 0)) | ||||
| 	    /* no tty assigned */; | ||||
| 	  else | ||||
| 	    { | ||||
| 	      fhraw = cnew_no_ctor (fhandler_console, -1);  | ||||
| 	      debug_printf ("not called from open for /dev/tty"); | ||||
| 	    } | ||||
| 	  else if (myself->ctty <= 0 && last_tty_dev | ||||
| 		   && !myself->set_ctty (fh_last_tty_dev, 0)) | ||||
| 	    debug_printf ("no /dev/tty assigned"); | ||||
| 	  else if (myself->ctty > 0) | ||||
| 	    { | ||||
| 	      debug_printf ("determining /dev/tty assignment for ctty %p", myself->ctty); | ||||
| 	      if (iscons_dev (myself->ctty)) | ||||
| 		fh = cnew (fhandler_console, pc.dev); | ||||
| 	      else | ||||
| 		fh = cnew (fhandler_pty_slave, myself->ctty); | ||||
| 	      fh->set_name ("/dev/tty"); | ||||
| 	      if (fh->dev () != FH_NADA) | ||||
| 		fh->set_name ("/dev/tty"); | ||||
| 	    } | ||||
| 	  break; | ||||
| 	case FH_KMSG: | ||||
| @@ -595,7 +607,7 @@ fh_alloc (path_conv& pc) | ||||
| } | ||||
|  | ||||
| fhandler_base * | ||||
| build_fh_pc (path_conv& pc, bool set_name) | ||||
| build_fh_pc (path_conv& pc) | ||||
| { | ||||
|   fhandler_base *fh = fh_alloc (pc); | ||||
|  | ||||
| @@ -604,35 +616,38 @@ build_fh_pc (path_conv& pc, bool set_name) | ||||
|       set_errno (ENXIO); | ||||
|       goto out; | ||||
|     } | ||||
|   else if (fh->get_name ()) | ||||
|     /* already got one */; | ||||
|   else if (fh->dev () != FH_NADA) | ||||
|     fh->set_name (fh->dev ().name); | ||||
|   else if (set_name) | ||||
|     fh->set_name (pc); | ||||
|  | ||||
|   if (!fh->use_archetype ()) | ||||
|     /* doesn't use archetypes */; | ||||
|     fh->set_name (pc); | ||||
|   else if ((fh->archetype = cygheap->fdtab.find_archetype (fh->dev ()))) | ||||
|     debug_printf ("found an archetype for %s(%d/%d) io_handle %p", fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor (), | ||||
| 		  fh->archetype->get_io_handle ()); | ||||
|     { | ||||
|       debug_printf ("found an archetype for %s(%d/%d) io_handle %p", fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor (), | ||||
| 		    fh->archetype->get_io_handle ()); | ||||
|       if (!fh->get_name ()) | ||||
| 	fh->set_name (fh->archetype->dev ().name); | ||||
|     } | ||||
|   else if (cygwin_finished_initializing && !pc.isopen ()) | ||||
|     fh->set_name (pc); | ||||
|   else | ||||
|     { | ||||
|       if (!fh->get_name ()) | ||||
| 	fh->set_name (fh->dev ().name); | ||||
|       fh->archetype = fh->clone (); | ||||
|       debug_printf ("created an archetype (%p) for %s(%d/%d)", fh->archetype, fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor ()); | ||||
|       fh->archetype->archetype = NULL; | ||||
|       *cygheap->fdtab.add_archetype () = fh->archetype; | ||||
|     } | ||||
|  | ||||
|   /* The fhandler_termios constructor keeps track of the last tty-like thing | ||||
|      opened but we're only interested in this if we don't have a controlling | ||||
|      terminal since we could potentially want to open it if /dev/tty is | ||||
|      referenced. */ | ||||
|  | ||||
|   /* Keep track of the last tty-like thing opened.  We could potentially want | ||||
|      to open it if /dev/tty is referenced. */ | ||||
|   if (myself->ctty > 0 || !fh->is_tty () || !pc.isctty_capable ()) | ||||
|     fhandler_termios::last = NULL; | ||||
|     last_tty_dev = FH_NADA; | ||||
|   else | ||||
|     last_tty_dev = fh->dev (); | ||||
|  | ||||
| out: | ||||
|   debug_printf ("fh %p, dev %p", fh, (DWORD) fh->dev ()); | ||||
|   debug_printf ("fh %p, dev %p", fh, fh ? (DWORD) fh->dev () : 0); | ||||
|   return fh; | ||||
| } | ||||
|  | ||||
| @@ -668,9 +683,10 @@ dtable::dup_worker (fhandler_base *oldfh, int flags) | ||||
| 	  debug_printf ("duped output_handles old %p, new %p", | ||||
| 			oldfh->get_output_handle (), | ||||
| 			newfh->get_output_handle ()); | ||||
| 	  debug_printf ("duped output_handles archetype old %p, archetype new %p", | ||||
| 			oldfh->archetype->get_output_handle (), | ||||
| 			newfh->archetype->get_output_handle ()); | ||||
| 	  if (oldfh->archetype) | ||||
| 	    debug_printf ("duped output_handles archetype old %p, archetype new %p", | ||||
| 			  oldfh->archetype->get_output_handle (), | ||||
| 			  newfh->archetype->get_output_handle ()); | ||||
| #endif /*DEBUGGING*/ | ||||
| 	} | ||||
|     } | ||||
|   | ||||
| @@ -95,7 +95,7 @@ public: | ||||
|  | ||||
| fhandler_base *build_fh_dev (const device&, const char * = NULL); | ||||
| fhandler_base *build_fh_name (const char *, unsigned = 0, suffix_info * = NULL); | ||||
| fhandler_base *build_fh_pc (path_conv& pc, bool set_name = true); | ||||
| fhandler_base *build_fh_pc (path_conv& pc); | ||||
|  | ||||
| void dtable_init (); | ||||
| void stdio_init (); | ||||
|   | ||||
| @@ -40,7 +40,7 @@ struct __cygwin_perfile *perfile_table; | ||||
| void | ||||
| fhandler_base::reset (const fhandler_base *from) | ||||
| { | ||||
|   pc = from->pc; | ||||
|   pc << from->pc; | ||||
|   rabuf = NULL; | ||||
|   ralen = 0; | ||||
|   raixget = 0; | ||||
| @@ -148,7 +148,7 @@ fhandler_base::get_readahead_into_buffer (char *buf, size_t buflen) | ||||
| void | ||||
| fhandler_base::set_name (path_conv &in_pc) | ||||
| { | ||||
|   pc = in_pc; | ||||
|   pc << in_pc; | ||||
| } | ||||
|  | ||||
| char *fhandler_base::get_proc_fd_name (char *buf) | ||||
|   | ||||
| @@ -437,7 +437,7 @@ public: | ||||
|  | ||||
|   virtual fhandler_base *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_base));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_base));  | ||||
|     fhandler_base *fh = new (ptr) fhandler_base (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -604,7 +604,7 @@ class fhandler_socket: public fhandler_base | ||||
|  | ||||
|   fhandler_socket *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_socket));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_socket));  | ||||
|     fhandler_socket *fh = new (ptr) fhandler_socket (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -658,7 +658,7 @@ public: | ||||
|  | ||||
|   virtual fhandler_base_overlapped *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_base_overlapped));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_base_overlapped));  | ||||
|     fhandler_base_overlapped *fh = new (ptr) fhandler_base_overlapped (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -704,7 +704,7 @@ public: | ||||
|  | ||||
|   fhandler_pipe *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_pipe));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_pipe));  | ||||
|     fhandler_pipe *fh = new (ptr) fhandler_pipe (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -754,7 +754,7 @@ public: | ||||
|  | ||||
|   fhandler_fifo *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_fifo));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_fifo));  | ||||
|     fhandler_fifo *fh = new (ptr) fhandler_fifo (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -783,7 +783,7 @@ class fhandler_mailslot : public fhandler_base_overlapped | ||||
|  | ||||
|   fhandler_mailslot *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_mailslot));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_mailslot));  | ||||
|     fhandler_mailslot *fh = new (ptr) fhandler_mailslot (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -832,7 +832,7 @@ class fhandler_dev_raw: public fhandler_base | ||||
|  | ||||
|   fhandler_dev_raw *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_raw));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_raw));  | ||||
|     fhandler_dev_raw *fh = new (ptr) fhandler_dev_raw (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -892,7 +892,7 @@ class fhandler_dev_floppy: public fhandler_dev_raw | ||||
|  | ||||
|   fhandler_dev_floppy *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_floppy));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_floppy));  | ||||
|     fhandler_dev_floppy *fh = new (ptr) fhandler_dev_floppy (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -940,7 +940,7 @@ class fhandler_dev_tape: public fhandler_dev_raw | ||||
|  | ||||
|   fhandler_dev_tape *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_tape));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_tape));  | ||||
|     fhandler_dev_tape *fh = new (ptr) fhandler_dev_tape (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1006,7 +1006,7 @@ class fhandler_disk_file: public fhandler_base | ||||
|  | ||||
|   fhandler_disk_file *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_disk_file));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_disk_file));  | ||||
|     fhandler_disk_file *fh = new (ptr) fhandler_disk_file (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1044,7 +1044,7 @@ class fhandler_cygdrive: public fhandler_disk_file | ||||
|  | ||||
|   fhandler_cygdrive *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_cygdrive));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_cygdrive));  | ||||
|     fhandler_cygdrive *fh = new (ptr) fhandler_cygdrive (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1108,7 +1108,7 @@ class fhandler_serial: public fhandler_base | ||||
|  | ||||
|   fhandler_serial *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_serial));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_serial));  | ||||
|     fhandler_serial *fh = new (ptr) fhandler_serial (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1134,18 +1134,11 @@ class fhandler_termios: public fhandler_base | ||||
|   tty_min *_tc; | ||||
|   tty *get_ttyp () {return (tty *) tc ();} | ||||
|  public: | ||||
|   static fhandler_termios *last; | ||||
|   tty_min*& tc () {return _tc;} | ||||
|   fhandler_termios () : | ||||
|   fhandler_base () | ||||
|   { | ||||
|     need_fork_fixup (true); | ||||
|     last = this; | ||||
|   } | ||||
|   ~fhandler_termios () | ||||
|   { | ||||
|     if (this == last) | ||||
|       last = NULL; | ||||
|   } | ||||
|   HANDLE& get_output_handle () { return output_handle; } | ||||
|   line_edit_status line_edit (const char *rptr, int nread, termios&); | ||||
| @@ -1173,7 +1166,7 @@ class fhandler_termios: public fhandler_base | ||||
|  | ||||
|   virtual fhandler_termios *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_termios));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_termios));  | ||||
|     fhandler_termios *fh = new (ptr) fhandler_termios (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1372,7 +1365,7 @@ private: | ||||
|  | ||||
|   fhandler_console *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_console));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_console));  | ||||
|     fhandler_console *fh = new (ptr) fhandler_console (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1415,7 +1408,7 @@ class fhandler_pty_common: public fhandler_termios | ||||
|  | ||||
|   virtual fhandler_pty_common *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_pty_common));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_pty_common));  | ||||
|     fhandler_pty_common *fh = new (ptr) fhandler_pty_common (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1469,7 +1462,7 @@ class fhandler_pty_slave: public fhandler_pty_common | ||||
|  | ||||
|   fhandler_pty_slave *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_pty_slave));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_pty_slave));  | ||||
|     fhandler_pty_slave *fh = new (ptr) fhandler_pty_slave (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1527,7 +1520,7 @@ public: | ||||
|  | ||||
|   fhandler_pty_master *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_pty_master));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_pty_master));  | ||||
|     fhandler_pty_master *fh = new (ptr) fhandler_pty_master (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1554,7 +1547,7 @@ class fhandler_dev_null: public fhandler_base | ||||
|  | ||||
|   fhandler_dev_null *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_null));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_null));  | ||||
|     fhandler_dev_null *fh = new (ptr) fhandler_dev_null (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1589,7 +1582,7 @@ class fhandler_dev_zero: public fhandler_base | ||||
|  | ||||
|   fhandler_dev_zero *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_zero));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_zero));  | ||||
|     fhandler_dev_zero *fh = new (ptr) fhandler_dev_zero (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1627,7 +1620,7 @@ class fhandler_dev_random: public fhandler_base | ||||
|  | ||||
|   fhandler_dev_random *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_random));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_random));  | ||||
|     fhandler_dev_random *fh = new (ptr) fhandler_dev_random (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1667,7 +1660,7 @@ class fhandler_dev_mem: public fhandler_base | ||||
|  | ||||
|   fhandler_dev_mem *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_mem));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_mem));  | ||||
|     fhandler_dev_mem *fh = new (ptr) fhandler_dev_mem (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1703,7 +1696,7 @@ class fhandler_dev_clipboard: public fhandler_base | ||||
|  | ||||
|   fhandler_dev_clipboard *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_clipboard));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_clipboard));  | ||||
|     fhandler_dev_clipboard *fh = new (ptr) fhandler_dev_clipboard (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1742,7 +1735,7 @@ class fhandler_windows: public fhandler_base | ||||
|  | ||||
|   fhandler_windows *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_windows));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_windows));  | ||||
|     fhandler_windows *fh = new (ptr) fhandler_windows (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1789,7 +1782,7 @@ class fhandler_dev_dsp: public fhandler_base | ||||
|  | ||||
|   fhandler_dev_dsp *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_dev_dsp));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_dev_dsp));  | ||||
|     fhandler_dev_dsp *fh = new (ptr) fhandler_dev_dsp (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1840,7 +1833,7 @@ class fhandler_virtual : public fhandler_base | ||||
|  | ||||
|   virtual fhandler_virtual *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_virtual));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_virtual));  | ||||
|     fhandler_virtual *fh = new (ptr) fhandler_virtual (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1872,7 +1865,7 @@ class fhandler_proc: public fhandler_virtual | ||||
|  | ||||
|   virtual fhandler_proc *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_proc));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_proc));  | ||||
|     fhandler_proc *fh = new (ptr) fhandler_proc (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1908,7 +1901,7 @@ class fhandler_procsys: public fhandler_virtual | ||||
|  | ||||
|   fhandler_procsys *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_procsys));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_procsys));  | ||||
|     fhandler_procsys *fh = new (ptr) fhandler_procsys (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1937,7 +1930,7 @@ class fhandler_procsysvipc: public fhandler_proc | ||||
|  | ||||
|   fhandler_procsysvipc *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_procsysvipc));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_procsysvipc));  | ||||
|     fhandler_procsysvipc *fh = new (ptr) fhandler_procsysvipc (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -1967,7 +1960,7 @@ class fhandler_netdrive: public fhandler_virtual | ||||
|  | ||||
|   fhandler_netdrive *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_netdrive));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_netdrive));  | ||||
|     fhandler_netdrive *fh = new (ptr) fhandler_netdrive (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -2007,7 +2000,7 @@ class fhandler_registry: public fhandler_proc | ||||
|  | ||||
|   fhandler_registry *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_registry));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_registry));  | ||||
|     fhandler_registry *fh = new (ptr) fhandler_registry (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -2039,7 +2032,7 @@ class fhandler_process: public fhandler_proc | ||||
|  | ||||
|   fhandler_process *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_process));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_process));  | ||||
|     fhandler_process *fh = new (ptr) fhandler_process (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
| @@ -2068,7 +2061,7 @@ class fhandler_procnet: public fhandler_proc | ||||
|  | ||||
|   fhandler_procnet *clone () | ||||
|   { | ||||
|     void *ptr = (void *) cmalloc (HEAP_FHANDLER, sizeof (fhandler_procnet));  | ||||
|     void *ptr = (void *) ccalloc (HEAP_FHANDLER, 1, sizeof (fhandler_procnet));  | ||||
|     fhandler_procnet *fh = new (ptr) fhandler_procnet (ptr);  | ||||
|     copyto (fh); | ||||
|     return fh; | ||||
|   | ||||
| @@ -784,7 +784,7 @@ fhandler_console::open (int flags, mode_t) | ||||
|  | ||||
|   /* Open the input handle as handle_ */ | ||||
|   h = CreateFile ("CONIN$", GENERIC_READ | GENERIC_WRITE, | ||||
| 		  FILE_SHARE_READ | FILE_SHARE_WRITE, sec_none_cloexec (flags), | ||||
| 		  FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none, | ||||
| 		  OPEN_EXISTING, 0, 0); | ||||
|  | ||||
|   if (h == INVALID_HANDLE_VALUE) | ||||
| @@ -795,7 +795,7 @@ fhandler_console::open (int flags, mode_t) | ||||
|   set_io_handle (h); | ||||
|  | ||||
|   h = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE, | ||||
| 		  FILE_SHARE_READ | FILE_SHARE_WRITE, sec_none_cloexec (flags), | ||||
| 		  FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none, | ||||
| 		  OPEN_EXISTING, 0, 0); | ||||
|  | ||||
|   if (h == INVALID_HANDLE_VALUE) | ||||
| @@ -2197,8 +2197,6 @@ fhandler_console::init (HANDLE h, DWORD a, mode_t bin) | ||||
|   if (a == (GENERIC_READ | GENERIC_WRITE)) | ||||
|     flags = O_RDWR; | ||||
|   open_with_arch (flags | O_BINARY | (h ? 0 : O_NOCTTY)); | ||||
|   if (h && h != INVALID_HANDLE_VALUE) | ||||
|     CloseHandle (h);	/* Reopened by open */ | ||||
|  | ||||
|   return !tcsetattr (0, &get_ttyp ()->ti); | ||||
| } | ||||
|   | ||||
| @@ -21,8 +21,6 @@ details. */ | ||||
| #include "cygtls.h" | ||||
| #include "ntdll.h" | ||||
|  | ||||
| fhandler_termios *fhandler_termios::last; | ||||
|  | ||||
| /* Common functions shared by tty/console */ | ||||
|  | ||||
| void | ||||
|   | ||||
| @@ -16,6 +16,7 @@ details. */ | ||||
|  | ||||
| #include <sys/ioctl.h> | ||||
| #include <fcntl.h> | ||||
| #include <alloca.h> | ||||
|  | ||||
| inline bool | ||||
| has_attribute (DWORD attributes, DWORD attribs_to_test) | ||||
| @@ -294,11 +295,12 @@ class path_conv | ||||
|     cfree_and_null (normalized_path); | ||||
|     cfree_and_null (wide_path); | ||||
|   } | ||||
|   path_conv &operator =(const path_conv& pc) | ||||
|   path_conv& eq_worker (const path_conv& pc, const char *in_path, | ||||
| 			const char *in_normalized_path) | ||||
|   { | ||||
|     free_strings (); | ||||
|     memcpy (this, &pc, sizeof pc); | ||||
|     path = cstrdup (pc.path); | ||||
|     path = cstrdup (in_path); | ||||
|     conv_handle.dup (pc.conv_handle); | ||||
|     normalized_path = cstrdup(pc.normalized_path); | ||||
|     if (pc.wide_path) | ||||
| @@ -310,6 +312,32 @@ class path_conv | ||||
|       } | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
|   path_conv &operator << (const path_conv& pc) | ||||
|   { | ||||
|     const char *save_path; | ||||
|     const char *save_normalized_path; | ||||
|     if (!path) | ||||
|       save_path = pc.path; | ||||
|     else | ||||
|       { | ||||
| 	save_path = (char *) alloca (strlen (path) + 1); | ||||
| 	strcpy ((char *) save_path, path); | ||||
|       } | ||||
|     if (!normalized_path) | ||||
|       save_normalized_path = pc.normalized_path; | ||||
|     else | ||||
|       { | ||||
| 	save_normalized_path = (char *) alloca (strlen (normalized_path) + 1); | ||||
| 	strcpy ((char *) save_normalized_path, path); | ||||
|       } | ||||
|     return eq_worker (pc, save_path, save_normalized_path); | ||||
|   } | ||||
|  | ||||
|   path_conv &operator =(const path_conv& pc) | ||||
|   { | ||||
|     return eq_worker (pc, pc.path, pc.normalized_path); | ||||
|   } | ||||
|   DWORD get_devn () {return (DWORD) dev;} | ||||
|   short get_unitn () const {return dev.get_minor ();} | ||||
|   DWORD file_attributes () const {return fileattr;} | ||||
|   | ||||
| @@ -375,6 +375,9 @@ _pinfo::_ctty (char *buf) | ||||
| bool | ||||
| _pinfo::set_ctty (fhandler_termios *fh, int flags) | ||||
| { | ||||
| debug_printf ("fh %p", fh); | ||||
| debug_printf ("tc %p", fh->tc ()); | ||||
| if (!this || !fh->tc ()) try_to_debug (); | ||||
|   tty_min& tc = *fh->tc (); | ||||
|   debug_printf ("old %s, ctty device number %p, tc.ntty device number %p flags & O_NOCTTY %p", __ctty (), ctty, tc.ntty, flags & O_NOCTTY); | ||||
|   if (fh && &tc && (ctty <= 0 || ctty == tc.ntty) && !(flags & O_NOCTTY)) | ||||
|   | ||||
| @@ -33,8 +33,6 @@ details. */ | ||||
|  | ||||
| #define no_signals_available(x) (!my_sendsig || ((x) && myself->exitcode & EXITCODE_SET) || (&_my_tls == _sig_tls)) | ||||
|  | ||||
| #define NPROCS	256 | ||||
|  | ||||
| /* | ||||
|  * Global variables | ||||
|  */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user