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];
}
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)
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;
}
{
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);
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 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.
int
create_udp_sock(struct addrinfo *addr)
{
- int s, flag;
+ int s;
# if defined(IPV6_V6ONLY)
int on=1;
# endif
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;
}
#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
}
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;
+}