VirtualBox

source: kBuild/vendor/grep/current/gnulib-tests/test-pthread_sigmask1.c

Last change on this file was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1/* Test of pthread_sigmask in a single-threaded program.
2 Copyright (C) 2011-2021 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2011. */
18
19#include <config.h>
20
21#include <signal.h>
22
23#include "signature.h"
24SIGNATURE_CHECK (pthread_sigmask, int, (int, const sigset_t *, sigset_t *));
25
26#include <errno.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <unistd.h>
30
31#include "macros.h"
32
33#if !(defined _WIN32 && !defined __CYGWIN__)
34
35static volatile int sigint_occurred;
36
37static void
38sigint_handler (int sig)
39{
40 sigint_occurred++;
41}
42
43int
44main (int argc, char *argv[])
45{
46 sigset_t set;
47 int pid = getpid ();
48 char command[80];
49
50 signal (SIGINT, sigint_handler);
51
52 sigemptyset (&set);
53 sigaddset (&set, SIGINT);
54
55 /* Check error handling. */
56 ASSERT (pthread_sigmask (1729, &set, NULL) == EINVAL);
57
58 /* Block SIGINT. */
59 ASSERT (pthread_sigmask (SIG_BLOCK, &set, NULL) == 0);
60
61 /* Request a SIGINT signal from outside. */
62 sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, pid);
63 ASSERT (system (command) == 0);
64
65 /* Wait. */
66 sleep (2);
67
68 /* The signal should not have arrived yet, because it is blocked. */
69 ASSERT (sigint_occurred == 0);
70
71 /* Unblock SIGINT. */
72 ASSERT (pthread_sigmask (SIG_UNBLOCK, &set, NULL) == 0);
73
74 /* The signal should have arrived now, because POSIX says
75 "If there are any pending unblocked signals after the call to
76 pthread_sigmask(), at least one of those signals shall be delivered
77 before the call to pthread_sigmask() returns." */
78 ASSERT (sigint_occurred == 1);
79
80 return 0;
81}
82
83#else
84
85/* On native Windows, getpid() values and the arguments that are passed to
86 the (Cygwin?) 'kill' program are not necessarily related. */
87
88int
89main ()
90{
91 fputs ("Skipping test: native Windows platform\n", stderr);
92 return 77;
93}
94
95#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette