Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upfunctions/detect_virt: use container env variable #9
Conversation
benaryorg left a comment
Mostly fine, except for it does not catch the case of |
if grep -q lxc /proc/self/environ >/dev/null; then | ||
export VIRTUALIZATION=1 | ||
fi | ||
test -z "$container" || export VIRTUALIZATION=1 |
This comment has been minimized.
This comment has been minimized.
benaryorg
Nov 19, 2019
This only checks whether the variable is not empty, not whether it is set.
I'd recommend using the (deleted) approach of grepping:
grep -zq ^container= /proc/self/environ 2>/dev/null && export VIRTUALIZATION=1
This comment has been minimized.
This comment has been minimized.
CameronNemo
Nov 19, 2019
•
Author
Contributor
not gonna work with busybox
/ # busybox grep -z
grep: invalid option -- 'z'
are there any container runtimes that set the var to empty?
This comment has been minimized.
This comment has been minimized.
benaryorg
Nov 19, 2019
On one hand I doubt so, on the other hand I've seen enough not to be particularly inclined to trust that assumption.
Anyways, which version of busybox are you using, the one I tested on my voidlinux installation and the one on my Gentoo box both have a -z
flag.
The Gentoo box running BusyBox v1.31.1.
This comment has been minimized.
This comment has been minimized.
CameronNemo
Nov 19, 2019
Author
Contributor
cameronnemo@cn-mbook ~> docker run --rm -it voidlinux/voidlinux sh
# xbps-install -Syu ; xbps-install -yu ; xbps-install -y busybox
[...]
# busybox grep -zq ^container= /proc/self/environ
grep: invalid option -- 'z'
BusyBox v1.30.1 (2019-08-02 18:59:22 UTC) multi-call binary.
Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...
This comment has been minimized.
This comment has been minimized.
leahneukirchen
Nov 20, 2019
Contributor
What's the purpose of this? Why not use [ "${container+x}" ]
This comment has been minimized.
This comment has been minimized.
benaryorg
Nov 21, 2019
@leahneukirchen entirely forgot about that construct.
Right, that seems more reasonable.
This comment has been minimized.
This comment has been minimized.
benaryorg
commented
Nov 19, 2019
Also, I think if your comment starts with |
CameronNemo commentedSep 28, 2018
No description provided.