summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Watkins <noahwatkins@gmail.com>2013-07-20 18:41:39 -0700
committerNoah Watkins <noahwatkins@gmail.com>2013-09-19 15:00:31 -0700
commitf3718c29bb387901f2dd520ecd75dc498fa322b7 (patch)
tree32d117b4ce7e45902a20b44fa6734cefdccf260d
parent59147be9aeea47576884e5587dd7da8bb58c6c53 (diff)
downloadceph-prctl-getname-test.tar.gz
code_env: use feature test for PR_GET_NAME supportprctl-getname-test
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>
-rw-r--r--configure.ac3
-rw-r--r--src/common/code_environment.cc24
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 <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];