about summary refs log tree commit homepage
path: root/dev.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-02-26 10:10:51 +0000
committerEric Wong <normalperson@yhbt.net>2012-02-26 11:53:50 +0000
commit920ba3f726684a3c95d323669004ab456c834b58 (patch)
tree34a8b3161c18983dba371a8b8a8fb4a950140a05 /dev.c
parenta5055d16b971de5f78b626cff91a6651e383d1c8 (diff)
downloadcmogstored-920ba3f726684a3c95d323669004ab456c834b58.tar.gz
No point in using goto to just jump to the next statement,
and need to trigger assert() on EBADF
Diffstat (limited to 'dev.c')
-rw-r--r--dev.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/dev.c b/dev.c
index f7727a9..202ce46 100644
--- a/dev.c
+++ b/dev.c
@@ -84,19 +84,22 @@ int mog_dev_mkusage(const struct mog_dev *dev, struct mog_svc *svc)
         if (emit_usage(dev, svc, fd, &v) < 0) goto out;
         if (fchmod(fd, svc->put_perms) < 0) goto out;
 
-        /* skip rename on EIO or EBADF if close() fails */
+        /* skip rename on EIO if close() fails */
         fd = close(fd);
-        if (fd < 0 && errno != EINTR) goto out;
+        if (fd < 0) {
+                assert(errno != EBADF && "attempted to close bad FD");
+                if (errno != EINTR) goto out;
+        }
+
         fd = -1;
         errno = 0;
-
-        if (mog_rename(svc, tmp_path, usage_path) < 0) goto out;
+        (void)mog_rename(svc, tmp_path, usage_path); /* we use errno later */
 out:
         PRESERVE_ERRNO(do {
                 if (errno)
                         (void)mog_unlink(svc, tmp_path);
                 if (fd >= 0)
-                        (void)close(fd);
+                        (void)mog_close(fd);
                 free(tmp_path);
                 free(usage_path);
         } while (0));