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

[Minios-devel] [UNIKRAFT PATCH 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:07:52 +0300
  • Cc: sharan.santhanam@xxxxxxxxx
  • Delivery-date: Mon, 09 Sep 2019 09:08:16 +0000
  • Ironport-phdr: 9a23:HZUBURwf5fjJTT7XCy+O+j09IxM/srCxBDY+r6Qd2+gSIJqq85mqBkHD//Il1AaPAdyBrasU1aGO4+jJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglVmjaxe65+IRa3oAneqsUbgpZpJ7osxBfOvnZGYfldy3lyJVKUkRb858Ow84Bm/i9Npf8v9NNOXLvjcaggQrNWEDopM2Yu5M32rhbDVheA5mEdUmoNjBVFBRXO4QzgUZfwtiv6sfd92DWfMMbrQ704RSiu4qF2QxLulSwJNSM28HvPh8JwkqxVvRyvqR94zYHWboGYL+Zycr/HcN8GX2dNQtpdWipcCY28dYsPCO8BMP5Goon6vFsOsRq+BQ+xD+3p1z9InmL21rA93us9FgHGxxAgH9MIsHjOqNX1Kb8SUf2uwabU1jXPdetW2Srm54TSaBAhpuiBULRtesTS0UkiDx7Jg1qNpYD/PD6Y1v4Bv3aF4+diT+6ihXYrpxx+rzSy3MshiYnEipgLxl3K+yh12ps5KNKmREN9fNWqCoFftzuAOItzWs4iRmZotzskxbAeop67eTQKyIwgxx7Cd/yLa4iI7QznVOaWOTp4mndld6i+hxa260Sv1vb8WtOs0FZXtSVJiMPMtncV2xzS7MiIVOd981+81TuAygzf8OJJLEAumabFNZIswKQ8m5QLvUTGBCD2mUH2jKGMdkUj/+il8/joYrL9pp+ANo90jBvyMqAzmsynHOQ1KRQBX3OB9eSkyb3s5lf1QK9NjvEuiKnWrIjaJdgHpq6+GwJV14cj6xC+Dzehy9QUhGQII0xbeB2Zi4jkIFXOIPHjDfejmFSgijhqyO7APrH7BZXNNHfDmq/7fblh805c1BYzzddH6pJPCrEOOujzVVX3tNDCFR82KQq0w/rnCNpn0IMRQ2ePD7SfMKzMrVCI4vggLPKWaIALpTauY8Qisvvvi34+ghoRcLek2bMTaWukBbJ2LkPfZmDj0fkbFmJflQ0lUO3swHmfSSMbM321RL494Hc/FZq7JYzYAJiwivqb23HoTdVtemlaBwXUQj/TfIKeVqJUZQ==
  • Ironport-sdr: ScdP9BE+XahU1KXP25GOfYp0uu0XBFsy2f4hEK7BHc1Ocx4lMoiUrfSro95WERdpRzlwdflc0d bWjhBN6Er9Ww==
  • 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®.