]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
adminsocket: check return value
authorSage Weil <sage@inktank.com>
Fri, 28 Sep 2012 01:02:10 +0000 (18:02 -0700)
committerSage Weil <sage@inktank.com>
Fri, 28 Sep 2012 20:18:03 +0000 (13:18 -0700)
CID 716847: Other violation (CHECKED_RETURN)
At (5): Calling function "fcntl(sock_fd, 2, 1)" without checking return value. This library function may fail and return an error code.
At (6): No check of the return value of "fcntl(sock_fd, 2, 1)".

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

index 93830045f87f759777f9d600e5a2a60cd3d76caf..c999c89864342be2a8d53fbc7b969f28f5c35196 100644 (file)
@@ -163,7 +163,13 @@ std::string AdminSocket::bind_and_listen(const std::string &sock_path, int *fd)
        << "failed to create socket: " << cpp_strerror(err);
     return oss.str();
   }
-  fcntl(sock_fd, F_SETFD, FD_CLOEXEC);
+  int r = fcntl(sock_fd, F_SETFD, FD_CLOEXEC);
+  if (r < 0) {
+    r = errno;
+    ostringstream oss;
+    oss << "AdminSocket::bind_and_listen: failed to fcntl on socket: " << cpp_strerror(r);
+    return oss.str();
+  }
   memset(&address, 0, sizeof(struct sockaddr_un));
   address.sun_family = AF_UNIX;
   snprintf(address.sun_path, sizeof(address.sun_path),