[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH 2/3] lib/vfscore: Return error when trying to close standard file descriptors



Hello,

Please find the comments inline.

Thanks & Regards

Sharan

On 9/2/19 3:22 PM, Costin Lupu wrote:
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..f1a268c4 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 -EINVAL;
Maybe we could 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 51f0791a..05434dfe 100644
--- a/lib/vfscore/include/vfscore/file.h
+++ b/lib/vfscore/include/vfscore/file.h
@@ -62,7 +62,7 @@ struct vfscore_file {
  };
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 be055b78..4498811d 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)

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.