-/* Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2003-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#include <aio.h>
#include <errno.h>
puts ("early cancellation succeeded");
+ if (ap == &a2)
+ {
+ /* The aio_read(&a) was not canceled because the read request was
+ already in progress. In the meanwhile aio_write(ap) wrote something
+ to the pipe and the read request either has already been finished or
+ is able to read the requested byte.
+ Wait for the read request before returning from this function because
+ the return value and error code from the read syscall will be written
+ to the struct aiocb a, which lies on the stack of this function.
+ Otherwise the stack from subsequent function calls - e.g. _dl_fini -
+ will be corrupted, which can lead to undefined behaviour like a
+ segmentation fault. */
+ const struct aiocb *l[1] = { &a };
+ TEMP_FAILURE_RETRY (aio_suspend(l, 1, NULL));
+ }
+
return 0;
}