From 3f5dd5fa812120764312a2326285e88b2be82c2f Mon Sep 17 00:00:00 2001
From: jiayi0118 <1398871225@qq.com>
Date: Wed, 17 Aug 2022 22:25:27 +0800
Subject: [PATCH] libblkid/src/topology/dm: close redundant write file
 description for pipe before reading data.

Reference:https://github.com/util-linux/util-linux/commit/1d5d50c277e459f4ccbb6e3db416dcb6eb2e2bc4
Conflict:NA
---
 libblkid/src/topology/dm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libblkid/src/topology/dm.c b/libblkid/src/topology/dm.c
index b210a805b..1a1cb8ac0 100644
--- a/libblkid/src/topology/dm.c
+++ b/libblkid/src/topology/dm.c
@@ -103,6 +103,10 @@ static int probe_dm_tp(blkid_probe pr,
 	if (!stream)
 		goto nothing;
 
+	if (dmpipe[1] != -1) {
+		close(dmpipe[1]);
+	}
+
 	if (fscanf(stream, "%lld %lld striped %d %d ",
 			&offset, &size, &stripes, &stripesize) != 0)
 		goto nothing;
@@ -111,7 +115,6 @@ static int probe_dm_tp(blkid_probe pr,
 	blkid_topology_set_optimal_io_size(pr, (stripes * stripesize) << 9);
 
 	fclose(stream);
-	close(dmpipe[1]);
 	return 0;
 
 nothing:
@@ -119,8 +122,6 @@ nothing:
 		fclose(stream);
 	else if (dmpipe[0] != -1)
 		close(dmpipe[0]);
-	if (dmpipe[1] != -1)
-		close(dmpipe[1]);
 	return 1;
 }
 
-- 
2.31.1

