This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Cygwin: AF_UNIX: Add state_lock to guard manipulating shared state info


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=848d5b70db94b924edfa5137fcc1f285025822b8

commit 848d5b70db94b924edfa5137fcc1f285025822b8
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Sun Mar 18 20:06:43 2018 +0100

    Cygwin: AF_UNIX: Add state_lock to guard manipulating shared state info
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler.h              | 5 +++++
 winsup/cygwin/fhandler_socket_unix.cc | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 0b04d7a..a4bf1d3 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 79fc4bc..89cf5b1 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) {}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]