]> sourceware.org Git - newlib-cygwin.git/commitdiff
* cygserver.cc (main): Call listen right after creating the
authorCorinna Vinschen <corinna@vinschen.de>
Fri, 23 Nov 2012 15:19:41 +0000 (15:19 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Fri, 23 Nov 2012 15:19:41 +0000 (15:19 +0000)
transport.
* transport_pipes.cc (transport_layer_pipes::listen): Create
first instance of the named pipe here.  Connect the client side
to block it for further use by the system.
(transport_layer_pipes::accept): Don't handle first pipe instance
here.  Change debug output accordingly.

winsup/cygserver/ChangeLog
winsup/cygserver/cygserver.cc
winsup/cygserver/transport_pipes.cc

index 677653194aa98c0cb5eb5d07c2f217b399e6b8a9..63a37c624d92e47a50cbba0ee99932f906907a45 100644 (file)
@@ -1,3 +1,13 @@
+2012-11-23  Corinna Vinschen  <corinna@vinschen.de>
+
+       * cygserver.cc (main): Call listen right after creating the
+       transport.
+       * transport_pipes.cc (transport_layer_pipes::listen): Create
+       first instance of the named pipe here.  Connect the client side
+       to block it for further use by the system.
+       (transport_layer_pipes::accept): Don't handle first pipe instance
+       here.  Change debug output accordingly.
+
 2012-11-23  Christopher Faylor  <me.cygwin2012@cgf.cx>
 
        * Makefile.in: Use /bin/mkdir to make install directories.
index c58b236fad4c86a1459b9f306bba8e7c9f9ae411..8b3fd4c45e01a5db281af7b20b5e7096e665a6c4 100644 (file)
@@ -715,15 +715,15 @@ main (const int argc, char *argv[])
   transport_layer_base *const transport = create_server_transport ();
   assert (transport);
 
+  if (transport->listen () == -1)
+    return 1;
+
   process_cache cache (process_cache_size, cleanup_threads);
 
   server_submission_loop submission_loop (&request_queue, transport, &cache);
 
   request_queue.add_submission_loop (&submission_loop);
 
-  if (transport->listen () == -1)
-    return 1;
-
   cache.start ();
 
   request_queue.start ();
index b44b98427a0729febe49764f1af5bbb4316e109a..ccd505d176e748ab46a309be662a60efd28d54b3 100644 (file)
@@ -107,7 +107,32 @@ transport_layer_pipes::listen ()
 
   _is_listening_endpoint = true;
 
-  /* no-op */
+  debug ("Try to create named pipe: %ls", _pipe_name);
+
+  HANDLE listen_pipe =
+    CreateNamedPipeW (_pipe_name,
+                     PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+                     PIPE_TYPE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
+                     0, 0, 1000, &sec_all_nih);
+  if (listen_pipe != INVALID_HANDLE_VALUE)
+    {
+      HANDLE connect_pipe =
+       CreateFileW (_pipe_name, GENERIC_READ | GENERIC_WRITE, 0, &sec_all_nih,
+                    OPEN_EXISTING, 0, NULL);
+      if (connect_pipe == INVALID_HANDLE_VALUE)
+       {
+         CloseHandle (listen_pipe);
+         listen_pipe = INVALID_HANDLE_VALUE;
+       }
+    }
+
+  if (listen_pipe == INVALID_HANDLE_VALUE)
+    {
+      system_printf ("failed to create named pipe: "
+                    "is the daemon already running?");
+      return -1;
+    }
+
   return 0;
 }
 
@@ -125,38 +150,19 @@ transport_layer_pipes::accept (bool *const recoverable)
   // Read: http://www.securityinternals.com/research/papers/namedpipe.php
   // See also the Microsoft security bulletins MS00-053 and MS01-031.
 
-  // FIXME: Remove FILE_CREATE_PIPE_INSTANCE.
-
-  const bool first_instance = (pipe_instance == 0);
-
-  debug ("Try to create named pipe: %ls", _pipe_name);
+  debug ("Try to create named pipe instance %ld: %ls",
+        pipe_instance + 1, _pipe_name);
 
   const HANDLE accept_pipe =
-    CreateNamedPipeW (_pipe_name,
-                    (PIPE_ACCESS_DUPLEX
-                     | (first_instance ? FILE_FLAG_FIRST_PIPE_INSTANCE : 0)),
-                    (PIPE_TYPE_BYTE | PIPE_WAIT),
-                    PIPE_UNLIMITED_INSTANCES,
-                    0, 0, 1000,
-                    &sec_all_nih);
-
-  const bool duplicate = (accept_pipe == INVALID_HANDLE_VALUE
-                         && pipe_instance == 0
-                         && GetLastError () == ERROR_ACCESS_DENIED);
+    CreateNamedPipeW (_pipe_name, PIPE_ACCESS_DUPLEX,
+                     PIPE_TYPE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
+                     0, 0, 1000, &sec_all_nih);
 
   if (accept_pipe != INVALID_HANDLE_VALUE)
     InterlockedIncrement (&pipe_instance);
 
   LeaveCriticalSection (&pipe_instance_lock);
 
-  if (duplicate)
-    {
-      *recoverable = false;
-      system_printf ("failed to create named pipe: "
-                    "is the daemon already running?");
-      return NULL;
-    }
-
   if (accept_pipe == INVALID_HANDLE_VALUE)
     {
       debug_printf ("error creating pipe (%lu).", GetLastError ());
@@ -164,8 +170,6 @@ transport_layer_pipes::accept (bool *const recoverable)
       return NULL;
     }
 
-  assert (accept_pipe);
-
   if (!ConnectNamedPipe (accept_pipe, NULL)
       && GetLastError () != ERROR_PIPE_CONNECTED)
     {
This page took 0.035989 seconds and 5 git commands to generate.