Cygwin: AF_UNIX: Add state_lock to guard manipulating shared state info

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2018-03-18 20:06:43 +01:00
parent 60ca1c1359
commit 848d5b70db
2 changed files with 9 additions and 0 deletions

View File

@ -887,6 +887,7 @@ class af_unix_shmem_t
deadlocks. */ deadlocks. */
af_unix_spinlock_t _bind_lock; af_unix_spinlock_t _bind_lock;
af_unix_spinlock_t _conn_lock; af_unix_spinlock_t _conn_lock;
af_unix_spinlock_t _state_lock;
af_unix_spinlock_t _io_lock; af_unix_spinlock_t _io_lock;
LONG _connection_state; /* conn_state */ LONG _connection_state; /* conn_state */
LONG _binding_state; /* bind_state */ LONG _binding_state; /* bind_state */
@ -899,6 +900,8 @@ class af_unix_shmem_t
void bind_unlock () { _bind_lock.unlock (); } void bind_unlock () { _bind_lock.unlock (); }
void conn_lock () { _conn_lock.lock (); } void conn_lock () { _conn_lock.lock (); }
void conn_unlock () { _conn_lock.unlock (); } 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_lock () { _io_lock.lock (); }
void io_unlock () { _io_lock.unlock (); } void io_unlock () { _io_lock.unlock (); }
@ -943,6 +946,8 @@ class fhandler_socket_unix : public fhandler_socket
void bind_unlock () { shmem->bind_unlock (); } void bind_unlock () { shmem->bind_unlock (); }
void conn_lock () { shmem->conn_lock (); } void conn_lock () { shmem->conn_lock (); }
void conn_unlock () { shmem->conn_unlock (); } 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_lock () { shmem->io_lock (); }
void io_unlock () { shmem->io_unlock (); } void io_unlock () { shmem->io_unlock (); }
conn_state connect_state (conn_state val) conn_state connect_state (conn_state val)

View File

@ -1225,8 +1225,10 @@ out:
if (param) if (param)
cfree (param); cfree (param);
conn_lock (); conn_lock ();
state_lock ();
so_error (error); so_error (error);
connect_state (error ? connect_failed : connected); connect_state (error ? connect_failed : connected);
state_unlock ();
conn_unlock (); conn_unlock ();
return error; return error;
} }
@ -1688,12 +1690,14 @@ fhandler_socket_unix::getpeereid (pid_t *pid, uid_t *euid, gid_t *egid)
{ {
__try __try
{ {
state_lock ();
if (pid) if (pid)
*pid = peer_cred.pid; *pid = peer_cred.pid;
if (euid) if (euid)
*euid = peer_cred.uid; *euid = peer_cred.uid;
if (egid) if (egid)
*egid = peer_cred.gid; *egid = peer_cred.gid;
state_unlock ();
ret = 0; ret = 0;
} }
__except (EFAULT) {} __except (EFAULT) {}