nanosleep autoconf check hangs forever
I tried to build GNU diffutils with emscripten
checking for library containing nanosleep... none required
checking for working nanosleep..
During an out-of-tree configure, this nanosleep check hangs forever.
Here is a zip with conftest.c: diffutils.zip
#include <errno.h>
#include <limits.h>
#include <signal.h>
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <time.h>
#include <unistd.h>
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
#define TYPE_MAXIMUM(t) ((t) (! TYPE_SIGNED (t) ? (t) -1 : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
#if HAVE_DECL_ALARM
static void
check_for_SIGALRM (int sig)
{
if (sig != SIGALRM)
_exit (1);
}
#endif
int
main ()
{
static struct timespec ts_sleep;
static struct timespec ts_remaining;
/* Test for major problems first. */
if (! nanosleep)
return 2;
ts_sleep.tv_sec = 0;
ts_sleep.tv_nsec = 1;
#if HAVE_DECL_ALARM
{
static struct sigaction act;
act.sa_handler = check_for_SIGALRM;
sigemptyset (&act.sa_mask);
sigaction (SIGALRM, &act, NULL);
alarm (1);
if (nanosleep (&ts_sleep, NULL) != 0)
return 3;
/* Test for a minor problem: the handling of large arguments. */
ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
ts_sleep.tv_nsec = 999999999;
alarm (1);
if (nanosleep (&ts_sleep, &ts_remaining) != -1)
return 4;
if (errno != EINTR)
return 5;
if (ts_remaining.tv_sec <= TYPE_MAXIMUM (time_t) - 10)
return 6;
}
#else /* A simpler test for native Windows. */
if (nanosleep (&ts_sleep, &ts_remaining) < 0)
return 3;
#endif
return 0;
}
sleep check also hangs forever:
checking whether sleep is declared... yes
checking for working sleep...
#include <errno.h>
#include <unistd.h>
#include <signal.h>
static void
handle_alarm (int sig)
{
if (sig != SIGALRM)
_exit (2);
}
int
main (void)
{
/* Failure to compile this test due to missing alarm is okay,
since all such platforms (mingw) also lack sleep. */
unsigned int pentecost = 50 * 24 * 60 * 60; /* 50 days. */
unsigned int remaining;
signal (SIGALRM, handle_alarm);
alarm (1);
remaining = sleep (pentecost);
if (remaining > pentecost)
return 3;
if (remaining <= pentecost - 10)
return 4;
return 0;
;
return 0;
}
maybe it's actually a problem with signals
Yes, looks like the sleep is for 50 days, so it never stops, and is never interrupted since we don't have signal support.
The issue is probably that we should fail with a compile-time error on not having the signal functions - but they have been useful for porting, which is why they exist, so I'm not sure what's best here.
Maybe emulate alarm function / timer specifically? It should be possible with something like asyncify?
How about failing at link time with an error like build with -s FAKE_SIGNALS if you want fake signal support? or do you think we want the portable fake signals on by default?
Also, adding busybox to tests could be a nice thing since it builds so many things under the hood: like in https://github.com/tbfleming/em-busybox/commits/master
@sbc100
I think it would be ok to error on signals by default, as long as the error said exactly what to do to get the fake support (build with -s FAKE_SIGNALS etc.). It would be a breaking change but one that's not surprising at least.
Maybe also alarm function could crash (this is related but not equivalent ot signal handling)
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.
I was also bitten by this when I tried to compile GNU sed. I was able to work around this with:
emconfigure ../configure ac_cv_have_decl_alarm=no gl_cv_func_sleep_works=yes
I am still experiencing this issue with version 4.0.7-git while trying to build libunistring.
Steps to reproduce
# Download source
curl -O https://mirror.ibcp.fr/pub/gnu/libunistring/libunistring-1.3
tar -xvf libunistring-1.3.tar.gz
# Configure
cd libunistring-1.3
emconfigure ./configure
Solution
For anyone coming across this issue, I managed to solve this by disabling the checks:
emconfigure ./configure \
ac_cv_search_nanosleep=no \
ac_cv_have_decl_sleep=no \
--disable-threads \
# ...
I am still experiencing this issue with version 4.0.7-git while trying to build libunistring.
@sbc100 should this be reopened?
@Jomy10 the checks code themselves is equivalent to my codes above?