mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
Small changes, nicer deallocation, nonblocking.
git-svn-id: file:///svn/unbound/trunk@158 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
a3abab528b
commit
3a1187b2f6
5 changed files with 50 additions and 19 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Reference in a new issue