tap: Clean up behaviour for errors on listening Unix socket
We call tap_sock_unix_new() to handle a new connection to the qemu socket if we get an EPOLLIN event on c->fd_tap_listen. If we get any other event on the fd, we'll fall through to the "tap reset" path. But that won't do anything relevant to the listening socket, it will just close the already connected socket. Furthermore, the only other event we're subscribed to for the listening socket is EPOLLRDHUP, which doesn't apply to a non connected socket. Remove EPOLLRDHUP from the subscribed events. We don't need to explicitly add EPOLLERR, because errors are always reported. There's no obvious case that would cause an error on a listening socket anyway, and it's not obvious how we'd recover, treat it as a fatal error if it ever does happen. Finally, fold all this handling into the tap_sock_unix_new() function, there's no real reason to split it between there and tap_handler(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
28877b0fcd
commit
548e05f76a
1 changed files with 8 additions and 4 deletions
12
tap.c
12
tap.c
|
@ -1108,7 +1108,7 @@ static void tap_sock_unix_init(struct ctx *c)
|
||||||
listen(fd, 0);
|
listen(fd, 0);
|
||||||
|
|
||||||
ev.data.fd = c->fd_tap_listen = fd;
|
ev.data.fd = c->fd_tap_listen = fd;
|
||||||
ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP;
|
ev.events = EPOLLIN | EPOLLET;
|
||||||
epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev);
|
epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev);
|
||||||
|
|
||||||
info("You can now start qemu (>= 7.2, with commit 13c6be96618c):");
|
info("You can now start qemu (>= 7.2, with commit 13c6be96618c):");
|
||||||
|
@ -1121,14 +1121,18 @@ static void tap_sock_unix_init(struct ctx *c)
|
||||||
/**
|
/**
|
||||||
* tap_sock_unix_new() - Handle new connection on listening socket
|
* tap_sock_unix_new() - Handle new connection on listening socket
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
|
* @events: epoll events
|
||||||
*/
|
*/
|
||||||
static void tap_sock_unix_new(struct ctx *c)
|
static void tap_sock_unix_new(struct ctx *c, uint32_t events)
|
||||||
{
|
{
|
||||||
struct epoll_event ev = { 0 };
|
struct epoll_event ev = { 0 };
|
||||||
int v = INT_MAX / 2;
|
int v = INT_MAX / 2;
|
||||||
struct ucred ucred;
|
struct ucred ucred;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
|
|
||||||
|
if (events != EPOLLIN)
|
||||||
|
die("Error on listening Unix socket, exiting");
|
||||||
|
|
||||||
len = sizeof(ucred);
|
len = sizeof(ucred);
|
||||||
|
|
||||||
/* Another client is already connected: accept and close right away. */
|
/* Another client is already connected: accept and close right away. */
|
||||||
|
@ -1284,8 +1288,8 @@ static void tap_sock_reset(struct ctx *c)
|
||||||
void tap_handler(struct ctx *c, int fd, uint32_t events,
|
void tap_handler(struct ctx *c, int fd, uint32_t events,
|
||||||
const struct timespec *now)
|
const struct timespec *now)
|
||||||
{
|
{
|
||||||
if (fd == c->fd_tap_listen && events == EPOLLIN) {
|
if (fd == c->fd_tap_listen) {
|
||||||
tap_sock_unix_new(c);
|
tap_sock_unix_new(c, events);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue