From 214c90d6b01017fe02675e133129cf389e740533 Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Fri, 26 Oct 2012 14:48:03 +0100 Subject: If SIGALRM isn't available, don't use alarm() to timeout gethostaddr(), just wait Win32 has neither SIGALRM nor sigaction(), so don't use SIGALRM to timeout gethostaddr(), just wait Signed-off-by: Jon TURNEY Reviewed-by: Colin Harrison --- xhost.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xhost.c b/xhost.c index a5edc08..fd13dae 100644 --- a/xhost.c +++ b/xhost.c @@ -653,7 +653,9 @@ get_hostname(XHostAddress *ha) char *kname; static char kname_out[255]; #endif +#ifdef SIGALRM struct sigaction sa; +#endif #ifdef TCPCONN #if defined(IPv6) && defined(AF_INET6) @@ -690,14 +692,18 @@ get_hostname(XHostAddress *ha) gethostbyaddr will continue after a signal, so we have to jump out of it. */ +#ifdef SIGALRM memset(&sa, 0, sizeof sa); sa.sa_handler = nameserver_lost; sa.sa_flags = 0; /* don't restart syscalls */ sigaction(SIGALRM, &sa, NULL); alarm(NAMESERVER_TIMEOUT); +#endif getnameinfo((struct sockaddr *) &saddr, saddrlen, inetname, sizeof(inetname), NULL, 0, 0); +#ifdef SIGALRM alarm(0); +#endif if (nameserver_timedout || inetname[0] == '\0') inet_ntop(((struct sockaddr *)&saddr)->sa_family, ha->address, inetname, sizeof(inetname)); @@ -711,13 +717,17 @@ get_hostname(XHostAddress *ha) gethostbyaddr will continue after a signal, so we have to jump out of it. */ +#ifdef SIGALRM memset(&sa, 0, sizeof sa); sa.sa_handler = nameserver_lost; sa.sa_flags = 0; /* don't restart syscalls */ sigaction(SIGALRM, &sa, NULL); alarm(4); +#endif hp = gethostbyaddr (ha->address, ha->length, AF_INET); +#ifdef SIGALRM alarm(0); +#endif if (hp) return (hp->h_name); else return (inet_ntoa(*((struct in_addr *)(ha->address)))); -- cgit v1.2.3