Skip to contentSkip to conversation

Make use of SAFE_CREAT()

PATCH New Cyril Hrubis 1 participant 13 messages Oct 3, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/13 Make use of SAFE_CREAT()

---
 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(-)
testcases/kernel/mem/vma/vma03.c +2 -3
index edad9f403..1db16eab1 100644
@@ -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;
testcases/kernel/syscalls/chroot/chroot03.c +1 -3
index de247b61c..b904e4ac9 100644
@@ -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,
testcases/kernel/syscalls/creat/creat01.c +1 -4
index 6b70be292..5d0ffc6a7 100644
@@ -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);
 
testcases/kernel/syscalls/fork/fork09.c +1 -4
index dedc8a41c..32bad89b3 100644
@@ -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);
testcases/kernel/syscalls/fork/fork10.c +2 -5
index 381ce6716..13db0555d 100644
@@ -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);
 
testcases/kernel/syscalls/getxattr/getxattr01.c +2 -4
index 8c09aa8a9..be410a536 100644
@@ -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) {
testcases/kernel/syscalls/getxattr/getxattr02.c +2 -3
index df75fb360..dca6b13be 100644
@@ -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)
testcases/kernel/syscalls/getxattr/getxattr03.c +2 -3
index 06c993415..b6ea14287 100644
@@ -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,
testcases/kernel/syscalls/open/open07.c +2 -6
index b941f4b81..f36db00cb 100644
@@ -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);
 
testcases/kernel/syscalls/open/open08.c +1 -3
index 6d1f37de0..d55d8e6bd 100644
@@ -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);
 
testcases/kernel/syscalls/open/open11.c +2 -4
index 6a3b0b8b1..c9239c6b4 100644
@@ -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);
testcases/kernel/syscalls/sendfile/sendfile08.c +2 -3
index 21b25868d..3212ca7cc 100644
@@ -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)
testcases/kernel/syscalls/setxattr/setxattr01.c +3 -7
index 478f99408..359991e3f 100644
@@ -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 */
testcases/kernel/syscalls/setxattr/setxattr02.c +2 -7
index b16ddce94..6d39236a3 100644
@@ -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);
testcases/kernel/syscalls/setxattr/setxattr03.c +4 -11
index c09211eeb..a2f6cbf36 100644
@@ -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);
Signature · 1 line
2.13.5
#1 lore raw

PATCH 2/13 Make use of SAFE_DUP()

---
 testcases/kernel/syscalls/fanotify/fanotify03.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify03.c +1 -4
index 1ab879843..ea5c02a7b 100644
@@ -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();
 
Signature · 1 line
2.13.5
#2 lore raw

PATCH 3/13 Make use of SAFE_MKDIR()

In reply to Cyril Hrubis
---
 testcases/kernel/syscalls/open/open11.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
testcases/kernel/syscalls/open/open11.c +1 -3
index c9239c6b4..9593671f2 100644
@@ -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)
Signature · 1 line
2.13.5
#3 lore raw

PATCH 4/13 Make use of SAFE_OPEN()

In reply to Cyril Hrubis
---
 .../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(-)
testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c +2 -3
index ae6a37429..90119e4ad 100644
@@ -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 */
 
testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c +2 -4
index 5fb3559c0..dc1546e88 100644
@@ -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 */
 
testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c +2 -3
index af4695f28..92b451793 100644
@@ -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 */
 
testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c +2 -3
index 9a7da9b36..c3348fb31 100644
@@ -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 */
 
testcases/kernel/controllers/cpuctl/cpuctl_test01.c +2 -5
index 385ee32fd..0cd587c3a 100644
@@ -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 */
testcases/kernel/controllers/cpuctl/cpuctl_test02.c +2 -5
index 6f5a0d9bf..d775a3e9f 100644
@@ -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 */
 
testcases/kernel/controllers/cpuctl/cpuctl_test03.c +2 -5
index 5076ab98a..8a80d6932 100644
@@ -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 */
 
testcases/kernel/controllers/cpuctl/cpuctl_test04.c +2 -5
index 0daca0ef5..bc67f41d9 100644
@@ -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 */
 
testcases/kernel/device-drivers/rtc/rtc01.c +2 -4
index b3c7e1df6..8a1f62ead 100644
@@ -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();
testcases/kernel/device-drivers/tbio/tbio_user/tbio.c +1 -5
index 4ab6b8344..be1420b98 100644
@@ -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 ");
 }
testcases/kernel/fs/ftest/ftest01.c +2 -5
index f7e320cd9..afad18095 100644
@@ -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);
testcases/kernel/fs/ftest/ftest03.c +2 -7
index 4d0fc803a..ed69e5736 100644
@@ -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);
testcases/kernel/fs/ftest/ftest04.c +3 -13
index ad26ece06..8eed84c74 100644
@@ -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();
testcases/kernel/fs/ftest/ftest05.c +2 -6
index b647f8b06..0bd32e4f6 100644
@@ -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);
testcases/kernel/fs/ftest/ftest07.c +2 -6
index f80f1922f..e5998b597 100644
@@ -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);
testcases/kernel/fs/ftest/ftest08.c +2 -6
index 1eec79d0d..5e462486a 100644
@@ -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);
 
testcases/kernel/logging/kmsg/kmsg01.c +7 -21
index 58b62d517..294d0a2d1 100644
@@ -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) {
testcases/kernel/mem/lib/mem.c +2 -6
index f4d12e088..dd82b08d2 100644
@@ -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);
 	}
testcases/kernel/mem/vma/vma03.c +1 -3
index 1db16eab1..4b34ab0a0 100644
@@ -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,
testcases/kernel/pty/hangup01.c +2 -3
index 5527bce98..aac3955c9 100644
@@ -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)
testcases/kernel/pty/ptem01.c +6 -20
index 8cfc02a89..68994d491 100644
@@ -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) {
testcases/kernel/pty/pty01.c +8 -28
index 283612d55..d390ce717 100644
@@ -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) {
testcases/kernel/syscalls/chmod/chmod01.c +1 -5
index 4428c9cd1..14002f23f 100644
@@ -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);
 
 }
testcases/kernel/syscalls/chmod/chmod07.c +1 -5
index 42272414a..6a3938840 100644
@@ -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);
 
testcases/kernel/syscalls/fadvise/posix_fadvise01.c +2 -6
index fd21f46fd..c12f0563c 100644
@@ -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);
 }
 
 /*
testcases/kernel/syscalls/fadvise/posix_fadvise03.c +2 -6
index 161074dfb..4aa3a8cd1 100644
@@ -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);
 }
 
 /*
testcases/kernel/syscalls/fallocate/fallocate01.c +3 -8
index 89ce9967d..02aa33100 100644
@@ -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);
 }
 
testcases/kernel/syscalls/fallocate/fallocate03.c +2 -3
index d73d07d5b..da2b3bfbe 100644
@@ -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 */
testcases/kernel/syscalls/fchmod/fchmod05.c +1 -6
index 0ab2f935d..7a270285a 100644
@@ -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);
 }
 
 /*
testcases/kernel/syscalls/fcntl/fcntl14.c +5 -9
index 5f99dc21e..ca68d0f98 100644
@@ -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");
testcases/kernel/syscalls/fcntl/fcntl16.c +2 -4
index c9defc68f..a77a81298 100644
@@ -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);
testcases/kernel/syscalls/flock/flock01.c +2 -3
index 06d89e3b9..a4133f140 100644
@@ -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);
 }
 
 /*
testcases/kernel/syscalls/flock/flock06.c +2 -3
index a35c8cf31..617eddf54 100644
@@ -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);
 }
 
testcases/kernel/syscalls/fork/fork04.c +2 -6
index d6b57d990..208636c6b 100644
@@ -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) {
testcases/kernel/syscalls/fork/fork10.c +1 -4
index 13db0555d..815eee1f6 100644
@@ -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)
testcases/kernel/syscalls/fstat/fstat01.c +2 -3
index 2ceed22b9..a5940c627 100644
@@ -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)
testcases/kernel/syscalls/fstat/fstat03.c +1 -4
index 1ff61c7ca..0fa62b847 100644
@@ -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);
 }
testcases/kernel/syscalls/fstat/fstat05.c +1 -4
index 29c253f48..8de5d070a 100644
@@ -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;
 }
testcases/kernel/syscalls/ftruncate/ftruncate01.c +2 -5
index 3bbae0a4f..3309af540 100644
@@ -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) {
testcases/kernel/syscalls/ftruncate/ftruncate02.c +2 -5
index 77f40e2ba..bc03075fc 100644
@@ -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) {
testcases/kernel/syscalls/inotify/inotify03.c +1 -5
index ae0c37e84..065890a25 100644
@@ -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) {
testcases/kernel/syscalls/ioctl/ioctl01.c +2 -3
index 79f27f664..ceb54aa65 100644
@@ -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++) {
 
testcases/kernel/syscalls/ioctl/ioctl02.c +2 -8
index 48e8eaa7f..a4b468e43 100644
@@ -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);
testcases/kernel/syscalls/mincore/mincore02.c +3 -5
index 713473acd..ab73f4bf5 100644
@@ -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) {
testcases/kernel/syscalls/mlock/mlock04.c +1 -3
index fb541ec08..8ac884583 100644
@@ -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);
 
testcases/kernel/syscalls/mprotect/mprotect01.c +2 -3
index d514b1352..7c4f10e02 100644
@@ -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();
 
testcases/kernel/syscalls/open/open05.c +1 -3
index 2577a34ff..051aec3b3 100644
@@ -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)
testcases/kernel/syscalls/open/open11.c +1 -3
index 9593671f2..6fa21b0bd 100644
@@ -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);
testcases/kernel/syscalls/readahead/readahead02.c +1 -3
index d21bb9c45..319dc91f5 100644
@@ -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();
testcases/kernel/syscalls/sendfile/sendfile08.c +2 -6
index 3212ca7cc..f9e2605c1 100644
@@ -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);
testcases/kernel/syscalls/setfsuid/setfsuid04.c +2 -3
index 6d02b1994..8585d6207 100644
@@ -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);
 
testcases/kernel/syscalls/setresuid/setresuid04.c +2 -3
index 4f17cb923..e197476ff 100644
@@ -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);
 
testcases/kernel/syscalls/setreuid/setreuid07.c +2 -4
index 30c392d36..ff222cd00 100644
@@ -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);
 
testcases/kernel/syscalls/setuid/setuid04.c +2 -3
index 5879e91fb..3459e6648 100644
@@ -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);
 
Signature · 1 line
2.13.5
#4 lore raw

PATCH 5/13 Make use of SAFE_PIPE()

In reply to Cyril Hrubis
---
 testcases/kernel/containers/pidns/pidns05.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
testcases/kernel/containers/pidns/pidns05.c +2 -3
index cdcf76a14..8462243cd 100644
@@ -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));
Signature · 1 line
2.13.5
#5 lore raw

PATCH 6/13 Make use of SAFE_LINK()

In reply to Cyril Hrubis
---
 testcases/kernel/syscalls/open/open11.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
testcases/kernel/syscalls/open/open11.c +1 -4
index 6fa21b0bd..b8cf7eb14 100644
@@ -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)
Signature · 1 line
2.13.5
#6 lore raw

PATCH 7/13 Make use of SAFE_SYMLINK()

In reply to Cyril Hrubis
---
 testcases/kernel/syscalls/open/open11.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/open/open11.c +2 -8
index b8cf7eb14..e56ef8203 100644
@@ -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)
Signature · 1 line
2.13.5
#7 lore raw

PATCH 8/13 Make use of SAFE_SYSCONF()

In reply to Cyril Hrubis
---
 testcases/kernel/syscalls/adjtimex/adjtimex02.c                   | 5 +----
 testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c | 5 ++---
 2 files changed, 3 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/adjtimex/adjtimex02.c +1 -4
index 577387d92..492225f19 100644
@@ -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;
 
testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c +2 -3
index 7e1146532..02f04b909 100644
@@ -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);
 }
 
Signature · 1 line
2.13.5
#8 lore raw

PATCH 9/13 Make use of SAFE_WAIT()

In reply to Cyril Hrubis
---
 testcases/kernel/syscalls/clone/clone01.c           | 6 ++----
 testcases/kernel/syscalls/exit_group/exit_group01.c | 5 ++---
 2 files changed, 4 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/clone/clone01.c +2 -4
index 855c1085d..e490b4e77 100644
@@ -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);
testcases/kernel/syscalls/exit_group/exit_group01.c +2 -3
index 3726b0652..d7bcbe9d6 100644
@@ -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");
Signature · 1 line
2.13.5
#9 lore raw

PATCH 10/13 Make use of SAFE_WAITPID()

In reply to Cyril Hrubis
---
 testcases/kernel/syscalls/fork/fork12.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/fork/fork12.c +2 -5
index 711fe9874..75278b012 100644
@@ -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)
Signature · 1 line
2.13.5
#10 lore raw

PATCH 11/13 Make use of SAFE_LSEEK()

In reply to Cyril Hrubis
---
 testcases/kernel/syscalls/sendfile/sendfile08.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
testcases/kernel/syscalls/sendfile/sendfile08.c +1 -4
index f9e2605c1..a29632712 100644
@@ -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",
Signature · 1 line
2.13.5
#11 lore raw

PATCH 12/13 Make use of SAFE_SOCKET()

In reply to Cyril Hrubis
---
 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(-)
testcases/kernel/syscalls/accept/accept01.c +2 -5
index 5a4966a0c..b50056520 100644
@@ -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);
 }
testcases/kernel/syscalls/bind/bind01.c +3 -4
index 6a3bc5065..868749368 100644
@@ -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)
testcases/kernel/syscalls/connect/connect01.c +2 -3
index d65af4ae0..2be83cfbb 100644
@@ -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)
testcases/kernel/syscalls/getsockname/getsockname01.c +2 -5
index c46b1763a..cce1543fd 100644
@@ -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);
 }
testcases/kernel/syscalls/getsockopt/getsockopt01.c +2 -5
index b39cfefb5..d1692fcd3 100644
@@ -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);
testcases/kernel/syscalls/listen/listen01.c +3 -5
index e421bb46d..d33f209c3 100644
@@ -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)
testcases/kernel/syscalls/recv/recv01.c +2 -3
index 3345e51e6..2f09864a5 100644
@@ -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");
testcases/kernel/syscalls/recvfrom/recvfrom01.c +2 -3
index e07879b06..853d1cb9f 100644
@@ -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");
testcases/kernel/syscalls/recvmsg/recvmsg01.c +2 -3
index 5bdc60cd9..13bcaa4e0 100644
@@ -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,
testcases/kernel/syscalls/send/send01.c +2 -3
index 31e8c1758..2e0ae2177 100644
@@ -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));
 }
 
testcases/kernel/syscalls/sendmsg/sendmsg01.c +6 -15
index d7f7b757c..36f6914ff 100644
@@ -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));
 
testcases/kernel/syscalls/sendto/sendto01.c +4 -6
index 5304da691..6fe0274ee 100644
@@ -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);
 }
testcases/kernel/syscalls/setsockopt/setsockopt01.c +2 -5
index 36988854b..743c6be14 100644
@@ -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));
 }
 
testcases/kernel/syscalls/sockioctl/sockioctl01.c +4 -10
index 79c53e042..486236af9 100644
@@ -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;
 }
Signature · 1 line
2.13.5
#12 lore raw

PATCH 13/13 syscalls/open11: Manual fixup

In reply to Cyril Hrubis

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

---
 testcases/kernel/syscalls/open/open11.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/open/open11.c +4 -7
index e56ef8203..78002f37d 100644
@@ -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)
Signature · 1 line
2.13.5