[Top][All Lists]

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

[Qemu-devel] [PATCH] virtio-9p: open should not return EBADF

From: Sripathi Kodi
Subject: [Qemu-devel] [PATCH] virtio-9p: open should not return EBADF
Date: Mon, 13 Sep 2010 20:01:45 +0530
User-agent: StGIT/0.14.3

When 9P server fails to create a file due to permission problems it should
return EPERM. However the current 9P2000.L code returns EBADF. EBADF is NOT
a valid return value from open() call.

The problem is because we do not preserve the errno variable properly. If the
file open had failed, the call to close() on the fd in v9fs_post_lcreate()
fails and sets errno to EBADF. We should preserve the errno that we got from
open() and we should call close() only if we had a valid fd.

Signed-off-by: Sripathi Kodi <address@hidden>

 hw/virtio-9p.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 32fa3bc..fd2147e 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1758,8 +1758,10 @@ static void v9fs_post_lcreate(V9fsState *s, 
V9fsLcreateState *vs, int err)
         err = vs->offset;
     } else {
         vs->fidp->fid_type = P9_FID_NONE;
-        close(vs->fidp->fs.fd);
         err = -errno;
+        if (vs->fidp->fs.fd > 0) {
+            close(vs->fidp->fs.fd);
+        }
     complete_pdu(s, vs->pdu, err);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]