]> arthur.barton.de Git - bup.git/commitdiff
Find SC_ARG_MAX via C sysconf().
authorRob Browning <rlb@defaultvalue.org>
Sat, 10 May 2014 23:02:52 +0000 (18:02 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 10 May 2014 23:07:26 +0000 (18:07 -0500)
Apparently os.sysconf('SC_ARG_MAX') returns -1, even in some common
cases.

Thanks to Alexander Barton <alex@barton.de> for reporting that at
least when run under make 3.81, os.sysconf('SC_ARG_MAX') was just
returning -1.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/_helpers.c
lib/bup/helpers.py

index b9b050bad10a2a40ad6de1289380628e69324853..ea49c0e7571045484a35c73a7e07344607f822eb 100644 (file)
@@ -1222,9 +1222,9 @@ PyMODINIT_FUNC init_helpers(void)
     if (m == NULL)
         return;
 
-#ifdef HAVE_UTIMENSAT
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wtautological-compare" // For INTEGER_TO_PY().
+#ifdef HAVE_UTIMENSAT
     {
         PyObject *value;
         value = INTEGER_TO_PY(AT_FDCWD);
@@ -1237,8 +1237,20 @@ PyMODINIT_FUNC init_helpers(void)
         PyObject_SetAttrString(m, "UTIME_NOW", value);
         Py_DECREF(value);
     }
-#pragma clang diagnostic pop  // ignored "-Wtautological-compare"
 #endif
+    {
+        PyObject *value;
+        const long arg_max = sysconf(_SC_ARG_MAX);
+        if (arg_max == -1)
+        {
+            fprintf(stderr, "Cannot find SC_ARG_MAX, please report a bug.\n");
+            exit(1);
+        }
+        value = INTEGER_TO_PY(arg_max);
+        PyObject_SetAttrString(m, "SC_ARG_MAX", value);
+        Py_DECREF(value);
+    }
+#pragma clang diagnostic pop  // ignored "-Wtautological-compare"
 
     e = getenv("BUP_FORCE_TTY");
     istty2 = isatty(2) || (atoi(e ? e : "0") & 2);
index 42f91297f9b68ada81b1791a3fb792c51449ad2d..a11e6d602659df5c01c1a2bea1cbb424ad61f847 100644 (file)
@@ -201,15 +201,6 @@ def readpipe(argv, preexec_fn=None):
     return out
 
 
-try:
-    _arg_max = os.sysconf('SC_ARG_MAX')
-    if _arg_max == -1:
-        raise ValueError()
-except ValueError, ex:
-    print >> sys.stderr, 'Cannot find SC_ARG_MAX, please report a bug.'
-    sys.exit(1)
-
-
 def _argmax_base(command):
     base_size = 2048
     for c in command:
@@ -223,14 +214,12 @@ def _argmax_args_size(args):
     return sum(len(x) + 1 + sizeof(c_void_p) for x in args)
 
 
-def batchpipe(command, args, preexec_fn=None, arg_max=None):
+def batchpipe(command, args, preexec_fn=None, arg_max=_helpers.SC_ARG_MAX):
     """If args is not empty, yield the output produced by calling the
 command list with args as a sequence of strings (It may be necessary
 to return multiple strings in order to respect ARG_MAX)."""
     # The optional arg_max arg is a workaround for an issue with the
     # current wvtest behavior.
-    if not arg_max:
-        arg_max = _arg_max
     base_size = _argmax_base(command)
     while args:
         room = arg_max - base_size