[Rpm-maint] [PATCH] Use getauxval(3) to read auxv data
Kirill A. Shutemov
kirill at shutemov.name
Mon Jul 1 00:25:32 UTC 2013
From: "Kirill A. Shutemov" <kirill at shutemov.name>
glibc >= 2.16 provides getauxval(): a reliable way to retrieve a value
from the auxiliary vector. It doesn't rely on /proc filesystem.
Let's switch to it and get rid of /proc dependency.
Signed-off-by: Kirill A. Shutemov <kirill at shutemov.name>
---
configure.ac | 1 +
lib/rpmrc.c | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index 0f2cb28..ec85ede 100644
--- a/configure.ac
+++ b/configure.ac
@@ -520,6 +520,7 @@ AC_CHECK_FUNCS(mempcpy)
AC_CHECK_FUNCS(fdatasync)
AC_CHECK_FUNCS(lutimes)
AC_CHECK_FUNCS(mergesort)
+AC_CHECK_FUNCS(getauxval)
AC_REPLACE_FUNCS(stpcpy stpncpy)
diff --git a/lib/rpmrc.c b/lib/rpmrc.c
index d6546c4..794d028 100644
--- a/lib/rpmrc.c
+++ b/lib/rpmrc.c
@@ -21,6 +21,10 @@
#define __power_pc() 0
#endif
+#ifdef HAVE_GETAUXVAL
+#include <sys/auxv.h>
+#endif
+
#include <rpm/rpmlib.h> /* RPM_MACTABLE*, Rc-prototypes */
#include <rpm/rpmmacro.h>
#include <rpm/rpmfileutil.h>
@@ -934,13 +938,19 @@ static int is_geode(void)
#if defined(__linux__)
/**
- * Populate rpmat structure with parsed info from /proc/self/auxv
+ * Populate rpmat structure with auxv values
*/
-static void parse_auxv(void)
+static void read_auxv(void)
{
static int oneshot = 1;
if (oneshot) {
+#ifdef HAVE_GETAUXVAL
+ rpmat.platform = (char *) getauxval(AT_PLATFORM);
+ if (!rpmat.platform)
+ rpmat.platform = "";
+ rpmat.hwcap = getauxval(AT_HWCAP);
+#else
rpmat.platform = "";
int fd = open("/proc/self/auxv", O_RDONLY);
@@ -965,6 +975,7 @@ static void parse_auxv(void)
}
close(fd);
}
+#endif
oneshot = 0; /* only try once even if it fails */
}
return;
@@ -984,7 +995,7 @@ static void defaultMachine(rpmrcCtx ctx, const char ** arch, const char ** os)
#if defined(__linux__)
/* Populate rpmat struct with hw info */
- parse_auxv();
+ read_auxv();
#endif
while (!gotDefaults) {
--
1.8.3.1
More information about the Rpm-maint
mailing list