From 3f15d91d99a12e9663f8e8f72a17835e00be1bde Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 15 Nov 2002 22:18:44 +0000 Subject: [PATCH] Put mutex around gethostbyname() git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@196 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 4 ++++ bacula/src/lib/bnet.c | 11 ++++++++--- bacula/src/version.h | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 709517b499..a30cad250c 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -16,8 +16,12 @@ Test: - blocksize recognition code. For 1.27 release: +- Add ORDER BY JobId to list of Jobs in query.sql, and in + ua_list.c (list command). +- Make gethostbyname() thread safe in bnet.c After 1.27 +- Check if both CatalogFiles and UseCatalog are set to SD. - Check if we can bump Bacula FD priorty in Win2000 - Implement FileOptions. - Make bcopy read through bad tape records. diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index f523179a91..e0620e2175 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -362,6 +362,8 @@ bnet_wait_data(BSOCK *bsock, int sec) } } +static pthread_mutex_t ip_mutex = PTHREAD_MUTEX_INITIALIZER; + /* * Convert a hostname or dotted IP address into * a s_addr. We handle only IPv4. @@ -379,16 +381,18 @@ static uint32_t *bget_host_ip(void *jcr, char *host) addr_list[0] = inaddr.s_addr; addr_list[1] = (uint32_t) -1; } else { - /******FIXME***** use gethostbyname_r or mutex ****/ + P(ip_mutex); if ((hp = gethostbyname(host)) == NULL) { Jmsg2(jcr, M_ERROR, 0, "gethostbyname() for %s failed: ERR=%s\n", host, strerror(errno)); + V(ip_mutex); return NULL; } if (hp->h_length != sizeof(inaddr.s_addr) || hp->h_addrtype != AF_INET) { - Jmsg2(jcr, M_ERROR, 0, _("gethostbyname() network address length error.\n\ + Jmsg2(jcr, M_ERROR, 0, _("gethostbyname() network address length error.\n\ Wanted %d got %d bytes for s_addr.\n"), sizeof(inaddr.s_addr), hp->h_length); - return NULL; + V(ip_mutex); + return NULL; } i = 0; for (p = hp->h_addr_list; *p != 0; p++) { @@ -401,6 +405,7 @@ Wanted %d got %d bytes for s_addr.\n"), sizeof(inaddr.s_addr), hp->h_length); addr_list[i++] = (*(struct in_addr **)p)->s_addr; } addr_list[i] = (uint32_t) -1; + V(ip_mutex); } return addr_list; } diff --git a/bacula/src/version.h b/bacula/src/version.h index 9ef301fe81..08a29752cc 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.27" #define VSTRING "1" -#define DATE "14 November 2002" -#define LSMDATE "14Nov02" +#define DATE "15 November 2002" +#define LSMDATE "15Nov02" /* Debug flags */ #define DEBUG 1 -- 2.39.5