1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

kernel: partial port to C++

This commit is contained in:
Steffen Vogel 2018-08-27 11:11:28 +02:00
parent b71eee85b8
commit ef5c365d9a
4 changed files with 79 additions and 20 deletions

View file

@ -34,9 +34,6 @@
extern "C" {
#endif
/* Forward declarations */
struct version;
#if WITH_CAP
#include <sys/capability.h>
@ -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

View file

@ -0,0 +1,35 @@
/** Linux kernel related functions.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @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 <http://www.gnu.org/licenses/>.
*********************************************************************************/
#pragma once
#include <villas/version.hpp>
namespace villas {
namespace kernel {
/** Get the version of the kernel. */
utils::Version getVersion();
} // namespace villas
} // namespace kernel

View file

@ -28,7 +28,6 @@
#include <inttypes.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/wait.h>
@ -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;

View file

@ -0,0 +1,44 @@
/** Linux kernel related functions.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @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 <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include <sys/utsname.h>
#include <villas/kernel/kernel.hpp>
#include <villas/exceptions.hpp>
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);
}