aboutsummaryrefslogtreecommitdiffhomepage
path: root/env.cpp
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-09-19 17:31:34 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-09-19 17:38:54 -0700
commit940f264ee6b75e013658d4ba7f6a6dd77ae014d3 (patch)
treecb14835d78554378343c4464167062ff7a650823 /env.cpp
parent761be8ab7fb62965b8dc9dfd6ac6451cda578ad0 (diff)
Decrement SHLVL when running `exec`
`exec` removes fish from the shell "stack", so SHLVL needs to be decremented to match. This means `exec fish` will result in the same SHLVL in the new fish instance. Also tweak the SHLVL logic to interpret an environment SHLVL of "3foo" as garbage instead of as the value "3". Fixes #1693.
Diffstat (limited to 'env.cpp')
-rw-r--r--env.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/env.cpp b/env.cpp
index 353085b8..c9f986b1 100644
--- a/env.cpp
+++ b/env.cpp
@@ -542,8 +542,10 @@ void env_init(const struct config_paths_t *paths /* or NULL */)
wcstring nshlvl_str = L"1";
if (! shlvl_str.missing())
{
- long shlvl_i = wcstol(shlvl_str.c_str(), NULL, 10);
- if (shlvl_i >= 0)
+ wchar_t *end;
+ long shlvl_i = wcstol(shlvl_str.c_str(), &end, 10);
+ while (iswspace(*end)) ++end; /* skip trailing whitespace */
+ if (shlvl_i >= 0 && *end == '\0')
{
nshlvl_str = to_string<long>(shlvl_i + 1);
}