Better fix for unlinking control sockets
authorAlan T. DeKok <aland@freeradius.org>
Mon, 26 Jul 2010 14:59:27 +0000 (16:59 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 26 Jul 2010 14:59:44 +0000 (16:59 +0200)
src/main/command.c
src/main/listen.c

index 60afa5c..650f5cd 100644 (file)
@@ -66,6 +66,7 @@ struct fr_command_table_t {
 
 typedef struct fr_command_socket_t {
        char    *path;
+       char    *copy;          /* <sigh> */
        uid_t   uid;
        gid_t   gid;
        int     mode;
@@ -254,6 +255,7 @@ static int fr_server_domain_socket(const char *path)
        return sockfd;
 }
 
+
 static void command_close_socket(rad_listen_t *this)
 {
        this->status = RAD_LISTEN_STATUS_CLOSED;
@@ -1831,6 +1833,16 @@ static fr_command_table_t command_table[] = {
 };
 
 
+static void command_socket_free(rad_listen_t *this)
+{
+       fr_command_socket_t *sock = this->data;
+
+       unlink(sock->copy);
+       free(sock->copy);
+       sock->copy = NULL;
+}
+
+
 /*
  *     Parse the unix domain sockets.
  *
@@ -1846,6 +1858,9 @@ static int command_socket_parse(CONF_SECTION *cs, rad_listen_t *this)
                return -1;
        }
 
+       sock->copy = NULL;
+       if (sock->path) sock->copy = strdup(sock->path);
+
 #if defined(HAVE_GETPEEREID) || defined (SO_PEERCRED)
        if (sock->uid_name) {
                struct passwd *pw;
index 1c36953..2ff447c 100644 (file)
@@ -1817,7 +1817,7 @@ static const rad_listen_master_t master_listen[RAD_LISTEN_MAX] = {
 
 #ifdef WITH_COMMAND_SOCKET
        /* TCP command socket */
-       { command_socket_parse, NULL,
+       { command_socket_parse, command_socket_free,
          command_domain_accept, command_domain_send,
          command_socket_print, command_socket_encode, command_socket_decode },
 #endif