mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +00:00
set: Print an error when setting umask
to a bad value
Repurpose the ENV_INVALID return value for env_set(), which wasn't currently used by anything. When a bad value is passed for the 'umask' key, return ENV_INVALID to signal this and print a good error message from the `set` builtin. This makes `set umask foo` properly produce an error.
This commit is contained in:
parent
d0c85471b4
commit
9f725bee1f
3 changed files with 6 additions and 4 deletions
|
@ -166,7 +166,7 @@ static int my_env_set(const wchar_t *key, const wcstring_list_t &val, int scope)
|
||||||
|
|
||||||
case ENV_INVALID:
|
case ENV_INVALID:
|
||||||
{
|
{
|
||||||
append_format(stderr_buffer, _(L"%ls: Unknown error"), L"set");
|
append_format(stderr_buffer, _(L"%ls: Tried to set the special variable '%ls' to an invalid value\n"), L"set", key);
|
||||||
retcode=1;
|
retcode=1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
6
env.cpp
6
env.cpp
|
@ -655,11 +655,13 @@ int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t var_mode)
|
||||||
if (!errno && (!*end) && (mask <= 0777) && (mask >= 0))
|
if (!errno && (!*end) && (mask <= 0777) && (mask >= 0))
|
||||||
{
|
{
|
||||||
umask(mask);
|
umask(mask);
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Do not actually create a umask variable, on env_get, it will be calculated dynamically */
|
/* Do not actually create a umask variable, on env_get, it will be calculated dynamically */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ENV_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Zero element arrays are internaly not coded as null but as this
|
Zero element arrays are internaly not coded as null but as this
|
||||||
|
|
2
env.h
2
env.h
|
@ -80,7 +80,7 @@ void env_init(const struct config_paths_t *paths = NULL);
|
||||||
|
|
||||||
* ENV_PERM, can only be returned when setting as a user, e.g. ENV_USER is set. This means that the user tried to change a read-only variable.
|
* ENV_PERM, can only be returned when setting as a user, e.g. ENV_USER is set. This means that the user tried to change a read-only variable.
|
||||||
* ENV_SCOPE, the variable cannot be set in the given scope. This applies to readonly/electric variables set from the local or universal scopes, or set as exported.
|
* ENV_SCOPE, the variable cannot be set in the given scope. This applies to readonly/electric variables set from the local or universal scopes, or set as exported.
|
||||||
* ENV_INVALID, the variable name or mode was invalid
|
* ENV_INVALID, the variable value was invalid. This applies only to special variables.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t mode);
|
int env_set(const wcstring &key, const wchar_t *val, env_mode_flags_t mode);
|
||||||
|
|
Loading…
Reference in a new issue