mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 05:57:58 +08:00
Print a hint if the exported variables appear too large
If we get an E2BIG while executing a process, we check how large the exported variables are. We already did this, but then immediately added it to the total. So now we keep the tally just for the variables around, and if it's over half (which is an atypical value if your system has an ARG_MAX of 2MB), we mention that in the error. Figuring out which variable is too big (in case it's just one) is probably too complicated, but we can at least complain if things seem suspect. Untested because I don't know *how* to do so portably
This commit is contained in:
parent
1326c286fa
commit
a5ce01cc38
|
@ -374,14 +374,16 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const *
|
|||
long arg_max = -1;
|
||||
|
||||
size_t sz = 0;
|
||||
size_t szenv = 0;
|
||||
const char *const *p;
|
||||
for (p = argv; *p; p++) {
|
||||
sz += std::strlen(*p) + 1;
|
||||
}
|
||||
|
||||
for (p = envv; *p; p++) {
|
||||
sz += std::strlen(*p) + 1;
|
||||
szenv += std::strlen(*p) + 1;
|
||||
}
|
||||
sz += szenv;
|
||||
|
||||
format_size_safe(sz1, sz);
|
||||
arg_max = sysconf(_SC_ARG_MAX);
|
||||
|
@ -402,6 +404,12 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const *
|
|||
"Failed to execute process '%s': An argument exceeds the OS "
|
||||
"argument length limit.", actual_cmd);
|
||||
}
|
||||
|
||||
if (szenv >= static_cast<unsigned long long>(arg_max) / 2) {
|
||||
FLOGF_SAFE(exec,
|
||||
"Hint: Your exported variables take up over half the limit. Try erasing or unexporting variables."
|
||||
);
|
||||
}
|
||||
} else {
|
||||
FLOGF_SAFE(exec,
|
||||
"Failed to execute process '%s': the total size of the argument list and "
|
||||
|
|
Loading…
Reference in New Issue
Block a user