Skip to content

Commit 2a10b8c

Browse files
Kontrabantsezero
authored andcommitted
wayland: Add a sigtimedwait() implementation for OpenBSD
sigtimedwait() is an optional part of POSIX.1-2001, and OpenBSD doesn't implement it. Add a replacement implementation based on https://comp.unix.programmer.narkive.com/rEDH0sPT/sigtimedwait-implementation (backported from commit 1049426) (cherry picked from commit d31d98d)
1 parent f610a3d commit 2a10b8c

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ if(SDL_LIBC)
10991099
endforeach()
11001100

11011101
check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
1102+
check_symbol_exists(sigtimedwait "signal.h" HAVE_SIGTIMEDWAIT)
11021103
check_symbol_exists(setjmp "setjmp.h" HAVE_SETJMP)
11031104
check_symbol_exists(nanosleep "time.h" HAVE_NANOSLEEP)
11041105
check_symbol_exists(sysconf "unistd.h" HAVE_SYSCONF)

configure

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19755,6 +19755,12 @@ if test "x$ac_cv_func_sigaction" = xyes
1975519755
then :
1975619756
printf "%s\n" "#define HAVE_SIGACTION 1" >>confdefs.h
1975719757

19758+
fi
19759+
ac_fn_c_check_func "$LINENO" "sigtimedwait" "ac_cv_func_sigtimedwait"
19760+
if test "x$ac_cv_func_sigtimedwait" = xyes
19761+
then :
19762+
printf "%s\n" "#define HAVE_SIGTIMEDWAIT 1" >>confdefs.h
19763+
1975819764
fi
1975919765
ac_fn_c_check_func "$LINENO" "setjmp" "ac_cv_func_setjmp"
1976019766
if test "x$ac_cv_func_setjmp" = xyes
@@ -22422,7 +22428,6 @@ printf %s "checking for NAS audio support... " >&6; }
2242222428
have_nas=yes
2242322429
NAS_CFLAGS="-I/usr/X11R6/include/"
2242422430
NAS_LIBS="-L/usr/X11R6/lib -laudio -lXt"
22425-
2242622431
fi
2242722432

2242822433
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_nas" >&5

configure.ac

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ dnl Checks for library functions.
359359
AC_DEFINE(HAVE_MPROTECT, 1, [ ])
360360
],[]),
361361
)
362-
AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv bsearch qsort abs bcopy memset memcmp memcpy memmove wcslen wcslcpy wcslcat _wcsdup wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtod strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp strcasestr vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll memfd_create posix_fallocate _Exit)
362+
AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv bsearch qsort abs bcopy memset memcmp memcpy memmove wcslen wcslcpy wcslcat _wcsdup wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtod strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp strcasestr vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction sigtimedwait setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll memfd_create posix_fallocate _Exit)
363363

364364
AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
365365
AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf trunc truncf fmod fmodf log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf sin sinf sqrt sqrtf tan tanf)
@@ -1247,7 +1247,6 @@ CheckNAS()
12471247
have_nas=yes
12481248
NAS_CFLAGS="-I/usr/X11R6/include/"
12491249
NAS_LIBS="-L/usr/X11R6/lib -laudio -lXt"
1250-
12511250
fi
12521251

12531252
AC_MSG_RESULT($have_nas)

include/SDL_config.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
#cmakedefine HAVE_MEMFD_CREATE 1
194194
#cmakedefine HAVE_POSIX_FALLOCATE 1
195195
#cmakedefine HAVE_SIGACTION 1
196+
#cmakedefine HAVE_SIGTIMEDWAIT 1
196197
#cmakedefine HAVE_SA_SIGACTION 1
197198
#cmakedefine HAVE_SETJMP 1
198199
#cmakedefine HAVE_NANOSLEEP 1

include/SDL_config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
#undef HAVE_FSEEKO
196196
#undef HAVE_FSEEKO64
197197
#undef HAVE_SIGACTION
198+
#undef HAVE_SIGTIMEDWAIT
198199
#undef HAVE_SA_SIGACTION
199200
#undef HAVE_SETJMP
200201
#undef HAVE_NANOSLEEP
@@ -216,6 +217,7 @@
216217
#undef HAVE__EXIT
217218

218219
#else
220+
219221
#define HAVE_STDARG_H 1
220222
#define HAVE_STDDEF_H 1
221223
#define HAVE_STDINT_H 1

src/video/wayland/SDL_waylanddatamanager.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,48 @@
4040
*/
4141
#define PIPE_MS_TIMEOUT 14
4242

43+
/* sigtimedwait() is an optional part of POSIX.1-2001, and OpenBSD doesn't implement it.
44+
* Based on https://comp.unix.programmer.narkive.com/rEDH0sPT/sigtimedwait-implementation
45+
*/
46+
#ifndef HAVE_SIGTIMEDWAIT
47+
#include <errno.h>
48+
#include <time.h>
49+
static int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
50+
{
51+
struct timespec elapsed = { 0 }, rem = { 0 };
52+
sigset_t pending;
53+
int signo;
54+
do {
55+
/* Check the pending signals, and call sigwait if there is at least one of interest in the set. */
56+
sigpending(&pending);
57+
for (signo = 1; signo < NSIG; ++signo) {
58+
if (sigismember(set, signo) && sigismember(&pending, signo)) {
59+
if (!sigwait(set, &signo)) {
60+
if (info) {
61+
SDL_memset(info, 0, sizeof *info);
62+
info->si_signo = signo;
63+
}
64+
return signo;
65+
} else {
66+
return -1;
67+
}
68+
}
69+
}
70+
71+
if (timeout->tv_sec || timeout->tv_nsec) {
72+
long ns = 20000000L; // 2/100ths of a second
73+
nanosleep(&(struct timespec){ 0, ns }, &rem);
74+
ns -= rem.tv_nsec;
75+
elapsed.tv_sec += (elapsed.tv_nsec + ns) / 1000000000L;
76+
elapsed.tv_nsec = (elapsed.tv_nsec + ns) % 1000000000L;
77+
}
78+
} while (elapsed.tv_sec < timeout->tv_sec || (elapsed.tv_sec == timeout->tv_sec && elapsed.tv_nsec < timeout->tv_nsec));
79+
80+
errno = EAGAIN;
81+
return -1;
82+
}
83+
#endif
84+
4385
static ssize_t write_pipe(int fd, const void *buffer, size_t total_length, size_t *pos)
4486
{
4587
int ready = 0;
@@ -75,7 +117,7 @@ static ssize_t write_pipe(int fd, const void *buffer, size_t total_length, size_
75117
}
76118
}
77119

78-
sigtimedwait(&sig_set, 0, &zerotime);
120+
sigtimedwait(&sig_set, NULL, &zerotime);
79121

80122
#ifdef SDL_THREADS_DISABLED
81123
sigprocmask(SIG_SETMASK, &old_sig_set, NULL);

0 commit comments

Comments
 (0)