title: How to create Unix Domain Socket with a specific permissions in C?
body: <p>I have a simple code, like:</p>
  
  <pre><code>sockaddr_un address;
  address.sun_family = AF_UNIX;
  strcpy(address.sun_path, path);
  unlink(path);
  
  int fd = socket(AF_UNIX, SOCK_STREAM, 0);
  bind(fd, (sockaddr*)(&amp;address), sizeof(address));
  listen(fd, 100);
  </code></pre>
  
  <p>I want to <strong>atomically</strong> create the Unix Domain Socket file with a specific permissions, say: <code>0777</code>. The manual doesn't say anything about socket file permissions with regard to <code>umask</code> or whatever. Even, if the <code>umask</code> does affect the socket file, then it's not an atomic way - in multi-threaded program.</p>
  
  <p>I hope, there is a way to achieve my goal without using synchronization of <code>umask()</code> calls.</p>