app-admin/sysstat: fix from Chromium OS for unaligned memory errors
authorMike Frysinger <vapier@chromium.org>
Fri, 5 May 2017 19:47:12 +0000 (15:47 -0400)
committerMike Frysinger <vapier@gentoo.org>
Fri, 5 May 2017 19:48:07 +0000 (15:48 -0400)
app-admin/sysstat/files/sysstat-11.4.3-memalign.patch [new file with mode: 0644]
app-admin/sysstat/sysstat-11.4.3-r1.ebuild [new file with mode: 0644]
app-admin/sysstat/sysstat-11.5.5.ebuild

diff --git a/app-admin/sysstat/files/sysstat-11.4.3-memalign.patch b/app-admin/sysstat/files/sysstat-11.4.3-memalign.patch
new file mode 100644 (file)
index 0000000..ab5fa7d
--- /dev/null
@@ -0,0 +1,40 @@
+sysstat declares 16 bytes alignment for many structs. But realloc does not
+guarantee 16 byte alignment (it maxes out at 8 bytes for most systems).
+Because of declared 16 byte alignement, the compiler is free to generate SIMD
+16 byte loads which require aligned addresses. Use posix_memalign instead to
+enforce 16 bytes data alignment to avoid crashes.
+
+https://github.com/sysstat/sysstat/issues/148
+
+Patch by Manoj Gupta <manojgupta@google.com>
+
+--- a/common.h
++++ b/common.h
+@@ -11,6 +11,7 @@
+ 
+ #include <time.h>
+ #include <sched.h>    /* For __CPU_SETSIZE */
++#include <stdlib.h>
+ #include <limits.h>
+ 
+ #ifdef HAVE_SYS_SYSMACROS_H
+@@ -91,13 +92,18 @@
+                                       TYPE *_p_;                                               \
+                                       _p_ = S;                                                 \
+                                       if (SIZE) {                                              \
+-                                              if ((S = (TYPE *) realloc(S, (SIZE))) == NULL) { \
++                                              void *_ptr = NULL;                               \
++                                              int error = posix_memalign(&_ptr, 16, SIZE);     \
++                                              if (error || _ptr == NULL) {                     \
+                                                       perror("realloc");                       \
+                                                       exit(4);                                 \
+                                               }                                                \
++                                              S = (TYPE *)_ptr;                                \
+                                               /* If the ptr was null, then it's a malloc() */  \
+                                               if (!_p_) {                                      \
+                                                       memset(S, 0, (SIZE));                    \
++                                              } else {                                         \
++                                                      memcpy(S, _p_, (SIZE));                  \
+                                               }                                                \
+                                       }                                                        \
+                                       if (!S) {                                                \
diff --git a/app-admin/sysstat/sysstat-11.4.3-r1.ebuild b/app-admin/sysstat/sysstat-11.4.3-r1.ebuild
new file mode 100644 (file)
index 0000000..74edb09
--- /dev/null
@@ -0,0 +1,96 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+inherit flag-o-matic multilib systemd toolchain-funcs
+
+DESCRIPTION="System performance tools for Linux"
+HOMEPAGE="http://pagesperso-orange.fr/sebastien.godard/"
+SRC_URI="${HOMEPAGE}${P}.tar.xz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
+IUSE="debug isag nls lm_sensors selinux static"
+
+CDEPEND="
+       isag? (
+               dev-lang/tk:0
+               dev-vcs/rcs
+               sci-visualization/gnuplot
+       )
+       nls? ( virtual/libintl )
+       lm_sensors? ( sys-apps/lm_sensors )
+"
+DEPEND="
+       ${CDEPEND}
+       nls? ( sys-devel/gettext )
+"
+RDEPEND="
+       ${CDEPEND}
+       selinux? ( sec-policy/selinux-sysstat )
+"
+PATCHES=(
+       "${FILESDIR}"/${PN}-10.0.4-flags.patch
+       "${FILESDIR}"/${PN}-11.0.4-cron.patch
+       "${FILESDIR}"/${PN}-11.4.3-memalign.patch
+)
+
+SYSSTAT_FAKE_RC_DIR=Gentoo-does-not-use-rc.d
+
+src_prepare() {
+       if use nls; then
+               strip-linguas -i nls/
+               local lingua pofile
+               for pofile in nls/*.po; do
+                       lingua=${pofile/nls\/}
+                       lingua=${lingua/.po}
+                       if ! has ${lingua} ${LINGUAS}; then
+                               rm "nls/${lingua}.po" || die
+                       fi
+               done
+       fi
+
+       default
+}
+
+src_configure() {
+       tc-export AR
+       use static && append-ldflags -static
+
+       sa_lib_dir=/usr/$(get_libdir)/sa \
+               conf_dir=/etc \
+               rcdir=${SYSSTAT_FAKE_RC_DIR} \
+               econf \
+                       $(use_enable debug debuginfo) \
+                       $(use_enable isag install-isag) \
+                       $(use_enable lm_sensors sensors) \
+                       $(use_enable nls) \
+                       --enable-copy-only \
+                       --enable-documentation \
+                       --enable-install-cron \
+                       --with-systemdsystemunitdir=$(systemd_get_systemunitdir)
+}
+
+src_compile() {
+       emake LFLAGS="${LDFLAGS}"
+}
+
+src_install() {
+       keepdir /var/log/sa
+
+       emake \
+               CHOWN=true \
+               DESTDIR="${D}" \
+               DOC_DIR=/usr/share/doc/${PF} \
+               MANGRPARG='' \
+               install
+
+       dodoc contrib/sargraph/sargraph
+
+       rm -r "${D}/${SYSSTAT_FAKE_RC_DIR}" || die
+       newinitd "${FILESDIR}"/${PN}.init.d ${PN}
+       systemd_dounit ${PN}.service
+
+       rm -f "${D}"usr/share/doc/${PF}/COPYING
+}
index c9bea3b2b27cf67cd0de224c8ae51ac3814ca08a..73565a64f8353a3c59f54cd0591aa515c0131e79 100644 (file)
@@ -28,6 +28,7 @@ RDEPEND="
 PATCHES=(
        "${FILESDIR}"/${PN}-10.0.4-flags.patch
        "${FILESDIR}"/${PN}-11.0.4-cron.patch
+       "${FILESDIR}"/${PN}-11.4.3-memalign.patch
 )
 
 SYSSTAT_FAKE_RC_DIR=Gentoo-does-not-use-rc.d