]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/common_init: use safe_read
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 10 Feb 2011 16:24:08 +0000 (08:24 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 10 Feb 2011 17:16:22 +0000 (09:16 -0800)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/common_init.cc

index c5c9ed6f65e0ea17c7b05028c84a09514b3e7104..65f138076663449dc7dd994baea8066a606c1526 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "auth/AuthSupported.h"
 #include "auth/KeyRing.h"
+#include "common/safe_io.h"
 #include "config.h"
 #include "common/common_init.h"
 #include "common/errno.h"
@@ -89,16 +90,17 @@ static void keyring_init(const char *filesearch)
       int err = errno;
       derr << "unable to open " << g_conf.keyfile << ": "
           << cpp_strerror(err) << dendl;
-      exit(1);
+      ceph_abort();
     }
-    int len = ::read(fd, buf, sizeof(buf));
+    memset(buf, 0, sizeof(buf));
+    int len = safe_read(fd, buf, sizeof(buf) - 1);
     if (len < 0) {
-      int err = errno;
       derr << "unable to read key from " << g_conf.keyfile << ": "
-          << cpp_strerror(err) << dendl;
-      exit(1);
+          << cpp_strerror(len) << dendl;
+      TEMP_FAILURE_RETRY(::close(fd));
+      ceph_abort();
     }
-    ::close(fd);
+    TEMP_FAILURE_RETRY(::close(fd));
 
     buf[len] = 0;
     string k = buf;