[PATCH 0/1] dib: handle unsetting functions in environment
This fixes this error I'm hitting when trying to run virt-dib: $ ./run virt-dib -v -x -B ~/git/diskimage-builder/lib/ --element-path ~/git/diskimage-builder/elements/ fedora-minimal [ 0.0] Elements: base fedora-minimal [ 0.0] Expanded elements: base dib-init-system dib-run-parts fedora-minimal install-types package-installs pkg-map redhat-common rpm-distro yum yum-minimal [ 0.0] Carried environment variables: [ 0.0] Preparing auxiliary data [ 0.2] Running: extra-data.d/10-create-pkg-map-dir /tmp/dib.hfC3qu/aux/fake-bin/sudo: line 39: unset: `BASH_FUNC_module()': not a valid identifier virt-dib: error: external command ''/tmp/dib.hfC3qu/run-part-extra.sh' '/tmp/dib.hfC3qu/aux/hooks/extra-data.d' '10-create-pkg-map-dir'' exited with error 1
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;; esac done fi -- 2.4.3
When I turned off debug and actually looked at the normal output, this is a bit noisy... [jeckersb@baozi libguestfs]$ ./run virt-dib -B ~/git/diskimage-builder/lib/ --element-path ~/git/diskimage-builder/elements/ fedora-minimal [ 0.0] Elements: base fedora-minimal [ 0.0] Expanded elements: base dib-init-system dib-run-parts fedora-minimal install-types package-installs pkg-map redhat-common rpm-distro yum yum-minimal [ 0.0] Carried environment variables: [ 0.0] Preparing auxiliary data [ 0.2] Running: extra-data.d/10-create-pkg-map-dir /tmp/dib.dQ8W3Z/aux/fake-bin/sudo: line 39: unset: `BASH_FUNC_module()': not a valid identifier /tmp/dib.dQ8W3Z/aux/fake-bin/sudo: line 39: unset: `BASH_FUNC_scl()': not a valid identifier /tmp/dib.dQ8W3Z/aux/fake-bin/sudo: line 39: unset: `BASH_FUNC_module()': not a valid identifier /tmp/dib.dQ8W3Z/aux/fake-bin/sudo: line 39: unset: `BASH_FUNC_scl()': not a valid identifier /tmp/dib.dQ8W3Z/aux/fake-bin/sudo: line 39: unset: `BASH_FUNC_module()': not a valid identifier /tmp/dib.dQ8W3Z/aux/fake-bin/sudo: line 39: unset: `BASH_FUNC_scl()': not a valid identifier [ 0.2] Running: extra-data.d/50-store-build-settings [ 0.2] Running: extra-data.d/99-enable-install-types [ 0.2] Running: extra-data.d/99-squash-package-install [ 0.3] Running: extra-data.d/99-yum-repo-conf [ 0.3] Opening the disks ...etc... So this one instead dumps the noise into /dev/null
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;; esac done fi -- 2.4.3
It helps if I actually include the amended commit...
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..e77d75d 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 2>/dev/null || unset -f $envvar;; esac done fi -- 2.4.3
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
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
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
participants (2)
-
John Eckersberg -
Pino Toscano