---
 src/base/unix_server_socket.cc | 14 +++++++++++---
 src/base/unix_server_socket.h  |  7 +++++--
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/base/unix_server_socket.cc b/src/base/unix_server_socket.cc
index 620efce9f..8a5290d24 100644
--- a/src/base/unix_server_socket.cc
+++ b/src/base/unix_server_socket.cc
@@ -23,8 +23,9 @@
 
 namespace base {
 
-UnixServerSocket::UnixServerSocket(const std::string& path, Mode mode)
-    : UnixSocket{path, mode} {}
+UnixServerSocket::UnixServerSocket(const std::string& path, Mode mode,
+                                   mode_t permissions)
+    : UnixSocket{path, mode}, permissions_{permissions} {}
 
 UnixServerSocket::UnixServerSocket(const sockaddr_un& addr, socklen_t addrlen,
                                    Mode mode)
@@ -46,7 +47,14 @@ bool UnixServerSocket::OpenHook(int sock) {
     close(tmp_sock);
     if (connect_result != 0 && connect_errno == ECONNREFUSED) Unlink();
   }
-  return bind(sock, addr(), addrlen()) == 0;
+  int bind_result = bind(sock, addr(), addrlen());
+  int chmod_result = 0;
+  if (bind_result == 0 && permissions_ != 0 && !IsAbstract()) {
+    do {
+      chmod_result = chmod(path(), permissions_);
+    } while (chmod_result == -1 && errno == EINTR);
+  }
+  return bind_result == 0 && chmod_result == 0;
 }
 
 void UnixServerSocket::CloseHook() { Unlink(); }
diff --git a/src/base/unix_server_socket.h b/src/base/unix_server_socket.h
index 6e108a1e1..e2cebbd5e 100644
--- a/src/base/unix_server_socket.h
+++ b/src/base/unix_server_socket.h
@@ -18,6 +18,7 @@
 #ifndef BASE_UNIX_SERVER_SOCKET_H_
 #define BASE_UNIX_SERVER_SOCKET_H_
 
+#include <sys/stat.h>
 #include <string>
 #include "base/unix_socket.h"
 
@@ -29,8 +30,9 @@ class UnixServerSocket : public UnixSocket {
   // Set the path name for this server socket. Note that this call does not
   // create the socket - you need to call Send() or Recv() for that to happen.
   // Abstract addresses are supported by passing '\0' as the first byte in @a
-  // path.
-  UnixServerSocket(const std::string& path, Mode mode);
+  // path. If @a permissions is not zero, change the file permissions to this
+  // value after the socket has been created.
+  UnixServerSocket(const std::string& path, Mode mode, mode_t permissions = 0);
   // Set the socket address for this server socket. Note that this call does 
not
   // create the socket - you need to call Send() or Recv() for that to happen.
   UnixServerSocket(const sockaddr_un& addr, socklen_t addrlen, Mode mode);
@@ -44,6 +46,7 @@ class UnixServerSocket : public UnixSocket {
 
  private:
   void Unlink();
+  mode_t permissions_;
 };
 
 }  // namespace base
-- 
2.13.3


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to