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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 2 Sep 2019 16:22:20 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Mon, 02 Sep 2019 13:22:45 +0000
  • Ironport-phdr: 9a23:rDvYMB+4xbkxsv9uRHKM819IXTAuvvDOBiVQ1KB21+wcTK2v8tzYMVDF4r011RmVBN+dsq0cwLSM+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxhWiDanfL9/Lgm6oQrQu8UInIBvNrs/xhzVr3VSZu9Y33loJVWdnxb94se/4ptu+DlOtvwi6sBNT7z0c7w3QrJEAjsmNXs15NDwuhnYUQSP/HocXX4InRdOHgPI8Qv1Xpb1siv9q+p9xCyXNtD4QLwoRTiv6bpgRRn1gykFKjE56nnahMxugqxGrhyvpBtxzIzaYIyOKPZyYrnQcc8ASGZdQspcUTFKDIOmb4sICuoMJfhVr47mp1sSrBu+AxSnCuXyyj9Qm3/9wKo33PgmEQHdwAwgHtQOvG7QrNXoLKcSTPu4w7XTzTnZd/NWxCzy5JLSchAmuPyBW697f8nJyUQ3Cg/IgUicpZbmMj6VzOgBrXaX4uh6We+hk2Irtg58riW1ysovioTFnJwZx17K+Clj3Yo4KsO0RUhmatC+CpRQrTuVN45uT8MnRGFnpTg1x6UduZ6+YCgK0JMnxwPDa/Cfc4iH/BbjVOGJLDdmgXJqYrO/hxKo/Ue80e3wTNG00EtRoSZfiNnMsWgB1x3V6seZVvtw5lqt1DmS2wzJ6exJIVo4mbTFJ5Mj2LI9mIIfsUHZES/3nEX2grWWdkIh+uWw9+vnZa7mpoOdN49ykA3+NrkumtSiAekjLgcORHKX+fyh1LL450H5WrJKguUskqbFqJDaOdgbpqmhDg9Q04Yj7Re/DzC90NgBgHYIMkxFdwyDj4XyP1HOIev4Deukg1i2nzZk2fbGMqfmApXXIXjJiK3hcqpl605A1AozyshS55xKBbEFIfLzQlH+uMbYDh8kMgy73+fnBc571owARW2PBrWWP7jIvVCW++IlO/OMa5MNuDbhN/gl4ObjjWQ5mVAHZ6mmx50XZGqjHvt8JUWZfXrsjc0HEWgQuwozV+rqh0OeXj5XfXm9RLgw6S8mCIi+F4fMWpitgKCd3Ce8BpBWfWFGClWLEXfubYmEWOoMZzyUIs5gjDMET6OsS4k/2h6ysA/10aFoIvDK9S0F5trf041w5uvSkgp3+TFqAsC112CWU3oyjm4OATgs0/NRu0t4n3yEyrR5hbR8CMROr6dCVRwmNJiay/FiFvj5QUTZY93PUlHwEYbuOi04Ut9km4xGWE16Adj31h0=
  • Ironport-sdr: LbgHNY9xa/Dgxr4VUSSwT95cxLoLvKeeof1SPv2DbrS4wlbJgX+kW9wKWCLnmIRu21hjl/Hjhf uc3VgM0I8EaA==
  • 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..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;
 
        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)
-- 
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®.