From 8f5235a53fc188a397b930ac2bb19e6521975884 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 3 Feb 2021 18:38:14 +0000 Subject: [PATCH] fix 'args list too long' on Linux, again (re: 63979488) That fix turned out to be insufficient as NixOS has huge environment variable lists because (due to each software package being installed in its own directory tree) it has to keep dozens of directories in variables like XDG_CONFIG_DIRS and others. The 'command -x' regression test was failing on NixOS. src/cmd/ksh93/sh/path.c: - Different strategy. Leave twice the size of the existing environment free. --- src/cmd/ksh93/sh/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index af9ca2d4f..b757dda37 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -162,9 +162,9 @@ static pid_t path_xargs(Shell_t *shp,const char *path, char *argv[],char *const pid_t pid; if(shp->xargmin < 0) return((pid_t)-1); - size = shp->gd->lim.arg_max - (ARG_EXTRA_BYTES > 2 ? 1024*ARG_EXTRA_BYTES : 2048); + size = shp->gd->lim.arg_max - 2048; for(ev=envp; cp= *ev; ev++) - size -= strlen(cp) + 1 + ARG_EXTRA_BYTES; + size -= 2 * (strlen(cp) + 1 + ARG_EXTRA_BYTES); for(av=argv; (cp= *av) && av< &argv[shp->xargmin]; av++) size -= strlen(cp) + 1 + ARG_EXTRA_BYTES; for(av=avlast; cp= *av; av++,nlast++)