diff --git a/Makefile b/Makefile index 0cfb65e80..5bc0e8a3c 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ LIBS = libs2ss.so # Object files for libs2ss LIB_OBJS = sample.o path.o node.o \ - linux.o \ + kernel.o \ list.o pool.o queue.o lstack.o \ log.o \ utils.o \ diff --git a/include/linux.h b/include/kernel.h similarity index 88% rename from include/linux.h rename to include/kernel.h index ec51aef65..08ca042ae 100644 --- a/include/linux.h +++ b/include/kernel.h @@ -10,6 +10,15 @@ #ifndef _LINUX_H_ #define _LINUX_H_ +//#include + +/** Check if current process has capability \p cap. + * + * @retval 0 If capabilty is present. + * @retval <0 If capability is not present. + */ +//int kernel_check_cap(cap_value_t cap): + /** Checks for realtime (PREEMPT_RT) patched kernel. * * See https://rt.wiki.kernel.org diff --git a/lib/gtfpga.c b/lib/gtfpga.c index c9dc4d647..7e07921d2 100644 --- a/lib/gtfpga.c +++ b/lib/gtfpga.c @@ -17,7 +17,7 @@ #include "utils.h" #include "timing.h" #include "utils.h" -#include "linux.h" +#include "kernel.h" static struct pci_access *pacc; diff --git a/lib/if.c b/lib/if.c index b86d8a767..6b417e24c 100644 --- a/lib/if.c +++ b/lib/if.c @@ -21,7 +21,7 @@ #include "nl.h" #include "socket.h" #include "utils.h" -#include "linux.h" +#include "kernel.h" struct interface * if_create(struct rtnl_link *link) { diff --git a/lib/linux.c b/lib/kernel.c similarity index 82% rename from lib/linux.c rename to lib/kernel.c index 0dd13377f..b2ff8c396 100644 --- a/lib/linux.c +++ b/lib/kernel.c @@ -20,7 +20,7 @@ #include "utils.h" #include "config.h" -#include "linux.h" +#include "kernel.h" int kernel_module_set_param(const char *module, const char *param, const char *value) { @@ -30,7 +30,7 @@ int kernel_module_set_param(const char *module, const char *param, const char *v snprintf(fn, sizeof(fn), "%s/module/%s/parameters/%s", SYSFS_PATH, module, param); f = fopen(fn, "w"); if (f) { - debug(5, "Set parameter %s of kernel module %s to %s", module, param, value); + debug(DBG_SOCKET | 5, "Set parameter %s of kernel module %s to %s", module, param, value); fprintf(f, "%s", value); fclose(f); } @@ -121,6 +121,8 @@ int kernel_has_cmdline(const char *substr) if (!fgets(cmd, sizeof(cmd), f)) return -1; + + fclose(f); return strstr(cmd, substr) ? 0 : -1; } @@ -128,4 +130,32 @@ int kernel_has_cmdline(const char *substr) int kernel_get_cacheline_size() { return sysconf(_SC_LEVEL1_ICACHE_LINESIZE); -} \ No newline at end of file +} + +#if 0 +int kernel_check_cap(cap_value_t cap) +{ + int ret; + + cap_t caps; + cap_flag_value_t value; + + caps = cap_get_proc(); + if (caps == NULL) + return -1; + + ret = cap_get_proc(caps); + if (ret == -1) + return -1; + + ret = cap_get_flag(caps, cap, CAP_EFFECTIVE, &value); + if (ret == -1) + return -1; + + ret = cap_free(caps); + if (ret) + return -1; + + return value == CAP_SET ? 0 : -1; +} +#endif \ No newline at end of file diff --git a/lib/pool.c b/lib/pool.c index 5298555d1..fbcf2c084 100644 --- a/lib/pool.c +++ b/lib/pool.c @@ -11,7 +11,7 @@ #include "utils.h" #include "pool.h" -#include "linux.h" +#include "kernel.h" int pool_init_mmap(struct pool *p, size_t blocksz, size_t cnt) {