Brendan O'Dea wrote on Mon, Nov 21, 2005 at 21:56:15 +1100:
> On Sat, Nov 19, 2005 at 02:23:18AM +0100, Markus Kolb wrote:
> >As someone has already posted before $relmajor should become $release in
> >the $relmajor assignment.
[...]
> >As it should be, shouldn't it?
> 
> Actually, I don't believe so.  Given the way these variables are
> actually used, I suspect that the correct fix is:
> 
>   release=`uname -r`
>   relmajor=`echo $release | sed 's/^\([0-9]*\).*/\1/'`
>   relminor=`echo $release | sed 's/^[0-9]*\.\([0-9]*\).*/\1/'`
>   release=`echo $release | sed 's/^[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/'`
> 
> i.e. for your example, 2.4.27-2-686 should map to relmajor=2, relminor=4
> and release=27.
> 
> Note that the script tests these variables like so:
> 
>   if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
> 
> which I would interpret as testing for 1.X.X or 2.0.X, rather than X.1.X
> or X.2.0 .


I interpreted it as a test for kernel version <= x.2.0 which would mean
<= 2.2.0.
Could make sense and I couldn't believe that someone writes

release=`echo $release | sed 's/\([0-9]*\)\..*/\1/'`

if he would intend to do something like

release=`echo $release | sed 's/^[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/'`

So I thought the vars are used like this
$release => VERSION
$relmajor => PATCHLEVEL
$relminor => SUBLEVEL

But I looked around and found that 1999 the code looked like this:

release=`uname -r`
release=`expr $release : '\(.*\)\..*'`
relmajor=`echo $release |sed -e 's/^\([^\.]*\)\..*$/\1/'`
relminor=`echo $release |sed -e 's/^.*\.\([^\.]*\)$/\1/'`

The tests didn't change.
And you could read a comment
"# added this code to fix this script for kernels greater than 2.0"

Is it modern to remove very useful code comments?

Have a look at the attached patch. Now it should do the right thing.
And please use comments like in my patch. 
--- /etc/dhclient-script.orig   2005-11-15 23:39:23.000000000 +0100
+++ /etc/dhclient-script        2005-11-21 18:25:36.000000000 +0100
@@ -71,10 +71,10 @@
   fi
 fi
 
+# kernel version $relmajor.$relminor.x
 release=`uname -r`
-relminor=`echo $release | sed 's/^[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/'`
-relmajor=`echo $relmajor | sed 's/^[0-9]*\.\([0-9]*\)\..*/\1/'`
-release=`echo $release | sed 's/\([0-9]*\)\..*/\1/'`
+relmajor=`echo $release | sed 's/^\([0-9]*\).*/\1/'`
+relminor=`echo $release | sed 's/^[0-9]*\.\([0-9]*\).*/\1/'`
 
 if [ x$new_broadcast_address != x ]; then
   new_broadcast_arg="broadcast $new_broadcast_address"
@@ -102,6 +102,7 @@
     # Bring down alias interface. Its routes will disappear too.
     ifconfig $interface:0- inet 0
   fi
+  # test for kernels <= 2.0.x
   if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
    then
     ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \

Reply via email to