Index: cygwin/Makefile.in
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/Makefile.in,v
retrieving revision 1.52
diff -u -p -2 -r1.52 Makefile.in
--- Makefile.in	2001/03/21 02:17:57	1.52
+++ Makefile.in	2001/03/28 17:06:02
@@ -114,6 +114,6 @@ EXTRA_OFILES=$(bupdir1)/libiberty/random
 DLL_IMPORTS:=$(w32api_lib)/libkernel32.a
 
-DLL_OFILES:=assert.o autoload.o cygheap.o dcrt0.o debug.o delqueue.o dir.o \
-	dlfcn.o \
+DLL_OFILES:=assert.o autoload.o cygheap.o cygserver_client.o dcrt0.o debug.o \
+	delqueue.o dir.o dlfcn.o \
 	dll_init.o dtable.o environ.o  errno.o exceptions.o exec.o external.o \
 	fcntl.o fhandler.o fhandler_clipboard.o fhandler_console.o \
Index: cygwin/dcrt0.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dcrt0.cc,v
retrieving revision 1.90
diff -u -p -2 -r1.90 dcrt0.cc
--- dcrt0.cc	2001/03/28 03:42:58	1.90
+++ dcrt0.cc	2001/03/28 17:06:02
@@ -36,4 +36,5 @@ details. */
 #include "host_dependent.h"
 #include "security.h"
+#include "cygwin/cygserver.h"
 
 #define MAX_AT_FILE_LEVEL 10
@@ -781,4 +782,6 @@ dll_crt0_1 ()
   /* Initialize signal/subprocess handling. */
   sigproc_init ();
+
+  cygserver_init ();
 
   /* Connect to tty. */
Index: cygwin/fhandler.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler.h,v
retrieving revision 1.50
diff -u -p -2 -r1.50 fhandler.h
--- fhandler.h	2001/03/22 22:11:34	1.50
+++ fhandler.h	2001/03/28 17:06:09
@@ -764,4 +764,6 @@ public:
   select_record *select_read (select_record *s);
   int ready_for_read (int fd, DWORD howlong, int ignra);
+
+  int cygserver_attach_tty (HANDLE*, HANDLE*);
 };
 
Index: cygwin/fhandler_tty.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_tty.cc,v
retrieving revision 1.30
diff -u -p -2 -r1.30 fhandler_tty.cc
--- fhandler_tty.cc	2001/03/19 18:27:36	1.30
+++ fhandler_tty.cc	2001/03/28 17:06:09
@@ -25,4 +25,5 @@ details. */
 #include "cygheap.h"
 #include "shared_info.h"
+#include "cygwin/cygserver.h"
 
 /* Tty master stuff */
@@ -499,39 +500,72 @@ fhandler_tty_slave::open (const char *, 
     }
 
-  HANDLE tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE,
-				     get_ttyp ()->master_pid);
-  if (tty_owner == NULL)
-    {
-      termios_printf ("can't open tty (%d) handle process %d",
-		      ttynum, get_ttyp ()->master_pid);
-      __seterrno ();
-      return 0;
-    }
+  HANDLE from_master_local, to_master_local;
 
-  HANDLE nh;
-  if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master, hMainProc, &nh, 0, TRUE,
-			DUPLICATE_SAME_ACCESS))
-    {
-      termios_printf ("can't duplicate input, %E");
-      __seterrno ();
-      return 0;
-    }
-  set_io_handle (nh);
-  ProtectHandle1 (nh, from_pty);
-  termios_printf ("duplicated from_master %p->%p from tty_owner %p",
-		  get_ttyp ()->from_master, nh, tty_owner);
-  if (!DuplicateHandle (tty_owner, get_ttyp ()->to_master, hMainProc, &nh, 0, TRUE,
-			DUPLICATE_SAME_ACCESS))
+  if (!cygserver_running || !cygserver_attach_tty ( &from_master_local, &to_master_local))
     {
-      termios_printf ("can't duplicate output, %E");
-      __seterrno ();
-      return 0;
+      termios_printf ("cannot dup handles via server. using old method.");
+
+      HANDLE tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE,
+			              get_ttyp ()->master_pid);
+      if (tty_owner == NULL)
+        {
+          termios_printf ("can't open tty (%d) handle process %d",
+		          ttynum, get_ttyp ()->master_pid);
+          __seterrno ();
+          return 0;
+        }
+
+      if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master,
+			    hMainProc, &from_master_local,
+			    0, TRUE,
+			    DUPLICATE_SAME_ACCESS))
+	{
+	  termios_printf ("can't duplicate input, %E");
+	  __seterrno ();
+	  return 0;
+	}
+      termios_printf ("duplicated from_master %p->%p from tty_owner %p",
+		       get_ttyp ()->from_master, from_master_local, tty_owner);
+
+      if (!DuplicateHandle (tty_owner, get_ttyp ()->to_master,
+			    hMainProc, &to_master_local, 0, TRUE,
+			    DUPLICATE_SAME_ACCESS))
+	{
+	  termios_printf ("can't duplicate output, %E");
+	  __seterrno ();
+	  return 0;
+	}
+      termios_printf ("duplicated to_master %p->%p from tty_owner %p",
+		       get_ttyp ()->to_master, to_master_local, tty_owner);
+      CloseHandle (tty_owner);
     }
-  set_output_handle (nh);
-  ProtectHandle1 (nh, to_pty);
-  CloseHandle (tty_owner);
 
+  set_io_handle (from_master_local);
+  ProtectHandle1 (from_master_local, from_pty);
+  set_output_handle (to_master_local);
+  ProtectHandle1 (to_master_local, to_pty);
+
   termios_printf ("tty%d opened", ttynum);
 
+  return 1;
+}
+
+int
+fhandler_tty_slave::cygserver_attach_tty (HANDLE* from_master_ptr,
+					  HANDLE* to_master_ptr)
+{
+  if (!from_master_ptr || !to_master_ptr)
+    return 0;
+
+  struct request_attach_tty req;
+  INIT_REQUEST (req, CYGSERVER_REQUEST_ATTACH_TTY);
+  req.pid = GetCurrentProcessId ();
+  req.master_pid = get_ttyp ()->master_pid;
+  req.from_master = get_ttyp ()->from_master;
+  req.to_master = get_ttyp ()->to_master;
+  if (cygserver_request ((struct request_header*) &req) != 0)
+    return 0;
+  *from_master_ptr = req.from_master;
+  *to_master_ptr = req.to_master;
   return 1;
 }
Index: cygwin/tty.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/tty.cc,v
retrieving revision 1.18
diff -u -p -2 -r1.18 tty.cc
--- tty.cc	2001/03/19 18:27:36	1.18
+++ tty.cc	2001/03/28 17:06:09
@@ -24,4 +24,5 @@ details. */
 #include "shared_info.h"
 #include "security.h"
+#include "cygwin/cygserver.h"
 
 extern fhandler_tty_master *tty_master;
@@ -388,7 +389,8 @@ tty::common_init (fhandler_pty_master *p
   /* Allow the others to open us (for handle duplication) */
 
-  if ((os_being_run == winNT) &&
-      (SetKernelObjectSecurity (hMainProc, DACL_SECURITY_INFORMATION,
-			       get_null_sd ()) == FALSE))
+  if (os_being_run == winNT &&
+      !cygserver_running &&
+      !SetKernelObjectSecurity (hMainProc, DACL_SECURITY_INFORMATION,
+			        get_null_sd ()))
     small_printf ("Can't set process security, %E");
 
Index: cygwin/winsup.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/winsup.h,v
retrieving revision 1.49
diff -u -p -2 -r1.49 winsup.h
--- winsup.h	2001/03/05 06:28:24	1.49
+++ winsup.h	2001/03/28 17:06:09
@@ -87,4 +87,6 @@ enum codepage_type {ansi_cp, oem_cp};
 extern codepage_type current_codepage;
 
+extern int cygserver_running;
+
 /* Used to check if Cygwin DLL is dynamically loaded. */
 extern int dynamically_loaded;
Index: utils/Makefile.in
===================================================================
RCS file: /cvs/src/src/winsup/utils/Makefile.in,v
retrieving revision 1.20
diff -u -p -2 -r1.20 Makefile.in
--- Makefile.in	2000/12/11 00:10:49	1.20
+++ Makefile.in	2001/03/28 17:06:10
@@ -71,5 +71,5 @@ PROGS:=mount$(EXEEXT) umount$(EXEEXT) ps
        mkpasswd$(EXEEXT) mkgroup$(EXEEXT) cygpath$(EXEEXT) cygcheck$(EXEEXT) \
        passwd$(EXEEXT) getfacl$(EXEEXT) setfacl$(EXEEXT) strace$(EXEEXT) \
-       regtool$(EXEEXT) ssp$(EXEEXT)
+       regtool$(EXEEXT) ssp$(EXEEXT) cygserver$(EXEEXT)
 
 CLEAN_PROGS:=$(PROGS)
@@ -89,4 +89,12 @@ all: Makefile $(PROGS)
 
 strace.exe: strace.cc mingw_getopt.o $(MINGW_DEP_LDLIBS)
+ifdef VERBOSE
+	$(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,2,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS)
+else
+	@echo $(CXX) -o $@ ${wordlist 1,2,$^} ${filter-out -B%, $(MINGW_CXXFLAGS) $(MINGW_LDFLAGS)};\
+	$(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,2,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS)
+endif
+
+cygserver.exe: cygserver.cc
 ifdef VERBOSE
 	$(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,2,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS)
