mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-24 13:53:11 +00:00
Disable config from file or envvar with build flag
This adds a new autoconf flag, --disable-user-config, which disables reading the configuration from /etc/malloc.conf or the MALLOC_CONF environment variable. This can be useful when integrating jemalloc in a binary that internally handles all aspects of the configuration and shouldn't be impacted by ambient change in the environment.
This commit is contained in:
18
configure.ac
18
configure.ac
@@ -1401,6 +1401,23 @@ if test "x$enable_stats" = "x1" ; then
|
|||||||
fi
|
fi
|
||||||
AC_SUBST([enable_stats])
|
AC_SUBST([enable_stats])
|
||||||
|
|
||||||
|
dnl Disable reading configuration from file and environment variable
|
||||||
|
AC_ARG_ENABLE([user_config],
|
||||||
|
[AS_HELP_STRING([--disable-user-config],
|
||||||
|
[Do not read malloc config from /etc/malloc.conf or MALLOC_CONF])],
|
||||||
|
[if test "x$enable_user_config" = "xno" ; then
|
||||||
|
enable_user_config="0"
|
||||||
|
else
|
||||||
|
enable_user_config="1"
|
||||||
|
fi
|
||||||
|
],
|
||||||
|
[enable_user_config="1"]
|
||||||
|
)
|
||||||
|
if test "x$enable_user_config" = "x1" ; then
|
||||||
|
AC_DEFINE([JEMALLOC_CONFIG_ENV], [ ], [ ])
|
||||||
|
AC_DEFINE([JEMALLOC_CONFIG_FILE], [ ], [ ])
|
||||||
|
fi
|
||||||
|
|
||||||
dnl Do not enable smallocx by default.
|
dnl Do not enable smallocx by default.
|
||||||
AC_ARG_ENABLE([experimental_smallocx],
|
AC_ARG_ENABLE([experimental_smallocx],
|
||||||
[AS_HELP_STRING([--enable-experimental-smallocx], [Enable experimental smallocx API])],
|
[AS_HELP_STRING([--enable-experimental-smallocx], [Enable experimental smallocx API])],
|
||||||
@@ -2962,6 +2979,7 @@ AC_MSG_RESULT([static libs : ${enable_static}])
|
|||||||
AC_MSG_RESULT([autogen : ${enable_autogen}])
|
AC_MSG_RESULT([autogen : ${enable_autogen}])
|
||||||
AC_MSG_RESULT([debug : ${enable_debug}])
|
AC_MSG_RESULT([debug : ${enable_debug}])
|
||||||
AC_MSG_RESULT([stats : ${enable_stats}])
|
AC_MSG_RESULT([stats : ${enable_stats}])
|
||||||
|
AC_MSG_RESULT([user_config : ${enable_user_config}])
|
||||||
AC_MSG_RESULT([experimental_smallocx : ${enable_experimental_smallocx}])
|
AC_MSG_RESULT([experimental_smallocx : ${enable_experimental_smallocx}])
|
||||||
AC_MSG_RESULT([prof : ${enable_prof}])
|
AC_MSG_RESULT([prof : ${enable_prof}])
|
||||||
AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
|
AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
|
||||||
|
|||||||
@@ -46,6 +46,12 @@
|
|||||||
*/
|
*/
|
||||||
#undef JEMALLOC_USE_CXX_THROW
|
#undef JEMALLOC_USE_CXX_THROW
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If undefined, disables reading configuration from environment variable or file
|
||||||
|
*/
|
||||||
|
#undef JEMALLOC_CONFIG_ENV
|
||||||
|
#undef JEMALLOC_CONFIG_FILE
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# ifdef _WIN64
|
# ifdef _WIN64
|
||||||
# define LG_SIZEOF_PTR_WIN 3
|
# define LG_SIZEOF_PTR_WIN 3
|
||||||
|
|||||||
@@ -985,44 +985,53 @@ obtain_malloc_conf(unsigned which_source, char readlink_buf[PATH_MAX + 1]) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: {
|
case 2: {
|
||||||
|
#ifndef JEMALLOC_CONFIG_FILE
|
||||||
|
ret = NULL;
|
||||||
|
break;
|
||||||
|
#else
|
||||||
ssize_t linklen = 0;
|
ssize_t linklen = 0;
|
||||||
#ifndef _WIN32
|
# ifndef _WIN32
|
||||||
int saved_errno = errno;
|
int saved_errno = errno;
|
||||||
const char *linkname =
|
const char *linkname =
|
||||||
# ifdef JEMALLOC_PREFIX
|
# ifdef JEMALLOC_PREFIX
|
||||||
"/etc/"JEMALLOC_PREFIX"malloc.conf"
|
"/etc/"JEMALLOC_PREFIX"malloc.conf"
|
||||||
# else
|
# else
|
||||||
"/etc/malloc.conf"
|
"/etc/malloc.conf"
|
||||||
# endif
|
# endif
|
||||||
;
|
;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to use the contents of the "/etc/malloc.conf" symbolic
|
* Try to use the contents of the "/etc/malloc.conf" symbolic
|
||||||
* link's name.
|
* link's name.
|
||||||
*/
|
*/
|
||||||
#ifndef JEMALLOC_READLINKAT
|
# ifndef JEMALLOC_READLINKAT
|
||||||
linklen = readlink(linkname, readlink_buf, PATH_MAX);
|
linklen = readlink(linkname, readlink_buf, PATH_MAX);
|
||||||
#else
|
# else
|
||||||
linklen = readlinkat(AT_FDCWD, linkname, readlink_buf, PATH_MAX);
|
linklen = readlinkat(AT_FDCWD, linkname, readlink_buf, PATH_MAX);
|
||||||
#endif
|
# endif
|
||||||
if (linklen == -1) {
|
if (linklen == -1) {
|
||||||
/* No configuration specified. */
|
/* No configuration specified. */
|
||||||
linklen = 0;
|
linklen = 0;
|
||||||
/* Restore errno. */
|
/* Restore errno. */
|
||||||
set_errno(saved_errno);
|
set_errno(saved_errno);
|
||||||
}
|
}
|
||||||
#endif
|
# endif
|
||||||
readlink_buf[linklen] = '\0';
|
readlink_buf[linklen] = '\0';
|
||||||
ret = readlink_buf;
|
ret = readlink_buf;
|
||||||
break;
|
break;
|
||||||
} case 3: {
|
|
||||||
const char *envname =
|
|
||||||
#ifdef JEMALLOC_PREFIX
|
|
||||||
JEMALLOC_CPREFIX"MALLOC_CONF"
|
|
||||||
#else
|
|
||||||
"MALLOC_CONF"
|
|
||||||
#endif
|
#endif
|
||||||
;
|
} case 3: {
|
||||||
|
#ifndef JEMALLOC_CONFIG_ENV
|
||||||
|
ret = NULL;
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
const char *envname =
|
||||||
|
# ifdef JEMALLOC_PREFIX
|
||||||
|
JEMALLOC_CPREFIX"MALLOC_CONF"
|
||||||
|
# else
|
||||||
|
"MALLOC_CONF"
|
||||||
|
# endif
|
||||||
|
;
|
||||||
|
|
||||||
if ((ret = jemalloc_getenv(envname)) != NULL) {
|
if ((ret = jemalloc_getenv(envname)) != NULL) {
|
||||||
opt_malloc_conf_env_var = ret;
|
opt_malloc_conf_env_var = ret;
|
||||||
@@ -1031,6 +1040,7 @@ obtain_malloc_conf(unsigned which_source, char readlink_buf[PATH_MAX + 1]) {
|
|||||||
ret = NULL;
|
ret = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
} case 4: {
|
} case 4: {
|
||||||
ret = je_malloc_conf_2_conf_harder;
|
ret = je_malloc_conf_2_conf_harder;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user