diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 1f5475995..0a702ffbd 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,9 @@
+Fri May 12 01:04:57 2000  Christopher Faylor <cgf@cygnus.com>
+
+	* Makefile.in (DLL_OFILES): Sort.
+	* fhandler_tty.cc (fhandler_tty_slave::send_ioctl_request): Eliminate.
+	(fhandler_tty_slave::ioctl): Rewrite to avoid races.
+
 2000-05-11  Mumit Khan  <khan@xraylith.wisc.edu>
 
 	* mmap.cc (list::erase): Increment loop counter.
diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 70c336f0e..b04b79a0c 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -118,20 +118,20 @@ DLL_IMPORTS:=$(w32api_lib)/libkernel32.a $(w32api_lib)/libadvapi32.a
 
 DLL_OFILES:=assert.o dcrt0.o debug.o delqueue.o dir.o dlfcn.o dll_init.o \
 	environ.o  errno.o exceptions.o exec.o external.o fcntl.o fhandler.o \
-	fhandler_console.o fhandler_serial.o fhandler_termios.o fhandler_tty.o \
-	fhandler_windows.o fhandler_raw.o fhandler_floppy.o fhandler_tape.o \
-        fhandler_zero.o fhandler_random.o \
-	fork.o glob.o grp.o heap.o hinfo.o init.o ioctl.o localtime.o malloc.o \
-	mmap.o net.o ntea.o passwd.o path.o pinfo.o pipe.o regexp.o regerror.o \
-	regsub.o registry.o resource.o scandir.o security.o select.o shared.o \
-	signal.o sigproc.o smallprint.o spawn.o strace.o strsep.o sync.o \
-	syscalls.o sysconf.o syslog.o termios.o times.o tty.o uinfo.o uname.o \
-	wait.o window.o \
+	fhandler_console.o fhandler_floppy.o fhandler_random.o fhandler_raw.o \
+	fhandler_serial.o fhandler_tape.o fhandler_termios.o fhandler_tty.o \
+	fhandler_windows.o fhandler_zero.o fork.o glob.o grp.o heap.o hinfo.o \
+	init.o ioctl.o localtime.o malloc.o mmap.o net.o ntea.o passwd.o \
+	path.o pinfo.o pipe.o regexp.o regerror.o regsub.o registry.o \
+	resource.o scandir.o security.o select.o shared.o signal.o sigproc.o \
+	smallprint.o spawn.o strace.o strsep.o sync.o syscalls.o sysconf.o \
+	syslog.o termios.o times.o tty.o uinfo.o uname.o wait.o window.o \
 	$(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MT_SAFE_OBJECTS)
 
 GMON_OFILES:= gmon.o mcount.o profil.o
 
-LD_STUFF=--dll $(DLL_OFILES) version.o winver.o $(DLL_IMPORTS) $(LIBM) $(LIBC) $(LIBGCC) -e $(DLL_ENTRY) --image-base=0x61000000
+LD_STUFF=--dll $(DLL_OFILES) version.o winver.o $(DLL_IMPORTS) $(LIBM) $(LIBC) \
+	 $(LIBGCC) -e $(DLL_ENTRY) --image-base=0x61000000
 
 .PHONY: all force dll_ofiles install
 
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index e81085ad7..a3002ab1b 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -645,8 +645,6 @@ public:
 
 class fhandler_tty_slave: public fhandler_tty_common
 {
-  void send_ioctl_request ();
-
 public:
   /* Constructor */
   fhandler_tty_slave (const char *name);
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index ef031b10f..5f1fc6fe1 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -779,18 +779,6 @@ fhandler_tty_slave::tcflush (int)
   return 0;
 }
 
-void
-fhandler_tty_slave::send_ioctl_request (void)
-{
-  if (ioctl_request_event == NULL || ioctl_done_event == NULL) // slave of pty
-    return;
-
-  acquire_output_mutex (INFINITE);
-  SetEvent (ioctl_request_event);
-  WaitForSingleObject (ioctl_done_event, INFINITE);
-  release_output_mutex ();
-}
-
 int
 fhandler_tty_slave::ioctl (unsigned int cmd, void *arg)
 {
@@ -804,31 +792,51 @@ fhandler_tty_slave::ioctl (unsigned int cmd, void *arg)
 		     myself->pgid, get_ttyp ()->getpgid (), myself->ctty);
       _raise (SIGTTOU);
     }
-  get_ttyp ()->cmd = cmd;
-  get_ttyp ()->ioctl_retval = 0;
+
   switch (cmd)
     {
     case TIOCGWINSZ:
-      get_ttyp ()->arg.winsize = get_ttyp ()->winsize;
-      send_ioctl_request ();
-      * (struct winsize *) arg = get_ttyp ()->arg.winsize;
-      get_ttyp ()->winsize = get_ttyp ()->arg.winsize;
-      break;
     case TIOCSWINSZ:
-      get_ttyp ()->ioctl_retval = -1;
-      get_ttyp ()->arg.winsize = * (struct winsize *) arg;
-      send_ioctl_request ();
       break;
     case FIONBIO:
       if (* (int *) arg)
 	set_flags (get_flags () | O_NONBLOCK);
       else
 	set_flags (get_flags () & ~O_NONBLOCK);
-      break;
+      goto out;
     default:
       set_errno (EINVAL);
       return -1;
     }
+
+  acquire_output_mutex (INFINITE);
+
+  get_ttyp ()->cmd = cmd;
+  get_ttyp ()->ioctl_retval = 0;
+  switch (cmd)
+    {
+    case TIOCGWINSZ:
+      get_ttyp ()->arg.winsize = get_ttyp ()->winsize;
+      if (ioctl_request_event)
+	SetEvent (ioctl_request_event);
+      * (struct winsize *) arg = get_ttyp ()->arg.winsize;
+      if (ioctl_done_event)
+	WaitForSingleObject (ioctl_done_event, INFINITE);
+      get_ttyp ()->winsize = get_ttyp ()->arg.winsize;
+      break;
+    case TIOCSWINSZ:
+      get_ttyp ()->ioctl_retval = -1;
+      get_ttyp ()->arg.winsize = * (struct winsize *) arg;
+      if (ioctl_request_event)
+	SetEvent (ioctl_request_event);
+      if (ioctl_done_event)
+	WaitForSingleObject (ioctl_done_event, INFINITE);
+      break;
+    }
+
+  release_output_mutex ();
+
+out:
   termios_printf ("%d = ioctl (%x)", get_ttyp ()->ioctl_retval, cmd);
   return get_ttyp ()->ioctl_retval;
 }