mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Glenn Sommer <glemsom@gmail.com>
To: Michal Marek <mmarek@suse.cz>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Use full path to dnsdomainname and domainname in  scripts/mkcompile_h
Date: Wed, 27 Jan 2010 11:14:47 +0100	[thread overview]
Message-ID: <d65b1b151001270214p6abb10e6l6d4a562f94e37db5@mail.gmail.com> (raw)
In-Reply-To: <d65b1b151001270212q737706f1md00953155135b271@mail.gmail.com>

2010/1/27 Michal Marek <mmarek@suse.cz>:
> 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@gmail.com> 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:


Ohh, I didn't know that! We DO need to be compatible with busybox! :/


>
> 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.
>
> Reported-by: Glenn Sommer <glemsom@gmail.com>
> Signed-off-by: Michal Marek <mmarek@suse.cz>
> ---
>  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
>
>

I tested above patch, and it seems to work fine.
Though, by looking a bit closer at the source - I found we actually
NEVER need to use 2> /dev/null.
We capture the output using ") > .tmpcompile", meaning we only capture
stdout _NOT_ stderr.
One could argue that we should remove the redirection of stderr for
debugging purposes. (In really rare cases where both dnsdomianname and
domainname are missing)
Though, I do NOT see the need for that!

I'm completely satisfied with the above patch! It does the job I
initially requested - which was to either use a complete path at all
times, or never use a complete path. :)

  parent reply	other threads:[~2010-01-27 10:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-19 18:29 Glenn Sommer
2010-01-20  3:26 ` Américo Wang
2010-01-20 15:06   ` Glenn Sommer
2010-01-26  3:55     ` Américo Wang
2010-01-26 15:03       ` Michal Marek
2010-01-26 19:10         ` Glenn Sommer
2010-01-27  2:44           ` Américo Wang
2010-01-27  8:52             ` Michal Marek
2010-01-27  9:34               ` Américo Wang
     [not found]               ` <d65b1b151001270212q737706f1md00953155135b271@mail.gmail.com>
2010-01-27 10:14                 ` Glenn Sommer [this message]
2010-01-27 13:15                   ` Michal Marek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d65b1b151001270214p6abb10e6l6d4a562f94e37db5@mail.gmail.com \
    --to=glemsom@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®