Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2012-11-23 19:19:41 +0400
committerCorinna Vinschen <corinna@vinschen.de>2012-11-23 19:19:41 +0400
commit5ed0628cf06d3e6b827d1f3eac17809dd485beb9 (patch)
treef529b599cbe124f1fec095ad4b133a9ef564d80c /winsup/cygserver
parent916015a6af6ee09395740ab37dd4db7acc8457a1 (diff)
* 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.
Diffstat (limited to 'winsup/cygserver')
-rw-r--r--winsup/cygserver/ChangeLog10
-rw-r--r--winsup/cygserver/cygserver.cc6
-rw-r--r--winsup/cygserver/transport_pipes.cc58
3 files changed, 44 insertions, 30 deletions
diff --git a/winsup/cygserver/ChangeLog b/winsup/cygserver/ChangeLog
index 677653194..63a37c624 100644
--- a/winsup/cygserver/ChangeLog
+++ b/winsup/cygserver/ChangeLog
@@ -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.
diff --git a/winsup/cygserver/cygserver.cc b/winsup/cygserver/cygserver.cc
index c58b236fa..8b3fd4c45 100644
--- a/winsup/cygserver/cygserver.cc
+++ b/winsup/cygserver/cygserver.cc
@@ -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 ();
diff --git a/winsup/cygserver/transport_pipes.cc b/winsup/cygserver/transport_pipes.cc
index b44b98427..ccd505d17 100644
--- a/winsup/cygserver/transport_pipes.cc
+++ b/winsup/cygserver/transport_pipes.cc
@@ -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)
{