From: luo.runbing Date: Fri, 20 Sep 2019 07:42:46 +0000 (+0800) Subject: common: fix compat of strerror_r X-Git-Tag: v15.1.0~1138^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e59a33eedfddea270da88fd4e7758c957c89a77d;p=ceph.git common: fix compat of strerror_r Signed-off-by: luo.runbing --- diff --git a/src/common/errno.cc b/src/common/errno.cc index 69e54254bab1..83992361c437 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 f19f74324c75..e67b3bf933af 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 8cfd2ec5df5a..9b821cb297ab 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; } }