Pino Toscano
2015-Aug-12 14:53 UTC
Re: [Libguestfs] [PATCH] dib: handle unsetting functions in environment
On Wednesday 12 August 2015 10:33:00 John Eckersberg wrote:> If a function name, with its trailing parentheses, is in the > environment , trying to unset it will error out with a message of "not > a valid identifier". In this case, try to unset it again with the -f > option which can handle the parentheses in the supplied identifier. > --- > dib/dib.ml | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/dib/dib.ml b/dib/dib.ml > index d730527..519da51 100644 > --- a/dib/dib.ml > +++ b/dib/dib.ml > @@ -283,7 +283,7 @@ if [ -z \"$preserve_env\" ]; then > for envvar in `env | grep '^\\w' | cut -d= -f1`; do > case \"$envvar\" in > PATH | USER | USERNAME | HOSTNAME | TERM | LANG | HOME | SHELL | LOGNAME ) ;; > - *) unset $envvar ;; > + *) unset $envvar || unset -f $envvar;;The diagnosis is good, although the fix could be improved: if bash functions need to be named as "BASH_FUNC_*", I'd match on that in the switch case above, and use -f for them. Thanks, -- Pino Toscano
John Eckersberg
2015-Aug-12 15:14 UTC
[Libguestfs] [PATCH v4] dib: handle unsetting functions in environment
If a function name, with its trailing parentheses, is in the environment , trying to unset it will error out with a message of "not a valid identifier". Handle this as a special case, and unset it with the -f option which can handle the parentheses in the supplied identifier. --- dib/dib.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/dib/dib.ml b/dib/dib.ml index d730527..16149ae 100644 --- a/dib/dib.ml +++ b/dib/dib.ml @@ -283,6 +283,7 @@ if [ -z \"$preserve_env\" ]; then for envvar in `env | grep '^\\w' | cut -d= -f1`; do case \"$envvar\" in PATH | USER | USERNAME | HOSTNAME | TERM | LANG | HOME | SHELL | LOGNAME ) ;; + BASH_FUNC_* ) unset -f $envvar ;; *) unset $envvar ;; esac done -- 2.4.3
Pino Toscano
2015-Aug-12 15:28 UTC
Re: [Libguestfs] [PATCH v4] dib: handle unsetting functions in environment
On Wednesday 12 August 2015 11:14:21 John Eckersberg wrote:> If a function name, with its trailing parentheses, is in the > environment , trying to unset it will error out with a message of "not > a valid identifier". Handle this as a special case, and unset it with > the -f option which can handle the parentheses in the supplied > identifier. > --- > dib/dib.ml | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/dib/dib.ml b/dib/dib.ml > index d730527..16149ae 100644 > --- a/dib/dib.ml > +++ b/dib/dib.ml > @@ -283,6 +283,7 @@ if [ -z \"$preserve_env\" ]; then > for envvar in `env | grep '^\\w' | cut -d= -f1`; do > case \"$envvar\" in > PATH | USER | USERNAME | HOSTNAME | TERM | LANG | HOME | SHELL | LOGNAME ) ;; > + BASH_FUNC_* ) unset -f $envvar ;; > *) unset $envvar ;; > esac > done >LGTM, pushed. Thanks, -- Pino Toscano
Maybe Matching Threads
- Re: [PATCH] dib: handle unsetting functions in environment
- [PATCH] dib: handle unsetting functions in environment
- [PATCH] dib: handle unsetting functions in environment
- [PATCH 0/1] dib: handle unsetting functions in environment
- [PATCH 01/10] dib: fix listing envvars in fake-sudo