Blob Blame History Raw
From be821157bb9c22ac1928c2f0e9b189880ce77505 Mon Sep 17 00:00:00 2001
From: xaizek <xaizek@openmailbox.org>
Date: Mon, 20 Jul 2015 20:36:52 +0300
Subject: [PATCH] Work around compilation on AArch64 GNU/Linux

Or in general on systems where MAX_ARG_STRLEN is defined, but is
unusable (it's either shouldn't be defined or should work, not the
way it is at the moment).  Thanks to Marcin Juszkiewicz (a.k.a.
hrw).
---
 ChangeLog             |  3 +++
 THANKS                |  1 +
 config.h.in           |  3 +++
 configure             | 17 +++++++++++++++++
 configure.ac          | 11 +++++++++++
 src/utils/utils_nix.c |  5 +++--
 6 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 837ed0c..772639c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,9 @@
 
 	Normalize surrounding spaces in menu and dialog titles.
 
+	Work around compilation on systems where MAX_ARG_STRLEN is defined, but
+	unusable.  Thanks to Marcin Juszkiewicz (a.k.a. hrw).
+
 	Fixed resetting "vborder" of 'fillchars' after it has been set to
 	something (as in `:set fillchars=vborder:\* fillchars&`).
 
diff --git a/THANKS b/THANKS
index 7f4ae95..93c4322 100644
--- a/THANKS
+++ b/THANKS
@@ -53,6 +53,7 @@ lcj
 Lomov Vladimir (lomov_vl)
 lyuts
 MadMaverick9
+Marcin Juszkiewicz (hrw)
 Martin Fischer
 Marton Balazs (balmar)
 Merovius
diff --git a/config.h.in b/config.h.in
index 9ad2014..6fa0c5a 100644
--- a/config.h.in
+++ b/config.h.in
@@ -43,6 +43,9 @@
 /* malloc.h header is available. */
 #undef HAVE_MALLOC_H
 
+/* MAX_ARG_STRLEN is available. */
+#undef HAVE_MAX_ARG_STRLEN
+
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
diff --git a/configure b/configure
index f7ae7d5..3cfc647 100755
--- a/configure
+++ b/configure
@@ -6315,6 +6315,23 @@ fi
 
 done
 
+if test "$ac_cv_header_sys_user_h" = yes -a "$ac_cv_header_linux_binfmts_h" = yes; then
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+             #include <linux/binfmts.h>
+             #include <sys/user.h>
+             int main() { (void)MAX_ARG_STRLEN; return 0; }
+
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+$as_echo "#define HAVE_MAX_ARG_STRLEN 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
 
 ac_fn_c_check_type "$LINENO" "uid_t" "ac_cv_type_uid_t" "$ac_includes_default"
 if test "x$ac_cv_type_uid_t" = xyes; then :
diff --git a/configure.ac b/configure.ac
index ee0200b..a81afc6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,6 +74,17 @@ AC_CHECK_HEADER([wchar.h], [], [AC_MSG_ERROR([wchar.h header not found.])])
 AC_CHECK_HEADER([wctype.h], [], [AC_MSG_ERROR([wctype.h header not found.])])
 dnl Headers required for breaking too long command-lines.
 AC_CHECK_HEADERS([sys/user.h linux/binfmts.h])
+if test "$ac_cv_header_sys_user_h" = yes -a "$ac_cv_header_linux_binfmts_h" = yes; then
+    AC_COMPILE_IFELSE(
+        AC_LANG_SOURCE(
+            [[
+             #include <linux/binfmts.h>
+             #include <sys/user.h>
+             int main() { (void)MAX_ARG_STRLEN; return 0; }
+            ]]
+        ),
+        [AC_DEFINE([HAVE_MAX_ARG_STRLEN], [1], [MAX_ARG_STRLEN is available.])])
+fi
 
 dnl Check for various system types.
 AC_CHECK_TYPE([uid_t])
diff --git a/src/utils/utils_nix.c b/src/utils/utils_nix.c
index 31efc0f..1d6a33d 100644
--- a/src/utils/utils_nix.c
+++ b/src/utils/utils_nix.c
@@ -20,7 +20,8 @@
 #include "utils_nix.h"
 #include "utils_int.h"
 
-#if defined (HAVE_LINUX_BINFMTS_H) && defined (HAVE_SYS_USER_H)
+#ifdef HAVE_MAX_ARG_STRLEN
+/* MAX_ARG_STRLEN is the only reason we need these headers. */
 #include <linux/binfmts.h>
 #include <sys/user.h>
 #endif
@@ -261,7 +262,7 @@ run_from_fork(int pipe[2], int err_only, char cmd[])
 char **
 make_execv_array(char shell[], char cmd[])
 {
-#ifdef MAX_ARG_STRLEN
+#ifdef HAVE_MAX_ARG_STRLEN
 	/* Don't use maximum length, leave some room or commands fail to run. */
 	const size_t safe_arg_len = MIN(MAX_ARG_STRLEN, MAX_ARG_STRLEN - 4096U);
 	const size_t npieces = DIV_ROUND_UP(strlen(cmd
100  4114    0  4114    0     0   6979      0 --:--:-- --:--:-- --:--:--  6972
), safe_arg_len);