Skip to content

Commit a8f01f8

Browse files
committed
Merge branch 'rs/daemon-fixes' into maint
* rs/daemon-fixes: daemon: remove write-only variable maxfd daemon: fix error message after bind() daemon: handle gethostbyname() error
2 parents 3c2dc76 + 107efbe commit a8f01f8

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

daemon.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -573,20 +573,21 @@ static void parse_host_arg(char *extra_args, int buflen)
573573
static char addrbuf[HOST_NAME_MAX + 1];
574574

575575
hent = gethostbyname(hostname);
576+
if (hent) {
577+
ap = hent->h_addr_list;
578+
memset(&sa, 0, sizeof sa);
579+
sa.sin_family = hent->h_addrtype;
580+
sa.sin_port = htons(0);
581+
memcpy(&sa.sin_addr, *ap, hent->h_length);
582+
583+
inet_ntop(hent->h_addrtype, &sa.sin_addr,
584+
addrbuf, sizeof(addrbuf));
576585

577-
ap = hent->h_addr_list;
578-
memset(&sa, 0, sizeof sa);
579-
sa.sin_family = hent->h_addrtype;
580-
sa.sin_port = htons(0);
581-
memcpy(&sa.sin_addr, *ap, hent->h_length);
582-
583-
inet_ntop(hent->h_addrtype, &sa.sin_addr,
584-
addrbuf, sizeof(addrbuf));
585-
586-
free(canon_hostname);
587-
canon_hostname = xstrdup(hent->h_name);
588-
free(ip_address);
589-
ip_address = xstrdup(addrbuf);
586+
free(canon_hostname);
587+
canon_hostname = xstrdup(hent->h_name);
588+
free(ip_address);
589+
ip_address = xstrdup(addrbuf);
590+
}
590591
#endif
591592
}
592593
}
@@ -834,7 +835,6 @@ static const char *ip2str(int family, struct sockaddr *sin, socklen_t len)
834835
static int setup_named_sock(char *listen_addr, int listen_port, struct socketlist *socklist)
835836
{
836837
int socknum = 0;
837-
int maxfd = -1;
838838
char pbuf[NI_MAXSERV];
839839
struct addrinfo hints, *ai0, *ai;
840840
int gai;
@@ -902,9 +902,6 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
902902
ALLOC_GROW(socklist->list, socklist->nr + 1, socklist->alloc);
903903
socklist->list[socklist->nr++] = sockfd;
904904
socknum++;
905-
906-
if (maxfd < sockfd)
907-
maxfd = sockfd;
908905
}
909906

910907
freeaddrinfo(ai0);
@@ -943,7 +940,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
943940
}
944941

945942
if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
946-
logerror("Could not listen to %s: %s",
943+
logerror("Could not bind to %s: %s",
947944
ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),
948945
strerror(errno));
949946
close(sockfd);

0 commit comments

Comments
 (0)