3

I wish I could be more thorough in my explanation, but I have been using my same Artix setup for a while now, without any issues I couldn't fix myself. However, after installing VirtualBox (Which I don't think is related to this issue) I suddenly cannot execute any command in the terminal after reboot. No matter how many arguments, or any at all, my zsh replies with Argument list too long. This happens with everything, from executing dwm to using ls. I have tried wiping my .zshrc to bare minimum, and whatever I try does not work. Bash and shell do work however. Any ideas?

4
  • 4
    This could mean that you have one or a few huge environment variables. In the zsh shell, does export show you anything unexpected? Commented Aug 28, 2020 at 16:08
  • 1
    Does (unset $(typeset +x); PATH=/usr/bin:/bin TERM=xterm zsh) give you a working shell (without any of your customizations)? Since you've managed to run a shell: if you start zsh -f from that shell, does it work (again, without your customizations)? With your minimal .zshrc, what gets printed when you run zsh -x and try to run ls? Commented Aug 28, 2020 at 16:14
  • I'll try both suggestions right now! Commented Aug 28, 2020 at 16:15
  • Same thing is happening. When logging in as myself, I get all of the argument list too long errors and no command can be executed. When I login as root, and then switch to myself, both commands work. export doesn't show anything out of the ordinary, and zsh -x returns my HISTFILE and HIST information. Commented Aug 28, 2020 at 16:19

3 Answers 3

8

Argument list too long is the error message that typically corresponds to the E2BIG error code:

$ zmodload zsh/system
$ syserror E2BIG
Argument list too long

E2BIG is the error code returned by execve() when asked to execute a command with a list of arguments and environment variable strings larger than supported, or on Linux when a single argument or environment string is larger than 128KiB.

The overall limit and how exactly the size is calculated depends on the system. In modern versions of Linux, it is derived from the current limit of the stack size. You can obtain it with getconf ARG_MAX (assuming you can execute getconf):

$ getconf ARG_MAX
2097152
$ limit stacksize 1024 # KiB, so 1MiB
$ getconf ARG_MAX
262144

That's a quarter of the limit on the stack size, though it's at least 128KiB (and if you drop the stacksize limit too low, you'll start running in all sorts of other problems).

Here, since you're getting the error for every command, including those with a small argument list, we can reasonably assume that that limit is reached because either you have a very large environment variable, or the cumulated size of the environment variables and their values as passed to executed commands is greater that ARG_MAX.

That could happen for instance if you have set the POSIX allexport option by mistake which results in all shell variables to be put in the environment, and have defined a lot of variables, possibly through the running of different completion functions some of which cache information in variables.

Check with:

echo $options[allexport]

Which should report off. If not, check in your startup files where that option is being set. Could be with set -a, set -o allexport, setopt allexport, options[allexport]=on, or the various possible spelling of that option (case and underscores are ignored, so it could also be setopt ALL_EXPORT for instance).

Some other things you can try:

Check the current limit of the stacksize:

$ limit stacksize
stacksize       8MB

Check the current value of ARG_MAX:

$ (typeset +x -m '*'; getconf ARG_MAX)
2097152

typeset +x -m '*' removes all variables for the environment. That includes $PATH, but your system should still be able to find getconf in the default $PATH.

Check the size of the environment:

$ typeset -x | wc -c
4395

(that's an approximation, that doesn't include variables that are not mapped to shell variables, the count could include some quoting characters added by typeset -x that are not in the values of the variables, and it doesn't take into account the fact that you also need to count the size of the list of pointers to those env strings).

Look for environment variables that have a size greater than 128KiB:

$ LC_ALL=C
$ export test=${(l[132000])}
$ for v (${(k)parameters[(R)*export*]}) {(( (l=${(P)#v}) >= 131071 )) && echo "$v: $l"}
test: 132000
$ ls
ls:2: argument list too long: ls

From a separate shell running as root that is not affected by that issue, you could also run:

strace -s150000 -vfe execve -p "$pid"

Where $pid is the process id of your shell that has that problem (see output of echo $$), and then try and run a command in that shell.

strace should show you the exact execve() system call that is being made and that is failing with E2BIG along with the full list of arguments and environment strings (truncated to 150000 bytes each), which should hopefully help you identify the problem.

1
  • I'm sorry, I ended up solving the issue. Somehow (I genuinely don't know how, yes I know things don't "magically" happen in computers xD) the PATH was changed, and was set as everything in /. I presume that helped contribute to what you were explaining, with the environment variables adding up to being way too large. Simply changing the PATH back to my .local/bin fixed everything. Thank you for a very in depth answer however, I did learn quite a bit! I'll still accept. Commented Aug 30, 2020 at 17:13
0

I got this error because I had too much stuff in an autogenerated .env file.

0

I got this error because my path shell parameter was very long and contained multiple duplicate entries. I figured this out by running the export command, which showed the extremely long path. The reason my path was so long was because I had incorrectly added directories to it in my .zshrc file by using path+=('/path/to/directory' $path) rather than just path+=('/path/to/directory').

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.