[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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 9 Sep 2019 12:58:00 +0300
  • Cc: sharan.santhanam@xxxxxxxxx
  • Delivery-date: Mon, 09 Sep 2019 09:58:27 +0000
  • Ironport-phdr: 9a23:FwXvtBPBgunD0PS04Sol6mtUPXoX/o7sNwtQ0KIMzox0Iv7/rarrMEGX3/hxlliBBdydt6sezbOG7eu5CSQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTagf79+Ngi6oAbQu8UZnIdvKbs6xwfUrHdPZ+lY335jK0iJnxb76Mew/Zpj/DpVtvk86cNOUrj0crohQ7BAAzsoL2465MvwtRneVgSP/WcTUn8XkhVTHQfI6gzxU4rrvSv7sup93zSaPdHzQLspVzmu87tnRRn1gyoBKjU38nzYitZogaxbvhyvuhJxzY3Tbo6XOvpzZb/Rcc8ASGZdRMtdSzBND4WhZIUPFeoBOuNYopHjqlsJthu+GQisBOXywTFOm3/2xbA62PkmHA7a2wwgBM4OsHXSrNnvMKcSTPi1zLTTwDrfdPNawy/96JXTfRw7u/GMWqt9fMzMwkcsDwPIlkicpIP4Mz+P1ekAs3KX4/R+We+tkWIqpRl9riWgy8sxkIXEhYIYxkra+Sh3zos5P8C0RUFlbdOiDZBerTuVN5FsTcMnW2xovSE6xaAYtpOjZygKzYgnxwbYa/yab4iE+hLjW/iVITd/nH9lZre/iAyz8Uik0OHzStK03ExSripYidbArGoN1xvL5siGTPty4Fuh1C6S2w3c9+1IO0M5mKrBJ5I/3LI9lIAfvErbEi/zgkr2jauWdks++uiv7uTqeqnpppiHN49oiwH+NL4imsiiAeQgLwgDRHSU+f+m2L374E32W69GjucxkqXBqpDVOdwbprKlAw9Syosj7he/DzGn0NQfhnkLNU9KdwyZj4f3P1HDO/T4Dfakg1Swizdn3f/HMaPnApnXKXjDirjhd65n60FA0Aoz0cxf55VMB7EaIPL8QFXxu8beDhMjKAy72eDnCMl91owEX2KAGKqZPbjUsVCW+u0vJ/ODa5QPtDnjNvh2r8Lp2Ho4n14aZuyl0IUabFi8H+96OAOJbHyqhc0OQkkQuQ9rZ+vxlFyEGRpOf2v6C6k7/S06DsSiEJ/ebou2xqSc1mGhGcsFNSh9FlmQHCKwJM2/UPAWZXfKLw==
  • Ironport-sdr: H1TCGP9IQd9qV8cPAgS9sJy0N/UVL6hMomJIYYeyjDByueANf+Uu1o76jOUSOLqCkF7daO3Rjn VqcjdynAa04A==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

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

 


Rackspace

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