[vlc-commits] cddb: do not use alarm()
Rémi Denis-Courmont
git at videolan.org
Sat Nov 5 17:28:00 CET 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 5 18:26:37 2011 +0200| [29d3ded7194271882f212b83aac232baa15f2939] | committer: Rémi Denis-Courmont
cddb: do not use alarm()
It does not work on Windows, and is not thread-safe on Linux.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=29d3ded7194271882f212b83aac232baa15f2939
---
contrib/src/cddb/cddb-no-alarm.patch | 50 ++++++++++++++++++++++++++++++++++
contrib/src/cddb/rules.mak | 1 +
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/contrib/src/cddb/cddb-no-alarm.patch b/contrib/src/cddb/cddb-no-alarm.patch
new file mode 100644
index 0000000..785b883
--- /dev/null
+++ b/contrib/src/cddb/cddb-no-alarm.patch
@@ -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,
diff --git a/contrib/src/cddb/rules.mak b/contrib/src/cddb/rules.mak
index 93063b8..24aee96 100644
--- a/contrib/src/cddb/rules.mak
+++ b/contrib/src/cddb/rules.mak
@@ -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
More information about the vlc-commits
mailing list