1 /* Test for completion signal handling.
2 Copyright (C) 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 /* We might need a bit longer timeout. */
29 #define TIMEOUT 10 /* sec */
33 volatile sig_atomic_t flag
;
37 sighandler (const int signo
)
53 printf ("signal handler received wrong signal, flag is %d\n", flag
);
66 do_test (int argc
, char *argv
[])
68 char name
[] = "/tmp/aio4.XXXXXX";
72 static const char buf
[] = "Hello World\n";
73 struct aioinit init
= {10, 20, 0};
79 printf ("RT signals not supported.\n");
83 /* Select a signal from the middle of the available choices... */
84 my_signo
= (SIGRTMAX
+ SIGRTMIN
) / 2;
89 printf ("cannot open temp name: %m\n");
95 /* Test also aio_init. */
101 int sz
= set_o_direct (fd
);
104 int err
= posix_memalign (&p
, sz
, sz
);
108 printf ("cannot allocate memory: %m\n");
111 memcpy (p
, buf
, sizeof (buf
) - 1);
112 memset (p
+ sizeof (buf
) - 1, ' ', sz
- sizeof (buf
) + 1);
113 printf ("Using O_DIRECT with block size %d\n", sz
);
118 sz
= sizeof (buf
) - 1;
122 cb
.aio_lio_opcode
= LIO_WRITE
;
127 cb
.aio_sigevent
.sigev_notify
= SIGEV_SIGNAL
;
128 cb
.aio_sigevent
.sigev_notify_function
= NULL
;
129 cb
.aio_sigevent
.sigev_notify_attributes
= NULL
;
130 cb
.aio_sigevent
.sigev_signo
= my_signo
;
131 cb
.aio_sigevent
.sigev_value
.sival_ptr
= NULL
;
133 ev
.sigev_notify
= SIGEV_SIGNAL
;
134 ev
.sigev_notify_function
= NULL
;
135 ev
.sigev_notify_attributes
= NULL
;
136 ev
.sigev_signo
= my_signo
;
138 sa
.sa_handler
= sighandler
;
139 sigemptyset (&sa
.sa_mask
);
140 sa
.sa_flags
= SA_RESTART
;
142 if (sigaction (my_signo
, &sa
, NULL
) < 0)
144 printf ("sigaction failed: %m\n");
149 /* First use aio_write. */
150 if (aio_write (arr
[0]) < 0)
154 puts ("no aio support in this configuration");
157 printf ("aio_write failed: %m\n");
164 puts ("aio_write OK");
167 /* Again with lio_listio. */
168 if (lio_listio (LIO_NOWAIT
, arr
, 1, &ev
) < 0)
170 printf ("lio_listio failed: %m\n");
182 #include "../test-skeleton.c"