All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Teigland <teigland@sourceware.org>
To: lvm-devel@redhat.com
Subject: main - lvmlockd: clean up get_local_nodeid
Date: Wed,  8 Mar 2023 17:13:10 +0000 (GMT)	[thread overview]
Message-ID: <20230308171310.800143858D33@sourceware.org> (raw)

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=da44f2b6fe1e0edbd3ee875c831f3e467f242bc0
Commit:        da44f2b6fe1e0edbd3ee875c831f3e467f242bc0
Parent:        cd14d3fcc0e03136d0cea1ab1a9edff3b8b9dbeb
Author:        David Teigland <teigland@redhat.com>
AuthorDate:    Wed Mar 8 11:11:32 2023 -0600
Committer:     David Teigland <teigland@redhat.com>
CommitterDate: Wed Mar 8 11:11:32 2023 -0600

lvmlockd: clean up get_local_nodeid

Hard to see if fclose calls were correct, and coverity couldn't figure
it out either, so make it clear.
---
 daemons/lvmlockd/lvmlockd-dlm.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/daemons/lvmlockd/lvmlockd-dlm.c b/daemons/lvmlockd/lvmlockd-dlm.c
index 248081d0e..ce9d9acf2 100644
--- a/daemons/lvmlockd/lvmlockd-dlm.c
+++ b/daemons/lvmlockd/lvmlockd-dlm.c
@@ -227,8 +227,9 @@ static int get_local_nodeid(void)
 	struct dirent *de;
 	DIR *ls_dir;
 	char ls_comms_path[PATH_MAX];
-	FILE *file = NULL;
+	FILE *file;
 	char line[LOCK_LINE_MAX];
+	char *str1, *str2;
 	int rv = -1, val;
 
 	memset(ls_comms_path, 0, sizeof(ls_comms_path));
@@ -243,30 +244,33 @@ static int get_local_nodeid(void)
 		memset(ls_comms_path, 0, sizeof(ls_comms_path));
 		snprintf(ls_comms_path, PATH_MAX, "%s/%s/local",
 		     DLM_COMMS_PATH, de->d_name);
-		file = fopen(ls_comms_path, "r");
-		if (!file)
+
+		if (!(file = fopen(ls_comms_path, "r")))
 			continue;
-		if (fgets(line, LOCK_LINE_MAX, file)) {
-			fclose(file);
+		str1 = fgets(line, LOCK_LINE_MAX, file);
+		fclose(file);
+
+		if (str1) {
 			rv = sscanf(line, "%d", &val);
 			if ((rv == 1) && (val == 1 )) {
 				memset(ls_comms_path, 0, sizeof(ls_comms_path));
 				snprintf(ls_comms_path, PATH_MAX, "%s/%s/nodeid",
 				    DLM_COMMS_PATH, de->d_name);
-				file = fopen(ls_comms_path, "r");
-				if (!file)
+
+				if (!(file = fopen(ls_comms_path, "r")))
 					continue;
-				if (fgets(line, LOCK_LINE_MAX, file)) {
+				str2 = fgets(line, LOCK_LINE_MAX, file);
+				fclose(file);
+
+				if (str2) {
 					rv = sscanf(line, "%d", &val);
 					if (rv == 1) {
-						fclose(file);
 						closedir(ls_dir);
 						return val;
 					}
 				}
 			}
 		}
-		fclose(file);
 	}
 
 	if (closedir(ls_dir))


                 reply	other threads:[~2023-03-08 17:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230308171310.800143858D33@sourceware.org \
    --to=teigland@sourceware.org \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.