]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: fix compat of strerror_r
authorluo.runbing <luo.runbing@zte.com.cn>
Fri, 20 Sep 2019 07:42:46 +0000 (15:42 +0800)
committerluo.runbing <luo.runbing@zte.com.cn>
Tue, 22 Oct 2019 08:46:04 +0000 (16:46 +0800)
Signed-off-by: luo.runbing <luo.runbing@zte.com.cn>
src/common/errno.cc
src/common/module.c
src/common/secret.c

index 69e54254bab1cad85553083e56f470c9eecc9dd9..83992361c437d4b5cc81002291275b07bee7d50d 100644 (file)
@@ -1,5 +1,6 @@
 #include "common/errno.h"
 #include "acconfig.h"
+#include "include/compat.h"
 
 #include <sstream>
 #include <string.h>
@@ -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;
 
index f19f74324c752db7e6164c875c9c022a39fee2e8..e67b3bf933afe5cd718f32395ae49cf4ccb30d32 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include "acconfig.h"
+#include "include/compat.h"
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -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));
index 8cfd2ec5df5a63ee250842ee56858062643fe9ba..9b821cb297ab87bad7137dee8868dceb4b76a014 100644 (file)
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <keyutils.h>
 
+#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;
       }
     }