Re: [PATCH] Use full path to dnsdomainname and domainname in scripts/mkcompile_h
From: AmÃrico Wang
Date: Wed Jan 27 2010 - 04:34:12 EST
On Wed, Jan 27, 2010 at 4:52 PM, Michal Marek <mmarek@xxxxxxx> wrote:
> On Wed, Jan 27, 2010 at 10:44:29AM +0800, AmÃrico Wang wrote:
>> On Wed, Jan 27, 2010 at 3:10 AM, Glenn Sommer <glemsom@xxxxxxxxx> wrote:
>> > --- scripts/mkcompile_h.orig  Â2010-01-26 18:59:37.000000000 +0100
>> > +++ scripts/mkcompile_h 2010-01-26 20:03:42.000000000 +0100
>> > @@ -67,9 +67,9 @@
>> > Â echo \#define LINUX_COMPILE_BY \"`whoami`\"
>> > Â echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\"
>> >
>> > - Âif [ -x /bin/dnsdomainname ]; then
>> > + Âif [ `command -v dnsdomainname 2> /dev/null` ]; then
>> > Â Â domain=`dnsdomainname 2> /dev/null`
>> > - Âelif [ -x /bin/domainname ]; then
>> > + Âelif [ `command -v domainname 2> /dev/null` ]; then
>> > Â Â domain=`domainname 2> /dev/null`
>> > Â fi
>> >
>>
>> No, this doesn't look good.
>>
>> First, you don't need to redirect stderr for 'command'.
>>
>> Second, 'command' also searches in shell built-in commands, aliases,
>> so I prefer 'whereis -b'.
>
>
> Well, 'command -v domainname' returns success iff 'domainname' can be
> executed (be it an external command, builtin, function, whatever), which
> is exactly what we do on the next line. But, there is no need to capture
> the output of 'command -v domainname' and pass it to [ ... ], just test
> the return code.
>
> ... crap, now I learned that busybox doesn't support 'command' :-(
> So what about simply trying 'dnsdomainname' and falling back to
> domainname if it fails? Like this:
>
>
> Subject: [PATCH] scripts/mkcompile_h: don't test for hardcoded paths
>
> Don't test for /bin/{dnsdomainname,domainname}, simply try to execute
> the command and check if it returned something.
Good!
>
> Reported-by: Glenn Sommer <glemsom@xxxxxxxxx>
> Signed-off-by: Michal Marek <mmarek@xxxxxxx>
Acked-by: WANG Cong <xiyou.wangcong@xxxxxxxxx>
> ---
> Âscripts/mkcompile_h | Â Â5 ++---
> Â1 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
> index 23dbad8..50ad317 100755
> --- a/scripts/mkcompile_h
> +++ b/scripts/mkcompile_h
> @@ -67,9 +67,8 @@ UTS_TRUNCATE="cut -b -$UTS_LEN"
> Â echo \#define LINUX_COMPILE_BY \"`whoami`\"
> Â echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\"
>
> - Âif [ -x /bin/dnsdomainname ]; then
> - Â Âdomain=`dnsdomainname 2> /dev/null`
> - Âelif [ -x /bin/domainname ]; then
> + Âdomain=`dnsdomainname 2> /dev/null`
> + Âif [ -z "$domain" ]; then
> Â Â domain=`domainname 2> /dev/null`
> Â fi
>
> --
> 1.6.5.3
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/