[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 10/13] libxl: don't try to fclose file twice on error in libxl_userdata_store
Do this by changing the function to not use stdio file operations, but just use write(2) directly. While at it, tidy up the function's style issues. Coverity-ID: 1056195 Signed-off-by: Matthew Daley <mattd@xxxxxxxxxxx> --- tools/libxl/libxl_dom.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index e9ac8f3..0fe0a77 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -1604,8 +1604,6 @@ int libxl_userdata_store(libxl_ctx *ctx, uint32_t domid, const char *newfilename; int e, rc; int fd = -1; - FILE *f = NULL; - size_t rs; filename = userdata_path(gc, domid, userdata_userid, "d"); if (!filename) { @@ -1626,38 +1624,33 @@ int libxl_userdata_store(libxl_ctx *ctx, uint32_t domid, rc = ERROR_FAIL; - fd= open(newfilename, O_RDWR|O_CREAT|O_TRUNC, 0600); - if (fd<0) + fd = open(newfilename, O_RDWR | O_CREAT | O_TRUNC, 0600); + if (fd < 0) goto err; - f= fdopen(fd, "wb"); - if (!f) + if (write(fd, data, datalen) != datalen) goto err; - fd = -1; - rs = fwrite(data, 1, datalen, f); - if (rs != datalen) { - assert(ferror(f)); + if (close(fd) < 0) { + fd = -1; goto err; } + fd = -1; - if (fclose(f)) - goto err; - f = 0; - - if (rename(newfilename,filename)) + if (rename(newfilename, filename)) goto err; rc = 0; err: - e = errno; - if (f) fclose(f); - if (fd>=0) close(fd); + if (fd >= 0) { + e = errno; + close(fd); + errno = e; + } - errno = e; - if ( rc ) - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "cannot write %s for %s", + if (rc) + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "cannot write/rename %s for %s", newfilename, filename); out: GC_FREE; -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |