aboutsummaryrefslogtreecommitdiff
path: root/lib/tran_sock.c
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-03-24 16:06:36 +0000
committerGitHub <noreply@github.com>2021-03-24 16:06:36 +0000
commit0c27dacfd1cf94609a8b07ece157ed83240915e0 (patch)
treed231f23e1a407d3fc60aa09e50b6411a9f694b96 /lib/tran_sock.c
parentc0c891a19d78ba8881f9bc77013bdfd583e223f2 (diff)
downloadlibvfio-user-0c27dacfd1cf94609a8b07ece157ed83240915e0.zip
libvfio-user-0c27dacfd1cf94609a8b07ece157ed83240915e0.tar.gz
libvfio-user-0c27dacfd1cf94609a8b07ece157ed83240915e0.tar.bz2
check for double attach (#403)
As seen in https://github.com/spdk/spdk/issues/1854, we should explicitly check for attaching an already-attached context, instead of silently over-writing the existing socket fd. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'lib/tran_sock.c')
-rw-r--r--lib/tran_sock.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index 3e90576..8919c3f 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -719,6 +719,13 @@ tran_sock_attach(vfu_ctx_t *vfu_ctx)
ts = vfu_ctx->tran_data;
+ if (ts->conn_fd != -1) {
+ vfu_log(vfu_ctx, LOG_ERR, "%s: already attached with fd=%d",
+ __func__, ts->conn_fd);
+ errno = EINVAL;
+ return -1;
+ }
+
ts->conn_fd = accept(ts->listen_fd, NULL, NULL);
if (ts->conn_fd == -1) {
return -1;