diff --git a/common/include/villas/kernel/kernel.h b/common/include/villas/kernel/kernel.h index 1f75e968a..64e61dc30 100644 --- a/common/include/villas/kernel/kernel.h +++ b/common/include/villas/kernel/kernel.h @@ -34,9 +34,6 @@ extern "C" { #endif -/* Forward declarations */ -struct version; - #if WITH_CAP #include @@ -66,9 +63,6 @@ int kernel_set_nr_hugepages(int nr); */ int kernel_get_cmdline_param(const char *param, char *buf, size_t len); -/** Get the version of the kernel. */ -int kernel_get_version(struct version *v); - /** Checks if a kernel module is loaded * * @param module the name of the module diff --git a/common/include/villas/kernel/kernel.hpp b/common/include/villas/kernel/kernel.hpp new file mode 100644 index 000000000..44d8d7762 --- /dev/null +++ b/common/include/villas/kernel/kernel.hpp @@ -0,0 +1,35 @@ +/** Linux kernel related functions. + * + * @file + * @author Steffen Vogel + * @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLAScommon + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +#pragma once + +#include + +namespace villas { +namespace kernel { + +/** Get the version of the kernel. */ +utils::Version getVersion(); + +} // namespace villas +} // namespace kernel diff --git a/common/lib/kernel/kernel.c b/common/lib/kernel/kernel.c index 1d29d3acd..4b7f72a06 100644 --- a/common/lib/kernel/kernel.c +++ b/common/lib/kernel/kernel.c @@ -28,7 +28,6 @@ #include #include -#include #include #include @@ -121,19 +120,6 @@ int kernel_module_loaded(const char *module) return ret; } -int kernel_get_version(struct version *v) -{ - struct utsname uts; - - if (uname(&uts) < 0) - return -1; - - if (version_parse(uts.release, v)) - return -1; - - return 0; -} - int kernel_get_cmdline_param(const char *param, char *buf, size_t len) { int ret; diff --git a/common/lib/kernel/kernel.cpp b/common/lib/kernel/kernel.cpp new file mode 100644 index 000000000..e8a557745 --- /dev/null +++ b/common/lib/kernel/kernel.cpp @@ -0,0 +1,44 @@ +/** Linux kernel related functions. + * + * @author Steffen Vogel + * @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLAScommon + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +#include + +#include +#include + +using namespace villas::utils; + +Version villas::kernel::getVersion() +{ + struct utsname uts; + + if (uname(&uts) < 0) + throw new SystemError("Failed to retrieve system identification"); + + std::string rel = uts.release; + + /* Remove release part. E.g. 4.9.93-linuxkit-aufs */ + auto sep = rel.find('-'); + auto ver = rel.substr(0, sep - 1); + + return Version(ver); +}