[PATCH 7/8] sigwaittest.c: Suppress warning

Cheng-Yang Chou
2025-07-12T13:42:49Z

src/sigwaittest/sigwaittest.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
index 026cc81..3944b54 100644
--- a/src/sigwaittest/sigwaittest.c
+++ b/src/sigwaittest/sigwaittest.c
@@ -72,6 +72,7 @@ void *semathread(void *param)
cpu_set_t mask;
int policy = SCHED_FIFO;
struct sched_param schedp;
+ int ret;

memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = par->priority;
@@ -168,7 +169,10 @@ void *semathread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n",
@@ -489,7 +493,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "Could not create shared memory\n");
return 1;
}
- ftruncate(shmem, totalsize);
+ if (ftruncate(shmem, totalsize) == -1) {
+ perror("ftruncate failed");
+ close(shmem);
+ shm_unlink("/sigwaittest");
+ return 1;
+ }
param = mmap(0, totalsize, PROT_READ|PROT_WRITE, MAP_SHARED,
shmem, 0);
if (param == MAP_FAILED) {
--
2.48.1