Skip to contentSkip to conversation

syscalls/dup203: Fix make use of SAFE_CLOSE()

PATCH New Cyril Hrubis 1 participant 1 message Oct 4, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/dup203: Fix make use of SAFE_CLOSE()

The patch:

commit df007542635aed8686b5ebc111b0807a67349b41

Author: Cyril Hrubis <[email protected]>
Date:   Tue Oct 3 13:29:15 2017 +0200

Make use of SAFE_CLOSE()

Broke the test since it opens and closes a fd in order to get free file descriptor to pass to dup2() as newfd. The problem here is that SAFE_CLOSE() sets the file descriptor to -1, which is usually good thing.

This patch fixes the problem by using temporary variable to store the fd to pass it to SAFE_CLOSE().

Fixes #219

---
 testcases/kernel/syscalls/dup2/dup203.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/dup2/dup203.c +3 -1
index d3c228362..e6f281adf 100644
@@ -144,7 +144,9 @@ int main(int ac, char **av)
 			tst_brkm(TBROK, cleanup, "Cannot create second file");
 		}
 
-		SAFE_CLOSE(cleanup, fd2);
+		/* SAFE_CLOSE() sets the fd to -1 avoid it here */
+		rval = fd2;
+		SAFE_CLOSE(cleanup, rval);
 
 		TEST(dup2(fd0, fd2));
 
Signature · 1 line
2.13.5