diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 0b04d7a55..a4bf1d315 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -887,6 +887,7 @@ class af_unix_shmem_t deadlocks. */ af_unix_spinlock_t _bind_lock; af_unix_spinlock_t _conn_lock; + af_unix_spinlock_t _state_lock; af_unix_spinlock_t _io_lock; LONG _connection_state; /* conn_state */ LONG _binding_state; /* bind_state */ @@ -899,6 +900,8 @@ class af_unix_shmem_t void bind_unlock () { _bind_lock.unlock (); } void conn_lock () { _conn_lock.lock (); } void conn_unlock () { _conn_lock.unlock (); } + void state_lock () { _state_lock.lock (); } + void state_unlock () { _state_lock.unlock (); } void io_lock () { _io_lock.lock (); } void io_unlock () { _io_lock.unlock (); } @@ -943,6 +946,8 @@ class fhandler_socket_unix : public fhandler_socket void bind_unlock () { shmem->bind_unlock (); } void conn_lock () { shmem->conn_lock (); } void conn_unlock () { shmem->conn_unlock (); } + void state_lock () { shmem->state_lock (); } + void state_unlock () { shmem->state_unlock (); } void io_lock () { shmem->io_lock (); } void io_unlock () { shmem->io_unlock (); } conn_state connect_state (conn_state val) diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc index 79fc4bc70..89cf5b1f7 100644 --- a/winsup/cygwin/fhandler_socket_unix.cc +++ b/winsup/cygwin/fhandler_socket_unix.cc @@ -1225,8 +1225,10 @@ out: if (param) cfree (param); conn_lock (); + state_lock (); so_error (error); connect_state (error ? connect_failed : connected); + state_unlock (); conn_unlock (); return error; } @@ -1688,12 +1690,14 @@ fhandler_socket_unix::getpeereid (pid_t *pid, uid_t *euid, gid_t *egid) { __try { + state_lock (); if (pid) *pid = peer_cred.pid; if (euid) *euid = peer_cred.uid; if (egid) *egid = peer_cred.gid; + state_unlock (); ret = 0; } __except (EFAULT) {}