All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT()
@ 2017-10-03 15:40 Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 02/13] Make use of SAFE_DUP() Cyril Hrubis
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/mem/vma/vma03.c                |  5 ++---
 testcases/kernel/syscalls/chroot/chroot03.c     |  4 +---
 testcases/kernel/syscalls/creat/creat01.c       |  5 +----
 testcases/kernel/syscalls/fork/fork09.c         |  5 +----
 testcases/kernel/syscalls/fork/fork10.c         |  7 ++-----
 testcases/kernel/syscalls/getxattr/getxattr01.c |  6 ++----
 testcases/kernel/syscalls/getxattr/getxattr02.c |  5 ++---
 testcases/kernel/syscalls/getxattr/getxattr03.c |  5 ++---
 testcases/kernel/syscalls/open/open07.c         |  8 ++------
 testcases/kernel/syscalls/open/open08.c         |  4 +---
 testcases/kernel/syscalls/open/open11.c         |  6 ++----
 testcases/kernel/syscalls/sendfile/sendfile08.c |  5 ++---
 testcases/kernel/syscalls/setxattr/setxattr01.c | 10 +++-------
 testcases/kernel/syscalls/setxattr/setxattr02.c |  9 ++-------
 testcases/kernel/syscalls/setxattr/setxattr03.c | 15 ++++-----------
 15 files changed, 29 insertions(+), 70 deletions(-)

diff --git a/testcases/kernel/mem/vma/vma03.c b/testcases/kernel/mem/vma/vma03.c
index edad9f403..1db16eab1 100644
--- a/testcases/kernel/mem/vma/vma03.c
+++ b/testcases/kernel/mem/vma/vma03.c
@@ -49,6 +49,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "tst_kernel.h"
 
 char *TCID = "vma03";
@@ -131,9 +132,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	fd = creat(TESTFILE, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "creat %s", TESTFILE);
+	fd = SAFE_CREAT(NULL, TESTFILE, 0644);
 	close(fd);
 
 	TEST_PAUSE;
diff --git a/testcases/kernel/syscalls/chroot/chroot03.c b/testcases/kernel/syscalls/chroot/chroot03.c
index de247b61c..b904e4ac9 100644
--- a/testcases/kernel/syscalls/chroot/chroot03.c
+++ b/testcases/kernel/syscalls/chroot/chroot03.c
@@ -143,9 +143,7 @@ static void setup(void)
 	 * ENOTDIR if the argument is not a directory.
 	 */
 	(void)sprintf(fname, "tfile_%d", getpid());
-	fd = creat(fname, 0777);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "Failed to creat a temp file");
+	fd = SAFE_CREAT(cleanup, fname, 0777);
 
 #if !defined(UCLINUX)
 	bad_addr = mmap(0, 1, PROT_NONE,
diff --git a/testcases/kernel/syscalls/creat/creat01.c b/testcases/kernel/syscalls/creat/creat01.c
index 6b70be292..5d0ffc6a7 100644
--- a/testcases/kernel/syscalls/creat/creat01.c
+++ b/testcases/kernel/syscalls/creat/creat01.c
@@ -53,10 +53,7 @@ static void verify_creat(unsigned int i)
 	struct stat buf;
 	char c;
 
-	fd = creat(filename, tcases[i].mode);
-
-	if (fd == -1)
-		tst_brk(TBROK | TERRNO, "creat() failed");
+	fd = SAFE_CREAT(filename, tcases[i].mode);
 
 	SAFE_STAT(filename, &buf);
 
diff --git a/testcases/kernel/syscalls/fork/fork09.c b/testcases/kernel/syscalls/fork/fork09.c
index dedc8a41c..32bad89b3 100644
--- a/testcases/kernel/syscalls/fork/fork09.c
+++ b/testcases/kernel/syscalls/fork/fork09.c
@@ -84,10 +84,7 @@ int main(int ac, char **av)
 
 		/* establish first free file */
 		sprintf(filname, "fork09.%d", mypid);
-		first = creat(filname, 0660);
-		if (first == -1)
-			tst_brkm(TBROK, cleanup, "Cannot open first file %s, "
-				 "errno = %d", filname, errno);
+		first = SAFE_CREAT(cleanup, filname, 0660);
 		close(first);
 
 		tst_resm(TINFO, "first file descriptor is %d ", first);
diff --git a/testcases/kernel/syscalls/fork/fork10.c b/testcases/kernel/syscalls/fork/fork10.c
index 381ce6716..13db0555d 100644
--- a/testcases/kernel/syscalls/fork/fork10.c
+++ b/testcases/kernel/syscalls/fork/fork10.c
@@ -45,6 +45,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "fork10";
 int TST_TOTAL = 1;
@@ -72,11 +73,7 @@ int main(int ac, char **av)
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		fildes = creat(fnamebuf, 0600);
-		if (fildes < 0)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "Parent: cannot open %s for " "write",
-				 fnamebuf);
+		fildes = SAFE_CREAT(cleanup, fnamebuf, 0600);
 		write(fildes, "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 27);
 		close(fildes);
 
diff --git a/testcases/kernel/syscalls/getxattr/getxattr01.c b/testcases/kernel/syscalls/getxattr/getxattr01.c
index 8c09aa8a9..be410a536 100644
--- a/testcases/kernel/syscalls/getxattr/getxattr01.c
+++ b/testcases/kernel/syscalls/getxattr/getxattr01.c
@@ -48,6 +48,7 @@
 # include <sys/xattr.h>
 #endif
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getxattr01";
 
@@ -142,10 +143,7 @@ static void setup(void)
 
 	/* Create test file and setup initial xattr */
 	snprintf(filename, BUFSIZ, "getxattr01testfile");
-	fd = creat(filename, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 filename);
+	fd = SAFE_CREAT(cleanup, filename, 0644);
 	close(fd);
 	if (setxattr(filename, XATTR_TEST_KEY, XATTR_TEST_VALUE,
 		     strlen(XATTR_TEST_VALUE), XATTR_CREATE) == -1) {
diff --git a/testcases/kernel/syscalls/getxattr/getxattr02.c b/testcases/kernel/syscalls/getxattr/getxattr02.c
index df75fb360..dca6b13be 100644
--- a/testcases/kernel/syscalls/getxattr/getxattr02.c
+++ b/testcases/kernel/syscalls/getxattr/getxattr02.c
@@ -54,6 +54,7 @@
 # include <sys/xattr.h>
 #endif
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getxattr02";
 
@@ -126,9 +127,7 @@ static void setup(void)
 	tst_tmpdir();
 
 	/* Test for xattr support */
-	fd = creat("testfile", 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
+	fd = SAFE_CREAT(cleanup, "testfile", 0644);
 	close(fd);
 	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
 		if (errno == ENOTSUP)
diff --git a/testcases/kernel/syscalls/getxattr/getxattr03.c b/testcases/kernel/syscalls/getxattr/getxattr03.c
index 06c993415..b6ea14287 100644
--- a/testcases/kernel/syscalls/getxattr/getxattr03.c
+++ b/testcases/kernel/syscalls/getxattr/getxattr03.c
@@ -42,6 +42,7 @@
 # include <sys/xattr.h>
 #endif
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getxattr03";
 
@@ -88,9 +89,7 @@ static void setup(void)
 	tst_tmpdir();
 
 	/* Test for xattr support and set attr value */
-	fd = creat(TESTFILE, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", TESTFILE);
+	fd = SAFE_CREAT(cleanup, TESTFILE, 0644);
 	close(fd);
 
 	if (setxattr(TESTFILE, XATTR_TEST_KEY, XATTR_TEST_VALUE,
diff --git a/testcases/kernel/syscalls/open/open07.c b/testcases/kernel/syscalls/open/open07.c
index b941f4b81..f36db00cb 100644
--- a/testcases/kernel/syscalls/open/open07.c
+++ b/testcases/kernel/syscalls/open/open07.c
@@ -163,9 +163,7 @@ static void setupfunc_test1(void)
 
 	sprintf(file1, "open03.1.%d", getpid());
 	sprintf(file2, "open03.2.%d", getpid());
-	fd1 = creat(file1, 00700);
-	if (fd1 < 0)
-		tst_brkm(TBROK, cleanup, "creat(2) failed: errno: %d", errno);
+	fd1 = SAFE_CREAT(cleanup, file1, 00700);
 
 	SAFE_SYMLINK(cleanup, file1, file2);
 
@@ -192,9 +190,7 @@ static void setupfunc_test3(void)
 	sprintf(file1, "open03.5.%d", getpid());
 	sprintf(file2, "open03.6.%d", getpid());
 	sprintf(file3, "open03.7.%d", getpid());
-	fd2 = creat(file1, 00700);
-	if (fd2 < 0)
-		tst_brkm(TBROK, cleanup, "creat(2) failed: errno: %d", errno);
+	fd2 = SAFE_CREAT(cleanup, file1, 00700);
 
 	SAFE_SYMLINK(cleanup, file1, file2);
 
diff --git a/testcases/kernel/syscalls/open/open08.c b/testcases/kernel/syscalls/open/open08.c
index 6d1f37de0..d55d8e6bd 100644
--- a/testcases/kernel/syscalls/open/open08.c
+++ b/testcases/kernel/syscalls/open/open08.c
@@ -148,9 +148,7 @@ static void setup(void)
 
 	sprintf(filename, "open3.%d", getpid());
 
-	fildes = creat(filename, 0600);
-	if (fildes == -1)
-		tst_brkm(TBROK, cleanup, "Can't creat %s", filename);
+	fildes = SAFE_CREAT(cleanup, filename, 0600);
 
 	close(fildes);
 
diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index 6a3b0b8b1..c9239c6b4 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -74,6 +74,7 @@
 #include <string.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "open11";
 
@@ -382,10 +383,7 @@ static void setup(void)
 	}
 	close(fd);
 
-	fd = creat(T_REG_EMPTY, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed",
-			 T_REG_EMPTY);
+	fd = SAFE_CREAT(cleanup, T_REG_EMPTY, 0644);
 	close(fd);
 
 	ret = link(T_REG, T_LINK_REG);
diff --git a/testcases/kernel/syscalls/sendfile/sendfile08.c b/testcases/kernel/syscalls/sendfile/sendfile08.c
index 21b25868d..3212ca7cc 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile08.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile08.c
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEST_MSG_IN "world"
 #define TEST_MSG_OUT "hello"
@@ -101,9 +102,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	in_fd = creat(in_file, 0700);
-	if (in_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", in_file);
+	in_fd = SAFE_CREAT(cleanup, in_file, 0700);
 
 	ret = write(in_fd, TEST_MSG_IN, strlen(TEST_MSG_IN));
 	if (ret == -1)
diff --git a/testcases/kernel/syscalls/setxattr/setxattr01.c b/testcases/kernel/syscalls/setxattr/setxattr01.c
index 478f99408..359991e3f 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr01.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr01.c
@@ -58,6 +58,7 @@
 # include <sys/xattr.h>
 #endif
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "setxattr01";
 
@@ -184,9 +185,7 @@ static void setup(void)
 	tst_tmpdir();
 
 	/* Test for xattr support */
-	fd = creat("testfile", 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
+	fd = SAFE_CREAT(cleanup, "testfile", 0644);
 	close(fd);
 	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
 		if (errno == ENOTSUP)
@@ -195,10 +194,7 @@ static void setup(void)
 
 	/* Create test file */
 	snprintf(filename, BUFSIZ, "setxattr01testfile");
-	fd = creat(filename, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 filename);
+	fd = SAFE_CREAT(cleanup, filename, 0644);
 	close(fd);
 
 	/* Prepare test cases */
diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c
index b16ddce94..6d39236a3 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr02.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr02.c
@@ -187,9 +187,7 @@ static void setup(void)
 	tst_tmpdir();
 
 	/* Test for xattr support */
-	fd = creat("testfile", 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
+	fd = SAFE_CREAT(cleanup, "testfile", 0644);
 	close(fd);
 	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
 		if (errno == ENOTSUP)
@@ -198,10 +196,7 @@ static void setup(void)
 	unlink("testfile");
 
 	/* Create test files */
-	fd = creat(FILENAME, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 FILENAME);
+	fd = SAFE_CREAT(cleanup, FILENAME, 0644);
 	close(fd);
 
 	SAFE_MKDIR(cleanup, DIRNAME, 0644);
diff --git a/testcases/kernel/syscalls/setxattr/setxattr03.c b/testcases/kernel/syscalls/setxattr/setxattr03.c
index c09211eeb..a2f6cbf36 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr03.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr03.c
@@ -50,6 +50,7 @@
 #include <linux/fs.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "setxattr03";
 
@@ -167,9 +168,7 @@ static void setup(void)
 	tst_tmpdir();
 
 	/* Test for xattr support */
-	fd = creat("testfile", 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
+	fd = SAFE_CREAT(cleanup, "testfile", 0644);
 	close(fd);
 	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
 		if (errno == ENOTSUP)
@@ -178,18 +177,12 @@ static void setup(void)
 	unlink("testfile");
 
 	/* Create test files and set file immutable or append-only */
-	immu_fd = creat(IMMU_FILE, 0644);
-	if (immu_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 IMMU_FILE);
+	immu_fd = SAFE_CREAT(cleanup, IMMU_FILE, 0644);
 	if (set_immutable_on(immu_fd))
 		tst_brkm(TBROK | TERRNO, cleanup, "Set %s immutable failed",
 			 IMMU_FILE);
 
-	append_fd = creat(APPEND_FILE, 0644);
-	if (append_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 APPEND_FILE);
+	append_fd = SAFE_CREAT(cleanup, APPEND_FILE, 0644);
 	if (set_append_on(append_fd))
 		tst_brkm(TBROK | TERRNO, cleanup, "Set %s append-only failed",
 			 APPEND_FILE);
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 02/13] Make use of SAFE_DUP()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 03/13] Make use of SAFE_MKDIR() Cyril Hrubis
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/fanotify/fanotify03.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify03.c b/testcases/kernel/syscalls/fanotify/fanotify03.c
index 1ab879843..ea5c02a7b 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify03.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify03.c
@@ -154,10 +154,7 @@ void test01(void)
 	int ret, len = 0, i = 0, test_num = 0;
 
 	if (fd_notify_backup == -1) {
-		fd_notify_backup = dup(fd_notify);
-		if (fd_notify_backup < 0)
-			tst_brk(TBROK | TERRNO,
-				 "dup(%d) failed", fd_notify);
+		fd_notify_backup = SAFE_DUP(fd_notify);
 	}
 	run_child();
 
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 03/13] Make use of SAFE_MKDIR()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 02/13] Make use of SAFE_DUP() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 04/13] Make use of SAFE_OPEN() Cyril Hrubis
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/open/open11.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index c9239c6b4..9593671f2 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -396,9 +396,7 @@ static void setup(void)
 		tst_brkm(TBROK | TERRNO, cleanup, "Symlink %s -> %s failed",
 			 T_REG, T_SYMLINK_REG);
 
-	ret = mkdir(T_DIR, 0755);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "mkdir %s failed", T_DIR);
+	ret = SAFE_MKDIR(cleanup, T_DIR, 0755);
 
 	ret = symlink(T_DIR, T_SYMLINK_DIR);
 	if (ret == -1)
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 04/13] Make use of SAFE_OPEN()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 02/13] Make use of SAFE_DUP() Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 03/13] Make use of SAFE_MKDIR() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 05/13] Make use of SAFE_PIPE() Cyril Hrubis
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 .../kernel/controllers/cpuctl/cpuctl_def_task01.c  |  5 ++-
 .../kernel/controllers/cpuctl/cpuctl_def_task02.c  |  6 ++--
 .../kernel/controllers/cpuctl/cpuctl_def_task03.c  |  5 ++-
 .../kernel/controllers/cpuctl/cpuctl_def_task04.c  |  5 ++-
 .../kernel/controllers/cpuctl/cpuctl_test01.c      |  7 ++---
 .../kernel/controllers/cpuctl/cpuctl_test02.c      |  7 ++---
 .../kernel/controllers/cpuctl/cpuctl_test03.c      |  7 ++---
 .../kernel/controllers/cpuctl/cpuctl_test04.c      |  7 ++---
 testcases/kernel/device-drivers/rtc/rtc01.c        |  6 ++--
 .../kernel/device-drivers/tbio/tbio_user/tbio.c    |  6 +---
 testcases/kernel/fs/ftest/ftest01.c                |  7 ++---
 testcases/kernel/fs/ftest/ftest03.c                |  9 ++----
 testcases/kernel/fs/ftest/ftest04.c                | 16 ++--------
 testcases/kernel/fs/ftest/ftest05.c                |  8 ++---
 testcases/kernel/fs/ftest/ftest07.c                |  8 ++---
 testcases/kernel/fs/ftest/ftest08.c                |  8 ++---
 testcases/kernel/logging/kmsg/kmsg01.c             | 28 +++++------------
 testcases/kernel/mem/lib/mem.c                     |  8 ++---
 testcases/kernel/mem/vma/vma03.c                   |  4 +--
 testcases/kernel/pty/hangup01.c                    |  5 ++-
 testcases/kernel/pty/ptem01.c                      | 26 ++++------------
 testcases/kernel/pty/pty01.c                       | 36 +++++-----------------
 testcases/kernel/syscalls/chmod/chmod01.c          |  6 +---
 testcases/kernel/syscalls/chmod/chmod07.c          |  6 +---
 .../kernel/syscalls/fadvise/posix_fadvise01.c      |  8 ++---
 .../kernel/syscalls/fadvise/posix_fadvise03.c      |  8 ++---
 testcases/kernel/syscalls/fallocate/fallocate01.c  | 11 ++-----
 testcases/kernel/syscalls/fallocate/fallocate03.c  |  5 ++-
 testcases/kernel/syscalls/fchmod/fchmod05.c        |  7 +----
 testcases/kernel/syscalls/fcntl/fcntl14.c          | 14 +++------
 testcases/kernel/syscalls/fcntl/fcntl16.c          |  6 ++--
 testcases/kernel/syscalls/flock/flock01.c          |  5 ++-
 testcases/kernel/syscalls/flock/flock06.c          |  5 ++-
 testcases/kernel/syscalls/fork/fork04.c            |  8 ++---
 testcases/kernel/syscalls/fork/fork10.c            |  5 +--
 testcases/kernel/syscalls/fstat/fstat01.c          |  5 ++-
 testcases/kernel/syscalls/fstat/fstat03.c          |  5 +--
 testcases/kernel/syscalls/fstat/fstat05.c          |  5 +--
 testcases/kernel/syscalls/ftruncate/ftruncate01.c  |  7 ++---
 testcases/kernel/syscalls/ftruncate/ftruncate02.c  |  7 ++---
 testcases/kernel/syscalls/inotify/inotify03.c      |  6 +---
 testcases/kernel/syscalls/ioctl/ioctl01.c          |  5 ++-
 testcases/kernel/syscalls/ioctl/ioctl02.c          | 10 ++----
 testcases/kernel/syscalls/mincore/mincore02.c      |  8 ++---
 testcases/kernel/syscalls/mlock/mlock04.c          |  4 +--
 testcases/kernel/syscalls/mprotect/mprotect01.c    |  5 ++-
 testcases/kernel/syscalls/open/open05.c            |  4 +--
 testcases/kernel/syscalls/open/open11.c            |  4 +--
 testcases/kernel/syscalls/readahead/readahead02.c  |  4 +--
 testcases/kernel/syscalls/sendfile/sendfile08.c    |  8 ++---
 testcases/kernel/syscalls/setfsuid/setfsuid04.c    |  5 ++-
 testcases/kernel/syscalls/setresuid/setresuid04.c  |  5 ++-
 testcases/kernel/syscalls/setreuid/setreuid07.c    |  6 ++--
 testcases/kernel/syscalls/setuid/setuid04.c        |  5 ++-
 54 files changed, 116 insertions(+), 310 deletions(-)

diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c b/testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c
index ae6a37429..90119e4ad 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c
@@ -57,6 +57,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #ifdef DEBUG
 #define dbg(x...)	printf(x);
@@ -137,9 +138,7 @@ int main(int argc, char *argv[])
 	write_to_file(mysharesfile, "w", myshares);
 	dbg("Default task's initial shares = %u", myshares);
 
-	fd = open("./myfifo", 0);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "Could not open fifo to synchronizae");
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* To fire all the tasks up at the same time */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c b/testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c
index 5fb3559c0..dc1546e88 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c
@@ -60,6 +60,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	3	/* How many iterations of TIME_INTERVAL */
@@ -148,10 +149,7 @@ int main(int argc, char *argv[])
 	pid = getpid();
 	write_to_file(mytaskfile, "a", pid);	/* Assign task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* Block task here to synchronize */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c b/testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c
index af4695f28..92b451793 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	2	/* How many iterations of TIME_INTERVAL */
@@ -144,9 +145,7 @@ int main(int argc, char *argv[])
 	pid = getpid();
 	write_to_file(mytaskfile, "a", pid);	/* Assign task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "Could not open fifo synchronize");
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* Block task here to synchronize */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c b/testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c
index 9a7da9b36..c3348fb31 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	100	/* Time interval in seconds */
 #define NUM_INTERVALS	2	/* How many iterations of TIME_INTERVAL */
@@ -154,9 +155,7 @@ int main(int argc, char *argv[])
 	mygroup_shares = 100;
 	write_to_file(mysharesfile, "w", mygroup_shares);
 
-	fd = open("./myfifo", 0);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "Could not open fifo synchronize");
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* Block task here to synchronize */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_test01.c b/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
index 385ee32fd..0cd587c3a 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
@@ -62,6 +62,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	3	/* How many iterations of TIME_INTERVAL */
@@ -139,11 +140,7 @@ int main(int argc, char *argv[])
 	write_to_file(mytaskfile, "a", pid);	/* Assign the task to it's group */
 	write_to_file(mysharesfile, "w", myshares);
 
-	fd = open("./myfifo", 0);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
-	}
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	fprintf(stdout, "\ntask-%d SHARES=%lu\n", my_group_num, myshares);
 	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_test02.c b/testcases/kernel/controllers/cpuctl/cpuctl_test02.c
index 6f5a0d9bf..d775a3e9f 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_test02.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_test02.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	3	/* How many iterations of TIME_INTERVAL */
@@ -151,11 +152,7 @@ int main(int argc, char *argv[])
 	pid = getpid();
 	write_to_file(mytaskfile, "a", pid);	/* Assign the task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
-	}
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_test03.c b/testcases/kernel/controllers/cpuctl/cpuctl_test03.c
index 5076ab98a..8a80d6932 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_test03.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_test03.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	2	/* How many iterations of TIME_INTERVAL */
@@ -147,11 +148,7 @@ int main(int argc, char *argv[])
 	pid = getpid();
 	write_to_file(mytaskfile, "a", pid);	/* Assign the task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
-	}
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_test04.c b/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
index 0daca0ef5..bc67f41d9 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	100	/* Time interval in seconds */
 #define NUM_INTERVALS	2	/* How many iterations of TIME_INTERVAL */
@@ -158,11 +159,7 @@ int main(int argc, char *argv[])
 
 	write_to_file(mytaskfile, "a", getpid());	/* Assign the task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
-	}
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */
 
diff --git a/testcases/kernel/device-drivers/rtc/rtc01.c b/testcases/kernel/device-drivers/rtc/rtc01.c
index b3c7e1df6..8a1f62ead 100644
--- a/testcases/kernel/device-drivers/rtc/rtc01.c
+++ b/testcases/kernel/device-drivers/rtc/rtc01.c
@@ -33,6 +33,7 @@
 #include <time.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 int rtc_fd = -1;
 char *TCID = "rtc01";
@@ -228,10 +229,7 @@ int main(int argc, char *argv[])
 	if (access(rtc_dev, F_OK) == -1)
 		tst_brkm(TCONF, NULL, "couldn't find rtc device '%s'", rtc_dev);
 
-	rtc_fd = open(rtc_dev, O_RDONLY);
-
-	if (rtc_fd < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "couldn't open %s", rtc_dev);
+	rtc_fd = SAFE_OPEN(NULL, rtc_dev, O_RDONLY);
 
 	/*Read and alarm tests */
 	read_alarm_test();
diff --git a/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c b/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c
index 4ab6b8344..be1420b98 100644
--- a/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c
+++ b/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c
@@ -133,11 +133,7 @@ void setup(void)
 			tst_brkm(TBROK | TERRNO, cleanup, "mknod() failed");
 	}
 
-	tbio_fd = open(DEVICE_NAME, O_RDWR);
-	if (tbio_fd < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "open of %s failed",
-			DEVICE_NAME);
-	}
+	tbio_fd = SAFE_OPEN(cleanup, DEVICE_NAME, O_RDWR);
 
 	tst_resm(TINFO, "Device opened successfully ");
 }
diff --git a/testcases/kernel/fs/ftest/ftest01.c b/testcases/kernel/fs/ftest/ftest01.c
index f7e320cd9..afad18095 100644
--- a/testcases/kernel/fs/ftest/ftest01.c
+++ b/testcases/kernel/fs/ftest/ftest01.c
@@ -159,11 +159,8 @@ static void runtest(void)
 
 		test_name[0] = 'a' + i;
 		test_name[1] = '\0';
-		fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-		if (fd < 0)
-			tst_brkm(TBROK | TERRNO, NULL, "Can't create %s/%s",
-				 fuss, test_name);
+		fd = SAFE_OPEN(NULL, test_name, O_RDWR | O_CREAT | O_TRUNC,
+			       0666);
 
 		if ((child = fork()) == 0) {
 			dotest(nchild, i, fd);
diff --git a/testcases/kernel/fs/ftest/ftest03.c b/testcases/kernel/fs/ftest/ftest03.c
index 4d0fc803a..ed69e5736 100644
--- a/testcases/kernel/fs/ftest/ftest03.c
+++ b/testcases/kernel/fs/ftest/ftest03.c
@@ -179,13 +179,8 @@ static void runtest(void)
 		test_name[0] = 'a' + i;
 		test_name[1] = '\0';
 
-		fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-		if (fd < 0) {
-			tst_brkm(TBROK, NULL, "\tError %d creating %s/%s.",
-				 errno,
-				 fuss, test_name);
-		}
+		fd = SAFE_OPEN(NULL, test_name, O_RDWR | O_CREAT | O_TRUNC,
+			       0666);
 
 		if ((child = fork()) == 0) {
 			dotest(nchild, i, fd);
diff --git a/testcases/kernel/fs/ftest/ftest04.c b/testcases/kernel/fs/ftest/ftest04.c
index ad26ece06..8eed84c74 100644
--- a/testcases/kernel/fs/ftest/ftest04.c
+++ b/testcases/kernel/fs/ftest/ftest04.c
@@ -48,6 +48,7 @@
 #include <errno.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "libftest.h"
 
 char *TCID = "ftest04";
@@ -120,11 +121,7 @@ static void setup(void)
 		sprintf(filename, "%s/ftest04.%d", getcwd(wdbuf, MAXPATHLEN),
 			getpid());
 
-	fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
-	if (fd < 0) {
-		tst_brkm(TBROK, NULL, "Error %d creating file %s", errno,
-			 filename);
-	}
+	fd = SAFE_OPEN(NULL, filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
 	close(fd);
 
 	/*
@@ -151,14 +148,7 @@ static void runtest(void)
 
 	for (i = 0; i < nchild; i++) {
 		if ((child = fork()) == 0) {
-			fd = open(filename, O_RDWR);
-			if (fd < 0) {
-				tst_brkm(TBROK,
-					 NULL,
-					 "\tTest[%d]: error %d openning %s.",
-					 i,
-					 errno, filename);
-			}
+			fd = SAFE_OPEN(NULL, filename, O_RDWR);
 			dotest(nchild, i, fd);
 			close(fd);
 			tst_exit();
diff --git a/testcases/kernel/fs/ftest/ftest05.c b/testcases/kernel/fs/ftest/ftest05.c
index b647f8b06..0bd32e4f6 100644
--- a/testcases/kernel/fs/ftest/ftest05.c
+++ b/testcases/kernel/fs/ftest/ftest05.c
@@ -166,12 +166,8 @@ static void runtest(void)
 	for (i = 0; i < nchild; i++) {
 		test_name[0] = 'a' + i;
 		test_name[1] = '\0';
-		fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-		if (fd < 0) {
-			tst_brkm(TBROK | TERRNO, NULL,
-				 "\tError creating %s/%s.", fuss, test_name);
-		}
+		fd = SAFE_OPEN(NULL, test_name, O_RDWR | O_CREAT | O_TRUNC,
+			       0666);
 
 		if ((child = fork()) == 0) {
 			dotest(nchild, i, fd);
diff --git a/testcases/kernel/fs/ftest/ftest07.c b/testcases/kernel/fs/ftest/ftest07.c
index f80f1922f..e5998b597 100644
--- a/testcases/kernel/fs/ftest/ftest07.c
+++ b/testcases/kernel/fs/ftest/ftest07.c
@@ -181,12 +181,8 @@ static void runtest(void)
 	for (i = 0; i < nchild; i++) {
 		test_name[0] = 'a' + i;
 		test_name[1] = '\0';
-		fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
-		if (fd < 0) {
-			tst_brkm(TBROK, NULL, "\tError %d creating %s/%s.",
-				 errno,
-				 fuss, test_name);
-		}
+		fd = SAFE_OPEN(NULL, test_name, O_RDWR | O_CREAT | O_TRUNC,
+			       0666);
 
 		if ((child = fork()) == 0) {
 			dotest(nchild, i, fd);
diff --git a/testcases/kernel/fs/ftest/ftest08.c b/testcases/kernel/fs/ftest/ftest08.c
index 1eec79d0d..5e462486a 100644
--- a/testcases/kernel/fs/ftest/ftest08.c
+++ b/testcases/kernel/fs/ftest/ftest08.c
@@ -55,6 +55,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "libftest.h"
 
 char *TCID = "ftest08";
@@ -124,12 +125,7 @@ static void init(void)
 		sprintf(filename, "%s/ftest08.%d", getcwd(wdbuf, MAXPATHLEN),
 			getpid());
 
-	fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-	if (fd < 0) {
-		tst_brkm(TBROK, NULL, "Error %d creating file %s", errno,
-			 filename);
-	}
+	fd = SAFE_OPEN(NULL, filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
 
 	close(fd);
 
diff --git a/testcases/kernel/logging/kmsg/kmsg01.c b/testcases/kernel/logging/kmsg/kmsg01.c
index 58b62d517..294d0a2d1 100644
--- a/testcases/kernel/logging/kmsg/kmsg01.c
+++ b/testcases/kernel/logging/kmsg/kmsg01.c
@@ -65,9 +65,7 @@
 static int inject_msg(const char *msg)
 {
 	int f;
-	f = open("/dev/kmsg", O_WRONLY);
-	if (f < 0)
-		tst_brk(TBROK | TERRNO, "failed to open /dev/kmsg");
+	f = SAFE_OPEN("/dev/kmsg", O_WRONLY);
 	TEST(write(f, msg, strlen(msg)));
 	SAFE_CLOSE(f);
 	errno = TEST_ERRNO;
@@ -93,9 +91,7 @@ static int find_msg(int fd, const char *text_to_find, char *buf, int bufsize,
 	char msg[MAX_MSGSIZE + 1];
 
 	if (fd < 0) {
-		f = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-		if (f < 0)
-			tst_brk(TBROK, "failed to open /dev/kmsg");
+		f = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 	} else {
 		f = fd;
 	}
@@ -251,9 +247,7 @@ static void test_read_nonblock(void)
 	int fd;
 
 	tst_res(TINFO, "TEST: nonblock read");
-	fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-	if (fd < 0)
-		tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+	fd = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 
 	TEST(timed_read_kmsg(fd, READ_TIMEOUT));
 	if (TEST_RETURN == -1 && TEST_ERRNO == EAGAIN)
@@ -269,9 +263,7 @@ static void test_read_block(void)
 	int fd;
 
 	tst_res(TINFO, "TEST: blocking read");
-	fd = open("/dev/kmsg", O_RDONLY);
-	if (fd < 0)
-		tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+	fd = SAFE_OPEN("/dev/kmsg", O_RDONLY);
 
 	TEST(timed_read_kmsg(fd, READ_TIMEOUT));
 	if (TEST_RETURN == -2)
@@ -287,9 +279,7 @@ static void test_partial_read(void)
 	int fd;
 
 	tst_res(TINFO, "TEST: partial read");
-	fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-	if (fd < 0)
-		tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+	fd = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 
 	TEST(read(fd, msg, 1));
 	if (TEST_RETURN < 0)
@@ -365,9 +355,7 @@ static void test_read_returns_first_message(void)
 	 * NUM_READ_RETRY attempts, report TWARN */
 	tst_res(TINFO, "TEST: mult. readers will get same first message");
 	while (j) {
-		fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-		if (fd < 0)
-			tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+		fd = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 
 		for (i = 0; i < NUM_READ_MSGS; i++) {
 			if (find_msg(-1, "", msg, sizeof(msg), 1) != 0)
@@ -420,9 +408,7 @@ static void test_messages_overwritten(void)
 	 * We know first message is overwritten when its seqno changes */
 	tst_res(TINFO, "TEST: read returns EPIPE when messages get "
 		"overwritten");
-	fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-	if (fd < 0)
-		tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+	fd = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 
 	if (find_msg(-1, "", msg, sizeof(msg), 1) == 0
 		&& get_msg_fields(msg, NULL, &first_seqno) == 0) {
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index f4d12e088..dd82b08d2 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -686,9 +686,7 @@ void read_cpuset_files(char *prefix, char *filename, char *retbuf)
 		if (errno == ENOENT) {
 			snprintf(path, BUFSIZ, "%s/cpuset.%s",
 				 prefix, filename);
-			fd = open(path, O_RDONLY);
-			if (fd == -1)
-				tst_brk(TBROK | TERRNO, "open %s", path);
+			fd = SAFE_OPEN(path, O_RDONLY);
 		} else
 			tst_brk(TBROK | TERRNO, "open %s", path);
 	}
@@ -713,9 +711,7 @@ void write_cpuset_files(char *prefix, char *filename, char *buf)
 		if (errno == ENOENT) {
 			snprintf(path, BUFSIZ, "%s/cpuset.%s",
 				 prefix, filename);
-			fd = open(path, O_WRONLY);
-			if (fd == -1)
-				tst_brk(TBROK | TERRNO, "open %s", path);
+			fd = SAFE_OPEN(path, O_WRONLY);
 		} else
 			tst_brk(TBROK | TERRNO, "open %s", path);
 	}
diff --git a/testcases/kernel/mem/vma/vma03.c b/testcases/kernel/mem/vma/vma03.c
index 1db16eab1..4b34ab0a0 100644
--- a/testcases/kernel/mem/vma/vma03.c
+++ b/testcases/kernel/mem/vma/vma03.c
@@ -85,9 +85,7 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		fd = open(TESTFILE, O_RDWR);
-		if (fd == -1)
-			tst_brkm(TBROK | TERRNO, NULL, "open %s", TESTFILE);
+		fd = SAFE_OPEN(NULL, TESTFILE, O_RDWR);
 
 		/*
 		 * The pgoff is counted in 4K units and must be page-aligned,
diff --git a/testcases/kernel/pty/hangup01.c b/testcases/kernel/pty/hangup01.c
index 5527bce98..aac3955c9 100644
--- a/testcases/kernel/pty/hangup01.c
+++ b/testcases/kernel/pty/hangup01.c
@@ -35,6 +35,7 @@
 
 /** LTP Port **/
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "hangup01";	/* Test program identifier.    */
 int TST_TOTAL = 5;		/* Total number of test cases. */
@@ -213,9 +214,7 @@ int main(int argc, char **argv)
 	pid_t childpid;
 
 /*--------------------------------------------------------------------*/
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "open %s", MASTERCLONE);
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL)
diff --git a/testcases/kernel/pty/ptem01.c b/testcases/kernel/pty/ptem01.c
index 8cfc02a89..68994d491 100644
--- a/testcases/kernel/pty/ptem01.c
+++ b/testcases/kernel/pty/ptem01.c
@@ -36,6 +36,7 @@
 
 /** LTP Port **/
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "ptem01";		/* Test program identifier.    */
 int TST_TOTAL = 6;		/* Total number of test cases. */
@@ -58,10 +59,7 @@ int test1(void)
 	struct termio termio;
 	struct termios termios;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -140,10 +138,7 @@ int test2(void)
 	struct winsize wsz1 = { 24, 80, 5, 10 };
 	struct winsize wsz2 = { 60, 100, 11, 777 };
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -221,10 +216,7 @@ int test3(void)
 	int masterfd, slavefd;
 	char *slavename;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -272,10 +264,7 @@ int test4(void)
 	int masterfd, slavefd, slavefd2, slavefd3;
 	char *slavename;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -396,10 +385,7 @@ int test6(void)
 	char *slavename;
 	struct termios termios;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
diff --git a/testcases/kernel/pty/pty01.c b/testcases/kernel/pty/pty01.c
index 283612d55..d390ce717 100644
--- a/testcases/kernel/pty/pty01.c
+++ b/testcases/kernel/pty/pty01.c
@@ -37,6 +37,7 @@
 
 /** LTP Port **/
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "pty01";		/* Test program identifier.    */
 int TST_TOTAL = 5;		/* Total number of test cases. */
@@ -78,10 +79,7 @@ static int test1(void)
 	struct stat st;
 	char buf[TESTSIZE];
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -115,10 +113,7 @@ static int test1(void)
 		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() failed");
 	}
 
-	slavefd = open(slavename, O_RDWR);
-	if (slavefd < 0) {
-		tst_brkm(TBROK, NULL, "Could not open %s", slavename);
-	}
+	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
 
 	/*
 	 * test writing to the master / reading from the slave
@@ -202,10 +197,7 @@ static void test2(void)
 	char *slavename;
 	char c;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -220,10 +212,7 @@ static void test2(void)
 		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() call failed");
 	}
 
-	slavefd = open(slavename, O_RDWR);
-	if (slavefd < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, "Could not open %s", slavename);
-	}
+	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
 
 	/*
 	 * close pty fds.  See what happens when we close the master
@@ -264,10 +253,7 @@ static void test3(void)
 {
 	int masterfd;		/* master pty fd */
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	if (ioctl(masterfd, TIOCGWINSZ, NULL) == 0) {
 		tst_brkm(TFAIL | TERRNO, NULL,
@@ -288,10 +274,7 @@ static void test4(void)
 	int slavefd3;
 	char *slavename;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -306,10 +289,7 @@ static void test4(void)
 		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() call failed");
 	}
 
-	slavefd = open(slavename, O_RDWR);
-	if (slavefd < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, "Could not open %s", slavename);
-	}
+	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
 
 	slavefd2 = open(slavename, O_RDWR);
 	if (slavefd < 0) {
diff --git a/testcases/kernel/syscalls/chmod/chmod01.c b/testcases/kernel/syscalls/chmod/chmod01.c
index 4428c9cd1..14002f23f 100644
--- a/testcases/kernel/syscalls/chmod/chmod01.c
+++ b/testcases/kernel/syscalls/chmod/chmod01.c
@@ -148,11 +148,7 @@ void setup(void)
 
 	tst_tmpdir();
 
-	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %o) failed",
-			 TESTFILE, FILE_MODE);
+	fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
 	SAFE_CLOSE(cleanup, fd);
 
 }
diff --git a/testcases/kernel/syscalls/chmod/chmod07.c b/testcases/kernel/syscalls/chmod/chmod07.c
index 42272414a..6a3938840 100644
--- a/testcases/kernel/syscalls/chmod/chmod07.c
+++ b/testcases/kernel/syscalls/chmod/chmod07.c
@@ -178,11 +178,7 @@ void setup(void)
 		tst_brkm(TBROK, cleanup, "getgrnam failed");
 	group1_gid = ltpgroup->gr_gid;
 
-	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %#o) failed",
-			 TESTFILE, FILE_MODE);
+	fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
 	SAFE_CLOSE(cleanup, fd);
 	SAFE_CHOWN(cleanup, TESTFILE, user1_uid, group1_gid);
 
diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
index fd21f46fd..c12f0563c 100644
--- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
+++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
@@ -42,6 +42,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #include "lapi/syscalls.h"
 #ifndef _FILE_OFFSET_BITS
@@ -144,12 +145,7 @@ void setup(void)
 
 	TEST_PAUSE;
 
-	fd = open(fname, O_RDONLY);
-	if (fd < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to open a file(\"%s\") for test: %s\n",
-			 fname, strerror(errno));
-	}
+	fd = SAFE_OPEN(cleanup, fname, O_RDONLY);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
index 161074dfb..4aa3a8cd1 100644
--- a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
+++ b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
@@ -41,6 +41,7 @@
 #include <errno.h>
 #include <limits.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #include "lapi/syscalls.h"
 #ifndef _FILE_OFFSET_BITS
@@ -194,12 +195,7 @@ void setup(void)
 
 	TEST_PAUSE;
 
-	fd = open(fname, O_RDONLY);
-	if (fd < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to open a file(\"%s\") for test: %s\n",
-			 fname, strerror(errno));
-	}
+	fd = SAFE_OPEN(cleanup, fname, O_RDONLY);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/fallocate/fallocate01.c b/testcases/kernel/syscalls/fallocate/fallocate01.c
index 89ce9967d..02aa33100 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate01.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate01.c
@@ -100,6 +100,7 @@
 #include <sys/utsname.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/fallocate.h"
 #include "lapi/fcntl.h"
 
@@ -145,18 +146,12 @@ void setup(void)
 	tst_tmpdir();
 
 	sprintf(fname_mode1, "tfile_mode1_%d", getpid());
-	fd_mode1 = open(fname_mode1, O_RDWR | O_CREAT, 0700);
-	if (fd_mode1 == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open(%s, O_RDWR) failed",
-			 fname_mode1);
+	fd_mode1 = SAFE_OPEN(cleanup, fname_mode1, O_RDWR | O_CREAT, 0700);
 	get_blocksize(fd_mode1);
 	populate_files(fd_mode1);
 
 	sprintf(fname_mode2, "tfile_mode2_%d", getpid());
-	fd_mode2 = open(fname_mode2, O_RDWR | O_CREAT, 0700);
-	if (fd_mode2 == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open(%s, O_RDWR) failed",
-			 fname_mode2);
+	fd_mode2 = SAFE_OPEN(cleanup, fname_mode2, O_RDWR | O_CREAT, 0700);
 	populate_files(fd_mode2);
 }
 
diff --git a/testcases/kernel/syscalls/fallocate/fallocate03.c b/testcases/kernel/syscalls/fallocate/fallocate03.c
index d73d07d5b..da2b3bfbe 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate03.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate03.c
@@ -96,6 +96,7 @@
 #include <sys/utsname.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/fallocate.h"
 
 #define BLOCKS_WRITTEN 12
@@ -164,9 +165,7 @@ void setup(void)
 	tst_tmpdir();
 
 	sprintf(fname, "tfile_sparse_%d", getpid());
-	fd = open(fname, O_RDWR | O_CREAT, 0700);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open(%s) failed", fname);
+	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 	get_blocksize(fd);
 	populate_file();
 	file_seek(BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS);	/* create holes */
diff --git a/testcases/kernel/syscalls/fchmod/fchmod05.c b/testcases/kernel/syscalls/fchmod/fchmod05.c
index 0ab2f935d..7a270285a 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod05.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod05.c
@@ -203,12 +203,7 @@ void setup(void)
 			 strerror(errno));
 
 	/* Open the test directory for reading */
-	fd = open(TESTDIR, O_RDONLY);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDONLY) failed, errno=%d : %s",
-			 TESTDIR, errno, strerror(errno));
-	}
+	fd = SAFE_OPEN(cleanup, TESTDIR, O_RDONLY);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/fcntl/fcntl14.c b/testcases/kernel/syscalls/fcntl/fcntl14.c
index 5f99dc21e..ca68d0f98 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl14.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl14.c
@@ -779,9 +779,7 @@ void run_test(int file_flag, int file_mode, int seek, int start, int end)
 	fail = 0;
 
 	for (test = start; test < end; test++) {
-		fd = open(tmpname, file_flag, file_mode);
-		if (fd < 0)
-			tst_brkm(TBROK, cleanup, "open() failed");
+		fd = SAFE_OPEN(cleanup, tmpname, file_flag, file_mode);
 
 		if (write(fd, FILEDATA, 10) < 0)
 			tst_brkm(TBROK, cleanup, "write() failed");
@@ -1017,9 +1015,8 @@ int main(int ac, char **av)
 		 * argument used for WHENCE (negative value)
 		 */
 
-		fd = open(tmpname, O_CREAT | O_RDWR | O_TRUNC, 0777);
-		if (fd < 0)
-			tst_brkm(TBROK, cleanup, "open failed");
+		fd = SAFE_OPEN(cleanup, tmpname, O_CREAT | O_RDWR | O_TRUNC,
+			       0777);
 
 		if (write(fd, FILEDATA, 10) < 0)
 			tst_brkm(TBROK, cleanup, "write failed");
@@ -1055,9 +1052,8 @@ int main(int ac, char **av)
 		 * additional data is appended to end of file and a new
 		 * process attempts to lock new data
 		 */
-		fd = open(tmpname, O_CREAT | O_RDWR | O_TRUNC, 0777);
-		if (fd < 0)
-			tst_brkm(TBROK, cleanup, "open failed");
+		fd = SAFE_OPEN(cleanup, tmpname, O_CREAT | O_RDWR | O_TRUNC,
+			       0777);
 
 		if (write(fd, FILEDATA, 10) < 0)
 			tst_brkm(TBROK, cleanup, "write failed");
diff --git a/testcases/kernel/syscalls/fcntl/fcntl16.c b/testcases/kernel/syscalls/fcntl/fcntl16.c
index c9defc68f..a77a81298 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl16.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl16.c
@@ -46,6 +46,7 @@
 #include <signal.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -451,10 +452,7 @@ int run_test(int file_flag, int file_mode, int start, int end)
 	/* loop through all test cases */
 	for (test = start; test < end; test++) {
 		/* open a temp file to lock */
-		fd = open(tmpname, file_flag, file_mode);
-		if (fd < 0) {
-			tst_brkm(TBROK, cleanup, "open failed");
-		}
+		fd = SAFE_OPEN(cleanup, tmpname, file_flag, file_mode);
 
 		/* write some dummy data to the file */
 		(void)write(fd, FILEDATA, 10);
diff --git a/testcases/kernel/syscalls/flock/flock01.c b/testcases/kernel/syscalls/flock/flock01.c
index 06d89e3b9..a4133f140 100644
--- a/testcases/kernel/syscalls/flock/flock01.c
+++ b/testcases/kernel/syscalls/flock/flock01.c
@@ -71,6 +71,7 @@
 #include <sys/file.h>
 #include <fcntl.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup(void);
 void cleanup(void);
@@ -154,9 +155,7 @@ void setup(void)
 	sprintf(filename, "flock01.%d", getpid());
 
 	/* creating temporary file */
-	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK, tst_rmdir, "creating a new file failed");
+	fd = SAFE_OPEN(tst_rmdir, filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/flock/flock06.c b/testcases/kernel/syscalls/flock/flock06.c
index a35c8cf31..617eddf54 100644
--- a/testcases/kernel/syscalls/flock/flock06.c
+++ b/testcases/kernel/syscalls/flock/flock06.c
@@ -67,6 +67,7 @@
 #include <sys/file.h>
 #include <sys/wait.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup(void);
 void cleanup(void);
@@ -158,9 +159,7 @@ void setup(void)
 	sprintf(filename, "flock06.%d", getpid());
 
 	/* creating temporary file */
-	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
-	if (fd < 0)
-		tst_brkm(TBROK, tst_rmdir, "creating a new file failed");
+	fd = SAFE_OPEN(tst_rmdir, filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	close(fd);
 }
 
diff --git a/testcases/kernel/syscalls/fork/fork04.c b/testcases/kernel/syscalls/fork/fork04.c
index d6b57d990..208636c6b 100644
--- a/testcases/kernel/syscalls/fork/fork04.c
+++ b/testcases/kernel/syscalls/fork/fork04.c
@@ -103,6 +103,7 @@
 #include <signal.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "fork04";
 
@@ -241,12 +242,7 @@ void parent_environment(void)
 	int ret;
 	char *var;
 
-	fildes = open(OUTPUT_FILE, O_RDWR);
-	if (fildes == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "fork() test. Parent open of temporary file failed. errno %d (%s)\n",
-			 errno, strerror(errno));
-	}
+	fildes = SAFE_OPEN(cleanup, OUTPUT_FILE, O_RDWR);
 	for (index = 0; index < NUMBER_OF_ENVIRON; index++) {
 		ret = read(fildes, tmp_line, MAX_LINE_LENGTH);
 		if (ret == 0) {
diff --git a/testcases/kernel/syscalls/fork/fork10.c b/testcases/kernel/syscalls/fork/fork10.c
index 13db0555d..815eee1f6 100644
--- a/testcases/kernel/syscalls/fork/fork10.c
+++ b/testcases/kernel/syscalls/fork/fork10.c
@@ -77,10 +77,7 @@ int main(int ac, char **av)
 		write(fildes, "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 27);
 		close(fildes);
 
-		fildes = open(fnamebuf, 0);
-		if (fildes == -1)
-			tst_brkm(TBROK, cleanup, "Parent: cannot open %s for "
-				 "reading", fnamebuf);
+		fildes = SAFE_OPEN(cleanup, fnamebuf, 0);
 
 		pid = fork();
 		if (pid == -1)
diff --git a/testcases/kernel/syscalls/fstat/fstat01.c b/testcases/kernel/syscalls/fstat/fstat01.c
index 2ceed22b9..a5940c627 100644
--- a/testcases/kernel/syscalls/fstat/fstat01.c
+++ b/testcases/kernel/syscalls/fstat/fstat01.c
@@ -116,6 +116,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -161,9 +162,7 @@ void setup(void)
 	tst_tmpdir();
 
 	sprintf(fname, "tfile_%d", getpid());
-	fd = open(fname, O_RDWR | O_CREAT, 0700);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open failed");
+	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/fstat/fstat03.c b/testcases/kernel/syscalls/fstat/fstat03.c
index 1ff61c7ca..0fa62b847 100644
--- a/testcases/kernel/syscalls/fstat/fstat03.c
+++ b/testcases/kernel/syscalls/fstat/fstat03.c
@@ -137,10 +137,7 @@ void setup(void)
 	tst_tmpdir();
 
 	/* Create a testfile under temporary directory */
-	fildes = open(TEST_FILE, O_RDWR | O_CREAT, 0666);
-	if (fildes == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, 0666) failed", TEST_FILE);
+	fildes = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0666);
 
 	SAFE_CLOSE(cleanup, fildes);
 }
diff --git a/testcases/kernel/syscalls/fstat/fstat05.c b/testcases/kernel/syscalls/fstat/fstat05.c
index 29c253f48..8de5d070a 100644
--- a/testcases/kernel/syscalls/fstat/fstat05.c
+++ b/testcases/kernel/syscalls/fstat/fstat05.c
@@ -211,10 +211,7 @@ void setup(void)
 	tst_tmpdir();
 
 	/* Create a testfile under temporary directory */
-	fildes = open(TEST_FILE, O_RDWR | O_CREAT, 0666);
-	if (fildes == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, 0666) failed", TEST_FILE);
+	fildes = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0666);
 
 	TEST_PAUSE;
 }
diff --git a/testcases/kernel/syscalls/ftruncate/ftruncate01.c b/testcases/kernel/syscalls/ftruncate/ftruncate01.c
index 3bbae0a4f..3309af540 100644
--- a/testcases/kernel/syscalls/ftruncate/ftruncate01.c
+++ b/testcases/kernel/syscalls/ftruncate/ftruncate01.c
@@ -75,6 +75,7 @@
 #include <inttypes.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TESTFILE	"testfile"	/* file under test */
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
@@ -170,11 +171,7 @@ void setup(void)
 	}
 
 	/* open a file for reading/writing */
-	fildes = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fildes == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %o) failed",
-			 TESTFILE, FILE_MODE);
+	fildes = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
 
 	/* Write to the file 1k data from the buffer */
 	while (c_total < FILE_SIZE) {
diff --git a/testcases/kernel/syscalls/ftruncate/ftruncate02.c b/testcases/kernel/syscalls/ftruncate/ftruncate02.c
index 77f40e2ba..bc03075fc 100644
--- a/testcases/kernel/syscalls/ftruncate/ftruncate02.c
+++ b/testcases/kernel/syscalls/ftruncate/ftruncate02.c
@@ -75,6 +75,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TESTFILE	"testfile"	/* file under test */
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
@@ -253,11 +254,7 @@ void setup(void)
 		tst_buff[i] = 'a';
 	}
 	/* open a file for reading/writing */
-	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %o) failed",
-			 TESTFILE, FILE_MODE);
+	fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
 
 	/* Write to the file 1k data from the buffer */
 	while (write_len < FILE_SIZE) {
diff --git a/testcases/kernel/syscalls/inotify/inotify03.c b/testcases/kernel/syscalls/inotify/inotify03.c
index ae0c37e84..065890a25 100644
--- a/testcases/kernel/syscalls/inotify/inotify03.c
+++ b/testcases/kernel/syscalls/inotify/inotify03.c
@@ -196,11 +196,7 @@ static void setup(void)
 	mount_flag = 1;
 
 	sprintf(fname, "%s/tfile_%d", mntpoint, getpid());
-	fd = open(fname, O_RDWR | O_CREAT, 0700);
-	if (fd == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) failed", fname);
-	}
+	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 
 	ret = write(fd, fname, 1);
 	if (ret == -1) {
diff --git a/testcases/kernel/syscalls/ioctl/ioctl01.c b/testcases/kernel/syscalls/ioctl/ioctl01.c
index 79f27f664..ceb54aa65 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl01.c
@@ -55,6 +55,7 @@
 #include <termio.h>
 #include <termios.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "ioctl01";
 int TST_TOTAL = 5;
@@ -119,9 +120,7 @@ int main(int ac, char **av)
 
 	setup();
 
-	fd = open(devname, O_RDWR, 0777);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Couldn't open %s", devname);
+	fd = SAFE_OPEN(cleanup, devname, O_RDWR, 0777);
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
diff --git a/testcases/kernel/syscalls/ioctl/ioctl02.c b/testcases/kernel/syscalls/ioctl/ioctl02.c
index 48e8eaa7f..a4b468e43 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl02.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl02.c
@@ -361,10 +361,7 @@ static int do_parent_setup(void)
 {
 	int pfd;
 
-	pfd = open(parenttty, O_RDWR, 0777);
-	if (pfd < 0)
-		tst_brkm(TBROK, cleanup, "Could not open %s in "
-			 "do_parent_setup(), errno = %d", parenttty, errno);
+	pfd = SAFE_OPEN(cleanup, parenttty, O_RDWR, 0777);
 
 	/* unset the closed flag */
 	closed = 0;
@@ -430,10 +427,7 @@ static void setup(void)
 	struct sigaction act;
 
 	/* XXX: TERRNO required all over the place */
-	fd = open(devname, O_RDWR, 0777);
-	if (fd < 0)
-		tst_brkm(TBROK, NULL, "Could not open %s in "
-			 "setup(), errno = %d", devname, errno);
+	fd = SAFE_OPEN(NULL, devname, O_RDWR, 0777);
 
 	/* Save the current device information - to be restored in cleanup() */
 	SAFE_IOCTL(cleanup, fd, TCGETA, &save_io);
diff --git a/testcases/kernel/syscalls/mincore/mincore02.c b/testcases/kernel/syscalls/mincore/mincore02.c
index 713473acd..ab73f4bf5 100644
--- a/testcases/kernel/syscalls/mincore/mincore02.c
+++ b/testcases/kernel/syscalls/mincore/mincore02.c
@@ -36,6 +36,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "mincore02";
 int TST_TOTAL = 1;
@@ -72,11 +73,8 @@ static void setup(void)
 	memset(buf, 42, size);
 	vec = malloc((size + page_size - 1) / page_size);
 	
-	fd = open("mincore02", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
-	if (fd == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-		         "Unable to create temporary file");
-	}
+	fd = SAFE_OPEN(cleanup, "mincore02", O_CREAT | O_RDWR,
+		       S_IRUSR | S_IWUSR);
 
 	/* fill the temporary file with two pages of data */
 	if (write(fd, buf, size) < 0) {
diff --git a/testcases/kernel/syscalls/mlock/mlock04.c b/testcases/kernel/syscalls/mlock/mlock04.c
index fb541ec08..8ac884583 100644
--- a/testcases/kernel/syscalls/mlock/mlock04.c
+++ b/testcases/kernel/syscalls/mlock/mlock04.c
@@ -87,9 +87,7 @@ static void setup(void)
 {
 	tst_tmpdir();
 
-	fd = open(testfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
 
 	SAFE_FTRUNCATE(cleanup, fd, file_len);
 
diff --git a/testcases/kernel/syscalls/mprotect/mprotect01.c b/testcases/kernel/syscalls/mprotect/mprotect01.c
index d514b1352..7c4f10e02 100644
--- a/testcases/kernel/syscalls/mprotect/mprotect01.c
+++ b/testcases/kernel/syscalls/mprotect/mprotect01.c
@@ -43,6 +43,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "mprotect01";
 int TST_TOTAL = 3;
@@ -136,9 +137,7 @@ static void setup2(struct test_case *self)
 
 static void setup3(struct test_case *self)
 {
-	fd = open("/etc/passwd", O_RDONLY);
-	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "open failed");
+	fd = SAFE_OPEN(cleanup, "/etc/passwd", O_RDONLY);
 	
 	self->len = getpagesize();
 
diff --git a/testcases/kernel/syscalls/open/open05.c b/testcases/kernel/syscalls/open/open05.c
index 2577a34ff..051aec3b3 100644
--- a/testcases/kernel/syscalls/open/open05.c
+++ b/testcases/kernel/syscalls/open/open05.c
@@ -129,9 +129,7 @@ static void setup(void)
 
 	sprintf(fname, "file.%d", getpid());
 
-	fd = open(fname, O_RDWR | O_CREAT, 0700);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "open() failed, errno: %d", errno);
+	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index 9593671f2..6fa21b0bd 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -373,9 +373,7 @@ static void setup(void)
 	tst_tmpdir();
 
 	/* Create test files */
-	fd = open(T_REG, O_WRONLY | O_CREAT, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", T_REG);
+	fd = SAFE_OPEN(cleanup, T_REG, O_WRONLY | O_CREAT, 0644);
 	ret = write(fd, T_MSG, sizeof(T_MSG));
 	if (ret == -1) {
 		close(fd);
diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index d21bb9c45..319dc91f5 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -211,9 +211,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
 	off_t offset = 0;
 	struct timeval now;
 
-	fd = open(fname, O_RDONLY);
-	if (fd < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "Failed to open %s", fname);
+	fd = SAFE_OPEN(cleanup, fname, O_RDONLY);
 
 	if (do_readahead) {
 		cached_start = get_cached_size();
diff --git a/testcases/kernel/syscalls/sendfile/sendfile08.c b/testcases/kernel/syscalls/sendfile/sendfile08.c
index 3212ca7cc..f9e2605c1 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile08.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile08.c
@@ -109,13 +109,9 @@ static void setup(void)
 		tst_brkm(TBROK | TERRNO, cleanup, "Write %s failed", in_file);
 	close(in_fd);
 
-	in_fd = open(in_file, O_RDONLY);
-	if (in_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Open %s failed", in_file);
+	in_fd = SAFE_OPEN(cleanup, in_file, O_RDONLY);
+	out_fd = SAFE_OPEN(cleanup, out_file, O_TRUNC | O_CREAT | O_RDWR, 0777);
 
-	out_fd = open(out_file, O_TRUNC | O_CREAT | O_RDWR, 0777);
-	if (out_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Open %s failed", out_file);
 	ret = write(out_fd, TEST_MSG_OUT, strlen(TEST_MSG_OUT));
 	if (ret == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "Write %s failed", out_file);
diff --git a/testcases/kernel/syscalls/setfsuid/setfsuid04.c b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
index 6d02b1994..8585d6207 100644
--- a/testcases/kernel/syscalls/setfsuid/setfsuid04.c
+++ b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
@@ -38,6 +38,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 TCID_DEFINE(setfsuid04);
@@ -174,9 +175,7 @@ static void setup(void)
 	tst_tmpdir();
 
 	/* Create test file */
-	fd = open(testfile, O_CREAT | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "cannot creat test file");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
diff --git a/testcases/kernel/syscalls/setresuid/setresuid04.c b/testcases/kernel/syscalls/setresuid/setresuid04.c
index 4f17cb923..e197476ff 100644
--- a/testcases/kernel/syscalls/setresuid/setresuid04.c
+++ b/testcases/kernel/syscalls/setresuid/setresuid04.c
@@ -51,6 +51,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <pwd.h>
 #include "compat_16.h"
 
@@ -202,9 +203,7 @@ void setup(void)
 	sprintf(testfile, "setresuid04file%d.tst", getpid());
 
 	/* Create test file */
-	fd = open(testfile, O_CREAT | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "cannot creat test file");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
diff --git a/testcases/kernel/syscalls/setreuid/setreuid07.c b/testcases/kernel/syscalls/setreuid/setreuid07.c
index 30c392d36..ff222cd00 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid07.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid07.c
@@ -36,6 +36,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 TCID_DEFINE(setreuid07);
@@ -176,10 +177,7 @@ static void setup(void)
 	sprintf(testfile, "setreuid07file%d.tst", getpid());
 
 	/* Create test file */
-	fd = open(testfile, O_CREAT | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK | TERRNO,
-			cleanup, "cannot create test file");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
diff --git a/testcases/kernel/syscalls/setuid/setuid04.c b/testcases/kernel/syscalls/setuid/setuid04.c
index 5879e91fb..3459e6648 100644
--- a/testcases/kernel/syscalls/setuid/setuid04.c
+++ b/testcases/kernel/syscalls/setuid/setuid04.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 char *TCID = "setuid04";
@@ -155,9 +156,7 @@ static void setup(void)
 	tst_tmpdir();
 
 	/* Create test file */
-	fd = open(testfile, O_CREAT | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "cannot creat test file");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 05/13] Make use of SAFE_PIPE()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (2 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 04/13] Make use of SAFE_OPEN() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 06/13] Make use of SAFE_LINK() Cyril Hrubis
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/containers/pidns/pidns05.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/containers/pidns/pidns05.c b/testcases/kernel/containers/pidns/pidns05.c
index cdcf76a14..8462243cd 100644
--- a/testcases/kernel/containers/pidns/pidns05.c
+++ b/testcases/kernel/containers/pidns/pidns05.c
@@ -49,6 +49,7 @@
 #include <errno.h>
 #include "pidns_helper.h"
 #include "test.h"
+#include "safe_macros.h"
 
 #define INIT_PID	1
 #define CINIT_PID	1
@@ -230,9 +231,7 @@ int main(int argc, char *argv[])
 
 	pid = getpid();
 	pgid = getpgid(pid);
-	ret = pipe(fd);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "pipe failed");
+	SAFE_PIPE(NULL, fd);
 
 	TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID,
 				   create_nested_container, (void *)&count));
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 06/13] Make use of SAFE_LINK()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (3 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 05/13] Make use of SAFE_PIPE() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 07/13] Make use of SAFE_SYMLINK() Cyril Hrubis
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/open/open11.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index 6fa21b0bd..b8cf7eb14 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -384,10 +384,7 @@ static void setup(void)
 	fd = SAFE_CREAT(cleanup, T_REG_EMPTY, 0644);
 	close(fd);
 
-	ret = link(T_REG, T_LINK_REG);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Hard link %s -> %s failed",
-			 T_REG, T_LINK_REG);
+	ret = SAFE_LINK(cleanup, T_REG, T_LINK_REG);
 
 	ret = symlink(T_REG, T_SYMLINK_REG);
 	if (ret == -1)
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 07/13] Make use of SAFE_SYMLINK()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (4 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 06/13] Make use of SAFE_LINK() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 08/13] Make use of SAFE_SYSCONF() Cyril Hrubis
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/open/open11.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index b8cf7eb14..e56ef8203 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -386,17 +386,11 @@ static void setup(void)
 
 	ret = SAFE_LINK(cleanup, T_REG, T_LINK_REG);
 
-	ret = symlink(T_REG, T_SYMLINK_REG);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Symlink %s -> %s failed",
-			 T_REG, T_SYMLINK_REG);
+	ret = SAFE_SYMLINK(cleanup, T_REG, T_SYMLINK_REG);
 
 	ret = SAFE_MKDIR(cleanup, T_DIR, 0755);
 
-	ret = symlink(T_DIR, T_SYMLINK_DIR);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Symlink %s -> %s failed",
-			 T_DIR, T_SYMLINK_DIR);
+	ret = SAFE_SYMLINK(cleanup, T_DIR, T_SYMLINK_DIR);
 
 	ret = mknod(T_DEV, S_IFCHR, makedev(1, 5));
 	if (ret == -1)
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 08/13] Make use of SAFE_SYSCONF()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (5 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 07/13] Make use of SAFE_SYMLINK() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 09/13] Make use of SAFE_WAIT() Cyril Hrubis
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/adjtimex/adjtimex02.c                   | 5 +----
 testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c | 5 ++---
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/adjtimex/adjtimex02.c b/testcases/kernel/syscalls/adjtimex/adjtimex02.c
index 577387d92..492225f19 100644
--- a/testcases/kernel/syscalls/adjtimex/adjtimex02.c
+++ b/testcases/kernel/syscalls/adjtimex/adjtimex02.c
@@ -206,10 +206,7 @@ void setup(void)
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	/* set the HZ from sysconf */
-	hz = sysconf(_SC_CLK_TCK);
-	if (hz == -1) {
-		tst_brkm(TBROK, NULL, "Failed to read the HZ from sysconf\n");
-	}
+	hz = SAFE_SYSCONF(NULL, _SC_CLK_TCK);
 
 	TEST_PAUSE;
 
diff --git a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
index 7e1146532..02f04b909 100644
--- a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
+++ b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
@@ -50,6 +50,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 
 char *TCID = "sched_getaffinity01";
@@ -162,9 +163,7 @@ static void setup(void)
 	TEST_PAUSE;
 	tst_tmpdir();
 
-	num = sysconf(_SC_NPROCESSORS_CONF);
-	if (num == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "sysconf");
+	num = SAFE_SYSCONF(NULL, _SC_NPROCESSORS_CONF);
 	tst_resm(TINFO, "system has %ld processor(s).", num);
 }
 
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 09/13] Make use of SAFE_WAIT()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (6 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 08/13] Make use of SAFE_SYSCONF() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 10/13] Make use of SAFE_WAITPID() Cyril Hrubis
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/clone/clone01.c           | 6 ++----
 testcases/kernel/syscalls/exit_group/exit_group01.c | 5 ++---
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/clone/clone01.c b/testcases/kernel/syscalls/clone/clone01.c
index 855c1085d..e490b4e77 100644
--- a/testcases/kernel/syscalls/clone/clone01.c
+++ b/testcases/kernel/syscalls/clone/clone01.c
@@ -30,6 +30,7 @@
 #include <sched.h>
 #include <sys/wait.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "clone_platform.h"
 
 static void setup(void);
@@ -58,10 +59,7 @@ int main(int ac, char **av)
 	if (TEST_RETURN == -1)
 		tst_resm(TFAIL | TTERRNO, "clone failed");
 
-	child_pid = wait(&status);
-	if (child_pid == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "wait failed, status: %d",
-			 status);
+	child_pid = SAFE_WAIT(cleanup, &status);
 
 	if (TEST_RETURN == child_pid)
 		tst_resm(TPASS, "clone returned %ld", TEST_RETURN);
diff --git a/testcases/kernel/syscalls/exit_group/exit_group01.c b/testcases/kernel/syscalls/exit_group/exit_group01.c
index 3726b0652..d7bcbe9d6 100644
--- a/testcases/kernel/syscalls/exit_group/exit_group01.c
+++ b/testcases/kernel/syscalls/exit_group/exit_group01.c
@@ -25,6 +25,7 @@
 #include <sys/wait.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 
 char *TCID = "exit_group01";
@@ -43,9 +44,7 @@ static void verify_exit_group(void)
 	if (cpid == 0) {
 		TEST(ltp_syscall(__NR_exit_group, 4));
 	} else {
-		w = wait(&status);
-		if (w == -1)
-			tst_brkm(TBROK | TERRNO, NULL, "wait() failed");
+		w = SAFE_WAIT(NULL, &status);
 
 		if (WIFEXITED(status) && (WEXITSTATUS(status) == 4)) {
 			tst_resm(TPASS, "exit_group() succeeded");
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 10/13] Make use of SAFE_WAITPID()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (7 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 09/13] Make use of SAFE_WAIT() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 11/13] Make use of SAFE_LSEEK() Cyril Hrubis
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/fork/fork12.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/syscalls/fork/fork12.c b/testcases/kernel/syscalls/fork/fork12.c
index 711fe9874..75278b012 100644
--- a/testcases/kernel/syscalls/fork/fork12.c
+++ b/testcases/kernel/syscalls/fork/fork12.c
@@ -44,6 +44,7 @@
 #include <errno.h>
 #include <string.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "fork12";
 int TST_TOTAL = 1;
@@ -73,11 +74,7 @@ int main(int ac, char **av)
 				exit(0);
 			}
 			forks++;
-			ret = waitpid(-1, &status, WNOHANG);
-			if (ret < 0)
-				tst_brkm(TBROK, cleanup,
-					 "waitpid failed %d: %s\n", errno,
-					 strerror(errno));
+			ret = SAFE_WAITPID(cleanup, -1, &status, WNOHANG);
 			if (ret > 0) {
 				/* a child may be killed by OOM killer */
 				if (WTERMSIG(status) == SIGKILL)
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 11/13] Make use of SAFE_LSEEK()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (8 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 10/13] Make use of SAFE_WAITPID() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 12/13] Make use of SAFE_SOCKET() Cyril Hrubis
  2017-10-03 15:41 ` [LTP] [COMMITTED] [PATCH 13/13] syscalls/open11: Manual fixup Cyril Hrubis
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/sendfile/sendfile08.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/sendfile/sendfile08.c b/testcases/kernel/syscalls/sendfile/sendfile08.c
index f9e2605c1..a29632712 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile08.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile08.c
@@ -67,10 +67,7 @@ int main(int argc, char *argv[])
 		if (TEST_RETURN == -1)
 			tst_brkm(TBROK | TTERRNO, cleanup, "sendfile() failed");
 
-		ret = lseek(out_fd, 0, SEEK_SET);
-		if (ret == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "lseek %s failed",
-				 out_file);
+		ret = SAFE_LSEEK(cleanup, out_fd, 0, SEEK_SET);
 		ret = read(out_fd, buf, BUFSIZ);
 		if (ret == -1)
 			tst_brkm(TBROK | TERRNO, cleanup, "read %s failed",
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 12/13] Make use of SAFE_SOCKET()
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (9 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 11/13] Make use of SAFE_LSEEK() Cyril Hrubis
@ 2017-10-03 15:40 ` Cyril Hrubis
  2017-10-03 15:41 ` [LTP] [COMMITTED] [PATCH 13/13] syscalls/open11: Manual fixup Cyril Hrubis
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:40 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/accept/accept01.c         |  7 ++-----
 testcases/kernel/syscalls/bind/bind01.c             |  7 +++----
 testcases/kernel/syscalls/connect/connect01.c       |  5 ++---
 .../kernel/syscalls/getsockname/getsockname01.c     |  7 ++-----
 testcases/kernel/syscalls/getsockopt/getsockopt01.c |  7 ++-----
 testcases/kernel/syscalls/listen/listen01.c         |  8 +++-----
 testcases/kernel/syscalls/recv/recv01.c             |  5 ++---
 testcases/kernel/syscalls/recvfrom/recvfrom01.c     |  5 ++---
 testcases/kernel/syscalls/recvmsg/recvmsg01.c       |  5 ++---
 testcases/kernel/syscalls/send/send01.c             |  5 ++---
 testcases/kernel/syscalls/sendmsg/sendmsg01.c       | 21 ++++++---------------
 testcases/kernel/syscalls/sendto/sendto01.c         | 10 ++++------
 testcases/kernel/syscalls/setsockopt/setsockopt01.c |  7 ++-----
 testcases/kernel/syscalls/sockioctl/sockioctl01.c   | 14 ++++----------
 14 files changed, 38 insertions(+), 75 deletions(-)

diff --git a/testcases/kernel/syscalls/accept/accept01.c b/testcases/kernel/syscalls/accept/accept01.c
index 5a4966a0c..b50056520 100644
--- a/testcases/kernel/syscalls/accept/accept01.c
+++ b/testcases/kernel/syscalls/accept/accept01.c
@@ -156,11 +156,8 @@ static void cleanup0(void)
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for accept "
-			 "test %d: %s", testno, strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(fsin1);
 }
diff --git a/testcases/kernel/syscalls/bind/bind01.c b/testcases/kernel/syscalls/bind/bind01.c
index 6a3bc5065..868749368 100644
--- a/testcases/kernel/syscalls/bind/bind01.c
+++ b/testcases/kernel/syscalls/bind/bind01.c
@@ -52,6 +52,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "bind01";
 int testno;
@@ -174,10 +175,8 @@ void cleanup(void)
 
 void setup0(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "socket() failed for bind test %d", testno);
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
 
 void cleanup0(void)
diff --git a/testcases/kernel/syscalls/connect/connect01.c b/testcases/kernel/syscalls/connect/connect01.c
index d65af4ae0..2be83cfbb 100644
--- a/testcases/kernel/syscalls/connect/connect01.c
+++ b/testcases/kernel/syscalls/connect/connect01.c
@@ -203,9 +203,8 @@ void cleanup0(void)
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket() failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
 
 void cleanup1(void)
diff --git a/testcases/kernel/syscalls/getsockname/getsockname01.c b/testcases/kernel/syscalls/getsockname/getsockname01.c
index c46b1763a..cce1543fd 100644
--- a/testcases/kernel/syscalls/getsockname/getsockname01.c
+++ b/testcases/kernel/syscalls/getsockname/getsockname01.c
@@ -168,11 +168,8 @@ void cleanup0(void)
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for getsockname "
-			 "test %d: %s", testno, strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(fsin1);
 }
diff --git a/testcases/kernel/syscalls/getsockopt/getsockopt01.c b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
index b39cfefb5..d1692fcd3 100644
--- a/testcases/kernel/syscalls/getsockopt/getsockopt01.c
+++ b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
@@ -194,11 +194,8 @@ void cleanup0(void)
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for getsockopt: "
-			 "%s", strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(fsin1);
 	optlen = sizeof(optval);
diff --git a/testcases/kernel/syscalls/listen/listen01.c b/testcases/kernel/syscalls/listen/listen01.c
index e421bb46d..d33f209c3 100644
--- a/testcases/kernel/syscalls/listen/listen01.c
+++ b/testcases/kernel/syscalls/listen/listen01.c
@@ -53,6 +53,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "listen01";
 int testno;
@@ -140,11 +141,8 @@ void cleanup0(void)
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for listen: "
-			 "%s", strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
 
 void cleanup1(void)
diff --git a/testcases/kernel/syscalls/recv/recv01.c b/testcases/kernel/syscalls/recv/recv01.c
index 3345e51e6..2f09864a5 100644
--- a/testcases/kernel/syscalls/recv/recv01.c
+++ b/testcases/kernel/syscalls/recv/recv01.c
@@ -193,9 +193,8 @@ void setup1(void)
 	struct timeval timeout;
 	int n;
 
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 	if (tdat[testno].type == SOCK_STREAM &&
 	    connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
 		tst_brkm(TBROK | TERRNO, cleanup, "connect failed");
diff --git a/testcases/kernel/syscalls/recvfrom/recvfrom01.c b/testcases/kernel/syscalls/recvfrom/recvfrom01.c
index e07879b06..853d1cb9f 100644
--- a/testcases/kernel/syscalls/recvfrom/recvfrom01.c
+++ b/testcases/kernel/syscalls/recvfrom/recvfrom01.c
@@ -215,9 +215,8 @@ void setup1(void)
 	struct timeval timeout;
 	int n;
 
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket() failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	if (tdat[testno].type == SOCK_STREAM &&
 	    connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
 		tst_brkm(TBROK | TERRNO, cleanup, "connect failed");
diff --git a/testcases/kernel/syscalls/recvmsg/recvmsg01.c b/testcases/kernel/syscalls/recvmsg/recvmsg01.c
index 5bdc60cd9..13bcaa4e0 100644
--- a/testcases/kernel/syscalls/recvmsg/recvmsg01.c
+++ b/testcases/kernel/syscalls/recvmsg/recvmsg01.c
@@ -295,9 +295,8 @@ void setup1(void)
 	struct timeval timeout;
 	int n;
 
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	if (tdat[testno].type == SOCK_STREAM) {
 		if (tdat[testno].domain == PF_INET) {
 			SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1,
diff --git a/testcases/kernel/syscalls/send/send01.c b/testcases/kernel/syscalls/send/send01.c
index 31e8c1758..2e0ae2177 100644
--- a/testcases/kernel/syscalls/send/send01.c
+++ b/testcases/kernel/syscalls/send/send01.c
@@ -325,9 +325,8 @@ static void cleanup0(void)
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	SAFE_CONNECT(cleanup, s, (const struct sockaddr *)&sin1, sizeof(sin1));
 }
 
diff --git a/testcases/kernel/syscalls/sendmsg/sendmsg01.c b/testcases/kernel/syscalls/sendmsg/sendmsg01.c
index d7f7b757c..36f6914ff 100644
--- a/testcases/kernel/syscalls/sendmsg/sendmsg01.c
+++ b/testcases/kernel/syscalls/sendmsg/sendmsg01.c
@@ -589,11 +589,8 @@ static void cleanup0(void)
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	if (tdat[testno].type == SOCK_STREAM &&
 	    connect(s, (struct sockaddr *)tdat[testno].to,
 		    tdat[testno].tolen) < 0) {
@@ -618,11 +615,8 @@ static void setup2(void)
 
 static void setup3(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
 
 static char tmpfilename[1024];
@@ -659,11 +653,8 @@ static void cleanup4(void)
 
 static void setup5(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 
 	SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1, sizeof(sin1));
 
diff --git a/testcases/kernel/syscalls/sendto/sendto01.c b/testcases/kernel/syscalls/sendto/sendto01.c
index 5304da691..6fe0274ee 100644
--- a/testcases/kernel/syscalls/sendto/sendto01.c
+++ b/testcases/kernel/syscalls/sendto/sendto01.c
@@ -395,9 +395,8 @@ static void cleanup0(void)
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	SAFE_CONNECT(cleanup, s, (const struct sockaddr *)&sin1, sizeof(sin1));
 }
 
@@ -417,7 +416,6 @@ static void setup2(void)
 
 static void setup3(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt01.c b/testcases/kernel/syscalls/setsockopt/setsockopt01.c
index 36988854b..743c6be14 100644
--- a/testcases/kernel/syscalls/setsockopt/setsockopt01.c
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt01.c
@@ -201,11 +201,8 @@ void cleanup0(void)
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for setsockopt:"
-			 " %s", strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 }
 
diff --git a/testcases/kernel/syscalls/sockioctl/sockioctl01.c b/testcases/kernel/syscalls/sockioctl/sockioctl01.c
index 79c53e042..486236af9 100644
--- a/testcases/kernel/syscalls/sockioctl/sockioctl01.c
+++ b/testcases/kernel/syscalls/sockioctl/sockioctl01.c
@@ -205,11 +205,8 @@ static void cleanup0(void)
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(fsin1);
 
@@ -221,11 +218,8 @@ static void setup1(void)
 
 static void setup2(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	ifc.ifc_len = sizeof(buf);
 	ifc.ifc_buf = buf;
 }
-- 
2.13.5


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

* [LTP] [COMMITTED] [PATCH 13/13] syscalls/open11: Manual fixup
  2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
                   ` (10 preceding siblings ...)
  2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 12/13] Make use of SAFE_SOCKET() Cyril Hrubis
@ 2017-10-03 15:41 ` Cyril Hrubis
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2017-10-03 15:41 UTC (permalink / raw)
  To: ltp

The assigment to ret is not used and could be removed in this case.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/open/open11.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index e56ef8203..78002f37d 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -384,13 +384,10 @@ static void setup(void)
 	fd = SAFE_CREAT(cleanup, T_REG_EMPTY, 0644);
 	close(fd);
 
-	ret = SAFE_LINK(cleanup, T_REG, T_LINK_REG);
-
-	ret = SAFE_SYMLINK(cleanup, T_REG, T_SYMLINK_REG);
-
-	ret = SAFE_MKDIR(cleanup, T_DIR, 0755);
-
-	ret = SAFE_SYMLINK(cleanup, T_DIR, T_SYMLINK_DIR);
+	SAFE_LINK(cleanup, T_REG, T_LINK_REG);
+	SAFE_SYMLINK(cleanup, T_REG, T_SYMLINK_REG);
+	SAFE_MKDIR(cleanup, T_DIR, 0755);
+	SAFE_SYMLINK(cleanup, T_DIR, T_SYMLINK_DIR);
 
 	ret = mknod(T_DEV, S_IFCHR, makedev(1, 5));
 	if (ret == -1)
-- 
2.13.5


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

end of thread, other threads:[~2017-10-03 15:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-03 15:40 [LTP] [COMMITTED] [PATCH 01/13] Make use of SAFE_CREAT() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 02/13] Make use of SAFE_DUP() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 03/13] Make use of SAFE_MKDIR() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 04/13] Make use of SAFE_OPEN() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 05/13] Make use of SAFE_PIPE() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 06/13] Make use of SAFE_LINK() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 07/13] Make use of SAFE_SYMLINK() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 08/13] Make use of SAFE_SYSCONF() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 09/13] Make use of SAFE_WAIT() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 10/13] Make use of SAFE_WAITPID() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 11/13] Make use of SAFE_LSEEK() Cyril Hrubis
2017-10-03 15:40 ` [LTP] [COMMITTED] [PATCH 12/13] Make use of SAFE_SOCKET() Cyril Hrubis
2017-10-03 15:41 ` [LTP] [COMMITTED] [PATCH 13/13] syscalls/open11: Manual fixup Cyril Hrubis

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.