@@ -25,6 +25,7 @@
#include <util/size.h>
#include <util/sysfs.h>
#include <util/strbuf.h>
+#include <util/parse-configs.h>
#include <ndctl/libndctl.h>
#include <ndctl/namespace.h>
#include <daxctl/libdaxctl.h>
@@ -266,22 +267,6 @@ NDCTL_EXPORT void ndctl_set_userdata(struct ndctl_ctx *ctx, void *userdata)
ctx->userdata = userdata;
}
-static int filter_conf(const struct dirent *dir)
-{
- if (!dir)
- return 0;
-
- if (dir->d_type == DT_REG) {
- const char *ext = strrchr(dir->d_name, '.');
- if ((!ext) || (ext == dir->d_name))
- return 0;
- if (strcmp(ext, ".conf") == 0)
- return 1;
- }
-
- return 0;
-}
-
NDCTL_EXPORT void ndctl_set_configs_dir(struct ndctl_ctx **ctx, char *conf_dir)
{
struct dirent **namelist;
@@ -291,7 +276,7 @@ NDCTL_EXPORT void ndctl_set_configs_dir(struct ndctl_ctx **ctx, char *conf_dir)
if ((!ctx) || (!conf_dir))
return;
- rc = scandir(conf_dir, &namelist, filter_conf, alphasort);
+ rc = scandir(conf_dir, &namelist, filter_conf_files, alphasort);
if (rc == -1) {
if (errno != ENOENT)
err(*ctx, "scandir for configs failed: %s\n",
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2021, FUJITSU LIMITED. ALL rights reserved.
+#include <dirent.h>
#include <stdbool.h>
#include <stdint.h>
+#include <string.h>
#include <util/util.h>
enum parse_conf_type {
@@ -11,6 +13,8 @@ enum parse_conf_type {
MONITOR_CALLBACK,
};
+int filter_conf_files(const struct dirent *dir);
+
struct config;
typedef int parse_conf_cb(const struct config *, const char *config_file);
@@ -6,6 +6,23 @@
#include <util/strbuf.h>
#include <util/iniparser.h>
+int filter_conf_files(const struct dirent *dir)
+{
+ if (!dir)
+ return 0;
+
+ if (dir->d_type == DT_REG) {
+ const char *ext = strrchr(dir->d_name, '.');
+
+ if ((!ext) || (ext == dir->d_name))
+ return 0;
+ if (strcmp(ext, ".conf") == 0)
+ return 1;
+ }
+
+ return 0;
+}
+
static void set_str_val(const char **value, const char *val)
{
struct strbuf buf = STRBUF_INIT;
@@ -15,6 +15,8 @@ libdaxctl_la_SOURCES =\
../../util/sysfs.h \
../../util/log.c \
../../util/log.h \
+ ../../util/parse-configs.h \
+ ../../util/parse-configs.c \
libdaxctl.c
libdaxctl_la_LIBADD =\
@@ -19,6 +19,8 @@ libndctl_la_SOURCES =\
../../util/wrapper.c \
../../util/usage.c \
../../util/fletcher.h \
+ ../../util/parse-configs.h \
+ ../../util/parse-configs.c \
dimm.c \
inject.c \
nfit.c \