]> git.sesse.net Git - vlc/commitdiff
cddb: do not use alarm()
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 5 Nov 2011 16:26:37 +0000 (18:26 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 5 Nov 2011 16:27:50 +0000 (18:27 +0200)
It does not work on Windows, and is not thread-safe on Linux.

contrib/src/cddb/cddb-no-alarm.patch [new file with mode: 0644]
contrib/src/cddb/rules.mak

diff --git a/contrib/src/cddb/cddb-no-alarm.patch b/contrib/src/cddb/cddb-no-alarm.patch
new file mode 100644 (file)
index 0000000..785b883
--- /dev/null
@@ -0,0 +1,50 @@
+diff -ru cddb.orig/lib/cddb_net.c cddb/lib/cddb_net.c
+--- cddb.orig/lib/cddb_net.c   2011-11-05 18:21:42.000000000 +0200
++++ cddb/lib/cddb_net.c        2011-11-05 18:22:11.000000000 +0200
+@@ -228,46 +228,9 @@
+ /* Time-out enabled work-alikes */
+-#ifdef HAVE_ALARM
+-/* time-out jump buffer */
+-static jmp_buf timeout_expired;
+-
+-/* time-out signal handler */
+-static void alarm_handler(int signum)
+-{
+-    longjmp(timeout_expired, 1);
+-}
+-#endif
+-
+ struct hostent *timeout_gethostbyname(const char *hostname, int timeout)
+ {
+-#ifdef HAVE_ALARM
+-    struct hostent *he = NULL;
+-    struct sigaction action;
+-    struct sigaction old;
+-
+-    /* no signal before setjmp */
+-    alarm(0);
+-
+-    /* register signal handler */
+-    memset(&action, 0, sizeof(action));
+-    action.sa_handler = alarm_handler;
+-    sigaction(SIGALRM, &action, &old);
+-
+-    /* save stack state */
+-    if (!setjmp(timeout_expired)) {
+-        alarm(timeout);         /* set time-out alarm */
+-        he = gethostbyname(hostname); /* execute DNS query */
+-        alarm(0);               /* reset alarm timer */
+-    } else {
+-        errno = ETIMEDOUT;
+-    }
+-    sigaction(SIGALRM, &old, NULL); /* restore previous signal handler */
+-
+-    return he;
+-#else
+     return gethostbyname(hostname); /* execute DNS query directly */
+-#endif
+ }
+ int timeout_connect(int sockfd, const struct sockaddr *addr, 
index 93063b8ef3c02d7751f72250e10cedd74104db1d..24aee962f18fbae1a811766851b993141913ee59 100644 (file)
@@ -18,6 +18,7 @@ cddb: libcddb-$(CDDB_VERSION).tar.bz2 .sum-cddb
        $(UNPACK)
        $(APPLY) $(SRC)/cddb/cross.patch
        $(APPLY) $(SRC)/cddb/getenv-crash.patch
+       $(APPLY) $(SRC)/cddb/cddb-no-alarm.patch
 ifdef HAVE_WIN32
        $(APPLY) $(SRC)/cddb/win32-pkg.patch
 endif