]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
bench/dumb_backend.cc: check return value of lseek()
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Tue, 28 May 2013 12:41:30 +0000 (14:41 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 31 May 2013 17:15:22 +0000 (19:15 +0200)
CID 743395 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)
  check_return: Calling function "lseek(fd, offset, 0)" without checking
   return value. This library function may fail and return an error code.
  unchecked_value: No check of the return value of "lseek(fd, offset, 0)".

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/test/bench/dumb_backend.cc

index 170fee7fab6a50b7e5c65da81ab70e0890e0bb2f..c36dce392da6565e0a10a124daa186d74cb6a1a6 100644 (file)
@@ -22,7 +22,14 @@ void DumbBackend::_write(
     std::cout << full_path << ": errno is " << errno << std::endl;
     assert(0);
   }
-  ::lseek(fd, offset, SEEK_SET);
+
+  int r =  ::lseek(fd, offset, SEEK_SET);
+  if (r < 0) {
+    r = errno;
+    std::cout << "lseek failed, errno is: " << r << std::endl;
+    ::close(fd);
+    return;
+  }
   bl.write_fd(fd);
   on_applied->complete(0);
   if (do_fsync)
@@ -31,7 +38,7 @@ void DumbBackend::_write(
     ::sync_file_range(fd, offset, bl.length(),
                      SYNC_FILE_RANGE_WAIT_AFTER);
   if (do_fadvise) {
-    int fa_r = posix_fadvise(fd, offset, bl.length(), POSIX_FADV_DONTNEED);
+    int fa_r = ::posix_fadvise(fd, offset, bl.length(), POSIX_FADV_DONTNEED);
     if (fa_r) {
         std::cout << "posix_fadvise failed, errno is: " << fa_r << std::endl;
     }
@@ -58,6 +65,8 @@ void DumbBackend::read(
 
   int r = ::lseek(fd, offset, SEEK_SET);
   if (r < 0) {
+    r = errno;
+    std::cout << "lseek failed, errno is: " << r << std::endl;
     ::close(fd);
     return;
   }