From e59a33eedfddea270da88fd4e7758c957c89a77d Mon Sep 17 00:00:00 2001 From: "luo.runbing" Date: Fri, 20 Sep 2019 15:42:46 +0800 Subject: [PATCH] common: fix compat of strerror_r Signed-off-by: luo.runbing --- src/common/errno.cc | 10 ++-------- src/common/module.c | 10 +++------- src/common/secret.c | 5 +++-- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/common/errno.cc b/src/common/errno.cc index 69e54254bab..83992361c43 100644 --- a/src/common/errno.cc +++ b/src/common/errno.cc @@ -1,5 +1,6 @@ #include "common/errno.h" #include "acconfig.h" +#include "include/compat.h" #include #include @@ -12,15 +13,8 @@ std::string cpp_strerror(int err) if (err < 0) err = -err; std::ostringstream oss; - buf[0] = '\0'; - // strerror_r returns char * on Linux, and does not always fill buf -#ifdef STRERROR_R_CHAR_P - errmsg = strerror_r(err, buf, sizeof(buf)); -#else - strerror_r(err, buf, sizeof(buf)); - errmsg = buf; -#endif + errmsg = ceph_strerror_r(err, buf, sizeof(buf)); oss << "(" << err << ") " << errmsg; diff --git a/src/common/module.c b/src/common/module.c index f19f74324c7..e67b3bf933a 100644 --- a/src/common/module.c +++ b/src/common/module.c @@ -11,6 +11,7 @@ */ #include "acconfig.h" +#include "include/compat.h" #include #include #include @@ -42,14 +43,9 @@ static int run_command(const char *command) if (status < 0) { char error_buf[80]; -#ifdef STRERROR_R_CHAR_P - char* dummy = strerror_r(errno, error_buf, sizeof(error_buf)); - (void)dummy; -#else - strerror_r(errno, error_buf, sizeof(error_buf)); -#endif + char* errp = ceph_strerror_r(errno, error_buf, sizeof(error_buf)); fprintf(stderr, "couldn't run '%s': %s\n", command, - error_buf); + errp); } else if (WIFSIGNALED(status)) { fprintf(stderr, "'%s' killed by signal %d\n", command, WTERMSIG(status)); diff --git a/src/common/secret.c b/src/common/secret.c index 8cfd2ec5df5..9b821cb297a 100644 --- a/src/common/secret.c +++ b/src/common/secret.c @@ -19,6 +19,7 @@ #include #include +#include "include/compat.h" #include "common/armor.h" #include "common/safe_io.h" @@ -65,7 +66,7 @@ int set_kernel_secret(const char *secret, const char *key_name) if (ret < 0) { char error_buf[80]; fprintf(stderr, "secret is not valid base64: %s.\n", - strerror_r(-ret, error_buf, sizeof(error_buf))); + ceph_strerror_r(-ret, error_buf, sizeof(error_buf))); return ret; } @@ -113,7 +114,7 @@ int get_secret_option(const char *secret, const char *key_name, } else { char error_buf[80]; fprintf(stderr, "adding ceph secret key to kernel failed: %s.\n", - strerror_r(-ret, error_buf, sizeof(error_buf))); + ceph_strerror_r(-ret, error_buf, sizeof(error_buf))); return ret; } } -- 2.39.5