Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern int dcc_total;
extern time_t now;
extern Tcl_Interp *interp;
#ifdef EGG_TDNS
pthread_attr_t attr;
struct dns_thread_node *dns_thread_head;
extern int pref_af;
#else
Expand All @@ -48,6 +49,15 @@ extern Tcl_Interp *interp;

devent_t *dns_events = NULL;

#ifdef EGG_TDNS
void init_tdns() {
if (pthread_attr_init(&attr))
fatal("ERROR: init_tnds(): pthread_attr_init()", 0);
dns_thread_head = nmalloc(sizeof(struct dns_thread_node));
dns_thread_head->next = NULL;
}
#endif

static int ipaddr_equal(const sockname_t *ip, const sockname_t *ip2)
{
if (!ip || !ip2) {
Expand Down Expand Up @@ -575,14 +585,7 @@ void *thread_dns_ipbyhost(void *arg)
void core_dns_hostbyip(sockname_t *addr)
{
struct dns_thread_node *dtn = nmalloc(sizeof(struct dns_thread_node));
pthread_attr_t attr;

if (pthread_attr_init(&attr)) {
putlog(LOG_MISC, "*", "core_dns_hostbyip(): pthread_attr_init(): error = %s", strerror(errno));
call_hostbyip(addr, iptostr(&addr->addr.sa), 0);
nfree(dtn);
return;
}
if (pthread_mutex_init(&dtn->mutex, NULL))
fatal("ERROR: core_dns_hostbyip(): pthread_mutex_init() failed", 0);
if (pipe(dtn->fildes) < 0) {
Expand All @@ -609,25 +612,19 @@ void core_dns_ipbyhost(char *host)
{
sockname_t addr;
struct dns_thread_node *dtn;
pthread_attr_t attr;

/* if addr is ip instead of host */
if (setsockname(&addr, host, 0, 0) != AF_UNSPEC) {
call_ipbyhost(host, &addr, 1);
return;
}
dtn = nmalloc(sizeof(struct dns_thread_node));
if (pthread_attr_init(&attr)) {
putlog(LOG_MISC, "*", "core_dns_ipbyhost(): pthread_attr_init(): error = %s", strerror(errno));
call_ipbyhost(host, &addr, 0);
nfree(dtn);
return;
}
if (pthread_mutex_init(&dtn->mutex, NULL))
fatal("ERROR: core_dns_ipbyhost(): pthread_mutex_init() failed", 0);
if (pipe(dtn->fildes) < 0) {
putlog(LOG_MISC, "*", "core_dns_ipbyhost(): pipe(): error: %s", strerror(errno));
call_ipbyhost(host, &addr, 0);
pthread_mutex_destroy(&dtn->mutex);
nfree(dtn);
return;
}
Expand All @@ -640,6 +637,7 @@ void core_dns_ipbyhost(char *host)
close(dtn->fildes[0]);
close(dtn->fildes[1]);
dns_thread_head->next = dtn->next;
pthread_mutex_destroy(&dtn->mutex);
nfree(dtn);
return;
}
Expand Down
5 changes: 2 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,9 +1068,8 @@ int main(int arg_c, char **arg_v)
link_statics();
#endif
#ifdef EGG_TDNS
/* initialize dns_thread_head before chanprog() */
dns_thread_head = nmalloc(sizeof(struct dns_thread_node));
dns_thread_head->next = NULL;
/* initialize attr and dns_thread_head before chanprog() */
init_tdns();
#endif
ctime_r(&now, s);
s[24] = 0;
Expand Down
1 change: 1 addition & 0 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ int sockread(char *s, int *len, sock_list *slist, int slistmax, int tclonly)
if (pthread_join(dtn->thread_id, &res))
putlog(LOG_MISC, "*", "sockread(): pthread_join(): error = %s", strerror(errno));
dtn_prev->next = dtn->next;
pthread_mutex_destroy(&dtn->mutex);
nfree(dtn);
dtn = dtn_prev;
} else
Expand Down
1 change: 1 addition & 0 deletions src/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void del_dcc(int);
void changeover_dcc(int, struct dcc_table *, int);

/* dns.c */
void init_tdns();
extern void (*dns_hostbyip) (sockname_t *);
void core_dns_hostbyip(sockname_t *);
void call_hostbyip(sockname_t *, char *, int);
Expand Down
Loading