From: Joerg Vehlow <lkml@jv-coder.de>
To: ltp@lists.linux.it, chrubis@suse.cz
Cc: Joerg Vehlow <joerg.vehlow@aox-tech.de>
Subject: [LTP] [PATCH 4/4] posix/interface/conformance: Fix all unused-result warnings
Date: Mon, 22 Nov 2021 08:26:01 +0100 [thread overview]
Message-ID: <20211122072601.4096577-4-lkml@jv-coder.de> (raw)
In-Reply-To: <20211122072601.4096577-1-lkml@jv-coder.de>
From: Joerg Vehlow <joerg.vehlow@aox-tech.de>
On error the failed function is printed and PTS_UNRESOLVED returned.
Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
---
.../conformance/interfaces/clock_getcpuclockid/5-1.c | 10 ++++++++--
.../conformance/interfaces/kill/2-2.c | 5 ++++-
.../conformance/interfaces/kill/3-1.c | 5 ++++-
.../conformance/interfaces/mmap/18-1.c | 8 ++++++--
.../conformance/interfaces/mq_open/16-1.c | 8 ++++++--
.../conformance/interfaces/sched_setparam/2-1.c | 5 ++++-
.../conformance/interfaces/sched_setparam/2-2.c | 5 ++++-
.../conformance/interfaces/sched_yield/1-1.c | 9 ++++++---
.../conformance/interfaces/shm_open/26-2.c | 9 ++++++---
.../conformance/interfaces/shm_unlink/8-1.c | 3 ++-
.../conformance/interfaces/shm_unlink/9-1.c | 6 ++++--
.../conformance/interfaces/sigaltstack/9-1.c | 5 ++++-
testcases/open_posix_testsuite/include/affinity.h | 3 ++-
13 files changed, 60 insertions(+), 21 deletions(-)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c
index 0046d5066..2e9961a19 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c
@@ -35,8 +35,14 @@ int main(void)
pwd = getpwnam("nobody");
if (pwd != NULL) {
- setgid(pwd->pw_gid);
- setuid(pwd->pw_uid);
+ if (setgid(pwd->pw_gid)) {
+ perror("setgid");
+ return PTS_UNRESOLVED;
+ }
+ if (setuid(pwd->pw_uid)) {
+ perror("setuid");
+ return PTS_UNRESOLVED;
+ }
}
}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c
index dd566831c..1cd3b2fdc 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c
@@ -55,7 +55,10 @@ int main(void)
*/
/* this is added incase user is root. If user is normal user, then it
* has no effect on the tests */
- setuid(1);
+ if (setuid(1)) {
+ perror("setuid");
+ return PTS_UNRESOLVED;
+ }
if (-1 == kill(1, 0)) {
if (EPERM == errno) {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c
index a5999332b..70a8c590c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c
@@ -23,7 +23,10 @@ int main(void)
{
/* this is added incase user is root. If user is normal user, then it
* has no effect on the tests */
- setuid(1);
+ if (setuid(1)) {
+ perror("setuid");
+ return PTS_UNRESOLVED;
+ }
if (kill(1, 0) != -1) {
printf
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c
index 113d01b8c..9d02a074d 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c
@@ -124,14 +124,18 @@ int main(void)
* EAGAIN:
* Lock all the memory by mlockall().
* Set resource limit setrlimit()
- * Change the user to non-root then only setrmilit is applicable.
+ * Change the user to non-root then only setrlimit is applicable.
*/
pa = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (pa == MAP_FAILED && errno == EAGAIN) {
printf("Got EAGAIN: %s\n", strerror(errno));
printf("Test PASSED\n");
/* Change user to root */
- seteuid(0);
+ if (seteuid(0)) {
+ close(fd);
+ perror("seteuid");
+ return PTS_UNRESOLVED;
+ }
close(fd);
munmap(pa, len);
return PTS_PASS;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
index eee55a748..ecbfb0f79 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
@@ -61,10 +61,14 @@ int main(void)
printf(TNAME " Error at open(): %s\n", strerror(errno));
return PTS_UNRESOLVED;
}
- /* file is empty now, will cause "Bus error" */
- write(fd, fname, sizeof(int));
unlink(fname);
+ if (ftruncate(fd, sizeof(int))) {
+ perror("ftruncate");
+ close(fd);
+ return PTS_UNRESOLVED;
+ }
+
pa = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (pa == MAP_FAILED) {
printf(TNAME " Error at mmap: %s\n", strerror(errno));
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c
index da56343d0..fb19ff6a4 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c
@@ -125,7 +125,10 @@ int main(void)
return PTS_UNRESOLVED;
}
- pipe(the_pipe);
+ if (pipe(the_pipe)) {
+ perror("pipe");
+ return PTS_UNRESOLVED;
+ }
for (i = 0; i < nb_child; i++) {
child_pid[i] = fork();
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c
index 6f10618b6..6c68120c3 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c
@@ -129,7 +129,10 @@ int main(void)
return PTS_UNRESOLVED;
}
- pipe(the_pipe);
+ if (pipe(the_pipe)) {
+ perror("pipe");
+ return PTS_UNRESOLVED;
+ }
for (i = 0; i < nb_child; i++) {
child_pid[i] = fork();
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
index 602733e60..2e1e3197a 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
@@ -45,18 +45,21 @@ static int child_busy(int fd)
alarm(4);
/* Tell the parent we're ready */
- write(fd, "go", 2);
+ if (write(fd, "go", 2) == -1) {
+ perror("write");
+ exit(PTS_UNRESOLVED);
+ }
for (;;) {
rc = sched_yield();
if (rc) {
ERR_LOG("child: sched_yield", rc);
- exit(1);
+ exit(PTS_FAIL);
}
}
/* should not get here */
- exit(2);
+ exit(PTS_UNRESOLVED);
}
int main(void)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c b/testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c
index 215d3e1af..69edeae85 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c
@@ -95,19 +95,22 @@ int main(void)
fd = shm_open(SHM_NAME, O_RDWR | O_TRUNC, 0);
if (fd == -1) {
perror("An error occurs when calling shm_open()");
- seteuid(getuid());
+ if (seteuid(getuid()))
+ perror("seteuid");
shm_unlink(SHM_NAME);
return PTS_UNRESOLVED;
}
if (fstat(fd, &stat_buf) != 0) {
perror("An error occurs when calling fstat()");
- seteuid(getuid());
+ if (seteuid(getuid()))
+ perror("seteuid");
shm_unlink(SHM_NAME);
return PTS_UNRESOLVED;
}
- seteuid(getuid());
+ if (seteuid(getuid()))
+ perror("seteuid");
shm_unlink(SHM_NAME);
if (stat_buf.st_uid == old_uid && stat_buf.st_gid == old_gid) {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c b/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c
index ed18cf213..d67d2fbe2 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c
@@ -86,7 +86,8 @@ int main(void)
return PTS_UNRESOLVED;
}
- seteuid(getuid());
+ if (seteuid(getuid()))
+ perror("seteuid");
if (fstat(fd, &stat_after) != 0) {
perror("An error occurs when calling fstat()");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c
index 5c52465c8..9ef4b0c65 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c
@@ -69,12 +69,14 @@ int main(void)
result = shm_unlink(SHM_NAME);
if (result == -1 && errno == EACCES) {
printf("Test PASSED\n");
- seteuid(getuid());
+ if (seteuid(getuid()))
+ perror("seteuid");
shm_unlink(SHM_NAME);
return PTS_PASS;
} else if (result == -1) {
perror("Unexpected error");
- seteuid(getuid());
+ if (seteuid(getuid()))
+ perror("seteuid");
shm_unlink(SHM_NAME);
return PTS_FAIL;
}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c
index 0236a752e..e9f9a8f71 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c
@@ -59,7 +59,10 @@ int main(int argc, char *argv[])
/* Get abs path if needed and exec ourself */
if (*argv[0] != '/') {
- getcwd(path, PATH_MAX);
+ if (getcwd(path, PATH_MAX) == NULL) {
+ perror("getcwd");
+ exit(PTS_UNRESOLVED);
+ }
strcat(path, "/");
strcat(path, argv[0]);
} else {
diff --git a/testcases/open_posix_testsuite/include/affinity.h b/testcases/open_posix_testsuite/include/affinity.h
index 86fb4f4c6..da7e6837e 100644
--- a/testcases/open_posix_testsuite/include/affinity.h
+++ b/testcases/open_posix_testsuite/include/affinity.h
@@ -46,7 +46,8 @@ static int get_online_cpu_from_sysfs(void)
f = fopen("/sys/devices/system/cpu/online", "r");
if (!f)
return -1;
- fscanf(f, "%d", &cpu);
+ if (!fscanf(f, "%d", &cpu))
+ cpu = -1;
fclose(f);
return cpu;
--
2.25.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2021-11-22 7:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-22 7:25 [LTP] [PATCH 1/4] posix/conformance/interfaces/fork/7-1: Fix test Joerg Vehlow
2021-11-22 7:25 ` [LTP] [PATCH 2/4] posix/conformance/interfaces: Fix all unused variable warnings Joerg Vehlow
2021-11-22 7:26 ` [LTP] [PATCH 3/4] posix/conformance/interfaces: Fix unused result for write Joerg Vehlow
2021-11-22 7:26 ` Joerg Vehlow [this message]
2021-11-22 9:41 ` [LTP] [PATCH 1/4] posix/conformance/interfaces/fork/7-1: Fix test Cyril Hrubis
2021-11-22 9:50 ` Joerg Vehlow
2021-11-22 10:32 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211122072601.4096577-4-lkml@jv-coder.de \
--to=lkml@jv-coder.de \
--cc=chrubis@suse.cz \
--cc=joerg.vehlow@aox-tech.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.