]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Small changes, nicer deallocation, nonblocking.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 1 Mar 2007 15:50:57 +0000 (15:50 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 1 Mar 2007 15:50:57 +0000 (15:50 +0000)
git-svn-id: file:///svn/unbound/trunk@158 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/worker.c
doc/Changelog
services/listen_dnsport.c
util/net_help.c
util/net_help.h

index 96e0c1f2d73d950f2ff1711d6191443109cb2342..cfaf0c9ccdfe889c5f47a9e5aeeda28e017cb9f7 100644 (file)
@@ -293,6 +293,12 @@ worker_create(struct daemon* daemon, int id)
                        log_err("socketpair: %s", strerror(errno));
                        return NULL;
                }
+               if(!fd_set_nonblock(sv[0]) || !fd_set_nonblock(sv[1])) {
+                       close(sv[0]);
+                       close(sv[1]);
+                       free(worker);
+                       return NULL;
+               }
                worker->cmd_send_fd = sv[0];
                worker->cmd_recv_fd = sv[1];
        }
@@ -313,6 +319,10 @@ worker_init(struct worker* worker, struct config_file *cfg,
                return 0;
        }
        if(do_sigs) {
+               ub_thread_sig_unblock(SIGHUP);
+               ub_thread_sig_unblock(SIGINT);
+               ub_thread_sig_unblock(SIGQUIT);
+               ub_thread_sig_unblock(SIGTERM);
                worker->comsig = comm_signal_create(worker->base, 
                        worker_sighandler, worker);
                if(!worker->comsig || !comm_signal_bind(worker->comsig, SIGHUP)
@@ -323,10 +333,6 @@ worker_init(struct worker* worker, struct config_file *cfg,
                        worker_delete(worker);
                        return 0;
                }
-               ub_thread_sig_unblock(SIGHUP);
-               ub_thread_sig_unblock(SIGINT);
-               ub_thread_sig_unblock(SIGQUIT);
-               ub_thread_sig_unblock(SIGTERM);
        } else { /* !do_sigs */
                worker->comsig = 0;
        }
@@ -393,12 +399,6 @@ worker_delete(struct worker* worker)
 {
        if(!worker) 
                return;
-       if(worker->cmd_send_fd != -1)
-               close(worker->cmd_send_fd);
-       worker->cmd_send_fd = -1;
-       if(worker->cmd_recv_fd != -1)
-               close(worker->cmd_recv_fd);
-       worker->cmd_recv_fd = -1;
        listen_delete(worker->front);
        outside_network_delete(worker->back);
        comm_signal_delete(worker->comsig);
@@ -406,6 +406,14 @@ worker_delete(struct worker* worker)
        comm_base_delete(worker->base);
        ub_randfree(worker->rndstate);
        free(worker->rndstate);
+       /* close fds after deleting commpoints, to be sure.
+          Also epoll does not like closing fd before event_del */
+       if(worker->cmd_send_fd != -1)
+               close(worker->cmd_send_fd);
+       worker->cmd_send_fd = -1;
+       if(worker->cmd_recv_fd != -1)
+               close(worker->cmd_recv_fd);
+       worker->cmd_recv_fd = -1;
        free(worker);
 }
 
index e0af11f9992869033d11bea608e8e991a59fa10f..9afc958242fdcbee870005fd29c4ff5672e6e251 100644 (file)
@@ -1,3 +1,8 @@
+1 March 2007: Wouter
+       - Signals, libevent and threads work well, with libevent patch and
+         changes to code (close after event_del).
+       - set ipc pipes nonblocking.
+
 27 February 2007: Wouter
        - ub_thread_join portable definition.
        - forking is used if no threading is available.
index d3d3c6d8518face098b273805d1f459234fdd174..52268647ba119b28e58316a7fee313eb1b244b51 100644 (file)
@@ -89,7 +89,7 @@ verbose_print_addr(struct addrinfo *addr)
 int
 create_udp_sock(struct addrinfo *addr)
 {
-       int s, flag;
+       int s;
 # if defined(IPV6_V6ONLY)
        int on=1;
 # endif
@@ -128,15 +128,8 @@ create_udp_sock(struct addrinfo *addr)
                log_err("can't bind socket: %s", strerror(errno));
                return -1;
        }
-       if((flag = fcntl(s, F_GETFL)) == -1) {
-               log_err("can't fcntl F_GETFL: %s", strerror(errno));
-               flag = 0;
-       }
-       flag |= O_NONBLOCK;
-       if(fcntl(s, F_SETFL, flag) == -1) {
-               log_err("can't fcntl F_SETFL: %s", strerror(errno));
+       if(!fd_set_nonblock(s))
                return -1;
-       }
        return s;
 }
 
index 8ffdf44caa870524d03d3b1290b9abe1f236e873..2ffd41d3fedaff243ea75d78f40d9642b49fce78 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "config.h"
 #include "util/net_help.h"
+#include "util/log.h"
+#include <fcntl.h>
 
 /** returns true is string addr is an ip6 specced address. */
 int
@@ -69,3 +71,19 @@ write_socket(int s, const void *buf, size_t size)
         }
         return 1;
 }
+
+int 
+fd_set_nonblock(int s) 
+{
+       int flag;
+       if((flag = fcntl(s, F_GETFL)) == -1) {
+               log_err("can't fcntl F_GETFL: %s", strerror(errno));
+               flag = 0;
+       }
+       flag |= O_NONBLOCK;
+       if(fcntl(s, F_SETFL, flag) == -1) {
+               log_err("can't fcntl F_SETFL: %s", strerror(errno));
+               return 0;
+       }
+       return 1;
+}
index 8fdcc548172a8b6a14345f0f6acb37c2bb4b2c14..78d432f76e8c16d75d4c2bf6caa1557af41f27c4 100644 (file)
@@ -59,4 +59,11 @@ int str_is_ip6(const char* str);
 int
 write_socket(int s, const void *buf, size_t size);
 
+/**
+ * Set fd nonblocking.
+ * @param s: file descriptor.
+ * @return: 0 on error (error is printed to log).
+ */
+int fd_set_nonblock(int s); 
+
 #endif /* NET_HELP_H */