[PATCH ucspi-vsock] vsock_accept: return fd instead of 0 on success
This would result in the spawned process being hooked up to stdin, instead of the vsock. Then stdin would be closed, so subsequent processes would be connected to nothing. Oops. --- I am... a bit embarassed that I didn't notice this after already fixing the exact same problem in vsock_connect[1]. Maybe I can write an integration test that runs vsockserver and vsockclient and checks they actually do the right thing... [1]: https://spectrum-os.org/lists/archives/spectrum-devel/20210309171816.8589-1-... vsock.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vsock.c b/vsock.c index d9ff3b6..e6a173c 100644 --- a/vsock.c +++ b/vsock.c @@ -32,14 +32,15 @@ int vsock_accept(int sockfd, uint32_t *cid, uint32_t *port) { struct sockaddr_vm addr = { 0 }; socklen_t addr_size = sizeof addr; + int fd; - if (accept(sockfd, (struct sockaddr *)&addr, &addr_size) == -1) + if ((fd = accept(sockfd, (struct sockaddr *)&addr, &addr_size)) == -1) return -1; *cid = addr.svm_cid; *port = addr.svm_port; - return 0; + return fd; } int vsock_connect(int fd, uint32_t cid, uint32_t port) -- 2.30.0
On Wed Mar 10, 2021 at 12:45 PM PST, Alyssa Ross wrote:
This would result in the spawned process being hooked up to stdin, instead of the vsock. Then stdin would be closed, so subsequent processes would be connected to nothing. Oops.
--- I am... a bit embarassed that I didn't notice this after already fixing the exact same problem in vsock_connect[1].
Technically, you _did_ notice this after fixing the the problem in vsock_connect -- just not immediately / at the same time ;)
Maybe I can write an integration test that runs vsockserver and vsockclient and checks they actually do the right thing...
[1]: https://spectrum-os.org/lists/archives/spectrum-devel/20210309171816.8589-1-...
vsock.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/vsock.c b/vsock.c index d9ff3b6..e6a173c 100644 --- a/vsock.c +++ b/vsock.c @@ -32,14 +32,15 @@ int vsock_accept(int sockfd, uint32_t *cid, uint32_t *port) { struct sockaddr_vm addr = { 0 }; socklen_t addr_size = sizeof addr; + int fd;
- if (accept(sockfd, (struct sockaddr *)&addr, &addr_size) == -1) + if ((fd = accept(sockfd, (struct sockaddr *)&addr, &addr_size)) == -1) return -1;
*cid = addr.svm_cid; *port = addr.svm_port;
- return 0; + return fd; }
int vsock_connect(int fd, uint32_t cid, uint32_t port) -- 2.30.0
Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
participants (2)
-
Alyssa Ross -
Cole Helbling