1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
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, see
17 <http://www.gnu.org/licenses/>. */
27 #include <sys/select.h>
42 static void __attribute__ ((noinline
))
43 clobber_lots_of_regs (void)
45 #define X1(n) long r##n = 10##n; __asm __volatile ("" : "+r" (r##n));
46 #define X2(n) X1(n##0) X1(n##1) X1(n##2) X1(n##3) X1(n##4)
47 #define X3(n) X2(n##0) X2(n##1) X2(n##2) X2(n##3) X2(n##4)
48 X3(0) X3(1) X3(2) X3(3) X3(4)
50 #define X1(n) __asm __volatile ("" : : "r" (r##n));
51 X3(0) X3(1) X3(2) X3(3) X3(4)
67 error (EXIT_FAILURE
, errno
, "couldn't create pipe");
69 rc
= pthread_create (&th
, NULL
, tf
, NULL
);
71 error (EXIT_FAILURE
, rc
, "couldn't create thread");
73 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
76 error (0, rc
, "1st pthread_setcanceltype failed");
79 if (old
!= PTHREAD_CANCEL_DEFERRED
&& old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
81 error (0, 0, "1st pthread_setcanceltype returned invalid value %d",
86 clobber_lots_of_regs ();
89 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
92 error (0, rc
, "pthread_setcanceltype after close failed");
95 if (old
!= PTHREAD_CANCEL_DEFERRED
)
97 error (0, 0, "pthread_setcanceltype after close returned invalid value %d",
102 clobber_lots_of_regs ();
105 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
108 error (0, rc
, "pthread_setcanceltype after 2nd close failed");
111 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
113 error (0, 0, "pthread_setcanceltype after 2nd close returned invalid value %d",
118 struct sigaction sa
= { .sa_handler
= handler
, .sa_flags
= 0 };
119 sigemptyset (&sa
.sa_mask
);
120 sigaction (SIGALRM
, &sa
, NULL
);
123 it
.it_value
.tv_sec
= 1;
124 it
.it_value
.tv_usec
= 0;
125 it
.it_interval
= it
.it_value
;
126 setitimer (ITIMER_REAL
, &it
, NULL
);
128 clobber_lots_of_regs ();
131 memset (&it
, 0, sizeof (it
));
132 setitimer (ITIMER_REAL
, &it
, NULL
);
134 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
137 error (0, rc
, "pthread_setcanceltype after pause failed");
140 if (old
!= PTHREAD_CANCEL_DEFERRED
)
142 error (0, 0, "pthread_setcanceltype after pause returned invalid value %d",
147 it
.it_value
.tv_sec
= 1;
148 it
.it_value
.tv_usec
= 0;
149 it
.it_interval
= it
.it_value
;
150 setitimer (ITIMER_REAL
, &it
, NULL
);
152 clobber_lots_of_regs ();
155 memset (&it
, 0, sizeof (it
));
156 setitimer (ITIMER_REAL
, &it
, NULL
);
158 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
161 error (0, rc
, "pthread_setcanceltype after 2nd pause failed");
164 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
166 error (0, 0, "pthread_setcanceltype after 2nd pause returned invalid value %d",
171 char fname
[] = "/tmp/tst-cancel19-dir-XXXXXX\0foo/bar";
172 char *enddir
= strchr (fname
, '\0');
173 if (mkdtemp (fname
) == NULL
)
175 error (0, errno
, "mkdtemp failed");
180 clobber_lots_of_regs ();
183 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
186 error (0, rc
, "pthread_setcanceltype after creat failed");
189 if (old
!= PTHREAD_CANCEL_DEFERRED
)
191 error (0, 0, "pthread_setcanceltype after creat returned invalid value %d",
196 clobber_lots_of_regs ();
199 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
202 error (0, rc
, "pthread_setcanceltype after 2nd creat failed");
205 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
207 error (0, 0, "pthread_setcanceltype after 2nd creat returned invalid value %d",
212 clobber_lots_of_regs ();
213 open (fname
, O_CREAT
, 0400);
215 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
218 error (0, rc
, "pthread_setcanceltype after open failed");
221 if (old
!= PTHREAD_CANCEL_DEFERRED
)
223 error (0, 0, "pthread_setcanceltype after open returned invalid value %d",
228 clobber_lots_of_regs ();
229 open (fname
, O_CREAT
, 0400);
231 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
234 error (0, rc
, "pthread_setcanceltype after 2nd open failed");
237 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
239 error (0, 0, "pthread_setcanceltype after 2nd open returned invalid value %d",
247 clobber_lots_of_regs ();
248 select (-1, NULL
, NULL
, NULL
, NULL
);
250 rc
= pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS
, &old
);
253 error (0, rc
, "pthread_setcanceltype after select failed");
256 if (old
!= PTHREAD_CANCEL_DEFERRED
)
258 error (0, 0, "pthread_setcanceltype after select returned invalid value %d",
263 clobber_lots_of_regs ();
264 select (-1, NULL
, NULL
, NULL
, NULL
);
266 rc
= pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &old
);
269 error (0, rc
, "pthread_setcanceltype after 2nd select failed");
272 if (old
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
274 error (0, 0, "pthread_setcanceltype after 2nd select returned invalid value %d",
279 pthread_join (th
, NULL
);
285 #define TEST_FUNCTION do_test ()
286 #include "../test-skeleton.c"