From f3718c29bb387901f2dd520ecd75dc498fa322b7 Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Sat, 20 Jul 2013 18:41:39 -0700 Subject: code_env: use feature test for PR_GET_NAME support Function `get_process_name` has platform specific dependencies. Check for Linux prctl function and correct command flag. Signed-off-by: Noah Watkins --- configure.ac | 3 +++ src/common/code_environment.cc | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index d7f96fd11f4..9ef4d0d3d10 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/common/code_environment.cc b/src/common/code_environment.cc index 2cf19f48bc5..662fa36c9bd 100644 --- a/src/common/code_environment.cc +++ b/src/common/code_environment.cc @@ -11,6 +11,7 @@ * Foundation. See file COPYING. * */ +#include "acconfig.h" #include "common/code_environment.h" @@ -19,7 +20,8 @@ #include #include #include -#if defined(__linux__) + +#ifdef HAVE_SYS_PRCTL_H #include #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]; -- cgit v1.2.1