os: add OsBlockSIGIO and OsReleaseSIGIO
Let the dix be in charge of changing the sigprocmask so we only have one entity that changes it. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
9f1edced9a
commit
6bf356ef28
|
@ -333,6 +333,12 @@ OsBlockSignals(void);
|
||||||
extern _X_EXPORT void
|
extern _X_EXPORT void
|
||||||
OsReleaseSignals(void);
|
OsReleaseSignals(void);
|
||||||
|
|
||||||
|
extern _X_EXPORT int
|
||||||
|
OsBlockSIGIO(void);
|
||||||
|
|
||||||
|
extern _X_EXPORT void
|
||||||
|
OsReleaseSIGIO(void);
|
||||||
|
|
||||||
extern _X_EXPORT void
|
extern _X_EXPORT void
|
||||||
OsAbort(void)
|
OsAbort(void)
|
||||||
_X_NORETURN;
|
_X_NORETURN;
|
||||||
|
|
54
os/utils.c
54
os/utils.c
|
@ -1165,14 +1165,14 @@ OsBlockSignals(void)
|
||||||
if (BlockedSignalCount++ == 0) {
|
if (BlockedSignalCount++ == 0) {
|
||||||
sigset_t set;
|
sigset_t set;
|
||||||
|
|
||||||
|
#ifdef SIGIO
|
||||||
|
OsBlockSIGIO();
|
||||||
|
#endif
|
||||||
sigemptyset(&set);
|
sigemptyset(&set);
|
||||||
sigaddset(&set, SIGALRM);
|
sigaddset(&set, SIGALRM);
|
||||||
sigaddset(&set, SIGVTALRM);
|
sigaddset(&set, SIGVTALRM);
|
||||||
#ifdef SIGWINCH
|
#ifdef SIGWINCH
|
||||||
sigaddset(&set, SIGWINCH);
|
sigaddset(&set, SIGWINCH);
|
||||||
#endif
|
|
||||||
#ifdef SIGIO
|
|
||||||
sigaddset(&set, SIGIO);
|
|
||||||
#endif
|
#endif
|
||||||
sigaddset(&set, SIGTSTP);
|
sigaddset(&set, SIGTSTP);
|
||||||
sigaddset(&set, SIGTTIN);
|
sigaddset(&set, SIGTTIN);
|
||||||
|
@ -1183,12 +1183,60 @@ OsBlockSignals(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SIG_BLOCK
|
||||||
|
static sig_atomic_t sigio_blocked;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns zero if this call caused SIGIO to be blocked now, non-zero if it
|
||||||
|
* was already blocked by a previous call to this function.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
OsBlockSIGIO(void)
|
||||||
|
{
|
||||||
|
#ifdef SIGIO
|
||||||
|
#ifdef SIG_BLOCK
|
||||||
|
if (sigio_blocked++ == 0) {
|
||||||
|
sigset_t set, old;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
sigemptyset(&set);
|
||||||
|
sigaddset(&set, SIGIO);
|
||||||
|
sigprocmask(SIG_BLOCK, &set, &old);
|
||||||
|
ret = sigismember(&old, SIGIO);
|
||||||
|
return ret;
|
||||||
|
} else
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
OsReleaseSIGIO(void)
|
||||||
|
{
|
||||||
|
#ifdef SIGIO
|
||||||
|
#ifdef SIG_BLOCK
|
||||||
|
if (--sigio_blocked == 0) {
|
||||||
|
sigset_t set;
|
||||||
|
|
||||||
|
sigemptyset(&set);
|
||||||
|
sigaddset(&set, SIGIO);
|
||||||
|
sigprocmask(SIG_UNBLOCK, &set, NULL);
|
||||||
|
} else if (sigio_blocked < 0) {
|
||||||
|
BUG_WARN(sigio_blocked < 0);
|
||||||
|
sigio_blocked = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
OsReleaseSignals(void)
|
OsReleaseSignals(void)
|
||||||
{
|
{
|
||||||
#ifdef SIG_BLOCK
|
#ifdef SIG_BLOCK
|
||||||
if (--BlockedSignalCount == 0) {
|
if (--BlockedSignalCount == 0) {
|
||||||
sigprocmask(SIG_SETMASK, &PreviousSignalMask, 0);
|
sigprocmask(SIG_SETMASK, &PreviousSignalMask, 0);
|
||||||
|
OsReleaseSIGIO();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ if XORG
|
||||||
# Tests that require at least some DDX functions in order to fully link
|
# Tests that require at least some DDX functions in order to fully link
|
||||||
# For now, requires xf86 ddx, could be adjusted to use another
|
# For now, requires xf86 ddx, could be adjusted to use another
|
||||||
SUBDIRS += xi2
|
SUBDIRS += xi2
|
||||||
noinst_PROGRAMS += xkb input xtest misc fixes xfree86 hashtabletest
|
noinst_PROGRAMS += xkb input xtest misc fixes xfree86 hashtabletest os
|
||||||
endif
|
endif
|
||||||
check_LTLIBRARIES = libxservertest.la
|
check_LTLIBRARIES = libxservertest.la
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ fixes_LDADD=$(TEST_LDADD)
|
||||||
xfree86_LDADD=$(TEST_LDADD)
|
xfree86_LDADD=$(TEST_LDADD)
|
||||||
touch_LDADD=$(TEST_LDADD)
|
touch_LDADD=$(TEST_LDADD)
|
||||||
hashtabletest_LDADD=$(TEST_LDADD) $(top_srcdir)/Xext/hashtable.c
|
hashtabletest_LDADD=$(TEST_LDADD) $(top_srcdir)/Xext/hashtable.c
|
||||||
|
os_LDADD=$(TEST_LDADD)
|
||||||
|
|
||||||
libxservertest_la_LIBADD = $(XSERVER_LIBS)
|
libxservertest_la_LIBADD = $(XSERVER_LIBS)
|
||||||
if XORG
|
if XORG
|
||||||
|
|
|
@ -0,0 +1,130 @@
|
||||||
|
/**
|
||||||
|
* Copyright © 2012 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_DIX_CONFIG_H
|
||||||
|
#include <dix-config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
static int
|
||||||
|
sig_is_blocked(int sig)
|
||||||
|
{
|
||||||
|
sigset_t current;
|
||||||
|
|
||||||
|
sigemptyset(¤t);
|
||||||
|
assert(sigprocmask(SIG_BLOCK, NULL, ¤t) == 0);
|
||||||
|
return sigismember(¤t, sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void block_sigio_test(void)
|
||||||
|
{
|
||||||
|
#ifdef SIG_BLOCK
|
||||||
|
sigset_t current;
|
||||||
|
|
||||||
|
sigemptyset(¤t);
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
/* block once */
|
||||||
|
OsBlockSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSIGIO();
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
/* block twice, nested */
|
||||||
|
OsBlockSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsBlockSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSIGIO();
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
/* block all */
|
||||||
|
OsBlockSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSignals();
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
/* block all nested */
|
||||||
|
OsBlockSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsBlockSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSignals();
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
/* mix the two */
|
||||||
|
/* ABBA */
|
||||||
|
OsBlockSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsBlockSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSignals();
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
/* ABAB */
|
||||||
|
OsBlockSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsBlockSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSIGIO();
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
/* BAAB */
|
||||||
|
OsBlockSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsBlockSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSIGIO();
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
/* BABA */
|
||||||
|
OsBlockSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsBlockSignals();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSIGIO();
|
||||||
|
assert(sig_is_blocked(SIGIO));
|
||||||
|
OsReleaseSignals();
|
||||||
|
assert(!sig_is_blocked(SIGIO));
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
block_sigio_test();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue