add logging everytime we create a filedescriptor in the main ctdb daemon
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 15 Oct 2009 00:24:54 +0000 (11:24 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 15 Oct 2009 00:24:54 +0000 (11:24 +1100)
so we can spot if there are leaks.

plug two leaks for filedescriptors related to when sending ARP fail
and one leak when we can not parse the local address during tcp connection establish

common/system_linux.c
server/ctdb_daemon.c
server/ctdb_lockwait.c
server/ctdb_logging.c
server/ctdb_persistent.c
server/ctdb_recover.c
server/ctdb_recoverd.c
server/ctdb_traverse.c
server/ctdb_vacuum.c
server/eventscript.c
tcp/tcp_connect.c

index 7a580cc584c8f9ef4cbf192ea5a82315b2a9009d..999208d2fe727a0b85392071d4afb82ced324c89 100644 (file)
@@ -92,9 +92,11 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
                        return -1;
                }
 
+               DEBUG(DEBUG_NOTICE, (__location__ " Created SOCKET FD:%d for sending arp\n", s));
                strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
                if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
                        DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not found\n", iface));
+                       close(s);
                        return -1;
                }
 
@@ -171,6 +173,7 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
                ret = sendto(s, buffer, 64, 0, (struct sockaddr *)&sall, sizeof(sall));
                if (ret < 0 ){
                        DEBUG(DEBUG_CRIT,(__location__ " failed sendto\n"));
+                       close(s);
                        return -1;
                }
 
@@ -183,9 +186,11 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
                        return -1;
                }
 
+               DEBUG(DEBUG_NOTICE, (__location__ " Created SOCKET FD:%d for sending arp\n", s));
                strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
                if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
                        DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not found\n", iface));
+                       close(s);
                        return -1;
                }
 
@@ -422,6 +427,8 @@ int ctdb_sys_open_capture_socket(const char *iface, void **private_data)
                return -1;
        }
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created RAW SOCKET FD:%d for tcp tickle\n", s));
+
        set_nonblocking(s);
        set_close_on_exec(s);
 
index 0af3bc1836e5b36483949dfcb63a5112efeb75ee..cc496f54715acc8823e9a22f402bd39e9b4ed248 100644 (file)
@@ -559,6 +559,8 @@ static void ctdb_accept_client(struct event_context *ev, struct fd_event *fde,
        set_nonblocking(fd);
        set_close_on_exec(fd);
 
+       DEBUG(DEBUG_NOTICE,(__location__ " Created SOCKET FD:%d to connected child\n", fd));
+
        client = talloc_zero(ctdb, struct ctdb_client);
 #ifdef _AIX
        if (getsockopt(fd, SOL_SOCKET, SO_PEERID, &cr, &crl) == 0) {
index be3a0979d9d19b58082671b43dd90bcc1b520dec..e02cd21a9443224fb1a64918e559e04c16c4c4d1 100644 (file)
@@ -146,6 +146,10 @@ struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
        }
 
        close(result->fd[1]);
+       set_close_on_exec(result->fd[0]);
+
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d to child lockwait process\n", result->fd[0]));
+
        talloc_set_destructor(result, lockwait_destructor);
 
        result->fde = event_add_fd(ctdb_db->ctdb->ev, result, result->fd[0],
index ebf4eef357491660b4ed66493e0eb2ebc6e70474..7cd58ad14286c4ab02113350f7b9d5f8ca3150db 100644 (file)
@@ -250,6 +250,8 @@ int ctdb_set_child_logging(struct ctdb_context *ctdb)
        set_close_on_exec(p[0]);
        ctdb->log->pfd = p[0];
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d for logging\n", p[0]));
+
        close(1);
        close(2);
        if (p[1] != 1) {
index f7578d158607bd4857592e20a583cae3e05b6bd0..77538d98f910fc70ed626183badf3d82c591bb28 100644 (file)
@@ -454,8 +454,12 @@ struct childwrite_handle *ctdb_childwrite(struct ctdb_db_context *ctdb_db,
        }
 
        close(result->fd[1]);
+       set_close_on_exec(result->fd[0]);
+
        talloc_set_destructor(result, childwrite_destructor);
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d for ctdb_childwrite\n", result->fd[0]));
+
        result->fde = event_add_fd(ctdb_db->ctdb->ev, result, result->fd[0],
                                   EVENT_FD_READ|EVENT_FD_AUTOCLOSE, childwrite_handler,
                                   (void *)result);
index 21dc28d05d23804dd20427c2bc63f891bc688afa..862168e97eab2c778d1eebc5592a2c5319cd5450 100644 (file)
@@ -736,10 +736,14 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
                _exit(0);
        }
        close(state->fd[1]);
+       set_close_on_exec(state->fd[0]);
+
        state->fd[1] = -1;
 
        talloc_set_destructor(state, set_recmode_destructor);
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d for setrecmode\n", state->fd[0]));
+
        state->te = event_add_timed(ctdb->ev, state, timeval_current_ofs(5, 0),
                                    ctdb_set_recmode_timeout, state);
 
index d759856cd97ebee2a151b5ef644de2cd0dbcff3d..83fc808aa966aae69f3ab4481d3d5bd7d0871abb 100644 (file)
@@ -2520,6 +2520,9 @@ static int check_recovery_lock(struct ctdb_context *ctdb)
        }
        close(state->fd[1]);
        state->fd[1] = -1;
+       set_close_on_exec(state->fd[0]);
+
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d for check_recovery_lock\n", state->fd[0]));
 
        talloc_set_destructor(state, check_reclock_destructor);
 
@@ -3311,6 +3314,8 @@ int ctdb_start_recoverd(struct ctdb_context *ctdb)
                exit(1);
        }
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d to recovery daemon\n", fd[0]));
+
        event_add_fd(ctdb->ev, ctdb, fd[0], EVENT_FD_READ|EVENT_FD_AUTOCLOSE, 
                     ctdb_recoverd_parent, &fd[0]);     
 
index dbb4b4f6cc6cb07df173fafd06fa92b0f2cce333..d66036f9a1c4de81a36b8c932cde89af0af82961 100644 (file)
@@ -176,6 +176,8 @@ static struct ctdb_traverse_local_handle *ctdb_traverse_local(struct ctdb_db_con
        }
 
        close(h->fd[1]);
+       set_close_on_exec(h->fd[0]);
+
        talloc_set_destructor(h, traverse_local_destructor);
 
        DLIST_ADD(ctdb_db->traverse, h);
@@ -184,6 +186,8 @@ static struct ctdb_traverse_local_handle *ctdb_traverse_local(struct ctdb_db_con
          setup a packet queue between the child and the parent. This
          copes with all the async and packet boundary issues
         */
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d to child traverse\n", h->fd[0]));
+
        h->queue = ctdb_queue_setup(ctdb_db->ctdb, h, h->fd[0], 0, ctdb_traverse_local_handler, h);
        if (h->queue == NULL) {
                talloc_free(h);
index 69991b51f2001cd81ac659ecfc569723d8120665..b1927bab67f6b10b4fa79b10b71a95f43985953c 100644 (file)
@@ -847,6 +847,8 @@ ctdb_vacuum_event(struct event_context *ev, struct timed_event *te,
                timeval_current_ofs(ctdb->tunable.vacuum_max_run_time, 0),
                vacuum_child_timeout, child_ctx);
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d to child vacuum process\n", child_ctx->fd[0]));
+
        event_add_fd(ctdb->ev, child_ctx, child_ctx->fd[0],
                EVENT_FD_READ|EVENT_FD_AUTOCLOSE,
                vacuum_child_handler,
index 6d2b370c1d010c170e860e1f74e4e70f5f4ca4df..3d139c0c0f32b1e8aba17bc8a443d117c424772a 100644 (file)
@@ -812,6 +812,8 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
        close(state->fd[1]);
        set_close_on_exec(state->fd[0]);
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created PIPE FD:%d to child eventscript process\n", state->fd[0]));
+
        event_add_fd(ctdb->ev, state, state->fd[0], EVENT_FD_READ|EVENT_FD_AUTOCLOSE,
                     ctdb_event_script_handler, state);
 
index e3d7772ae4e044576ceb95faa25973730796203a..20748606018dd3dbe11bffc3f3418d18e103a788 100644 (file)
@@ -158,6 +158,8 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
        set_nonblocking(tnode->fd);
        set_close_on_exec(tnode->fd);
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created TCP SOCKET FD:%d\n", tnode->fd));
+
        /* Bind our side of the socketpair to the same address we use to listen
         * on incoming CTDB traffic.
         * We must specify this address to make sure that the address we expose to
@@ -166,6 +168,8 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
         */
        ZERO_STRUCT(sock_in);
        if (ctdb_tcp_get_address(ctdb, ctdb->address.address, &sock_in) != 0) {
+               DEBUG(DEBUG_ERR, (__location__ " Failed to find our address. Failing bind.\n"));
+               close(tnode->fd);
                return;
        }
 
@@ -186,6 +190,7 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
        default:
                DEBUG(DEBUG_ERR, (__location__ " unknown family %u\n",
                        sock_in.sa.sa_family));
+               close(tnode->fd);
                return;
        }
 #ifdef HAVE_SOCK_SIN_LEN
@@ -253,6 +258,8 @@ static void ctdb_listen_event(struct event_context *ev, struct fd_event *fde,
        set_nonblocking(in->fd);
        set_close_on_exec(in->fd);
 
+       DEBUG(DEBUG_NOTICE, (__location__ " Created SOCKET FD:%d to incoming ctdb connection\n", fd));
+
         setsockopt(in->fd,SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(one));
 
        in->queue = ctdb_queue_setup(ctdb, in, in->fd, CTDB_TCP_ALIGNMENT,