From 9f65451e3e9b5a3a5c7c35343daee24a09d1d3a2 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 23 Nov 2011 18:56:57 +0000 Subject: [PATCH] * fhandler.h (fhandler_pipe::create): Rename from the misnamed "create_selectable". Change return to DWORD. (fhandler_pty_common::pipesize): New constant. * fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Reflect create_selectable name change. * miscfuncs.cc (CreatePipeOverlapped): Ditto. * pipe.cc (fhandler_pipe::create): Ditto. (fhandler_pipe::create): Rename from the misnamed "create_selectable". Return DWORD. Only set pipe size to default when it is passed in as zero. * fhandler_tty.cc (fhandler_pty_master::setup): Ditto. Use fhandler_pty_common::pipesize rather than a raw constant. * tty.cc (tty::not_allocated): Ditto. * sigproc.cc (sigproc_init): Use create_selectable to create the signal pipe to get a more appropriate message based pipe. --- winsup/cygwin/ChangeLog | 19 +++++++++++++++++++ winsup/cygwin/fhandler.h | 5 +++-- winsup/cygwin/fhandler_fifo.cc | 2 +- winsup/cygwin/fhandler_tty.cc | 4 ++-- winsup/cygwin/miscfuncs.cc | 4 ++-- winsup/cygwin/pipe.cc | 10 +++++----- winsup/cygwin/sigproc.cc | 12 +++++++----- winsup/cygwin/tty.cc | 7 ++++--- 8 files changed, 43 insertions(+), 20 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 2c7934204..6cc089dd9 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,22 @@ +2011-11-23 Christopher Faylor + + * fhandler.h (fhandler_pipe::create): Rename from the misnamed + "create_selectable". Change return to DWORD. + (fhandler_pty_common::pipesize): New constant. + * fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Reflect + create_selectable name change. + * miscfuncs.cc (CreatePipeOverlapped): Ditto. + * pipe.cc (fhandler_pipe::create): Ditto. + (fhandler_pipe::create): Rename from the misnamed "create_selectable". + Return DWORD. Only set pipe size to default when it is passed in as + zero. + * fhandler_tty.cc (fhandler_pty_master::setup): Ditto. Use + fhandler_pty_common::pipesize rather than a raw constant. + * tty.cc (tty::not_allocated): Ditto. + + * sigproc.cc (sigproc_init): Use create_selectable to create the signal + pipe to get a more appropriate message based pipe. + 2011-11-21 Christopher Faylor * sigproc.cc (remove_proc): Don't do busy loop when exiting since it diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 4ceba4e5d..e94a8bf2f 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -690,8 +690,8 @@ public: int __stdcall ftruncate (_off64_t, bool) __attribute__ ((regparm (3))); int init (HANDLE, DWORD, mode_t); static int create (fhandler_pipe *[2], unsigned, int); - static int create_selectable (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD, - const char *, DWORD); + static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD, + const char *, DWORD); fhandler_pipe (void *) {} void copyto (fhandler_base *x) @@ -1370,6 +1370,7 @@ class fhandler_pty_common: public fhandler_termios { pc.file_attributes (FILE_ATTRIBUTE_NORMAL); } + static const unsigned pipesize = 128 * 1024; HANDLE output_mutex, input_mutex; HANDLE input_available_event; diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index 0b1b7b562..a7aecef96 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -34,7 +34,7 @@ fhandler_fifo::fhandler_fifo (): #define fnevent(w) fifo_name (npbuf, w "-event") #define fnpipe() fifo_name (npbuf, "fifo") #define create_pipe(r, w) \ - fhandler_pipe::create_selectable (sa_buf, (r), (w), 0, fnpipe (), open_mode) + fhandler_pipe::create (sa_buf, (r), (w), 0, fnpipe (), open_mode) char * fhandler_fifo::fifo_name (char *buf, const char *what) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index d8881b28d..4b0538fed 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -1630,8 +1630,8 @@ fhandler_pty_master::setup () char pipename[sizeof("ptyNNNN-from-master")]; __small_sprintf (pipename, "pty%d-to-master", unit); - res = fhandler_pipe::create_selectable (&sec_none, &get_io_handle (), - &to_master, 128 * 1024, pipename, 0); + res = fhandler_pipe::create (&sec_none, &get_io_handle (), &to_master, + fhandler_pty_common::pipesize, pipename, 0); if (res) { errstr = "output pipe"; diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index b94f0997d..414abbf87 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -337,8 +337,8 @@ nice_to_winprio (int &nice) BOOL WINAPI CreatePipeOverlapped (PHANDLE hr, PHANDLE hw, LPSECURITY_ATTRIBUTES sa) { - int ret = fhandler_pipe::create_selectable (sa, hr, hw, 0, NULL, - FILE_FLAG_OVERLAPPED); + int ret = fhandler_pipe::create (sa, hr, hw, 0, NULL, + FILE_FLAG_OVERLAPPED); if (ret) SetLastError (ret); return ret == 0; diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index 7bbe96fab..60b59ff62 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -196,9 +196,9 @@ fhandler_pipe::dup (fhandler_base *child, int flags) which is used to implement select and nonblocking writes. Note that the return value is either 0 or GetLastError, unlike CreatePipe, which returns a bool for success or failure. */ -int -fhandler_pipe::create_selectable (LPSECURITY_ATTRIBUTES sa_ptr, HANDLE *r, - HANDLE *w, DWORD psize, const char *name, DWORD open_mode) +DWORD +fhandler_pipe::create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w, + DWORD psize, const char *name, DWORD open_mode) { /* Default to error. */ if (r) @@ -207,7 +207,7 @@ fhandler_pipe::create_selectable (LPSECURITY_ATTRIBUTES sa_ptr, HANDLE *r, *w = NULL; /* Ensure that there is enough pipe buffer space for atomic writes. */ - if (psize < DEFAULT_PIPEBUFSIZE) + if (!psize) psize = DEFAULT_PIPEBUFSIZE; char pipename[MAX_PATH]; @@ -327,7 +327,7 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode) SECURITY_ATTRIBUTES *sa = sec_none_cloexec (mode); int res = -1; - int ret = create_selectable (sa, &r, &w, psize, NULL, FILE_FLAG_OVERLAPPED); + int ret = create (sa, &r, &w, psize, NULL, FILE_FLAG_OVERLAPPED); if (ret) __seterrno_from_win_error (ret); else if ((fhs[0] = (fhandler_pipe *) build_fh_dev (*piper_dev)) == NULL) diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 8d3113986..43b329373 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -464,12 +464,14 @@ void __stdcall sigproc_init () { char char_sa_buf[1024]; - PSECURITY_ATTRIBUTES sa_buf = sec_user_nih ((PSECURITY_ATTRIBUTES) char_sa_buf, cygheap->user.sid()); - for (int i = 5; - i > 0 && !CreatePipe (&my_readsig, &my_sendsig, sa_buf, 0); - i--) - if (i == 1) + PSECURITY_ATTRIBUTES sa = sec_user_nih ((PSECURITY_ATTRIBUTES) char_sa_buf, cygheap->user.sid()); + DWORD err = fhandler_pipe::create (sa, &my_readsig, &my_sendsig, + sizeof (sigpacket), NULL, 0); + if (err) + { + SetLastError (err); api_fatal ("couldn't create signal pipe, %E"); + } ProtectHandle (my_readsig); myself->sendsig = my_sendsig; /* sync_proc_subproc is used by proc_subproc. It serializes diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index 095c5b5df..829d773aa 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -158,9 +158,10 @@ tty::not_allocated (HANDLE& r, HANDLE& w) then it exists although we may not have privileges to actually use it. */ char pipename[sizeof("ptyNNNN-from-master")]; __small_sprintf (pipename, "pty%d-from-master", get_unit ()); - /* fhandler_pipe::create_selectable returns 0 when creation succeeds */ - return fhandler_pipe::create_selectable (&sec_none, &r, &w, 128 * 1024, - pipename, 0) == 0; + /* fhandler_pipe::create returns 0 when creation succeeds */ + return fhandler_pipe::create (&sec_none, &r, &w, + fhandler_pty_common::pipesize, pipename, + 0) == 0; } bool