]> mj.ucw.cz Git - subauth.git/blobdiff - server/subauthd.c
Debian packaging: init
[subauth.git] / server / subauthd.c
index 9cf7c714141dca322e07b12298f8660ca09cdf0d..393c8342031b91a9aaa4a06e67bf7c1bab04a8c9 100644 (file)
@@ -44,7 +44,7 @@ static void client_close(struct client *c)
   timer_del(&c->timer);
   close(c->socket.fd);
   json_delete(c->json);
-  xfree(c);
+  mp_delete(c->pool);          // This includes the connection structure
   num_connections--;
 }
 
@@ -228,7 +228,9 @@ static int listen_read_handler(struct main_file *fi)
   if (fcntl(new_sk, F_SETFL, fcntl(new_sk, F_GETFL) | O_NONBLOCK) < 0)
     die("Cannot set O_NONBLOCK: %m");
 
-  struct client *c = xmalloc_zero(sizeof(*c));
+  struct mempool *mp = mp_new(4096);
+  struct client *c = mp_alloc_zero(mp, sizeof(*c));
+  c->pool = mp;
   c->json = json_new();
 
   c->socket.fd = new_sk;
@@ -267,7 +269,7 @@ static void init_socket(void)
   if (listen(sk, 64) < 0)
     die("listen(): %m");
 
-  int one;
+  int one = 1;
   if (setsockopt(sk, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0)
     die("setsockopt(SO_PASSCRED): %m");
 
@@ -275,6 +277,9 @@ static void init_socket(void)
   listen_socket.read_handler = listen_read_handler;
   file_add(&listen_socket);
 
+  if (chmod(socket_path, 0666) < 0)
+    die("Cannot chmod socket: %m");
+
   msg(L_INFO, "Listening on %s", socket_path);
 }