linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ver_linux: module-init-tools.patch
@ 2015-10-01 18:49 Alexander Kapshuk
  2015-10-02 18:10 ` Jim Davis
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Kapshuk @ 2015-10-01 18:49 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg KH

The current implementation relies on 'depmod' to be available in the
PATH. It also expects the version number to be found in the last field
as seen by 'awk'. Should the output format be different, this approach
would no longer be reliable.

The proposed implementation locates 'depmod', and uses 'sed' as a more
flexible tool to handle varying output formats.

Tested on:
Gentoo Linux
Debian 6.0.10
Oracle Linux Server release 7.1
Arch Linux
openSuSE 13.2


Signed-off-by: Alexander Kapshuk <alexander.kapshuk@gmail.com>
---

--- linux/scripts/ver_linux.orig    2015-10-01 18:36:49.090519891 +0300
+++ linux/scripts/ver_linux    2015-10-01 21:48:09.985628346 +0300
@@ -25,7 +25,14 @@
 echo -n "mount                  "
 mount --version | awk '{print $NF}' | sed -e s/^mount-// -e s/\)$//

-depmod -V  2>&1 | awk 'NR==1 {print "module-init-tools     ",$NF}'
+depmod=`whereis depmod | awk '{print $2}'`
+test -n "$depmod" &&
+$depmod -V 2>&1 |
+sed '
+    /[0-9]$/!d
+    s/[^0-9\.]//g
+    s/^/module-init-tools\t/
+'

 tune2fs 2>&1 | grep "^tune2fs" | sed 's/,//' |  awk \
 'NR==1 {print "e2fsprogs             ", $2}'

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ver_linux: module-init-tools.patch
  2015-10-01 18:49 [PATCH] ver_linux: module-init-tools.patch Alexander Kapshuk
@ 2015-10-02 18:10 ` Jim Davis
  2015-10-02 19:03   ` Alexander Kapshuk
  0 siblings, 1 reply; 9+ messages in thread
From: Jim Davis @ 2015-10-02 18:10 UTC (permalink / raw)
  To: Alexander Kapshuk; +Cc: linux-kernel, Greg KH

On Thu, Oct 1, 2015 at 11:49 AM, Alexander Kapshuk
<alexander.kapshuk@gmail.com> wrote:
> The current implementation relies on 'depmod' to be available in the
> PATH. It also expects the version number to be found in the last field
> as seen by 'awk'. Should the output format be different, this approach
> would no longer be reliable.
>
> The proposed implementation locates 'depmod', and uses 'sed' as a more
> flexible tool to handle varying output formats.
>
> Tested on:
> Gentoo Linux
> Debian 6.0.10
> Oracle Linux Server release 7.1
> Arch Linux
> openSuSE 13.2
>
>
> Signed-off-by: Alexander Kapshuk <alexander.kapshuk@gmail.com>
> ---
>
> --- linux/scripts/ver_linux.orig    2015-10-01 18:36:49.090519891 +0300
> +++ linux/scripts/ver_linux    2015-10-01 21:48:09.985628346 +0300
> @@ -25,7 +25,14 @@
>  echo -n "mount                  "
>  mount --version | awk '{print $NF}' | sed -e s/^mount-// -e s/\)$//
>
> -depmod -V  2>&1 | awk 'NR==1 {print "module-init-tools     ",$NF}'
> +depmod=`whereis depmod | awk '{print $2}'`

Hmm.

jim@krebstar:~$ which depmod
/usr/local/bin/depmod
jim@krebstar:~$ whereis depmod
depmod: /sbin/depmod /etc/depmod.d /usr/local/bin/depmod
/usr/share/man/man8/depmod.8.gz

So while according to my $PATH preferences I'd rather run
/usr/local/bin/depmod, it looks like the '{print $2}' thing would pick
/sbin/depmod instead.

Not a big deal, but I suspect those sort of considerations are why the
scripts tend just to check the $PATH.

-- 
Jim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ver_linux: module-init-tools.patch
  2015-10-02 18:10 ` Jim Davis
@ 2015-10-02 19:03   ` Alexander Kapshuk
  2015-10-02 19:35     ` Jim Davis
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Kapshuk @ 2015-10-02 19:03 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jim Davis

On Fri, Oct 2, 2015 at 9:10 PM, Jim Davis <jim.epost@gmail.com> wrote:
> On Thu, Oct 1, 2015 at 11:49 AM, Alexander Kapshuk
> <alexander.kapshuk@gmail.com> wrote:
>> The current implementation relies on 'depmod' to be available in the
>> PATH. It also expects the version number to be found in the last field
>> as seen by 'awk'. Should the output format be different, this approach
>> would no longer be reliable.
>>
>> The proposed implementation locates 'depmod', and uses 'sed' as a more
>> flexible tool to handle varying output formats.
>>
>> Tested on:
>> Gentoo Linux
>> Debian 6.0.10
>> Oracle Linux Server release 7.1
>> Arch Linux
>> openSuSE 13.2
>>
>>
>> Signed-off-by: Alexander Kapshuk <alexander.kapshuk@gmail.com>
>> ---
>>
>> --- linux/scripts/ver_linux.orig    2015-10-01 18:36:49.090519891 +0300
>> +++ linux/scripts/ver_linux    2015-10-01 21:48:09.985628346 +0300
>> @@ -25,7 +25,14 @@
>>  echo -n "mount                  "
>>  mount --version | awk '{print $NF}' | sed -e s/^mount-// -e s/\)$//
>>
>> -depmod -V  2>&1 | awk 'NR==1 {print "module-init-tools     ",$NF}'
>> +depmod=`whereis depmod | awk '{print $2}'`
>
> Hmm.
>
> jim@krebstar:~$ which depmod
> /usr/local/bin/depmod
> jim@krebstar:~$ whereis depmod
> depmod: /sbin/depmod /etc/depmod.d /usr/local/bin/depmod
> /usr/share/man/man8/depmod.8.gz
>
> So while according to my $PATH preferences I'd rather run
> /usr/local/bin/depmod, it looks like the '{print $2}' thing would pick
> /sbin/depmod instead.
>
> Not a big deal, but I suspect those sort of considerations are why the
> scripts tend just to check the $PATH.
>
> --
> Jim

Thanks for your feedback.

Is '/sbin/depmod' perhaps a symlink to '/usr/local/bin/depmod' on your system?

On some distros, I found that 'which' may not necessarily locate the
binary in question, because the $PATH is not set in a uniform fashion
across various distros. Whereas 'whereis' was found to return a valid
path to the binaries invoked by 'ver_linux' across all the distros I
have been able to test-run 'ver_linux' on, especially on those where
'which' failed to do so. Which is something I found confusing
considering the fact the manpages for both 'which' and 'whereis' claim
to be searching the $PATH to find binaries.

E.g. on Gentoo I get this:

which depmod
which: no depmod in
(/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.8.5:/usr/games/bin:/home/alkap/bin:/usr/local/plan9/bin)

whereis -b depmod
depmod: /sbin/depmod

ls -l /sbin/depmod
lrwxrwxrwx 1 root root 9 Aug  8 14:47 /sbin/depmod -> /bin/kmod

If you have a more reliable approach to suggest, I am open to suggestions.

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ver_linux: module-init-tools.patch
  2015-10-02 19:03   ` Alexander Kapshuk
@ 2015-10-02 19:35     ` Jim Davis
  2015-10-02 19:45       ` Jim Davis
  0 siblings, 1 reply; 9+ messages in thread
From: Jim Davis @ 2015-10-02 19:35 UTC (permalink / raw)
  To: Alexander Kapshuk; +Cc: linux-kernel

On Fri, Oct 2, 2015 at 12:03 PM, Alexander Kapshuk
<alexander.kapshuk@gmail.com> wrote:
> On Fri, Oct 2, 2015 at 9:10 PM, Jim Davis <jim.epost@gmail.com> wrote:
>> On Thu, Oct 1, 2015 at 11:49 AM, Alexander Kapshuk
>> <alexander.kapshuk@gmail.com> wrote:
>>> The current implementation relies on 'depmod' to be available in the
>>> PATH. It also expects the version number to be found in the last field
>>> as seen by 'awk'. Should the output format be different, this approach
>>> would no longer be reliable.
>>>
>>> The proposed implementation locates 'depmod', and uses 'sed' as a more
>>> flexible tool to handle varying output formats.
>>>
>>> Tested on:
>>> Gentoo Linux
>>> Debian 6.0.10
>>> Oracle Linux Server release 7.1
>>> Arch Linux
>>> openSuSE 13.2
>>>
>>>
>>> Signed-off-by: Alexander Kapshuk <alexander.kapshuk@gmail.com>
>>> ---
>>>
>>> --- linux/scripts/ver_linux.orig    2015-10-01 18:36:49.090519891 +0300
>>> +++ linux/scripts/ver_linux    2015-10-01 21:48:09.985628346 +0300
>>> @@ -25,7 +25,14 @@
>>>  echo -n "mount                  "
>>>  mount --version | awk '{print $NF}' | sed -e s/^mount-// -e s/\)$//
>>>
>>> -depmod -V  2>&1 | awk 'NR==1 {print "module-init-tools     ",$NF}'
>>> +depmod=`whereis depmod | awk '{print $2}'`
>>
>> Hmm.
>>
>> jim@krebstar:~$ which depmod
>> /usr/local/bin/depmod
>> jim@krebstar:~$ whereis depmod
>> depmod: /sbin/depmod /etc/depmod.d /usr/local/bin/depmod
>> /usr/share/man/man8/depmod.8.gz
>>
>> So while according to my $PATH preferences I'd rather run
>> /usr/local/bin/depmod, it looks like the '{print $2}' thing would pick
>> /sbin/depmod instead.
>>
>> Not a big deal, but I suspect those sort of considerations are why the
>> scripts tend just to check the $PATH.
>>
>> --
>> Jim
>
> Thanks for your feedback.
>
> Is '/sbin/depmod' perhaps a symlink to '/usr/local/bin/depmod' on your system?

No.  It's a contrived example, but /sbin/depmod and
/usr/local/bin/depmod are separate programs.  I can imagine a
developer wanting his or her own version for testing.

>
> On some distros, I found that 'which' may not necessarily locate the
> binary in question, because the $PATH is not set in a uniform fashion
> across various distros. Whereas 'whereis' was found to return a valid
> path to the binaries invoked by 'ver_linux' across all the distros I
> have been able to test-run 'ver_linux' on, especially on those where
> 'which' failed to do so. Which is something I found confusing
> considering the fact the manpages for both 'which' and 'whereis' claim
> to be searching the $PATH to find binaries.
>
> E.g. on Gentoo I get this:
>
> which depmod
> which: no depmod in
> (/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.8.5:/usr/games/bin:/home/alkap/bin:/usr/local/plan9/bin)
>
> whereis -b depmod
> depmod: /sbin/depmod
>
> ls -l /sbin/depmod
> lrwxrwxrwx 1 root root 9 Aug  8 14:47 /sbin/depmod -> /bin/kmod
>
> If you have a more reliable approach to suggest, I am open to suggestions.

I suspect it'll be hard to come up with something that's 100%
foolproof and respects user's choices.  Sticking with searching the
user's $PATH at least won't lead to surprises about which program is
being run...


-- 
Jim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ver_linux: module-init-tools.patch
  2015-10-02 19:35     ` Jim Davis
@ 2015-10-02 19:45       ` Jim Davis
  2015-10-02 20:22         ` Alexander Kapshuk
  0 siblings, 1 reply; 9+ messages in thread
From: Jim Davis @ 2015-10-02 19:45 UTC (permalink / raw)
  To: Alexander Kapshuk; +Cc: linux-kernel

On Fri, Oct 2, 2015 at 12:35 PM, Jim Davis <jim.epost@gmail.com> wrote:
> On Fri, Oct 2, 2015 at 12:03 PM, Alexander Kapshuk
>
>>>> +depmod=`whereis depmod | awk '{print $2}'`
>>>

> I suspect it'll be hard to come up with something that's 100%
> foolproof and respects user's choices.  Sticking with searching the
> user's $PATH at least won't lead to surprises about which program is
> being run...

Though looking back at your patch, what might work is to look first
for depmod in the user's $PATH and then try whereis only if that
fails.  I'm not convinced that's much better than just searching
$PATH, but that at least would go with the user's preference first.

-- 
Jim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ver_linux: module-init-tools.patch
  2015-10-02 19:45       ` Jim Davis
@ 2015-10-02 20:22         ` Alexander Kapshuk
  2015-10-02 20:57           ` Alexander Kapshuk
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Kapshuk @ 2015-10-02 20:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jim Davis

On Fri, Oct 2, 2015 at 10:45 PM, Jim Davis <jim.epost@gmail.com> wrote:
> On Fri, Oct 2, 2015 at 12:35 PM, Jim Davis <jim.epost@gmail.com> wrote:
>> On Fri, Oct 2, 2015 at 12:03 PM, Alexander Kapshuk
>>
>>>>> +depmod=`whereis depmod | awk '{print $2}'`
>>>>
>
>> I suspect it'll be hard to come up with something that's 100%
>> foolproof and respects user's choices.  Sticking with searching the
>> user's $PATH at least won't lead to surprises about which program is
>> being run...
>
> Though looking back at your patch, what might work is to look first
> for depmod in the user's $PATH and then try whereis only if that
> fails.  I'm not convinced that's much better than just searching
> $PATH, but that at least would go with the user's preference first.
>
> --
> Jim

Seems like the way to go. Thanks.

I'll resubmit this and the other patches tomorrow with this
consideration in mind.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ver_linux: module-init-tools.patch
  2015-10-02 20:22         ` Alexander Kapshuk
@ 2015-10-02 20:57           ` Alexander Kapshuk
  2015-10-02 23:14             ` Jim Davis
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Kapshuk @ 2015-10-02 20:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jim Davis

On Fri, Oct 2, 2015 at 11:22 PM, Alexander Kapshuk
<alexander.kapshuk@gmail.com> wrote:
> On Fri, Oct 2, 2015 at 10:45 PM, Jim Davis <jim.epost@gmail.com> wrote:
>> On Fri, Oct 2, 2015 at 12:35 PM, Jim Davis <jim.epost@gmail.com> wrote:
>>> On Fri, Oct 2, 2015 at 12:03 PM, Alexander Kapshuk
>>>
>>>>>> +depmod=`whereis depmod | awk '{print $2}'`
>>>>>
>>
>>> I suspect it'll be hard to come up with something that's 100%
>>> foolproof and respects user's choices.  Sticking with searching the
>>> user's $PATH at least won't lead to surprises about which program is
>>> being run...
>>
>> Though looking back at your patch, what might work is to look first
>> for depmod in the user's $PATH and then try whereis only if that
>> fails.  I'm not convinced that's much better than just searching
>> $PATH, but that at least would go with the user's preference first.
>>
>> --
>> Jim
>
> Seems like the way to go. Thanks.
>
> I'll resubmit this and the other patches tomorrow with this
> consideration in mind.

What do you think of this?

which depmod >/dev/null 2>&1 && depmod=depmod ||
depmod=`whereis depmod | awk '{print $2}'`

test -n "$depmod" -a -x "$depmod" &&
$depmod -V 2>&1 |
sed '
    /[0-9]$/!d
    s/[^0-9\.]//g
    s/^/module-init-tools\t/
'

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ver_linux: module-init-tools.patch
  2015-10-02 20:57           ` Alexander Kapshuk
@ 2015-10-02 23:14             ` Jim Davis
  2015-10-03 12:13               ` Alexander Kapshuk
  0 siblings, 1 reply; 9+ messages in thread
From: Jim Davis @ 2015-10-02 23:14 UTC (permalink / raw)
  To: Alexander Kapshuk; +Cc: linux-kernel

On Fri, Oct 2, 2015 at 1:57 PM, Alexander Kapshuk
<alexander.kapshuk@gmail.com> wrote:
> On Fri, Oct 2, 2015 at 11:22 PM, Alexander Kapshuk
> <alexander.kapshuk@gmail.com> wrote:
>> On Fri, Oct 2, 2015 at 10:45 PM, Jim Davis <jim.epost@gmail.com> wrote:
>>> On Fri, Oct 2, 2015 at 12:35 PM, Jim Davis <jim.epost@gmail.com> wrote:
>>>> On Fri, Oct 2, 2015 at 12:03 PM, Alexander Kapshuk
>>>>
>>>>>>> +depmod=`whereis depmod | awk '{print $2}'`
>>>>>>
>>>
>>>> I suspect it'll be hard to come up with something that's 100%
>>>> foolproof and respects user's choices.  Sticking with searching the
>>>> user's $PATH at least won't lead to surprises about which program is
>>>> being run...
>>>
>>> Though looking back at your patch, what might work is to look first
>>> for depmod in the user's $PATH and then try whereis only if that
>>> fails.  I'm not convinced that's much better than just searching
>>> $PATH, but that at least would go with the user's preference first.
>>>
>>> --
>>> Jim
>>
>> Seems like the way to go. Thanks.
>>
>> I'll resubmit this and the other patches tomorrow with this
>> consideration in mind.
>
> What do you think of this?
>
> which depmod >/dev/null 2>&1 && depmod=depmod ||
> depmod=`whereis depmod | awk '{print $2}'`
>
> test -n "$depmod" -a -x "$depmod" &&
> $depmod -V 2>&1 |
> sed '
>     /[0-9]$/!d
>     s/[^0-9\.]//g
>     s/^/module-init-tools\t/
> '

Looks good, thanks.
-- 
Jim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ver_linux: module-init-tools.patch
  2015-10-02 23:14             ` Jim Davis
@ 2015-10-03 12:13               ` Alexander Kapshuk
  0 siblings, 0 replies; 9+ messages in thread
From: Alexander Kapshuk @ 2015-10-03 12:13 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jim Davis

On Sat, Oct 3, 2015 at 2:14 AM, Jim Davis <jim.epost@gmail.com> wrote:
> On Fri, Oct 2, 2015 at 1:57 PM, Alexander Kapshuk
> <alexander.kapshuk@gmail.com> wrote:
>> On Fri, Oct 2, 2015 at 11:22 PM, Alexander Kapshuk
>> <alexander.kapshuk@gmail.com> wrote:
>>> On Fri, Oct 2, 2015 at 10:45 PM, Jim Davis <jim.epost@gmail.com> wrote:
>>>> On Fri, Oct 2, 2015 at 12:35 PM, Jim Davis <jim.epost@gmail.com> wrote:
>>>>> On Fri, Oct 2, 2015 at 12:03 PM, Alexander Kapshuk
>>>>>
>>>>>>>> +depmod=`whereis depmod | awk '{print $2}'`
>>>>>>>
>>>>
>>>>> I suspect it'll be hard to come up with something that's 100%
>>>>> foolproof and respects user's choices.  Sticking with searching the
>>>>> user's $PATH at least won't lead to surprises about which program is
>>>>> being run...
>>>>
>>>> Though looking back at your patch, what might work is to look first
>>>> for depmod in the user's $PATH and then try whereis only if that
>>>> fails.  I'm not convinced that's much better than just searching
>>>> $PATH, but that at least would go with the user's preference first.
>>>>
>>>> --
>>>> Jim
>>>
>>> Seems like the way to go. Thanks.
>>>
>>> I'll resubmit this and the other patches tomorrow with this
>>> consideration in mind.
>>
>> What do you think of this?
>>
>> which depmod >/dev/null 2>&1 && depmod=depmod ||
>> depmod=`whereis depmod | awk '{print $2}'`
>>
>> test -n "$depmod" -a -x "$depmod" &&
>> $depmod -V 2>&1 |
>> sed '
>>     /[0-9]$/!d
>>     s/[^0-9\.]//g
>>     s/^/module-init-tools\t/
>> '
>
> Looks good, thanks.
> --
> Jim

Thanks to you too.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-03 12:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-01 18:49 [PATCH] ver_linux: module-init-tools.patch Alexander Kapshuk
2015-10-02 18:10 ` Jim Davis
2015-10-02 19:03   ` Alexander Kapshuk
2015-10-02 19:35     ` Jim Davis
2015-10-02 19:45       ` Jim Davis
2015-10-02 20:22         ` Alexander Kapshuk
2015-10-02 20:57           ` Alexander Kapshuk
2015-10-02 23:14             ` Jim Davis
2015-10-03 12:13               ` Alexander Kapshuk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).