Skip to content

Commit a7151a8

Browse files
committed
selftests/sched: fix warn_unused_result build warns
Fix the following warns by adding return check and error handling. gcc -O2 -Wall -g -I./ -isystem .../tools/testing/selftests/../../../usr/include -Wl,-rpath=./ cs_prctl_test.c -lpthread -o .../tools/testing/selftests/sched/cs_prctl_test cs_prctl_test.c: In function ‘create_processes’: cs_prctl_test.c:187:17: warning: ignoring return value of ‘read’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 187 | read(proc[i].pfd[0], &proc[i].thr_tids, sizeof(int) * proc[i].num_threads); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cs_prctl_test.c: In function ‘child_func_process’: cs_prctl_test.c:159:9: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 159 | write(ca->pfd[1], &ca->thr_tids, sizeof(int) * ca->num_threads); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Shuah Khan <[email protected]>
1 parent 6e81461 commit a7151a8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tools/testing/selftests/sched/cs_prctl_test.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sys/prctl.h>
2828
#include <unistd.h>
2929
#include <time.h>
30+
#include <errno.h>
3031
#include <stdio.h>
3132
#include <stdlib.h>
3233
#include <string.h>
@@ -151,12 +152,17 @@ static void create_threads(int num_threads, int thr_tids[])
151152
static int child_func_process(void *arg)
152153
{
153154
struct child_args *ca = (struct child_args *)arg;
155+
int ret;
154156

155157
close(ca->pfd[0]);
156158

157159
create_threads(ca->num_threads, ca->thr_tids);
158160

159-
write(ca->pfd[1], &ca->thr_tids, sizeof(int) * ca->num_threads);
161+
ret = write(ca->pfd[1], &ca->thr_tids, sizeof(int) * ca->num_threads);
162+
if (ret == -1)
163+
printf("write failed on pfd[%d] - error (%s)\n",
164+
ca->pfd[1], strerror(errno));
165+
160166
close(ca->pfd[1]);
161167

162168
while (1)
@@ -169,7 +175,7 @@ static unsigned char child_func_process_stack[STACK_SIZE];
169175
void create_processes(int num_processes, int num_threads, struct child_args proc[])
170176
{
171177
pid_t cpid;
172-
int i;
178+
int i, ret;
173179

174180
for (i = 0; i < num_processes; ++i) {
175181
proc[i].num_threads = num_threads;
@@ -184,7 +190,10 @@ void create_processes(int num_processes, int num_threads, struct child_args proc
184190
}
185191

186192
for (i = 0; i < num_processes; ++i) {
187-
read(proc[i].pfd[0], &proc[i].thr_tids, sizeof(int) * proc[i].num_threads);
193+
ret = read(proc[i].pfd[0], &proc[i].thr_tids, sizeof(int) * proc[i].num_threads);
194+
if (ret == -1)
195+
printf("read failed on proc[%d].pfd[0] error (%s)\n",
196+
i, strerror(errno));
188197
close(proc[i].pfd[0]);
189198
}
190199
}

0 commit comments

Comments
 (0)