1/* Test for notification mechanism in lio_listio.
2 Copyright (C) 2000-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <aio.h>
20#include <signal.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <unistd.h>
24#include <errno.h>
25#include <pthread.h>
26
27
28static pthread_barrier_t b;
29
30
31static void
32thrfct (sigval_t arg)
33{
34 int e = pthread_barrier_wait (barrier: &b);
35 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
36 {
37 puts (s: "thread: barrier_wait failed");
38 exit (1);
39 }
40}
41
42
43static int
44do_test (int argc, char *argv[])
45{
46 char name[] = "/tmp/aio2.XXXXXX";
47 int fd;
48 struct aiocb *arr[1];
49 struct aiocb cb;
50 static const char buf[] = "Hello World\n";
51
52 fd = mkstemp (template: name);
53 if (fd == -1)
54 {
55 printf (format: "cannot open temp name: %m\n");
56 return 1;
57 }
58
59 unlink (name: name);
60
61 if (pthread_barrier_init (barrier: &b, NULL, count: 2) != 0)
62 {
63 puts (s: "barrier_init failed");
64 return 1;
65 }
66
67 arr[0] = &cb;
68
69 cb.aio_fildes = fd;
70 cb.aio_lio_opcode = LIO_WRITE;
71 cb.aio_reqprio = 0;
72 cb.aio_buf = (void *) buf;
73 cb.aio_nbytes = sizeof (buf) - 1;
74 cb.aio_offset = 0;
75 cb.aio_sigevent.sigev_notify = SIGEV_THREAD;
76 cb.aio_sigevent.sigev_notify_function = thrfct;
77 cb.aio_sigevent.sigev_notify_attributes = NULL;
78 cb.aio_sigevent.sigev_value.sival_ptr = NULL;
79
80 if (lio_listio (LIO_WAIT, list: arr, nent: 1, NULL) < 0)
81 {
82 if (errno == ENOSYS)
83 {
84 puts (s: "no aio support in this configuration");
85 return 0;
86 }
87 printf (format: "lio_listio failed: %m\n");
88 return 1;
89 }
90
91 puts (s: "lio_listio returned");
92
93 int e = pthread_barrier_wait (barrier: &b);
94 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
95 {
96 puts (s: "barrier_wait failed");
97 return 1;
98 }
99
100 puts (s: "all OK");
101
102 return 0;
103}
104
105#include "../test-skeleton.c"
106

source code of glibc/rt/tst-aio2.c