[newlib-cygwin] select(2): Drop checking descriptors in case of immediate timeout.
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=20ddde2f552afedf7ef662bb21fec7a56f50040f commit 20ddde2f552afedf7ef662bb21fec7a56f50040f Author: Corinna Vinschen Date: Mon Jan 11 10:36:33 2016 +0100 select(2): Drop checking descriptors in case of immediate timeout. * select.cc (select): Call sel.poll only if sel.wait returned select_ok. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/select.cc | 17 +++-- 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index b4c3778..fa6859c 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -189,12 +189,17 @@ select (int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, UNIX_FD_ZERO (readfds, maxfds); UNIX_FD_ZERO (writefds, maxfds); UNIX_FD_ZERO (exceptfds, maxfds); - /* Set bit mask from sel records even in case of a timeout so we -don't miss one. This also sets ret to the right value >= 0, -matching the number of bits set in the fds records. */ - ret = sel.poll (readfds, writefds, exceptfds); - if (!ret && res != select_stuff::select_set_zero) - res = select_stuff::select_loop; + if (res == select_stuff::select_set_zero) + ret = 0; + else + { + /* Set bit mask from sel records. This also sets ret to the +right value >= 0, matching the number of bits set in the +fds records. if ret is 0, continue to loop. */ + ret = sel.poll (readfds, writefds, exceptfds); + if (!ret) + res = select_stuff::select_loop; + } } /* Always clean up everything here. If we're looping then build it all up again. */
[newlib-cygwin] Return unique inode numbers when calling stat/fstat on pipes and IP sockets
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a10d96923188977446ebd84323b47f7085fb5cb4 commit a10d96923188977446ebd84323b47f7085fb5cb4 Author: Corinna Vinschen Date: Mon Jan 11 12:35:41 2016 +0100 Return unique inode numbers when calling stat/fstat on pipes and IP sockets * fhandler.h (class fhandler_base): Convert unique_id to int64_t. (fhandler_base::set_ino): New protected inline method. (fhandler_base::get_unique_id): Convert to int64_t. (fhandler_base::set_unique_id): New inline method taking int64_t. (fhandler_pipe::fstat): Declare. (fhandler_pipe::init): Take extra parameter. (fhandler_pipe::create): Ditto. * fhandler_socket.cc (fhandler_socket::init_events): Set inode number to serial number. (fhandler_socket::fstat): Set device to DEV_TCP_MAJOR. Create st_ino from get_ino. * include/cygwin/signal.h (struct _sigcommune): Replace _si_pipe_fhandler with _si_pipe_unique_id. * pinfo.h (_pinfo::pipe_fhandler): Take unique id instead of HANDLE. * pinfo.cc (commune_process): Accommodate change to _si_pipe_unique_id. (_pinfo::commune_request): Ditto. (_pinfo::pipe_fhandler): Ditto. * pipe.cc (fhandler_pipe::init): Take unique id as argument and set inode number and unique_id from there. (fhandler_pipe::open): Rework to find any matching pipe from unique id in filename. (fhandler_pipe::get_proc_fd_name): Create filename using inode number. (fhandler_pipe::create): Generate and return unique id from process pid and pipe_unique_id. In outer method, call init with additional unique id as parameter. (fhandler_pipe::fstat): New method. (pipe_worker): Accommodate using 64 bit inode number in filename. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler.h | 11 ++-- winsup/cygwin/fhandler_socket.cc | 5 +- winsup/cygwin/include/cygwin/signal.h | 2 +- winsup/cygwin/pinfo.cc| 10 ++-- winsup/cygwin/pinfo.h | 2 +- winsup/cygwin/pipe.cc | 100 +++--- winsup/cygwin/release/2.4.0 | 3 + 7 files changed, 88 insertions(+), 45 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index adb8441..8bcf83f 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -182,8 +182,9 @@ class fhandler_base size_t rabuflen; /* Used for advisory file locking. See flock.cc. */ - long long unique_id; + int64_t unique_id; void del_my_locks (del_lock_called_from); + void set_ino (ino_t i) { ino = i; } HANDLE read_state; @@ -304,7 +305,7 @@ class fhandler_base const char *get_win32_name () { return pc.get_win32 (); } virtual dev_t get_dev () { return get_device (); } ino_t get_ino () { return ino ?: ino = hash_path_name (0, pc.get_nt_native_path ()); } - long long get_unique_id () const { return unique_id; } + int64_t get_unique_id () const { return unique_id; } /* Returns name used for /proc//fd in buf. */ virtual char *get_proc_fd_name (char *buf); @@ -319,6 +320,7 @@ class fhandler_base int open_null (int flags); virtual int open (int, mode_t); virtual void open_setup (int flags); + void set_unique_id (int64_t u) { unique_id = u; } void set_unique_id () { NtAllocateLocallyUniqueId ((PLUID) &unique_id); } int close_with_arch (); @@ -731,13 +733,14 @@ public: int open (int flags, mode_t mode = 0); int dup (fhandler_base *child, int); int ioctl (unsigned int cmd, void *); + int __reg2 fstat (struct stat *buf); int __reg2 fstatvfs (struct statvfs *buf); int __reg3 fadvise (off_t, off_t, int); int __reg3 ftruncate (off_t, bool); - int init (HANDLE, DWORD, mode_t); + int init (HANDLE, DWORD, mode_t, int64_t); static int create (fhandler_pipe *[2], unsigned, int); static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD, - const char *, DWORD); + const char *, DWORD, int64_t *unique_id = NULL); fhandler_pipe (void *) {} void copyto (fhandler_base *x) diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 21bc731..094cc65 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -594,6 +594,7 @@ fhandler_socket::init_events () InterlockedIncrement (&socket_serial_number); if (!new_serial_number) /* 0 is reserved for global mutex */ InterlockedIncrement (&socket_serial_number); + set_ino (new_serial_number); RtlInitUnicodeString (&uname, sock_shared_name (name, new_serial_number)); InitializeObjectAttributes (&attr, &uname, OBJ_INHERIT | OBJ_OPENIF,
[newlib-cygwin] Revert "autoload.cc: Drop using full paths for system DLLs"
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b4cf3f454d8c2a05d6956fbc1eae3942d2f1730a commit b4cf3f454d8c2a05d6956fbc1eae3942d2f1730a Author: Corinna Vinschen Date: Mon Jan 11 18:46:01 2016 +0100 Revert "autoload.cc: Drop using full paths for system DLLs" This reverts commit 4b104ce07070e32363a217a554441a8b4df69d12. The DLLs always guaranteed to be loaded from the system dir are only those in the KnownDLLs list. We're using some DLLs not in that list on all supported OSes, thus we need to make sure to use full paths. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/autoload.cc | 14 +++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index e14647c..836597d 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -420,15 +420,18 @@ std_dll_init () { fenv_t fpuenv; fegetenv (&fpuenv); + WCHAR dll_path[MAX_PATH]; DWORD err = ERROR_SUCCESS; int i; + /* http://www.microsoft.com/technet/security/advisory/2269637.mspx */ + wcpcpy (wcpcpy (dll_path, windows_system_directory), dll->name); /* MSDN seems to imply that LoadLibrary can fail mysteriously, so, since there have been reports of this in the mailing list, retry several times before giving up. */ for (i = 1; i <= RETRY_COUNT; i++) { /* If loading the library succeeds, just leave the loop. */ - if (dll_load (dll->handle, dll->name)) + if (dll_load (dll->handle, dll_path)) break; /* Otherwise check error code returned by LoadLibrary. If the error code is neither NOACCESS nor DLL_INIT_FAILED, break out @@ -441,10 +444,15 @@ std_dll_init () } if ((uintptr_t) dll->handle <= 1) { - if ((func->decoration & 1)) + /* If LoadLibrary with full path returns one of the weird errors +reported on the Cygwin mailing list, retry with only the DLL +name. Only do this when the above retry loop has been exhausted. */ + if (i > RETRY_COUNT && dll_load (dll->handle, dll->name)) + /* got it with the fallback */; + else if ((func->decoration & 1)) dll->handle = INVALID_HANDLE_VALUE; else - api_fatal ("unable to load %W, %E", dll->name); + api_fatal ("unable to load %W, %E", dll_path); } fesetenv (&fpuenv); }
[newlib-cygwin] Fix previous fix for generating unique inode numbers for sockets
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=27086d628e814b7b73a5c858ff2d9138c22d5543 commit 27086d628e814b7b73a5c858ff2d9138c22d5543 Author: Corinna Vinschen Date: Mon Jan 11 19:10:45 2016 +0100 Fix previous fix for generating unique inode numbers for sockets * fhandler.h (fhandler_base::get_plain_ino): New inline method. Add comment to explain what it's supposed to be used for. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): Create filename using inode number. (fhandler_socket::fstat): Generate inode number from filename if ino is not set (that's the case in a stat(2) call). * pipe.cc: Throughout, use get_plain_ino when appropriate. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler.h | 2 ++ winsup/cygwin/fhandler_socket.cc | 6 -- winsup/cygwin/pipe.cc| 12 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 8bcf83f..d94f38d 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -304,6 +304,8 @@ class fhandler_base const char *get_name () const { return pc.get_posix (); } const char *get_win32_name () { return pc.get_win32 (); } virtual dev_t get_dev () { return get_device (); } + /* Use get_plain_ino if the caller needs to avoid hashing if ino is 0. */ + ino_t get_plain_ino () { return ino; } ino_t get_ino () { return ino ?: ino = hash_path_name (0, pc.get_nt_native_path ()); } int64_t get_unique_id () const { return unique_id; } /* Returns name used for /proc//fd in buf. */ diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 094cc65..7d3efad 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -250,7 +250,7 @@ fhandler_socket::~fhandler_socket () char * fhandler_socket::get_proc_fd_name (char *buf) { - __small_sprintf (buf, "socket:[%lu]", get_socket ()); + __small_sprintf (buf, "socket:[%lu]", get_plain_ino ()); return buf; } @@ -939,7 +939,9 @@ fhandler_socket::fstat (struct stat *buf) if (!res) { buf->st_dev = FHDEV (DEV_TCP_MAJOR, 0); - buf->st_ino = (ino_t) get_ino (); + if (!(buf->st_ino = get_plain_ino ())) + sscanf (get_name (), "/proc/%*d/fd/socket:[%lld]", +(long long *) &buf->st_ino); buf->st_mode = S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO; buf->st_size = 0; } diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index 4ec4fa4..4ccfef6 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -142,7 +142,8 @@ fhandler_pipe::open (int flags, mode_t mode) __seterrno (); goto out; } - init (nio_hdl, fh->get_access (), mode & O_TEXT ?: O_BINARY, fh->get_ino ()); + init (nio_hdl, fh->get_access (), mode & O_TEXT ?: O_BINARY, + fh->get_plain_ino ()); cfree (fh); CloseHandle (proc); return 1; @@ -181,7 +182,7 @@ fhandler_pipe::ftruncate (off_t length, bool allow_truncate) char * fhandler_pipe::get_proc_fd_name (char *buf) { - __small_sprintf (buf, "pipe:[%D]", get_ino ()); + __small_sprintf (buf, "pipe:[%D]", get_plain_ino ()); return buf; } @@ -422,8 +423,7 @@ fhandler_pipe::fstat (struct stat *buf) if (!ret) { buf->st_dev = FH_PIPE; - /* Don't use get_ino, it doesn't return 0 but a hash instead. */ - if (!(buf->st_ino = get_unique_id ())) + if (!(buf->st_ino = get_plain_ino ())) sscanf (get_name (), "/proc/%*d/fd/pipe:[%lld]", (long long *) &buf->st_ino); } @@ -447,9 +447,9 @@ pipe_worker (int filedes[2], unsigned int psize, int mode) cygheap_fdnew fdin; cygheap_fdnew fdout (fdin, false); char buf[sizeof ("/dev/fd/pipe:[9223372036854775807]")]; - __small_sprintf (buf, "/dev/fd/pipe:[%D]", fhs[0]->get_ino ()); + __small_sprintf (buf, "/dev/fd/pipe:[%D]", fhs[0]->get_plain_ino ()); fhs[0]->pc.set_posix (buf); - __small_sprintf (buf, "pipe:[%D]", fhs[1]->get_ino ()); + __small_sprintf (buf, "pipe:[%D]", fhs[1]->get_plain_ino ()); fhs[1]->pc.set_posix (buf); fdin = fhs[0]; fdout = fhs[1];