]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
code_env: use feature test for PR_GET_NAME support 607/head
authorNoah Watkins <noahwatkins@gmail.com>
Sun, 21 Jul 2013 01:41:39 +0000 (18:41 -0700)
committerNoah Watkins <noahwatkins@gmail.com>
Thu, 19 Sep 2013 22:00:31 +0000 (15:00 -0700)
Function `get_process_name` has platform specific dependencies. Check
for Linux prctl function and correct command flag.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
configure.ac
src/common/code_environment.cc

index d7f96fd11f43598adabb9530314cb5483f9e222e..9ef4d0d3d104b49cc9a2e2a1a26ed3ddf7fb2c0a 100644 (file)
@@ -536,6 +536,9 @@ AC_CHECK_FUNC([fallocate],
        [])
 
 
+AC_CHECK_HEADERS([sys/prctl.h])
+AC_CHECK_FUNCS([prctl])
+
 # Checks for typedefs, structures, and compiler characteristics.
 #AC_HEADER_STDBOOL
 #AC_C_CONST
index 2cf19f48bc575bb02044ffd1b5bc72b357830865..662fa36c9bdf0937179c8a9e71e8b6c83eebb61c 100644 (file)
@@ -11,6 +11,7 @@
  * Foundation.  See file COPYING.
  *
  */
+#include "acconfig.h"
 
 #include "common/code_environment.h"
 
@@ -19,7 +20,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <string>
-#if defined(__linux__)
+
+#ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
 #endif
 
@@ -45,6 +47,8 @@ std::ostream &operator<<(std::ostream &oss, enum code_environment_t e)
   return oss;
 }
 
+#if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME) /* Since 2.6.11 */
+
 int get_process_name(char *buf, int len)
 {
   if (len <= 16) {
@@ -53,17 +57,19 @@ int get_process_name(char *buf, int len)
      * null-terminated. */
     return -ENAMETOOLONG;
   }
-#if defined(__FreeBSD__)
-#warning XXX
-    return -ENAMETOOLONG;
-#else
   memset(buf, 0, len);
-  int ret;
-  ret = prctl(PR_GET_NAME, buf);
-  return ret;
-#endif
+  return prctl(PR_GET_NAME, buf);
 }
 
+#else
+
+int get_process_name(char *buf, int len)
+{
+  return -ENOSYS;
+}
+
+#endif
+
 std::string get_process_name_cpp()
 {
   char buf[32];