diff mbox series

[ndctl,v4,2/4] cxl/monitor: replace monitor.log_file with monitor.ctx.log_file

Message ID 20230711115344.562823-3-lizhijian@fujitsu.com
State Accepted
Commit 4bf6769716a3337369abdb04969dbb45c06bd3d1
Headers show
Series cxl/monitor and ndctl/monitor fixes | expand

Commit Message

Zhijian Li (Fujitsu) July 11, 2023, 11:53 a.m. UTC
Commit ba5825b0b7e0 ("ndctl/monitor: move common logging functions to util/log.c")
have replaced monitor.log_file with monitor.ctx.log_file for
ndctl-monitor, but for cxl-monitor, it forgot to do such work.

So where user specifies its own logfile, a segmentation fault will be
trggered like below:

 # build/cxl/cxl monitor -l ./monitor.log
Segmentation fault (core dumped)

Fixes: 299f69f974a6 ("cxl/monitor: add a new monitor command for CXL trace events")
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
V4: add reviewed tag
V2: exchange order of previous patch1 and patch2 # Alison
    a few commit log updated
---
 cxl/monitor.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Alison Schofield July 11, 2023, 5:57 p.m. UTC | #1
On Tue, Jul 11, 2023 at 07:53:42PM +0800, Li Zhijian wrote:
> Commit ba5825b0b7e0 ("ndctl/monitor: move common logging functions to util/log.c")
> have replaced monitor.log_file with monitor.ctx.log_file for
> ndctl-monitor, but for cxl-monitor, it forgot to do such work.
> 
> So where user specifies its own logfile, a segmentation fault will be
> trggered like below:
> 
>  # build/cxl/cxl monitor -l ./monitor.log
> Segmentation fault (core dumped)

Reviewed-by: Alison Schofield <alison.schofield@intel.com>


> 
> Fixes: 299f69f974a6 ("cxl/monitor: add a new monitor command for CXL trace events")
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> V4: add reviewed tag
> V2: exchange order of previous patch1 and patch2 # Alison
>     a few commit log updated
> ---
>  cxl/monitor.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/cxl/monitor.c b/cxl/monitor.c
> index d8245ed8d0e9..e83455b63d35 100644
> --- a/cxl/monitor.c
> +++ b/cxl/monitor.c
> @@ -37,7 +37,6 @@ const char *default_log = "/var/log/cxl-monitor.log";
>  static struct monitor {
>  	const char *log;
>  	struct log_ctx ctx;
> -	FILE *log_file;
>  	bool human;
>  	bool verbose;
>  	bool daemon;
> @@ -192,8 +191,8 @@ int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
>  	if (strncmp(log, "./standard", 10) == 0)
>  		monitor.ctx.log_fn = log_standard;
>  	else {
> -		monitor.log_file = fopen(log, "a+");
> -		if (!monitor.log_file) {
> +		monitor.ctx.log_file = fopen(log, "a+");
> +		if (!monitor.ctx.log_file) {
>  			rc = -errno;
>  			error("open %s failed: %d\n", log, rc);
>  			goto out;
> @@ -212,7 +211,7 @@ int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
>  	rc = monitor_event(ctx);
>  
>  out:
> -	if (monitor.log_file)
> -		fclose(monitor.log_file);
> +	if (monitor.ctx.log_file)
> +		fclose(monitor.ctx.log_file);
>  	return rc;
>  }
> -- 
> 2.29.2
>
diff mbox series

Patch

diff --git a/cxl/monitor.c b/cxl/monitor.c
index d8245ed8d0e9..e83455b63d35 100644
--- a/cxl/monitor.c
+++ b/cxl/monitor.c
@@ -37,7 +37,6 @@  const char *default_log = "/var/log/cxl-monitor.log";
 static struct monitor {
 	const char *log;
 	struct log_ctx ctx;
-	FILE *log_file;
 	bool human;
 	bool verbose;
 	bool daemon;
@@ -192,8 +191,8 @@  int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
 	if (strncmp(log, "./standard", 10) == 0)
 		monitor.ctx.log_fn = log_standard;
 	else {
-		monitor.log_file = fopen(log, "a+");
-		if (!monitor.log_file) {
+		monitor.ctx.log_file = fopen(log, "a+");
+		if (!monitor.ctx.log_file) {
 			rc = -errno;
 			error("open %s failed: %d\n", log, rc);
 			goto out;
@@ -212,7 +211,7 @@  int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
 	rc = monitor_event(ctx);
 
 out:
-	if (monitor.log_file)
-		fclose(monitor.log_file);
+	if (monitor.ctx.log_file)
+		fclose(monitor.ctx.log_file);
 	return rc;
 }