Index: configure.ac =================================================================== RCS file: /sources/freeipmi/freeipmi/configure.ac,v retrieving revision 1.71 diff -u -d -p -r1.71 configure.ac --- configure.ac 8 Dec 2006 01:19:16 -0000 1.71 +++ configure.ac 11 Dec 2006 13:25:20 -0000 @@ -159,11 +159,6 @@ if test "x${have_gcrypt}" = "xno"; then AC_MSG_NOTICE([Note: libgpg-error required for libgcrypt]) fi -dnl FreeBSD has argp as a separate library -AC_CHECK_FUNC([argp_parse], , - AC_CHECK_LIB([argp], [argp_parse], , - AC_MSG_ERROR([argp library not found. argp-standalone required.]))) - dnl FreeBSD < 5 has getopt_long in a separate gnugetopt library AC_CHECK_FUNC([getopt_long], [have_getopt_long=yes], AC_CHECK_LIB([gnugetopt], [getopt_long], [have_getopt_long=yes], @@ -184,12 +179,43 @@ AC_FUNC_MMAP AC_CHECK_FUNCS([strchr memcpy memset mlock]) AC_caolan_FUNC_WHICH_GETHOSTBYNAME_R dnl There is no error(), strndup() and getline() on FreeBSD -AC_CHECK_FUNCS([error strndup getline strerror_r getprogname]) +AC_CHECK_FUNCS([error strndup getline strerror_r getprogname getpwuid_r]) dnl FreeBSD has no exp10() nor log2(), FreeBSD < 5 has no exp2() AC_CHECK_LIB([m], [exp10]) AC_CHECK_LIB([m], [exp2]) AC_CHECK_LIB([m], [log2]) +dnl Check for thread-safe gethostbyname() +AC_MSG_CHECKING([for thread-safe gethostbyname()]) +have_thread_safe_gethostbyname=no +case "$host_os" in +*freebsd*) + AC_TRY_CPP([ + #include + #if __FreeBSD_version < 505000 + #error "gethostbyname() is not thread-safe" + #endif + ], [have_thread_safe_gethostbyname=yes]) + ;; +esac +if test "x$have_thread_safe_gethostbyname" = "xyes"; then + AC_DEFINE([HAVE_THREAD_SAFE_GETHOSTBYNAME], [1], + [Define if you have thread-safe gethostbyname() implementation]) + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi + +dnl FreeBSD has argp as a separate library +dnl CAVEAT: argp-standalone library exports it's own strndup() function, +dnl not conforming to strndup(3). If we have no strndup() in libc (as +dnl in FreeBSD), and strndup() check is placed after argp check, argp's +dnl strndup() will be detected, which is wrong. So place argp check _after_ +dnl strndup() check. +AC_CHECK_FUNC([argp_parse], , + AC_CHECK_LIB([argp], [argp_parse], , + AC_MSG_ERROR([argp library not found. argp-standalone required.]))) + ACX_PTHREAD([], AC_MSG_ERROR([Posix threads required to build libipmiconsole])) dnl Checks for header files. Index: bmc-watchdog/src/Makefile.am =================================================================== RCS file: /sources/freeipmi/freeipmi/bmc-watchdog/src/Makefile.am,v retrieving revision 1.6 diff -u -d -p -r1.6 Makefile.am --- bmc-watchdog/src/Makefile.am 3 Nov 2006 18:14:28 -0000 1.6 +++ bmc-watchdog/src/Makefile.am 11 Dec 2006 13:25:20 -0000 @@ -4,7 +4,7 @@ bmc_watchdog_SOURCES = bmc-watchdog.c bmc_watchdog_LDADD = ../../libfreeipmi/src/libfreeipmi.la -bmc_watchdog_CFLAGS = \ +bmc_watchdog_CPPFLAGS = \ -I$(srcdir)/../../libfreeipmi/include \ -DBMC_WATCHDOG_LOGFILE=\"$(localstatedir)/log/freeipmi/bmc-watchdog.log\" Index: common/src/freeipmi-portability.c =================================================================== RCS file: /sources/freeipmi/freeipmi/common/src/freeipmi-portability.c,v retrieving revision 1.2 diff -u -d -p -r1.2 freeipmi-portability.c --- common/src/freeipmi-portability.c 13 Sep 2006 21:23:56 -0000 1.2 +++ common/src/freeipmi-portability.c 11 Dec 2006 13:25:20 -0000 @@ -22,14 +22,19 @@ #include #endif +#include +#include + #include #include #if STDC_HEADERS #include #include #endif /* STDC_HEADERS */ -#include #include +#include +#include +#include #include "freeipmi-portability.h" @@ -132,3 +137,123 @@ freeipmi_getline(char **buf, size_t *siz } } #endif + +/* + * Replacement for 6-argument variant of gethostbyname_r(). This is a + * slightly modified version of gethostbyname_r() by Enzo Michelangeli + * from http://www.cygwin.com/ml/cygwin/2004-04/msg00532.html. + * + * If we have thread-safe gethostbyname() we just need to protect + * static thread data from being overwritten by next call to + * gethostbyname(). So mutex is not required. + */ +#ifdef LOCAL_GETHOSTBYNAME_R +int freeipmi_gethostbyname_r(const char *name, + struct hostent *ret, + char *buf, + size_t buflen, + struct hostent **result, + int *h_errnop) +{ + int hsave; + struct hostent *ph; +#ifndef HAVE_THREAD_SAFE_GETHOSTBYNAME + static pthread_mutex_t __mutex = PTHREAD_MUTEX_INITIALIZER; + + pthread_mutex_lock(&__mutex); /* begin critical area */ +#endif + hsave = h_errno; + ph = gethostbyname(name); + *h_errnop = h_errno; /* copy h_errno to *h_herrnop */ + + if (ph == NULL) { + *result = NULL; + } else { + char **p, **q; + char *pbuf; + int nbytes=0; + int naddr=0, naliases=0; + + /* determine if we have enough space in buf */ + + /* count how many addresses */ + for (p = ph->h_addr_list; *p != 0; p++) { + nbytes += ph->h_length; /* addresses */ + nbytes += sizeof(*p); /* pointers */ + naddr++; + } + nbytes += sizeof(*p); /* one more for the terminating NULL */ + + /* count how many aliases, and total length of strings */ + + for (p = ph->h_aliases; *p != 0; p++) { + nbytes += (strlen(*p)+1); /* aliases */ + nbytes += sizeof(*p); /* pointers */ + naliases++; + } + nbytes += sizeof(*p); /* one more for the terminating NULL */ + + /* here nbytes is the number of bytes required in buffer */ + /* as a terminator must be there, the minimum value is ph->h_length */ + if(nbytes > buflen) { + *result = NULL; +#ifndef HAVE_THREAD_SAFE_GETHOSTBYNAME + pthread_mutex_unlock(&__mutex); /* end critical area */ +#endif + return ERANGE; /* not enough space in buf!! */ + } + + /* There is enough space. Now we need to do a deep copy! */ + /* Allocation in buffer: + from [0] to [(naddr-1) * sizeof(*p)]: + pointers to addresses + at [naddr * sizeof(*p)]: + NULL + from [(naddr+1) * sizeof(*p)] to [(naddr+naliases) * sizeof(*p)] : + pointers to aliases + at [(naddr+naliases+1) * sizeof(*p)]: + NULL + then naddr addresses (fixed length), and naliases aliases (asciiz). + */ + + *ret = *ph; /* copy whole structure (not its address!) */ + + /* copy addresses */ + q = (char **)buf; /* pointer to pointers area (type: char **) */ + ret->h_addr_list = q; /* update pointer to address list */ + pbuf = buf + ((naddr+naliases+2)*sizeof(*p)); /* skip that area */ + for (p = ph->h_addr_list; *p != 0; p++) { + memcpy(pbuf, *p, ph->h_length); /* copy address bytes */ + *q++ = pbuf; /* the pointer is the one inside buf... */ + pbuf += ph->h_length; /* advance pbuf */ + } + *q++ = NULL; /* address list terminator */ + + /* copy aliases */ + + ret->h_aliases = q; /* update pointer to aliases list */ + for (p = ph->h_aliases; *p != 0; p++) { + strcpy(pbuf, *p); /* copy alias strings */ + *q++ = pbuf; /* the pointer is the one inside buf... */ + pbuf += strlen(*p); /* advance pbuf */ + *pbuf++ = 0; /* string terminator */ + } + *q++ = NULL; /* terminator */ + + strcpy(pbuf, ph->h_name); /* copy alias strings */ + ret->h_name = pbuf; + pbuf += strlen(ph->h_name); /* advance pbuf */ + *pbuf++ = 0; /* string terminator */ + + *result = ret; /* and let *result point to structure */ + + } + h_errno = hsave; /* restore h_errno */ + +#ifndef HAVE_THREAD_SAFE_GETHOSTBYNAME + pthread_mutex_unlock(&__mutex); /* end critical area */ +#endif + + return (*result == NULL); +} +#endif Index: common/src/freeipmi-portability.h =================================================================== RCS file: /sources/freeipmi/freeipmi/common/src/freeipmi-portability.h,v retrieving revision 1.2 diff -u -d -p -r1.2 freeipmi-portability.h --- common/src/freeipmi-portability.h 13 Sep 2006 21:23:56 -0000 1.2 +++ common/src/freeipmi-portability.h 11 Dec 2006 13:25:20 -0000 @@ -33,6 +33,7 @@ extern "C" { #include #include #include +#include #if !defined(EBADMSG) && defined(ENOMSG) #define EBADMSG ENOMSG @@ -130,6 +131,21 @@ char *freeipmi_strndup(const char *, siz ssize_t freeipmi_getline(char **buf, size_t *bufsize, FILE *fp); #endif +#ifndef HAVE_FUNC_GETHOSTBYNAME_R_6 +#define HAVE_FUNC_GETHOSTBYNAME_R_6 1 +#define LOCAL_GETHOSTBYNAME_R +#ifdef gethostbyname_r +#undef gethostbyname_r +#endif +#define gethostbyname_r freeipmi_gethostbyname_r +int freeipmi_gethostbyname_r(const char *name, + struct hostent *ret, + char *buf, + size_t buflen, + struct hostent **result, + int *h_errnop); +#endif /* !HAVE_FUNC_GETHOSTBYNAME_R_6 */ + #ifdef __cplusplus } #endif Index: common/src/ipmi-sdr-api.c =================================================================== RCS file: /sources/freeipmi/freeipmi/common/src/ipmi-sdr-api.c,v retrieving revision 1.10 diff -u -d -p -r1.10 ipmi-sdr-api.c --- common/src/ipmi-sdr-api.c 8 Dec 2006 07:54:29 -0000 1.10 +++ common/src/ipmi-sdr-api.c 11 Dec 2006 13:25:21 -0000 @@ -165,12 +165,25 @@ _get_home_directory () uid_t user_id; struct passwd *user_passwd = alloca (sizeof (*user_passwd)); char *home_dir = NULL; - long int buf_len = sysconf (_SC_GETPW_R_SIZE_MAX); - char *buf = alloca (buf_len); + long int buf_len; + char *buf; + +#if defined(_SC_GETPW_R_SIZE_MAX) + buf_len = sysconf(_SC_GETPW_R_SIZE_MAX); + if (buf_len < 0) + /* Variable was not implemented */ +#endif + buf_len = 1024; /* XXX */ + buf = alloca (buf_len); user_id = getuid (); if (getpwuid_r (user_id, user_passwd, buf, buf_len, &user_passwd) != 0) return NULL; + if (user_passwd == NULL) { + /* User not found */ + errno = ENOENT; + return NULL; + } if (user_passwd->pw_dir) { Index: common/src/ipmi-sdr-cache-reads.c =================================================================== RCS file: /sources/freeipmi/freeipmi/common/src/ipmi-sdr-cache-reads.c,v retrieving revision 1.3 diff -u -d -p -r1.3 ipmi-sdr-cache-reads.c --- common/src/ipmi-sdr-cache-reads.c 13 Sep 2006 21:23:56 -0000 1.3 +++ common/src/ipmi-sdr-cache-reads.c 11 Dec 2006 13:25:21 -0000 @@ -38,7 +38,6 @@ Foundation, Inc., 675 Mass Ave, Cambridg #include #include #include -#include #if TIME_WITH_SYS_TIME #include #include @@ -49,6 +48,7 @@ Foundation, Inc., 675 Mass Ave, Cambridg #include #endif /* !HAVE_SYS_TIME_H */ #endif /* !TIME_WITH_SYS_TIME */ +#include #include #include #include Index: common/src/ipmi-sdr-cache-writes.c =================================================================== RCS file: /sources/freeipmi/freeipmi/common/src/ipmi-sdr-cache-writes.c,v retrieving revision 1.2 diff -u -d -p -r1.2 ipmi-sdr-cache-writes.c --- common/src/ipmi-sdr-cache-writes.c 13 Sep 2006 21:23:56 -0000 1.2 +++ common/src/ipmi-sdr-cache-writes.c 11 Dec 2006 13:25:21 -0000 @@ -38,7 +38,6 @@ Foundation, Inc., 675 Mass Ave, Cambridg #include #include #include -#include #if TIME_WITH_SYS_TIME #include #include @@ -49,6 +48,7 @@ Foundation, Inc., 675 Mass Ave, Cambridg #include #endif /* !HAVE_SYS_TIME_H */ #endif /* !TIME_WITH_SYS_TIME */ +#include #include #include #include Index: doc/examples/Makefile.am =================================================================== RCS file: /sources/freeipmi/freeipmi/doc/examples/Makefile.am,v retrieving revision 1.13 diff -u -d -p -r1.13 Makefile.am --- doc/examples/Makefile.am 3 Nov 2006 18:14:28 -0000 1.13 +++ doc/examples/Makefile.am 11 Dec 2006 13:25:21 -0000 @@ -4,7 +4,7 @@ LIBFREEIPMI_EXAMPLES = udm-test.c noinst_PROGRAMS = udm-test udm_test_SOURCES = $(LIBFREEIPMI_EXAMPLES) udm_test_LDADD = ../../libfreeipmi/src/libfreeipmi.la -AM_CFLAGS = -Wall +AM_CFLAGS = -Wall $(PTHREAD_CFLAGS) AM_CPPFLAGS = -I$(srcdir)/../../libfreeipmi/include \ -D_GNU_SOURCE -DPATH_CFG=\"$(sysconfdir)\" -DDATADIR=\"$(datadir)\" Index: ipmi-sel/src/ipmi-sel.c =================================================================== RCS file: /sources/freeipmi/freeipmi/ipmi-sel/src/ipmi-sel.c,v retrieving revision 1.18 diff -u -d -p -r1.18 ipmi-sel.c --- ipmi-sel/src/ipmi-sel.c 14 Nov 2006 01:05:45 -0000 1.18 +++ ipmi-sel/src/ipmi-sel.c 11 Dec 2006 13:25:21 -0000 @@ -67,7 +67,10 @@ init_sdr_cache (ipmi_device_t dev, struc if ((sdr_cache_filename = get_sdr_cache_filename (args->common.host, args->sdr_cache_dir)) == NULL) - return (-1); + { + perror ("error: get_sdr_cache_filename (): "); + return (-1); + } if ((fp = fopen (sdr_cache_filename, "r"))) { Index: ipmiconsole/src/ipmiconsole/Makefile.am =================================================================== RCS file: /sources/freeipmi/freeipmi/ipmiconsole/src/ipmiconsole/Makefile.am,v retrieving revision 1.1 diff -u -d -p -r1.1 Makefile.am --- ipmiconsole/src/ipmiconsole/Makefile.am 6 Nov 2006 00:13:12 -0000 1.1 +++ ipmiconsole/src/ipmiconsole/Makefile.am 11 Dec 2006 13:25:21 -0000 @@ -15,7 +15,7 @@ ipmiconsole_SOURCES = \ ipmiconsole_config.c \ error.c -ipmiconsole_CFLAGS = -I$(srcdir)/../libipmiconsole \ +ipmiconsole_CPPFLAGS = -I$(srcdir)/../libipmiconsole \ -I$(srcdir)/../../../common/src \ -I$(srcdir)/../../../libfreeipmi/include @@ -26,6 +26,6 @@ ipmiconsole_LDADD = ../../../common/src/ $(MAKE) -C $(dir $@) $(notdir $@) ../libipmiconsole/libipmiconsole.la: force-dependency-check - @cd `dirname address@hidden && make `basename address@hidden + $(MAKE) -C $(dir $@) $(notdir $@) force-dependency-check: Index: ipmiconsole/src/libipmiconsole/Makefile.am =================================================================== RCS file: /sources/freeipmi/freeipmi/ipmiconsole/src/libipmiconsole/Makefile.am,v retrieving revision 1.1 diff -u -d -p -r1.1 Makefile.am --- ipmiconsole/src/libipmiconsole/Makefile.am 6 Nov 2006 00:13:12 -0000 1.1 +++ ipmiconsole/src/libipmiconsole/Makefile.am 11 Dec 2006 13:25:21 -0000 @@ -29,10 +29,11 @@ libipmiconsole_la_SOURCES = ipmiconsole. ipmiconsole_packet.c \ ipmiconsole_processing.c -libipmiconsole_la_CFLAGS = -I$(srcdir)/../../../config \ +libipmiconsole_la_CFLAGS = $(PTHREAD_CFLAGS) + +libipmiconsole_la_CPPFLAGS = -I$(srcdir)/../../../config \ -I$(srcdir)/../../../common/src \ -I$(srcdir)/../../../libfreeipmi/include \ - $(PTHREAD_CFLAGS) \ -DWITH_SECURE_MALLOC=1 \ -DWITH_PTHREADS=1 @@ -41,9 +42,12 @@ libipmiconsole_la_LDFLAGS = $(PTHREAD_LI $(OTHER_FLAGS) libipmiconsole_la_LIBADD = ../../../common/src/libllnlcommon.la \ - ../../../libfreeipmi/src/libfreeipmi.la + ../../../libfreeipmi/src/libfreeipmi.la \ + ../../../common/src/libfreeipmiportability.la -install-data-hook: +install-data-hook: $(INSTALL_LOGDIR) + +install-logdir: $(top_srcdir)/install-sh -m 755 -d $(DESTDIR)/var/log/ipmiconsole EXTRA_DIST = ipmiconsole.map Index: ipmiconsole/src/libipmiconsole/ipmiconsole_engine.c =================================================================== RCS file: /sources/freeipmi/freeipmi/ipmiconsole/src/libipmiconsole/ipmiconsole_engine.c,v retrieving revision 1.1 diff -u -d -p -r1.1 ipmiconsole_engine.c --- ipmiconsole/src/libipmiconsole/ipmiconsole_engine.c 6 Nov 2006 00:13:12 -0000 1.1 +++ ipmiconsole/src/libipmiconsole/ipmiconsole_engine.c 11 Dec 2006 13:25:21 -0000 @@ -69,6 +69,8 @@ #include "ipmiconsole_fiid_wrappers.h" #include "ipmiconsole_processing.h" +#include "freeipmi-portability.h" + /* * Locking notes: * Index: ipmiping/src/Makefile.am =================================================================== RCS file: /sources/freeipmi/freeipmi/ipmiping/src/Makefile.am,v retrieving revision 1.7 diff -u -d -p -r1.7 Makefile.am --- ipmiping/src/Makefile.am 3 Nov 2006 18:14:28 -0000 1.7 +++ ipmiping/src/Makefile.am 11 Dec 2006 13:25:21 -0000 @@ -6,7 +6,7 @@ ipmiping_LDADD = \ ../../libfreeipmi/src/libfreeipmi.la \ ../../common/src/libipmiping.la -ipmiping_CFLAGS = \ +ipmiping_CPPFLAGS = \ -I$(srcdir)/../../libfreeipmi/include \ -I$(srcdir)/../../common/src Index: ipmipower/src/Makefile.am =================================================================== RCS file: /sources/freeipmi/freeipmi/ipmipower/src/Makefile.am,v retrieving revision 1.12 diff -u -d -p -r1.12 Makefile.am --- ipmipower/src/Makefile.am 6 Nov 2006 00:13:12 -0000 1.12 +++ ipmipower/src/Makefile.am 11 Dec 2006 13:25:21 -0000 @@ -24,7 +24,7 @@ ipmipower_LDADD = \ ../../common/src/libllnlcommon.la \ ../../libfreeipmi/src/libfreeipmi.la -ipmipower_CFLAGS = \ +ipmipower_CPPFLAGS = \ -I$(srcdir)/../../common/src \ -I$(srcdir)/../../libfreeipmi/include \ -DWITH_LSD_FATAL_ERROR_FUNC=1 \ Index: libfreeipmi/src/udm/ipmi-udm.c =================================================================== RCS file: /sources/freeipmi/freeipmi/libfreeipmi/src/udm/ipmi-udm.c,v retrieving revision 1.32 diff -u -d -p -r1.32 ipmi-udm.c --- libfreeipmi/src/udm/ipmi-udm.c 16 Oct 2006 23:59:43 -0000 1.32 +++ libfreeipmi/src/udm/ipmi-udm.c 11 Dec 2006 13:25:21 -0000 @@ -172,7 +172,7 @@ ipmi_open_outofband (ipmi_driver_type_t &h_errnop)); ERR_EINVAL_CLEANUP (hptr); #else /* !HAVE_FUNC_GETHOSTBYNAME_R */ - ERR_EINVAL_CLEANUP ((hptr = gethostbyname(hostname))); +#error Additional threadsafe gethostbyname support needed #endif /* !HAVE_FUNC_GETHOSTBYNAME_R */ dev->io.outofband.remote_host.sin_family = AF_INET; Index: rmcpping/src/Makefile.am =================================================================== RCS file: /sources/freeipmi/freeipmi/rmcpping/src/Makefile.am,v retrieving revision 1.7 diff -u -d -p -r1.7 Makefile.am --- rmcpping/src/Makefile.am 3 Nov 2006 18:14:29 -0000 1.7 +++ rmcpping/src/Makefile.am 11 Dec 2006 13:25:21 -0000 @@ -6,7 +6,7 @@ rmcpping_LDADD = \ ../../libfreeipmi/src/libfreeipmi.la \ ../../common/src/libipmiping.la -rmcpping_CFLAGS = \ +rmcpping_CPPFLAGS = \ -I$(srcdir)/../../libfreeipmi/include \ -I$(srcdir)/../../common/src