From c7886ba5b5d5eb0068f9c974fe38ac5bb2681437 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Thu, 10 Feb 2011 08:24:08 -0800 Subject: [PATCH] common/common_init: use safe_read Signed-off-by: Colin McCabe --- src/common/common_init.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/common/common_init.cc b/src/common/common_init.cc index c5c9ed6f65e0e..65f1380766634 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -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; -- 2.39.5