Fixed multi-archness of the `demo' script.
[libobjid.git] / tst-resethand.c
1 /* $Id$ */
2 /* Copyright (C) 2003 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
20
21 #include <errno.h>
22 #include <error.h>
23 #include <signal.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26
27 volatile int count;
28
29 void
30 sh (int sig)
31 {
32   ++count;
33 }
34
35 int
36 main (void)
37 {
38   struct sigaction sa;
39   sa.sa_handler = sh;
40   sigemptyset (&sa.sa_mask);
41   sa.sa_flags = SA_RESETHAND;
42   sigaction (SIGCHLD, NULL, NULL);
43   if (sigaction (SIGCHLD, &sa, NULL) < 0)
44     {
45       printf ("sigaction set failed: %m\n");
46       exit (1);
47     }
48   if (raise (SIGCHLD) < 0)
49     {
50       printf ("first raise failed: %m\n");
51       exit (1);
52     }
53   if (raise (SIGCHLD) < 0)
54     {
55       printf ("second raise failed: %m\n");
56       exit (1);
57     }
58   if (count != 1)
59     {
60       printf ("signal handler not called 1 times\n");
61       exit (1);
62     }
63   if (sigaction (SIGCHLD, NULL, &sa) < 0)
64     {
65       printf ("sigaction get failed: %m\n");
66       exit (1);
67     }
68   if (sa.sa_handler != SIG_DFL)
69     {
70       printf ("sigaction retrieved sa_handler: %p\n", sa.sa_handler);
71       exit (1);
72     }
73   /* `SA_RESTORER' gets set on `glibc-2.3.4-2.25.i686'
74      but not on `glibc-2.5-7.i686'.  */
75 #ifndef SA_RESTORER
76 #define SA_RESTORER 0x04000000
77 #endif
78   if ((sa.sa_flags & ~SA_RESTORER) != SA_RESETHAND)
79     {
80       printf ("sigaction retrieved sa_flags: 0x%x\n", sa.sa_flags);
81       exit (1);
82     }
83   exit (0);
84 }