From fa380602cf2218c092e941cb41824eb09860fcc7 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 9 Jun 2011 15:07:40 +0000 Subject: [PATCH] Accept kernel version 3 (3.0-rc and similar). --- WHATS_NEW_DM | 1 + libdm/ioctl/libdm-iface.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 5b2a60377..278bdf8a2 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.65 - ================================== + Accept new kernel version 3 formats in initialisation. Version 1.02.64 - 29th April 2011 ================================== diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index f54cf1d20..ad3434472 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -73,9 +73,9 @@ static unsigned _dm_version_minor = 0; static unsigned _dm_version_patchlevel = 0; static int _log_suppress = 0; -static int _kernel_major; -static int _kernel_minor; -static int _kernel_release; +static int _kernel_major = 0; +static int _kernel_minor = 0; +static int _kernel_release = 0; /* * If the kernel dm driver only supports one major number @@ -152,6 +152,7 @@ static int _uname(void) { static int _uts_set = 0; struct utsname _uts; + int parts; if (_uts_set) return 1; @@ -160,10 +161,14 @@ static int _uname(void) log_error("uname failed: %s", strerror(errno)); return 0; } - if (sscanf(_uts.release, "%d.%d.%d", + + parts = sscanf(_uts.release, "%d.%d.%d", &_kernel_major, &_kernel_minor, - &_kernel_release) != 3) { + &_kernel_release); + + /* Kernels with a major number of 2 always had 3 parts. */ + if (parts < 1 || (_kernel_major < 3 && parts < 3)) { log_error("Could not determine kernel version used."); return 0; }