Skip to content

Commit 4b67c51

Browse files
Jakub Kicinskidavem330
authored andcommitted
selftests: bpf: test_sockmap: handle file creation failures gracefully
test_sockmap creates a temporary file to use for sendpage. this may fail for various reasons. Handle the error rather than segfault. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Simon Horman <simon.horman@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c5daa6c commit 4b67c51

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎tools/testing/selftests/bpf/test_sockmap.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,22 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt,
332332
int i, fp;
333333

334334
file = fopen(".sendpage_tst.tmp", "w+");
335+
if (!file) {
336+
perror("create file for sendpage");
337+
return 1;
338+
}
335339
for (i = 0; i < iov_length * cnt; i++, k++)
336340
fwrite(&k, sizeof(char), 1, file);
337341
fflush(file);
338342
fseek(file, 0, SEEK_SET);
339343
fclose(file);
340344

341345
fp = open(".sendpage_tst.tmp", O_RDONLY);
346+
if (fp < 0) {
347+
perror("reopen file for sendpage");
348+
return 1;
349+
}
350+
342351
clock_gettime(CLOCK_MONOTONIC, &s->start);
343352
for (i = 0; i < cnt; i++) {
344353
int sent = sendfile(fd, fp, NULL, iov_length);

0 commit comments

Comments
 (0)