[Ovirt-devel] [PATCH] Add trivial error() function and change code to use it
Jim Meyering
jim at meyering.net
Sat Oct 4 08:46:52 UTC 2008
"Perry N. Myers" <pmyers at redhat.com> wrote:
> Jeff Schroeder wrote:
>> Remove the multiple echo ... && exit 1 references and replace
>> them with a simple function. This makes the code a bit cleaner.
>
> No problem with this patch in concept, but this patch appears to be
> against the old repository. See the instructions on:
> http://ovirt.org/build-instructions.html
>
> for getting access to the new repositories.
>
> The file you're patching is now located in the ovirt-server repository
> and it's location is:
>
> scripts/ovirt-server-install
...
>> +error() {
>> + echo $* >&2
>> + exit 1
>> +}
Hi Jeff,
Thanks for the clean up.
However, the above use of $* is underquoted.
Here are a couple examples of what can go wrong:
shell tokenization
$ bash -c 'error() { echo $*; }; error "a b"'
a b
ok when no file matches the "a*" glob:
$ bash -c 'error() { echo $*; }; error "a*"'
a*
but when one does, ...
$ touch a-file
$ bash -c 'error() { echo $*; }; error "a*"'
a-file
So, please use something like the existing "die",
which also prints the usual "$program_name: " prefix.
The following appears in several files:
ME=$(basename "$0")
warn() { printf "$ME: $@\n" >&2; }
die() { warn "$@"; exit 1; }
But I've just realized that's not quite correct, in case $ME or $@ ever
expand to something containing a % (or, far less likely, a \c sequence
that printf recognizes), so this is better:
ME=$(basename "$0")
warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
die() { warn "$@"; exit 1; }
For the record, none of our existing uses of warn or die
would trigger the malfunction.
I've just posted a patch to fix those warn definitions.
paranoid^W defensively, ...
Jim
More information about the ovirt-devel
mailing list