From: Sripathi Kodi Date: Mon, 20 Sep 2010 17:54:29 +0000 (+0530) Subject: [virtio-9p] open should not return EBADF X-Git-Tag: TizenStudio_2.0_p2.3.2~208^2~7076 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ab03b63d7a9c7978d51e56c191f0b86888d121dc;p=sdk%2Femulator%2Fqemu.git [virtio-9p] open should not return EBADF 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 Signed-off-by: Venkateswararao Jujjuri --- diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 3b2d49c..3379a30 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1760,8 +1760,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);