Sometimes `if (access(...) && errno == ENOENT)' doesn't work due to
errno not captures correctly from access() exection. This patch put them
into 2 nested if-condition statements.

Signed-off-by: Caspar Zhang <cas...@casparzhang.com>
---
 testcases/kernel/mem/zram/zram01.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/mem/zram/zram01.c b/testcases/kernel/mem/zram/zram01.c
index 63437c1..c382525 100644
--- a/testcases/kernel/mem/zram/zram01.c
+++ b/testcases/kernel/mem/zram/zram01.c
@@ -106,16 +106,24 @@ int main(int argc, char *argv[])
 
 void setup(void)
 {
+	int retried = 0;
+
 	tst_require_root(NULL);
 
-	if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT) {
-		system("modprobe zram");
-		modprobe = 1;
-		if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT)
-			tst_brkm(TCONF, NULL, "system has no zram device.");
-		else
+retry:
+	if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1) {
+		if (errno == ENOENT) {
+			if (retried)
+				tst_brkm(TCONF, NULL,
+					"system has no zram device.");
+			system("modprobe zram");
+			modprobe = 1;
+			retried  = 1;
+			goto retry;
+		} else
 			tst_brkm(TBROK|TERRNO, NULL, "access");
 	}
+
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 	TEST_PAUSE;
 }
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to