]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: fix error paths in do_put()
authorSage Weil <sage@inktank.com>
Fri, 28 Sep 2012 15:03:11 +0000 (08:03 -0700)
committerSage Weil <sage@inktank.com>
Fri, 28 Sep 2012 20:18:06 +0000 (13:18 -0700)
CID 716986: Improper use of negative value (NEGATIVE_RETURNS)
At (9): "count" is passed to a parameter that cannot be negative. [hide details]

+ other stuff

Signed-off-by: Sage Weil <sage@inktank.com>
src/rados.cc

index 4b59773092e1e5b4e9418a89d8dc3850c8e4a8b4..e07df5f3a79b57ba6f57db84461ed8e947dc3441 100644 (file)
@@ -341,12 +341,17 @@ static int do_put(IoCtx& io_ctx, const char *objname, const char *infile, int op
   uint64_t offset = 0;
   while (count != 0) {
     count = read(fd, buf, op_size);
+    if (count < 0) {
+      ret = -errno;
+      cerr << "error reading input file " << infile << ": " << cpp_strerror(ret) << std::endl;
+      goto out;
+    }
     if (count == 0) {
       if (!offset) {
-       int ret = io_ctx.create(oid, true);
+       ret = io_ctx.create(oid, true);
        if (ret < 0) {
          cerr << "WARNING: could not create object: " << oid << std::endl;
-         return 1;
+         goto out;
        }
       }
       continue;
@@ -359,13 +364,14 @@ static int do_put(IoCtx& io_ctx, const char *objname, const char *infile, int op
     indata.clear();
 
     if (ret < 0) {
-      close(fd);
-      return ret;
+      goto out;
     }
     offset += count;
   }
-  close(fd);
-  return 0;
+  ret = 0;
+ out:
+  TEMP_FAILURE_RETRY(close(fd));
+  return ret;
 }
 
 class RadosWatchCtx : public librados::WatchCtx {