[virt-tools-list] [virt-what] review of allow to use sysctl

Darren Kenny darren.kenny at oracle.com
Mon Aug 27 10:41:30 UTC 2018


Hi Anatoly,

On Sat, Aug 25, 2018 at 12:36:54PM +0300, Anatoly Pugachev wrote:
>Hello!
>
>virt-what$ git desc
>v1.18-6-gd7fd8a7
>
>Latest commit in git "Allow using sysctl, for example when /proc isn't
>available"
>doesn't look good for me. Can someone please review/revert this commit
>or explain me what does this code do (git show -1):

What this is meant to achieve, is that use_sysctl would return true
(a 0 exit code) if the OS is OpenBSD. Might be clearer if it added a
line like 'return $?' after the [..], but it is unnecessary.


>
>+use_sysctl() {
>+    # Lacking /proc, on some systems sysctl can be used instead.
>+    OS=$(uname) || fail "failed to get operating system name"
>+
>+    [ "$OS" == "OpenBSD" ]
>+}
>
>Running on a linux:
>
>virt-what# PATH=$PATH:. ./virt-what
>./virt-what: 45: [: Linux: unexpected operator

The test operator should be seeing something like:

  [ "Linux" == "OpenBSD" ]

but the error you're seeing looks more like what happens if a shell
interprets it differently - or at least is getting something else,
like the following:

  [ somethingelse Linux == "OpenBSD" ]

which will give an error like you're seeing above in some shells
(not all), where it is interpreting the 'Linux' as an operator, and
is similar to:

  /bin/test somethingelse Linux == "OpenBSD"

where the shell doesn't have an internal implementation of '[', like
some older bourne shell versions.

But, even if uname outputs more than one word, it should be
contained by the quotes in "$OS" in the test code above - on
whatever shell you're using that doesn't appear to be the case.

You might get more of an idea of what is happening by running the
shellscript with the -x option, e.g.

  virt-what# PATH=$PATH:. /bin/sh -x ./virt-what

Thanks,

Darren.




More information about the virt-tools-list mailing list