Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel version sort incorrect for RHEL #73

Closed
mxey opened this issue Aug 28, 2017 · 5 comments
Closed

Kernel version sort incorrect for RHEL #73

mxey opened this issue Aug 28, 2017 · 5 comments
Labels

Comments

@mxey
Copy link
Contributor

mxey commented Aug 28, 2017

needrestart sorts RHEL kernel versions incorrectly:

[root@host~]# needrestart -k -b
NEEDRESTART-VER: 2.9
NEEDRESTART-KCUR: 3.10.0-693.1.1.el7.x86_64
NEEDRESTART-KEXP: 3.10.0-693.el7.x86_64
NEEDRESTART-KSTA: 3

That output is from needrestart 2.9, but I have a small test that reproduces the problem on latest Git master:

#!/usr/bin/perl
use v5.14;
use warnings;
use Test::More tests => 1;

use lib 'perl/lib';

use NeedRestart::Kernel;

my @kernels = qw(
    3.10.0-693.1.1.el7.x86_64
    3.10.0-693.el7.x86_64
    3.10.0-514.21.1.el7.x86_64
    3.10.0-327.el7.x86_64
);
my ($version) = reverse sort {nr_kernel_vcmp($a, $b);} @kernels;

is $version, '3.10.0-693.1.1.el7.x86_64';

Output:

1..1
not ok 1
#   Failed test at /…/kernel_sort.t line 18.
#          got: '3.10.0-693.el7.x86_64'
#     expected: '3.10.0-693.1.1.el7.x86_64'
# Looks like you failed 1 test of 1.
@liske liske added the bug label Oct 1, 2017
@liske
Copy link
Owner

liske commented Oct 1, 2017

Is there any documentation available on howto compare RHEL (kernel) versions?

@mxey
Copy link
Contributor Author

mxey commented Oct 2, 2017

I don't think so, except the implementation of "rpmvercmp” in RPM. I found this Perl module that implements it though: https://metacpan.org/pod/RPM::VersionSort

Similar to Debian epoch, upstream version, Debian revision, RPM has epoch, version and release, which are different fields that probably have to be compared individually. In “3.10.0-693.1.1.el7” the version is 3.10.0 and the release is 693.1.1.el7. The epoch defaults to 0.

@liske liske closed this as completed in 6437981 Oct 31, 2017
@liske
Copy link
Owner

liske commented Oct 31, 2017

I've adopted the version handling of RPM::VersionSort which will be used on RHEL environments (there is a line using RPM version sorting in verbose mode). It seems to work with your test.

Thanks for reporting this issue.

@mxey
Copy link
Contributor Author

mxey commented Nov 2, 2017

I took a quick look at your commit. You only check for /etc/redhat-version, which I see neither on RHEL nor CentOS. I have a /etc/redhat-release though.

The combined check for the absence of dpkg might lead to a false negative, in case somebody has installed dpkg (which you can do, just like the RPM tools are available in Debian)

@liske
Copy link
Owner

liske commented Nov 2, 2017

Thanks for looking at the commit.

  • /etc/redhat-release - this was a typo, I should have used copy'n'paste ;-)
  • dpkg - I did not expect that dpkg can be installed as rpm on Debian. I've replaced the check by testing if /etc/debian_version does not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants