struct commcommon *cc=&uc->cc;
for (i=0; i<socks->n_socks; i++) {
+ struct udpsock *us=&socks->socks[i];
if (i>=nfds) continue;
if (!(fds[i].revents & POLLIN)) continue;
- assert(fds[i].fd == socks->socks[i].fd);
- int fd=socks->socks[i].fd;
+ assert(fds[i].fd == us->fd);
+ int fd=us->fd;
do {
fromlen=sizeof(from);
BUF_ASSERT_FREE(cc->rbuf);
BUF_FREE(cc->rbuf);
}
BUF_ASSERT_FREE(cc->rbuf);
- } else {
+ } else { /* rv<=0 */
BUF_FREE(cc->rbuf);
}
} while (rv>=0);
uint8_t *sa;
if (uc->use_proxy) {
+ struct udpsock *us=&socks->socks[0];
sa=buf_prepend(buf,8);
if (dest->ia.sa.sa_family != AF_INET) {
Message(M_INFO,
memcpy(sa,&dest->ia.sin.sin_addr,4);
memset(sa+4,0,4);
memcpy(sa+6,&dest->ia.sin.sin_port,2);
- sendto(socks->socks[0].fd,sa,buf->size+8,0,&uc->proxy.sa,
+ sendto(us->fd,sa,buf->size+8,0,&uc->proxy.sa,
iaddr_socklen(&uc->proxy));
buf_unprepend(buf,8);
} else {
int i,r;
bool_t allunsupported=True;
+ int af=dest->ia.sa.sa_family;
for (i=0; i<socks->n_socks; i++) {
- if (dest->ia.sa.sa_family != socks->socks[i].addr.sa.sa_family)
+ struct udpsock *us=&socks->socks[i];
+ if (us->addr.sa.sa_family != af)
/* no point even trying */
continue;
- r=sendto(socks->socks[i].fd, buf->start, buf->size, 0,
+ r=sendto(us->fd, buf->start, buf->size, 0,
&dest->ia.sa, iaddr_socklen(&dest->ia));
if (r>=0) return True;
if (!(errno==EAFNOSUPPORT || errno==ENETUNREACH))
return True;
}
+void udp_destroy_socket(struct udpcommon *uc, struct udpsock *us)
+{
+ if (us->fd>=0) {
+ close(us->fd);
+ us->fd=-1;
+ }
+}
+
bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
int failmsgclass)
{
us->fd=socket(addr->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
if (us->fd<0) FAIL("socket");
- if (fcntl(us->fd, F_SETFL, fcntl(us->fd, F_GETFL)|O_NONBLOCK)==-1)
- FAIL("fcntl(set O_NONBLOCK)");
+ setnonblock(us->fd);
setcloexec(us->fd);
#ifdef CONFIG_IPV6
if (addr->sa.sa_family==AF_INET6) {
char *argv[5], addrstr[33], portstr[5];
const char *addrfam;
int port;
+ afterfork();
switch (addr->sa.sa_family) {
case AF_INET:
sprintf(addrstr,"%08lX",(long)addr->sin.sin_addr.s_addr);
if (errno==EINTR) continue;
FAIL("waitpid for authbind");
}
- if (WIFSIGNALED(status)) {
- lg_perror(FAIL_LG,0,"authbind died on signal %s (%d)",
- strsignal(WTERMSIG(status)),WTERMSIG(status));
- goto failed;
- }
- if (WIFEXITED(status) && WEXITSTATUS(status)!=0) {
- lg_perror(FAIL_LG,0,
- "authbind died with error exit status %d",
- WEXITSTATUS(status));
+ if (status) {
+ if (WIFEXITED(status) && WEXITSTATUS(status)<127) {
+ int es=WEXITSTATUS(status);
+ lg_perror(FAIL_LG,es,
+ "authbind exited with error exit status %d;"
+ " indicates error",es);
+ } else {
+ lg_exitstatus(FAIL_LG,status,"authbind");
+ }
goto failed;
}
} else {
return True;
failed:
- if (us->fd>=0) {
- close(us->fd);
- us->fd=-1;
- }
+ udp_destroy_socket(uc,us);
return False;
#undef FAIL