passt: Initialise socket after getting addresses and routes

...otherwise, both IPv4 and IPv6 are considered disabled, and nothing
works anymore.

While at it, don't fork to background on debug builds, and log to
stderr too in that case.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-03-20 21:12:19 +01:00
parent 9f80499313
commit 35015ce72e

14
passt.c
View file

@ -540,21 +540,25 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (icmp_sock_init(&c) || tcp_sock_init(&c) || udp_sock_init(&c)) #if DEBUG
exit(EXIT_FAILURE); openlog("passt", LOG_PERROR, LOG_DAEMON);
#else
fd_unix = sock_unix();
openlog("passt", 0, LOG_DAEMON); openlog("passt", 0, LOG_DAEMON);
if (daemon(0, 0)) { if (daemon(0, 0)) {
fprintf(stderr, "Failed to fork into background\n"); fprintf(stderr, "Failed to fork into background\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif
get_routes(&c); get_routes(&c);
get_addrs(&c); get_addrs(&c);
get_dns(&c); get_dns(&c);
fd_unix = sock_unix();
if (icmp_sock_init(&c) || tcp_sock_init(&c) || udp_sock_init(&c))
exit(EXIT_FAILURE);
if (c.v4) { if (c.v4) {
info("ARP:"); info("ARP:");
info(" address: %02x:%02x:%02x:%02x:%02x:%02x from %s", info(" address: %02x:%02x:%02x:%02x:%02x:%02x from %s",