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-17 10:12:05 -0700
commitb495563ddf73b319f67dd211dc0a026a24b094d3 (patch)
tree738eb0d39c1631ede8faf3ed4156b5c9893415ff
parent2080f258cc118665d508aa2eac5a45c9498ea21c (diff)
downloadceph-b495563ddf73b319f67dd211dc0a026a24b094d3.tar.gz
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 <noahwatkins@gmail.com>
-rw-r--r--configure.ac3
-rw-r--r--src/common/code_environment.cc15
2 files changed, 10 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index 7d0d6a6fbea..9cd605a6825 100644
--- a/configure.ac
+++ b/configure.ac
@@ -551,6 +551,9 @@ AC_CHECK_MEMBER([struct stat.st_mtimespec.tv_nsec],
[AC_DEFINE(HAVE_STAT_ST_TIMESPEC, 1,
[Define if you have struct stat.st_mtimespec.tv_nsec])])
+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..f6c5c44c00a 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
@@ -47,20 +49,17 @@ std::ostream &operator<<(std::ostream &oss, enum code_environment_t e)
int get_process_name(char *buf, int len)
{
+#if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME) /* Since 2.6.11 */
if (len <= 16) {
/* The man page discourages using this prctl with a buffer shorter
* than 16 bytes. With a 16-byte buffer, it might not be
* 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;
+ return prctl(PR_GET_NAME, buf);
+#else
+ return -ENOSYS;
#endif
}