Index: Makefile
===================================================================
RCS file: /cvs/ports/sysutils/apcupsd/Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile
--- Makefile	17 Jun 2010 18:43:43 -0000	1.3
+++ Makefile	4 Oct 2010 17:50:35 -0000
@@ -5,9 +5,11 @@ COMMENT-cgi =		CGI scripts for web monit
 COMMENT-x11 =		gapcmon - GUI for apcupsd
 
 DISTNAME =		apcupsd-3.14.8
-PKGNAME-main =		${DISTNAME}p1
+PKGNAME-main =		${DISTNAME}
+REVISION-main = 	2
 PKGNAME-cgi =		${DISTNAME:S/-/-cgi-/}
-PKGNAME-x11 =		${DISTNAME:S/-/-x11-/}p0
+PKGNAME-x11 =		${DISTNAME:S/-/-x11-/}
+REVISION-x11 = 		1
 
 CATEGORIES =		sysutils
 
@@ -53,23 +55,22 @@ MULTI_PACKAGES =	-main
 MULTI_PACKAGES +=	-cgi
 PREFIX-cgi =		${WEB_ROOT}
 CONFIGURE_ARGS +=	--enable-cgi
-LIB_DEPENDS-cgi =	gd::graphics/gd
+WANTLIB-cgi = 		${WANTLIB} gd
+LIB_DEPENDS-cgi =	::graphics/gd
 RUN_DEPENDS-cgi =
 
 .if !${FLAVOR:L:Mno_x11}
 MULTI_PACKAGES +=	-x11
 USE_X11 =		Yes
 CONFIGURE_ARGS +=	--enable-gapcmon
-LIB_DEPENDS-x11 =	atk-1.0.>=2009::devel/atk \
-			cairo.>=7::graphics/cairo \
-			gconf-2.>=6::devel/gconf2 \
+LIB_DEPENDS-x11 =	::devel/gconf2 \
 			${MODGETTEXT_LIB_DEPENDS}
 RUN_DEPENDS-x11 =	:desktop-file-utils-*:devel/desktop-file-utils \
 			${MODGETTEXT_RUN_DEPENDS}
 
-WANTLIB-x11 += ORBit-2 X11 Xau Xcomposite Xcursor Xdamage Xdmcp Xext
-WANTLIB-x11 += Xfixes Xi Xinerama Xrandr Xrender dbus-1 expat fontconfig
-WANTLIB-x11 += freetype gdk-x11-2.0 gdk_pixbuf-2.0 gio-2.0 glib-2.0
+WANTLIB-x11 += ORBit-2 X11 Xau Xcomposite Xcursor Xdamage Xdmcp Xext Xfixes
+WANTLIB-x11 += Xi Xinerama Xrandr Xrender atk-1.0 cairo expat fontconfig
+WANTLIB-x11 += freetype gconf-2 gdk-x11-2.0 gdk_pixbuf-2.0 gio-2.0 glib-2.0
 WANTLIB-x11 += glitz gmodule-2.0 gobject-2.0 gthread-2.0 gtk-x11-2.0
 WANTLIB-x11 += m pango-1.0 pangocairo-1.0 pangoft2-1.0 pixman-1 png
 WANTLIB-x11 += pthread-stubs xcb xcb-render xcb-render-util z ${WANTLIB}
@@ -77,8 +78,8 @@ WANTLIB-x11 += pthread-stubs xcb xcb-ren
 
 .if ${FLAVOR:L:Msnmp}
 CONFIGURE_ARGS +=	--enable-net-snmp
-LIB_DEPENDS-main +=	netsnmp::net/net-snmp
-WANTLIB-main =		${WANTLIB} crypto
+LIB_DEPENDS-main +=	::net/net-snmp
+WANTLIB-main =		${WANTLIB} crypto netsnmp
 .endif
 
 FAKE_FLAGS =		sysconfdir=${TRUEPREFIX}/share/examples/apcupsd/etc
Index: patches/patch-src_gapcmon_gapcmon_c
===================================================================
RCS file: patches/patch-src_gapcmon_gapcmon_c
diff -N patches/patch-src_gapcmon_gapcmon_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_gapcmon_gapcmon_c	4 Oct 2010 17:50:35 -0000
@@ -0,0 +1,68 @@
+$OpenBSD$
+--- src/gapcmon/gapcmon.c.orig	Tue Sep 16 08:58:20 2008
++++ src/gapcmon/gapcmon.c	Sat Jul  3 03:11:35 2010
+@@ -79,6 +79,7 @@
+ #include <netinet/in.h>         /* sockaddr_in */
+ #include <netdb.h>              /* gethostbyname() */
+ #include <errno.h>
++#include <pthread.h>
+ #include <string.h>             /* memset() */
+ #include <time.h>
+ #include <stdlib.h>             /* malloc() */
+@@ -171,8 +172,10 @@ static gint gapc_panel_graph_property_page(PGAPC_CONFI
+  * Common interface to the various versions of gethostbyname_r().
+  * Implemented in gethostname.c.
+  */
+-struct hostent * gethostname_re
+-    (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen);
++int	gethostname_re (const char *, struct hostent *);
++#ifdef HAVE_FUNC_GETHOSTBYNAME_R_0
++extern pthread_mutex_t	ghn_mutex;
++#endif
+ 
+ /* 
+  * Some small number of globals are required
+@@ -2504,14 +2507,10 @@ static GIOChannel *sknet_net_open (PSKCOMM psk)
+     nrc = inet_aton (psk->ch_ip_string, (struct in_addr *)&tcp_serv_addr->sin_addr.s_addr);
+     if ( nrc == 0) /* inet_aton failed */
+     {
+-        struct hostent he, *phe;
+-        char *buff;
+-        size_t bufflen = 0;
++        struct hostent he;
+ 
+-        phe = gethostname_re(psk->ch_ip_string, &he, &buff, &bufflen);
+-        if (phe == NULL)
++        if (gethostname_re(psk->ch_ip_string, &he) == -1)
+         {
+-            free(buff);
+             sknet_util_log_msg ("sknet_net_open", "gethostbyname() failed", "");
+             g_snprintf(psk->ch_error_msg, sizeof(psk->ch_error_msg), "gethostbyname() failed");
+             psk->ioc = NULL;
+@@ -2519,7 +2518,6 @@ static GIOChannel *sknet_net_open (PSKCOMM psk)
+         }
+         if (he.h_length != sizeof (struct in_addr) || he.h_addrtype != AF_INET)
+         {
+-            free(buff);
+             sknet_util_log_msg ("sknet_net_open", "struct hostent", "argument error");
+             g_snprintf(psk->ch_error_msg, sizeof(psk->ch_error_msg),"%s","argument error");
+             psk->ioc = NULL;
+@@ -2527,7 +2525,6 @@ static GIOChannel *sknet_net_open (PSKCOMM psk)
+         }
+ 
+         tcp_serv_addr->sin_addr.s_addr = *(unsigned int *) he.h_addr;
+-        free(buff);
+     } /* end if inet_addr */
+     
+   } /* end if b_network */ 
+@@ -6431,6 +6428,10 @@ extern int main(int argc, char *argv[])
+     * enter the GTK main loop
+     */
+    gdk_threads_enter();
++#ifdef HAVE_FUNC_GETHOSTBYNAME_R_0
++   pthread_mutex_init(&ghn_mutex, NULL);
++#endif
++
+    gtk_main();
+    gdk_flush();
+    gdk_threads_leave();
Index: patches/patch-src_gapcmon_gethostname_c
===================================================================
RCS file: patches/patch-src_gapcmon_gethostname_c
diff -N patches/patch-src_gapcmon_gethostname_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_gapcmon_gethostname_c	4 Oct 2010 17:50:35 -0000
@@ -0,0 +1,152 @@
+$OpenBSD$
+--- src/gapcmon/gethostname.c.orig	Tue Jan 29 05:14:57 2008
++++ src/gapcmon/gethostname.c	Sun Jul 11 20:55:21 2010
+@@ -1,81 +1,89 @@
+ #include <netdb.h>
+ #include <errno.h>
+ #include <stdlib.h>
++#include <string.h>
+ 
+-#ifdef HAVE_FUNC_GETHOSTBYNAME_R_6
+-struct hostent * gethostname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen)
++#if defined(HAVE_FUNC_GETHOSTBYNAME_R_6) || defined(HAVE_FUNC_GETHOSTBYNAME_R_5)
++int gethostname_re (const char *host, struct hostent *hostbuf);
+ {
+-	struct hostent *hp;
+-	int herr,res;
++	struct hostent	*hp;
++	size_t		 hstbuflen;
++	int		 herr, oerrno, res;
++	char		*tmphstbuf, *ntmphstbuf;
+ 
+-	if (*hstbuflen == 0)
+-	{
+-		*hstbuflen = 1024; 
+-		*tmphstbuf = (char *)malloc (*hstbuflen);
+-	}
++	res = 0;
++	hstbuflen = 1024; 
++	tmphstbuf = calloc(hstbuflen, 1);
++	if (tmphstbuf == NULL)
++		return -1;
+ 
+-	while (( res = 
+-		gethostbyname_r(host,hostbuf,*tmphstbuf,*hstbuflen,&hp,&herr))
+-		&& (errno == ERANGE))
++#ifdef HAVE_FUNC_GETHOSTBYNAME_R_6
++	while ((res = gethostbyname_r(host, hostbuf, tmphstbuf,
++	    hstbuflen, &hp, &herr)) && errno == ERANGE)
++#else /* HAVE_FUNC_GETHOSTBYNAME_R_5 */
++	while ((NULL == (hp = gethostbyname_r(host, hostbuf, tmphstbuf,
++	    hstbuflen, &herr))) && errno == ERANGE)
++#endif
+ 	{
+ 		/* Enlarge the buffer. */
+-		*hstbuflen *= 2;
+-		*tmphstbuf = (char *)realloc (*tmphstbuf,*hstbuflen);
+-	}
+-	if (res)
+-		return NULL;
+-	return hp;
+-}
++		ntmphstbuf = realloc(tmphstbuf, hstbuflen * 2);
++		if (ntmphstbuf == NULL) {
++#ifdef HAVE_FUNC_GETHOSTBYNAME_R_6
++			res = -1;
+ #endif
+-#ifdef HAVE_FUNC_GETHOSTBYNAME_R_5
+-struct hostent * gethostname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen)
+-{
+-	struct hostent *hp;
+-	int herr;
+-
+-	if (*hstbuflen == 0)
+-	{
+-		*hstbuflen = 1024;
+-		*tmphstbuf = (char *)malloc (*hstbuflen);
++			break;
++		}
++		memset(ntmphstbuf + hstbuflen, 0, hstbuflen);
++		hstbuflen *= 2;
++		tmphstbuf = ntmphstbuf;
+ 	}
+ 
+-	while ((NULL == ( hp = 
+-		gethostbyname_r(host,hostbuf,*tmphstbuf,*hstbuflen,&herr)))
+-		&& (errno == ERANGE))
+-	{
+-		/* Enlarge the buffer. */
+-		*hstbuflen *= 2;
+-		*tmphstbuf = (char *)realloc (*tmphstbuf,*hstbuflen);
+-	}
+-	return hp;
+-}
++#ifdef HAVE_FUNC_GETHOSTBYNAME_R_5
++	if (hp == NULL)
++		res = -1;
+ #endif
++	if (!res)
++		memcpy(hostbuf, hp, sizeof(struct hostent));
++	oerrno = errno;
++	free(tmphstbuf);
++	errno = oerrno;
++	return res;
++}
++#endif	/* defined(HAVE_FUNC_GETHOSTBYNAME_R_6) || defined(HAVE_FUNC_GETHOSTBYNAME_R_5) */
++
+ #ifdef HAVE_FUNC_GETHOSTBYNAME_R_3
+-struct hostent * gethostname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen)
++int gethostname_re (const char *host, struct hostent *hostbuf)
+ {
+-	if (*hstbuflen == 0)
+-	{
+-		*hstbuflen = sizeof(struct hostent_data);
+-		*tmphstbuf = (char *)malloc (*hstbuflen);
+-	}
+-	else if (*hstbuflen < sizeof(struct hostent_data))
+-	{
+-		*hstbuflen = sizeof(struct hostent_data);
+-		*tmphstbuf = (char *)realloc(*tmphstbuf, *hstbuflen);
+-	}
+-	memset((void *)(*tmphstbuf),0,*hstbuflen);
++	struct hostent_data	hed;
+ 
+-	if (0 != gethostbyname_r(host,hostbuf,(struct hostent_data *)*tmphstbuf))
+-		return NULL;
+-	return hostbuf;
++	memset(hed, 0, sizeof(struct hostent_data));
++	return gethostbyname_r(host, hostbuf, &hed);
+ }
+ #endif
+ #ifdef HAVE_FUNC_GETHOSTBYNAME_R_0
+-#warning WARNING! Your system does not have a thread-safe DNS resolver (gethostbyname_r)!
+-#warning WARNING! Name service lookups may be corrupted. Consider switching to 
+-#warning WARNING! a more thread-friendly platform.
+-struct hostent * gethostname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen)
++#include <pthread.h>
++
++pthread_mutex_t	ghn_mutex;
++
++int gethostname_re (const char *name, struct hostent *hostbuf)
+ {
+-	return gethostbyname(host);
++	struct hostent	*he;
++	int		 rv;
++
++	/* play safe */
++	rv = 0;
++	memset(hostbuf, 0, sizeof(struct hostent));
++
++	pthread_mutex_lock(&ghn_mutex);
++	he = gethostbyname(name);
++	if (he == NULL) {
++		rv = -1;
++		goto end;
++	}
++	memcpy(hostbuf, he, sizeof(struct hostent));
++
++end:
++	pthread_mutex_unlock(&ghn_mutex);
++	return rv;
+ }
+ #endif
