aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorShivaprasad G Bhat <sbhat@linux.ibm.com>2022-03-17 15:02:41 +0530
committerVishal Verma <vishal.l.verma@intel.com>2022-04-08 16:31:45 -0600
commit318375a08b794acf4bb63333ecf3819928f1c9e5 (patch)
tree193c58e360114cfc3b03658bd3c4330800017564
parent97031db9300654260bc2afb45b3600ac01beaeba (diff)
monitor: Fix the monitor config file parsing
Presently, ndctl monitor is not parsing both the default and user specified config files. The behaviour is quitely masked with the recent iniparser parsing code without any signs until you remove the /etc/ndctl.conf.d directory when the command fails as, #ndctl monitor -d nmem0 iniparser: cannot open /etc/ndctl.conf.d The error is coming from the libiniparser when the monitor parser is initialised with MONITOR_CALLBACK type with parse_monitor_config() as the callback. The configs->key is set to the NDCTL_CONF_FILE for this. The parse_config_file() compares the filename with the key before calling the custom callback. The current code calls the parse_config_prefix() with either the default directory path or the custom config filepath(i.e -c <XYZ>) while the configs->key is set to the NDCTL_CONF_FILE. Since both these strings don't match the NDCTL_CONF_FILE, parse_monitor_config() is not called at all and instead generic iniparser code path is taken. The patch sets the config key to the correct filename before the calls to parse_config_prefix(). The previous behaviour for missing monitor.conf file in the default path was to ignore and continue. The current callback parse_monitor_config() reports an error as e889fa5e removed the chunk taking care of this case. So the patch gets the "current" config directory and checks if the default monitor.conf file exists, dont attempt to parse if the file is missing. Link: https://lore.kernel.org/r/164750955519.2000193.16903542741359443926.stgit@LAPTOP-TBQTPII8 Fixes: e889fa5ef7ff ("ndctl, monitor: refator monitor for supporting multiple config files") Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com> Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
-rw-r--r--ndctl/monitor.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/ndctl/monitor.c b/ndctl/monitor.c
index 3e6a4252..54678d61 100644
--- a/ndctl/monitor.c
+++ b/ndctl/monitor.c
@@ -14,6 +14,7 @@
#include <ndctl/ndctl.h>
#include <ndctl/libndctl.h>
#include <sys/epoll.h>
+#include <sys/stat.h>
#define BUF_SIZE 2048
/* reuse the core log helpers for the monitor logger */
@@ -588,7 +589,7 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)
"ndctl monitor [<options>]",
NULL
};
- const struct config configs[] = {
+ struct config configs[] = {
CONF_MONITOR(NDCTL_CONF_FILE, parse_monitor_config),
CONF_STR("core:bus", &param.bus, NULL),
CONF_STR("core:region", &param.region, NULL),
@@ -604,7 +605,9 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)
const char *prefix = "./", *ndctl_configs;
struct ndctl_filter_ctx fctx = { 0 };
struct monitor_filter_arg mfa = { 0 };
- int i, rc;
+ int i, rc = 0;
+ struct stat st;
+ char *path = NULL;
argc = parse_options_prefix(argc, argv, prefix, options, u, 0);
for (i = 0; i < argc; i++) {
@@ -622,14 +625,20 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)
monitor.ctx.log_priority = LOG_INFO;
ndctl_configs = ndctl_get_config_path(ctx);
- if (monitor.configs)
+ if (!monitor.configs && ndctl_configs) {
+ rc = asprintf(&path, "%s/monitor.conf", ndctl_configs);
+ if (rc < 0)
+ goto out;
+
+ if (stat(path, &st) == 0)
+ monitor.configs = path;
+ }
+ if (monitor.configs) {
+ configs[0].key = monitor.configs;
rc = parse_configs_prefix(monitor.configs, prefix, configs);
- else if (ndctl_configs)
- rc = parse_configs_prefix(ndctl_configs, prefix, configs);
- else
- rc = 0;
- if (rc)
- goto out;
+ if (rc)
+ goto out;
+ }
if (monitor.log) {
if (strncmp(monitor.log, "./", 2) != 0)
@@ -687,5 +696,7 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)
out:
if (monitor.log_file)
fclose(monitor.log_file);
+ if (path)
+ free(path);
return rc;
}