@@ -164,6 +164,7 @@ int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
};
const char *prefix ="./";
int rc = 0, i;
+ const char *log;
argc = parse_options_prefix(argc, argv, prefix, options, u, 0);
for (i = 0; i < argc; i++)
@@ -171,32 +172,33 @@ int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
if (argc)
usage_with_options(u, options);
+ // sanity check
+ if (monitor.daemon && monitor.log && !strncmp(monitor.log, "./", 2)) {
+ error("standard or relative path for <file> will not work for daemon mode\n");
+ return -EINVAL;
+ }
+
log_init(&monitor.ctx, "cxl/monitor", "CXL_MONITOR_LOG");
- monitor.ctx.log_fn = log_standard;
+ if (monitor.log)
+ log = monitor.log;
+ else
+ log = monitor.daemon ? default_log : "./standard";
if (monitor.verbose)
monitor.ctx.log_priority = LOG_DEBUG;
else
monitor.ctx.log_priority = LOG_INFO;
- if (monitor.log) {
- if (strncmp(monitor.log, "./", 2) != 0)
- fix_filename(prefix, (const char **)&monitor.log);
- if (strncmp(monitor.log, "./standard", 10) == 0 && !monitor.daemon) {
- monitor.ctx.log_fn = log_standard;
- } else {
- const char *log = monitor.log;
-
- if (!monitor.log)
- log = default_log;
- monitor.log_file = fopen(log, "a+");
- if (!monitor.log_file) {
- rc = -errno;
- error("open %s failed: %d\n", monitor.log, rc);
- goto out;
- }
- monitor.ctx.log_fn = log_file;
+ if (strncmp(log, "./standard", 10) == 0)
+ monitor.ctx.log_fn = log_standard;
+ else {
+ monitor.log_file = fopen(log, "a+");
+ if (!monitor.log_file) {
+ rc = -errno;
+ error("open %s failed: %d\n", log, rc);
+ goto out;
}
+ monitor.ctx.log_fn = log_file;
}
if (monitor.daemon) {