Bug 55690 - Linux kernel version check broken
Summary: Linux kernel version check broken
Status: RESOLVED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: HEAD
Hardware: All Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-22 16:44 UTC by Arfrever Frehtes Taifersar Arahesis
Modified: 2013-11-15 12:19 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arfrever Frehtes Taifersar Arahesis 2013-10-22 16:44:29 UTC
configure.in contains broken check of Linux kernel version:

case $host in
...
    *linux*)
        os_version=`uname -r | sed -e 's/\(.\)\.\(.\)\.\(.\).*/\1\2\3/'`
        ;;


It fails with all kernels >=3.10.0.
It also treats e.g. 2.6.3 and 2.6.32 as the same version.

./configure prints:

...
checking for create_area... no
checking for MAP_ANON in sys/mman.h... yes
checking for /dev/zero... yes
checking for mmap that can map /dev/zero... yes
./configure: line 21360: test: 3.10.17-gentoo: integer expression expected
decision on anonymous shared memory allocation method... 4.4BSD-style mmap() via MAP_ANON
./configure: line 21672: test: 3.10.17-gentoo: integer expression expected
decision on namebased memory allocation method... SysV IPC shmget()
checking for size_t... yes
checking for working alloca.h... yes
checking for alloca... yes
...
Comment 1 Joe Orton 2013-10-23 13:34:21 UTC
I just noticed this yesterday for the first time... 3.11.x kernel is breaking it.

Fixed in r1535027

If you're able to test that on a 2.6 or pre-2.4 Linux I'd appreciate that.
Comment 2 Arfrever Frehtes Taifersar Arahesis 2013-10-23 15:37:57 UTC
(I do not use old kernels anymore.)

Your solution does not work for 4.0.* versions. If also fails when the last ".0" is skipped.
I have tested your solution in shell by defining uname() function.

$ uname() { echo 3.11.6; }
$ os_major=`uname -r | sed -e 's/\([1-9][0-9]*\)\..*/\1/'`
$ os_minor=`uname -r | sed -e 's/[1-9][0-9]*\.\([1-9][0-9]*\)\..*/\1/'`
$ declare -p os_major os_minor
declare -- os_major="3"
declare -- os_minor="11"
$ uname() { echo 4.0.1; }
$ os_major=`uname -r | sed -e 's/\([1-9][0-9]*\)\..*/\1/'`
$ os_minor=`uname -r | sed -e 's/[1-9][0-9]*\.\([1-9][0-9]*\)\..*/\1/'`
$ declare -p os_major os_minor
declare -- os_major="4"
declare -- os_minor="4.0.1"
$ uname() { echo 3.12; }
$ os_major=`uname -r | sed -e 's/\([1-9][0-9]*\)\..*/\1/'`
$ os_minor=`uname -r | sed -e 's/[1-9][0-9]*\.\([1-9][0-9]*\)\..*/\1/'`
$ declare -p os_major os_minor
declare -- os_major="3"
declare -- os_minor="3.12"
Comment 3 Arfrever Frehtes Taifersar Arahesis 2013-10-23 15:42:53 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #2)
> Your solution does not work for 4.0.* versions.

Or just 3.0.*.
Comment 4 Joe Orton 2013-10-23 20:23:20 UTC
Thanks - r1535157 - anything still broken?
Comment 5 Joe Orton 2013-10-23 20:26:57 UTC
Oh, and Linux has always used x.y.z-style versioning AFAIK so I'm not worried about failing if .z is missing.
Comment 6 Arfrever Frehtes Taifersar Arahesis 2013-10-23 20:38:00 UTC
(In reply to Joe Orton from comment #5)
> Oh, and Linux has always used x.y.z-style versioning AFAIK so I'm not
> worried about failing if .z is missing.

The last .0 is skipped at least in names of tarballs.
https://www.kernel.org/pub/linux/kernel/v3.x/
Comment 7 Arfrever Frehtes Taifersar Arahesis 2013-10-23 21:22:42 UTC
(In reply to Joe Orton from comment #4)
> Thanks - r1535157 - anything still broken?

It does not fix os_minor. You need to escape + character:

$ uname() { echo 3.0.5; }
$ os_major=`uname -r | sed -e 's/\([1-9][0-9]*\)\..*/\1/'`
$ os_minor=`uname -r | sed -e 's/[1-9][0-9]*\.\([0-9]+\)\..*/\1/'`
$ declare -p os_major os_minor
declare -- os_major="3"
declare -- os_minor="3.0.5"
$ os_minor=`uname -r | sed -e 's/[1-9][0-9]*\.\([0-9]\+\)\..*/\1/'`
$ declare -p os_major os_minor
declare -- os_major="3"
declare -- os_minor="0"
Comment 8 Arfrever Frehtes Taifersar Arahesis 2013-11-13 08:37:11 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #7)

And something like this now occurs:

...
configure: Check for compiler flags...
checking whether the compiler provides atomic builtins... yes
checking whether to enable -D_LARGEFILE64_SOURCE... no
./configure: line 19058: test: 3.11.7-gentoo: integer expression expected
configure: Configured for Linux 3.3.11.7-gentoo
configure: 
configure: Checking for libraries...
checking for library containing gethostbyname... none required
checking for library containing gethostname... none required
...


Sufficient patch:

--- configure.in
+++ configure.in
@@ -681,7 +681,7 @@
         ;;
     *linux*)
         os_major=[`uname -r | sed -e 's/\([1-9][0-9]*\)\..*/\1/'`]
-        os_minor=[`uname -r | sed -e 's/[1-9][0-9]*\.\([0-9]+\)\..*/\1/'`]
+        os_minor=[`uname -r | sed -e 's/[1-9][0-9]*\.\([0-9]\+\)\..*/\1/'`]
         if test $os_major -lt 2 -o \( $os_major -eq 2 -a $os_minor -lt 4 \); then
             AC_MSG_WARN([Configured for pre-2.4 Linux $os_major.$os_minor])
             os_pre24linux=1
[
Comment 9 Jeff Trawick 2013-11-13 12:16:46 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #8)
...
> Sufficient patch:
...
> -        os_minor=[`uname -r | sed -e 's/[1-9][0-9]*\.\([0-9]+\)\..*/\1/'`]
> +        os_minor=[`uname -r | sed -e 's/[1-9][0-9]*\.\([0-9]\+\)\..*/\1/'`]

This patch committed to apr trunk as r1541486...

All three revisions merged to the 1.5.x branch with r1541489...
Comment 10 Joe Orton 2013-11-15 12:19:56 UTC
Thanks Jeff and Arfrever.