All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] client: remove warning on mkdir return
@ 2021-02-09 20:37 James Prestwood
  2021-02-09 20:50 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: James Prestwood @ 2021-02-09 20:37 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1461 bytes --]

This fixes up a previous commit which breaks iwctl. The
check was added to satisfy static analysis but it ended
up preventing iwctl from starting. In this case mkdir
can fail (e.g. if the directory already exists) and only
if it fails should the history be read. Otherwise a
successful mkdir return indicates the history folder is
new and there is no reason to try reading it.
---
 client/display.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/client/display.c b/client/display.c
index 4b9ee8f0..07cb7bda 100644
--- a/client/display.c
+++ b/client/display.c
@@ -681,7 +681,6 @@ void display_init(void)
 {
 	const char *data_home;
 	char *data_path;
-	int ret;
 
 	display_refresh.redo_entries = l_queue_new();
 
@@ -702,16 +701,15 @@ void display_init(void)
 	}
 
 	if (data_path) {
-		ret = mkdir(data_path, 0700);
-		/* Not much can be done since display isn't even initialized */
-		if (L_WARN_ON(ret < 0)) {
-			l_free(data_path);
-			return;
+		/*
+		 * If mkdir succeeds that means its a new directory, no need
+		 * to read the history since it doesn't exist
+		 */
+		if (mkdir(data_path, 0700) != 0) {
+			history_path = l_strdup_printf("%s/history", data_path);
+			read_history(history_path);
 		}
 
-		history_path = l_strdup_printf("%s/history", data_path);
-		read_history(history_path);
-
 		l_free(data_path);
 	} else {
 		history_path = NULL;
-- 
2.26.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] client: remove warning on mkdir return
  2021-02-09 20:37 [PATCH v2] client: remove warning on mkdir return James Prestwood
@ 2021-02-09 20:50 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-02-09 20:50 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 602 bytes --]

Hi James,

On 2/9/21 2:37 PM, James Prestwood wrote:
> This fixes up a previous commit which breaks iwctl. The
> check was added to satisfy static analysis but it ended
> up preventing iwctl from starting. In this case mkdir
> can fail (e.g. if the directory already exists) and only
> if it fails should the history be read. Otherwise a
> successful mkdir return indicates the history folder is
> new and there is no reason to try reading it.
> ---
>   client/display.c | 16 +++++++---------
>   1 file changed, 7 insertions(+), 9 deletions(-)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-09 20:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 20:37 [PATCH v2] client: remove warning on mkdir return James Prestwood
2021-02-09 20:50 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.