[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v3 2/4] lib/vfscore: Return error when trying to close standard file descriptors
Some applications may want to close the standard file descriptors (stdin, stdout, stderr), that is perfectly normal. The underlying platform should return an error if such request is not allowed, instead of crashing. Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx> --- lib/vfscore/fd.c | 7 +++++-- lib/vfscore/include/vfscore/file.h | 2 +- lib/vfscore/main.c | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/vfscore/fd.c b/lib/vfscore/fd.c index e09dd54c..7efed741 100644 --- a/lib/vfscore/fd.c +++ b/lib/vfscore/fd.c @@ -73,14 +73,15 @@ exit: return ret; } -void vfscore_put_fd(int fd) +int vfscore_put_fd(int fd) { struct vfscore_file *fp; unsigned long flags; UK_ASSERT(fd < (int) FDTABLE_MAX_FILES); /* Currently it is not allowed to free std(in|out|err) */ - UK_ASSERT(fd > 2); + if (fd <= 2) + return -EBUSY; flags = ukplat_lcpu_save_irqf(); uk_bitmap_clear(fdtable.bitmap, fd, 1); @@ -94,6 +95,8 @@ void vfscore_put_fd(int fd) */ if (fp) fdrop(fp); + + return 0; } int vfscore_install_fd(int fd, struct vfscore_file *file) diff --git a/lib/vfscore/include/vfscore/file.h b/lib/vfscore/include/vfscore/file.h index 354a414e..c698201d 100644 --- a/lib/vfscore/include/vfscore/file.h +++ b/lib/vfscore/include/vfscore/file.h @@ -66,7 +66,7 @@ struct vfscore_file { #define FD_UNLOCK(fp) uk_mutex_unlock(&(fp->f_lock)) int vfscore_alloc_fd(void); -void vfscore_put_fd(int fd); +int vfscore_put_fd(int fd); int vfscore_install_fd(int fd, struct vfscore_file *file); struct vfscore_file *vfscore_get_file(int fd); void vfscore_put_file(struct vfscore_file *file); diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c index 8d0e4b2c..925ce762 100644 --- a/lib/vfscore/main.c +++ b/lib/vfscore/main.c @@ -205,15 +205,17 @@ UK_TRACEPOINT(trace_vfs_close_err, "%d", int); int fdclose(int fd) { struct vfscore_file *fp; + int error; fp = vfscore_get_file(fd); if (!fp) return EBADF; - vfscore_put_fd(fd); - fdrop(fp); + error = vfscore_put_fd(fd); + if (!error) + fdrop(fp); - return 0; + return error; } int close(int fd) -- 2.20.1 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |