chiark / gitweb /
server/admin.c (a_init): Abort if we can't set socket permissions.
[tripe] / server / admin.c
index 228cce1565ee906d7f5c4bf4f674055188e2321f..32b35772fc52788792859a3c63b2974b690f6e5a 100644 (file)
@@ -2226,6 +2226,7 @@ void a_init(const char *name, uid_t u, gid_t g)
   struct sockaddr_un sun;
   struct sigaction sa;
   size_t sz;
+  mode_t omask;
 
   /* --- Create services table --- */
 
@@ -2243,7 +2244,7 @@ void a_init(const char *name, uid_t u, gid_t g)
 
   /* --- Attempt to bind to the socket --- */
 
-  umask(0077);
+  omask = umask(0077);
 again:
   if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
     die(EXIT_FAILURE, "couldn't create socket: %s", strerror(errno));
@@ -2274,12 +2275,15 @@ again:
     close(fd);
     goto again;
   }
-  chmod(sun.sun_path, 0600);
+  if (chmod(sun.sun_path, 0600)) {
+    die(EXIT_FAILURE, "failed to set socket permissions: %s",
+       strerror(errno));
+  }
   if (chown(sun.sun_path, u, g)) {
-    T( trace(T_ADMIN,
-            "admin: failed to give away socket: %s",
-            strerror(errno)); )
+    die(EXIT_FAILURE, "failed to set socket owner: %s",
+       strerror(errno));
   }
+  umask(omask);
   fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
   if (listen(fd, 5))
     die(EXIT_FAILURE, "couldn't listen on socket: %s", strerror(errno));