Linux – Raise 128KiB Limit on Environment Variables

environment-variableslinux

Linux seems to have a default limit of 128KiB (131072) on the length of any single environment variable — any attempt to set an envvar longer than this and then run any program will result in an 'Argument list too long' error.

This seems like it should be a configuration parameter, but I've been unable to find any way to raise it. Is there any way to increase it?

It is problematic for tools like "automake" which try to pull together long lists of files or tests in an environment variable as part of their building and testing process.

Best Answer

MAX_ARG_STRLEN is a constant defined as PAGESIZE*32 in include/uapi/linux/binfmts.h. Its value cannot be changed without recompiling the kernel.

/*
 * These are the maximum length and maximum number of strings passed to the
 * execve() system call.  MAX_ARG_STRLEN is essentially random but serves to
 * prevent the kernel from being unduly impacted by misaddressed pointers.
 * MAX_ARG_STRINGS is chosen to fit in a signed 32-bit integer.
 */
#define MAX_ARG_STRLEN (PAGE_SIZE * 32)
#define MAX_ARG_STRINGS 0x7FFFFFFF