Allow the use of readlinkat over readlink.

This can be useful in situations where readlink is disallowed.
This commit is contained in:
David Goldblatt 2018-08-03 12:47:40 -07:00 committed by David Goldblatt
parent 126252a7e6
commit e8ec9528ab
3 changed files with 27 additions and 0 deletions

View File

@ -1277,6 +1277,22 @@ if test "x$enable_log" = "x1" ; then
fi fi
AC_SUBST([enable_log]) AC_SUBST([enable_log])
dnl Do not use readlinkat by default
AC_ARG_ENABLE([readlinkat],
[AS_HELP_STRING([--enable-readlinkat], [Use readlinkat over readlink])],
[if test "x$enable_readlinkat" = "xno" ; then
enable_readlinkat="0"
else
enable_readlinkat="1"
fi
],
[enable_readlinkat="0"]
)
if test "x$enable_readlinkat" = "x1" ; then
AC_DEFINE([JEMALLOC_READLINKAT], [ ])
fi
AC_SUBST([enable_readlinkat])
JE_COMPILABLE([a program using __builtin_unreachable], [ JE_COMPILABLE([a program using __builtin_unreachable], [
void foo (void) { void foo (void) {

View File

@ -245,6 +245,12 @@
*/ */
#undef JEMALLOC_LOG #undef JEMALLOC_LOG
/*
* If defined, use readlinkat() (instead of readlink()) to follow
* /etc/malloc_conf.
*/
#undef JEMALLOC_READLINKAT
/* /*
* Darwin (OS X) uses zones to work around Mach-O symbol override shortcomings. * Darwin (OS X) uses zones to work around Mach-O symbol override shortcomings.
*/ */

View File

@ -961,7 +961,12 @@ malloc_conf_init(sc_data_t *sc_data) {
* Try to use the contents of the "/etc/malloc.conf" * Try to use the contents of the "/etc/malloc.conf"
* symbolic link's name. * symbolic link's name.
*/ */
#ifndef JEMALLOC_READLINKAT
linklen = readlink(linkname, buf, sizeof(buf) - 1); linklen = readlink(linkname, buf, sizeof(buf) - 1);
#else
linklen = readlinkat(AT_FDCWD, linkname, buf,
sizeof(buf) - 1);
#endif
if (linklen == -1) { if (linklen == -1) {
/* No configuration specified. */ /* No configuration specified. */
linklen = 0; linklen = 0;