tap: Exit if we fail to bind a UNIX domain socket with explicit path

In tap_sock_unix_open(), if we have a given path for the socket from
configuration, we don't need to loop over possible paths, so we exit
the loop on the first iteration, unconditionally.

But if we failed to bind() the socket to that explicit path, we should
exit, instead of continuing. Otherwise we'll pretend we're up and
running, but nobody can contact us, and this might be mildly confusing
for users.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=2299474
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Stefano Brivio 2024-07-24 23:05:23 +02:00
parent f72d35a78d
commit 6ff702f325

7
tap.c
View file

@ -1139,8 +1139,11 @@ int tap_sock_unix_open(char *sock_path)
close(ex); close(ex);
unlink(path); unlink(path);
if (!bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) || ret = bind(fd, (const struct sockaddr *)&addr, sizeof(addr));
*sock_path) if (*sock_path && ret)
die_perror("Failed to bind UNIX domain socket");
if (!ret)
break; break;
} }