From: Mihai Pogonaru Date: Sat, 29 Jun 2019 13:54:59 +0000 (+0300) Subject: sockets.c: Change error handling to match vfs expectations X-Git-Tag: RELEASE-0.4~50 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d6239927cbe780ee6fd1891ac2b9684e16c6283f;p=unikraft%2Flibs%2Flwip.git sockets.c: Change error handling to match vfs expectations vfs expects file system functions (vnops) to return 0 on success (and update the uio structure) or a positive error number in case of an error. Signed-off-by: Mihai Pogonaru Reviewed-by: Costin Lupu --- diff --git a/sockets.c b/sockets.c index 1a3ddfd..38639f8 100644 --- a/sockets.c +++ b/sockets.c @@ -237,9 +237,18 @@ static int sock_net_close(struct vnode *s_vnode, /* * Free socket file * The rest of the resources will be freed by vfs + * + * TODO: vfs ignores close errors right now, so free our file */ uk_free(uk_alloc_get_default(), file); + /* + * lwip sets errno and returns -1 in case of error, but + * vfs expects us to return a positive errno + */ + if (ret < 0) + return errno; + return ret; } @@ -255,9 +264,12 @@ static int sock_net_write(struct vnode *s_vnode, file->vfscore_file->fd, file->sock_fd)); ret = lwip_writev(file->sock_fd, buf->uio_iov, buf->uio_iovcnt); - /* lwip sets errno and returns -1 in case of error */ + /* + * lwip sets errno and returns -1 in case of error, but + * vfs expects us to return a positive errno + */ if (ret < 0) - return ret; + return errno; buf->uio_resid -= ret; return 0; @@ -276,9 +288,12 @@ static int sock_net_read(struct vnode *s_vnode, file->vfscore_file->fd, file->sock_fd)); ret = lwip_readv(file->sock_fd, buf->uio_iov, buf->uio_iovcnt); - /* lwip sets errno and returns -1 in case of error */ + /* + * lwip sets errno and returns -1 in case of error, but + * vfs expects us to return a positive errno + */ if (ret < 0) - return ret; + return errno; buf->uio_resid -= ret; return 0;