]> arthur.barton.de Git - bup.git/commitdiff
Read ARG_MAX directly via os.sysconf('SC_ARG_MAX').
authorRob Browning <rlb@defaultvalue.org>
Sat, 10 May 2014 20:51:38 +0000 (15:51 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 10 May 2014 20:56:28 +0000 (15:56 -0500)
For now, this code also adds an optional arg_max parameter to
batchpipe(), exclusively for testing.

There appears to be an issue with wvtest at the moment that causes
assignments to something like helpers.arg_max to have no effect from
the importers perspective.

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

index 0923761fb4f5fdb4be224f2c7d7ea9abd94d7cf0..42f91297f9b68ada81b1791a3fb792c51449ad2d 100644 (file)
@@ -3,7 +3,7 @@
 from ctypes import sizeof, c_void_p
 from os import environ
 import sys, os, pwd, subprocess, errno, socket, select, mmap, stat, re, struct
-import config, hashlib, heapq, operator, time, grp
+import hashlib, heapq, operator, time, grp
 
 from bup import _version, _helpers
 import bup._helpers as _helpers
@@ -201,6 +201,15 @@ 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:
@@ -214,13 +223,17 @@ 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):
+def batchpipe(command, args, preexec_fn=None, arg_max=None):
     """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 = config.arg_max - base_size
+        room = arg_max - base_size
         i = 0
         while i < len(args):
             next_size = _argmax_args_size(args[i:i+1])
index 38596d7447e1e33c416cb399748506a2613e232a..b5427076dddc9e93ffd882af8a4ef9aa744408e0 100644 (file)
@@ -1,4 +1,3 @@
-import config
 import helpers
 import math
 import os
@@ -131,18 +130,16 @@ def test_batchpipe():
         batchpipe(['bash', '-c'], ['exit 42'])
     except Exception, ex:
         WVPASSEQ(str(ex), "subprocess 'bash -c exit 42' failed with status 42")
-    oldmax = config.arg_max
     args = [str(x) for x in range(6)]
     # Force batchpipe to break the args into batches of 3.  This
     # approach assumes all args are the same length.
-    config.arg_max = \
+    arg_max = \
         helpers._argmax_base(['echo']) + helpers._argmax_args_size(args[:3])
-    batches = batchpipe(['echo'], args)
+    batches = batchpipe(['echo'], args, arg_max=arg_max)
     WVPASSEQ(next(batches), '0 1 2\n')
     WVPASSEQ(next(batches), '3 4 5\n')
     WVPASSEQ(next(batches, None), None)
-    batches = batchpipe(['echo'], [str(x) for x in range(5)])
+    batches = batchpipe(['echo'], [str(x) for x in range(5)], arg_max=arg_max)
     WVPASSEQ(next(batches), '0 1 2\n')
     WVPASSEQ(next(batches), '3 4\n')
     WVPASSEQ(next(batches, None), None)
-    config.arg_max = oldmax