Do not use command in profile
v4 cover Do not use command in profile
Since we apparently cannot rely on the command utility to always exist, it is better to avoid using it in the profile script. Rather than using command to detect if tty and resize exist (which obviously will not work if command itself does not exist), just call them directly while piping any output for stderr to /dev/null. This should actually be a little bit more efficient in the case that they do exist, and the same in the case that they do not exist.
I leave to you to decide whether you want to revert commit e41c90b852 that enabled the command utility in busybox or not.
PATCHv2: Correct a typo in the commit message.
PATCHv3: Run resize twice, once to determine if it exists, and once to actually do the resize.
PATCHv4: Correct the same typo in the commit message once more...
//Peter
The following changes since commit 13cc30cd7de4841990b600e83e1249c81a5171dd:
local.conf.sample.extended: Drop obsolete rpc and libnsl (2018-05-15 11:07:50 +0100)
are available in the git repository at:
git://push.yoctoproject.org/poky-contrib pkj/profile_without_command
Peter Kjellerstedt (1):
base-files: profile: Avoid using "command" to determine if programs
exist
meta/recipes-core/base-files/base-files/profile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.12.0
PATCH v4 1/1 base-files: profile: Avoid using "command" to determine if programs exist
Since the existence of "command" in itself is not guaranteed, using it to determine if other executables exist is moot. Instead just run the executables and let the shell determine if they exist. By piping stderr to /dev/null we avoid unnecessary warnings in case they do not exist.
--- meta/recipes-core/base-files/base-files/profile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
meta/recipes-core/base-files/base-files/profile +10 -8
@@ -20,14 +20,16 @@ if [ -d /etc/profile.d ]; then unset i fi -if command -v resize >/dev/null && command -v tty >/dev/null; then - # Make sure we are on a serial console (i.e. the device used starts with - # /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which - # tries do use ssh - case $(tty) in - /dev/tty[A-z]*) resize >/dev/null;; - esac -fi +# Make sure we are on a serial console (i.e. the device used starts with +# /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which tries do +# use ssh +case $(tty 2>/dev/null) in + # The first invocation of resize verifies that it exists, the second + # does the actual resizing. This is due to that resize uses stderr to + # determine the size of the tty, which does not work if it is redirected + # to /dev/null. + /dev/tty[A-z]*) resize >/dev/null 2>&1 && resize >/dev/null;; +esac export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM
Signature · 1 line
2.12.0