Skip to content

Commit 1faa387

Browse files
jstancekmetan-ucw
authored andcommitted
aio_cancel: wait for requests which are already in progress
If request is already in progress, wait for it to complete, so it doesn't race with exit of testcase (aiocb is allocated on main's stack), to avoid aio_cancel_1-1 and 2-1 sporadically crashing. For example: Core was generated by `./aio_cancel_2-1.run-test '. Program terminated with signal 11, Segmentation fault. (gdb) bt #0 0x00003fffa6e81158 in __GI__exit (status=0) #1 0x00003fffa6df3054 in __run_exit_handlers (...) #2 0x00003fffa6df3134 in __GI_exit (status=<optimized out>) #3 0x00003fffa6dd4588 in generic_start_main (main=0x10000bbc ...) #4 0x00003fffa6dd4774 in __libc_start_main (...) #5 0x0000000000000000 in ?? () Signed-off-by: Jan Stancek <[email protected]> Acked-by: Cyril Hrubis <[email protected]>
1 parent 94ccba8 commit 1faa387

File tree

2 files changed

+16
-4
lines changed
  • testcases/open_posix_testsuite/conformance/interfaces/aio_cancel

2 files changed

+16
-4
lines changed

testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/1-1.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(void)
3939
char tmpfname[256];
4040
#define BUF_SIZE 1024
4141
char buf[BUF_SIZE];
42-
int fd;
42+
int fd, err;
4343
struct aiocb aiocb;
4444

4545
if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
@@ -67,9 +67,15 @@ int main(void)
6767
return PTS_FAIL;
6868
}
6969

70-
if (aio_cancel(fd, &aiocb) == -1) {
70+
switch (aio_cancel(fd, &aiocb)) {
71+
case -1:
7172
printf(TNAME " Error at aio_cancel(): %s\n", strerror(errno));
7273
return PTS_FAIL;
74+
case AIO_NOTCANCELED:
75+
do {
76+
usleep(10000);
77+
err = aio_error(&aiocb);
78+
} while (err == EINPROGRESS);
7379
}
7480

7581
close(fd);

testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/2-1.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int main(void)
4444
char tmpfname[256];
4545
#define BUF_SIZE 1024
4646
char buf[BUF_SIZE];
47-
int fd;
47+
int fd, err;
4848
struct aiocb aiocb;
4949

5050
if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
@@ -72,9 +72,15 @@ int main(void)
7272
return PTS_FAIL;
7373
}
7474

75-
if (aio_cancel(fd, NULL) == -1) {
75+
switch (aio_cancel(fd, NULL)) {
76+
case -1:
7677
printf(TNAME " Error at aio_cancel(): %s\n", strerror(errno));
7778
return PTS_FAIL;
79+
case AIO_NOTCANCELED:
80+
do {
81+
usleep(10000);
82+
err = aio_error(&aiocb);
83+
} while (err == EINPROGRESS);
7884
}
7985

8086
close(fd);

0 commit comments

Comments
 (0)