From 968b62beade052100504d3b7859d5f20a29d3982 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Wed, 25 Jun 2008 14:47:54 +0000 Subject: [PATCH] Build fixes for Solaris MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Use __func__ and define it to __FUNCTION__ if not defined. it's the C99 standard. * Tests for certain linking libraries (libnsl, libsocket, libresolv) (configure.ac) * Defines INADDR_NONE if not defined * Search for in addition to (configure.ac) * Changes include of to . I _think_ this should be safe on all platforms (and it's the standard) * Changes local variable name s_addr to saddr in takeover.c. s_addr is a Single Unix Specification defined name. * Checks if LOG_AUTHPRIV exists (it does not in Solaris) Original patch by Magne Mæhre, applied with minor changes --- configure.ac | 15 ++++++++++++++- include/system.h | 17 ++++++++++++++++- include/util.h | 6 +++--- src/system.c | 3 +++ src/takeover.c | 10 +++++----- src/util.c | 4 +++- 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index d8d9d32..3f1b047 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,15 @@ if test "$GCC" = "yes"; then LDFLAGS="$old_LDFLAGS"]) fi +dnl Check if compiler supports __func__ +AC_CACHE_CHECK([whether compiler supports __func__], pgac_cv_funcname_func, + [AC_TRY_COMPILE([#include ], [printf("%s\n", __func__);], + [pgac_cv_funcname_func=yes], [pgac_cv_funcname_func=no])]) +if test x"$pgac_cv_funcname_func" = xyes ; then + AC_DEFINE(HAVE_FUNCNAME__FUNC, 1, + [Define to 1 if your compiler understands __func__.]) +fi + dnl asciidoc >= 8.2 AC_CHECK_PROGS(ASCIIDOC, asciidoc) if test -n "$ASCIIDOC"; then @@ -67,8 +76,9 @@ fi dnl Checks for header files. AC_CHECK_HEADERS([crypt.h sys/param.h sys/socket.h libgen.h]) + dnl ucred.h may have prereqs -AC_CHECK_HEADERS([sys/ucred.h], [], [], [ +AC_CHECK_HEADERS([ucred.h sys/ucred.h], [], [], [ #ifdef HAVE_SYS_TYPES_H #include #endif @@ -100,6 +110,9 @@ dnl Checks for library functions. AC_CHECK_FUNCS(strlcpy strlcat getpeereid getpeerucred basename) AC_SEARCH_LIBS(crypt, crypt, [], AC_MSG_ERROR([crypt not found])) AC_SEARCH_LIBS(clock_gettime, rt) +AC_SEARCH_LIBS(getsockname, socket) +AC_SEARCH_LIBS(gethostbyname, nsl) +AC_SEARCH_LIBS(hstrerror, resolv) dnl Find libevent AC_MSG_CHECKING([for libevent]) diff --git a/include/system.h b/include/system.h index 6e07e38..a9151a6 100644 --- a/include/system.h +++ b/include/system.h @@ -24,7 +24,7 @@ #include "config.h" #endif -#include +#include #include #include #include @@ -127,6 +127,21 @@ typedef unsigned char bool; #define INT4OID 23 #define TEXTOID 25 +/* + * Make sure __func__ works. + */ + +#ifndef HAVE_FUNCNAME__FUNC +#define __func__ __FUNCTION__ +#endif + +/* + * Some systems (Solaris) does not define INADDR_NONE + */ +#ifndef INADDR_NONE +#define INADDR_NONE ((unsigned long) -1) +#endif + /* * libc compat functions. */ diff --git a/include/util.h b/include/util.h index 1f4540f..944bcb1 100644 --- a/include/util.h +++ b/include/util.h @@ -69,11 +69,11 @@ void slog_level(const char *level, const PgSocket *sock, const char *fmt, ...) void _fatal(const char *file, int line, const char *func, bool do_exit, const char *s, ...) _PRINTF(5, 6); void _fatal_perror(const char *file, int line, const char *func, const char *s, ...) _PRINTF(4, 5); #define fatal(args...) \ - _fatal(__FILE__, __LINE__, __FUNCTION__, true, ## args) + _fatal(__FILE__, __LINE__, __func__, true, ## args) #define fatal_noexit(args...) \ - _fatal(__FILE__, __LINE__, __FUNCTION__, false, ## args) + _fatal(__FILE__, __LINE__, __func__, false, ## args) #define fatal_perror(args...) \ - _fatal_perror(__FILE__, __LINE__, __FUNCTION__, ## args) + _fatal_perror(__FILE__, __LINE__, __func__, ## args) /* * non-interruptible operations diff --git a/src/system.c b/src/system.c index ce81948..ca0295a 100644 --- a/src/system.c +++ b/src/system.c @@ -25,6 +25,9 @@ #ifdef HAVE_SYS_PARAM_H #include #endif +#ifdef HAVE_UCRED_H +#include +#endif #ifdef HAVE_SYS_UCRED_H #include #endif diff --git a/src/takeover.c b/src/takeover.c index 8533297..fe74c64 100644 --- a/src/takeover.c +++ b/src/takeover.c @@ -78,7 +78,7 @@ static void takeover_finish_part1(PgSocket *bouncer) static void takeover_load_fd(MBuf *pkt, const struct cmsghdr *cmsg) { int fd; - char *task, *s_addr, *user, *db; + char *task, *saddr, *user, *db; char *client_enc, *std_string, *datestyle, *timezone; int oldfd, port, linkfd; int got; @@ -100,9 +100,9 @@ static void takeover_load_fd(MBuf *pkt, const struct cmsghdr *cmsg) /* parse row contents */ got = scan_text_result(pkt, "issssiqissss", &oldfd, &task, &user, &db, - &s_addr, &port, &ckey, &linkfd, + &saddr, &port, &ckey, &linkfd, &client_enc, &std_string, &datestyle, &timezone); - if (task == NULL || s_addr == NULL) + if (task == NULL || saddr == NULL) fatal("NULL data from old process"); log_debug("FD row: fd=%d(%d) linkfd=%d task=%s user=%s db=%s enc=%s", @@ -111,11 +111,11 @@ static void takeover_load_fd(MBuf *pkt, const struct cmsghdr *cmsg) client_enc ? client_enc : "NULL"); /* fill address */ - addr.is_unix = strcmp(s_addr, "unix") == 0 ? true : false; + addr.is_unix = strcmp(saddr, "unix") == 0 ? true : false; if (addr.is_unix) { addr.port = cf_listen_port; } else { - addr.ip_addr.s_addr = inet_addr(s_addr); + addr.ip_addr.s_addr = inet_addr(saddr); addr.port = port; } diff --git a/src/util.c b/src/util.c index 274884b..937879d 100644 --- a/src/util.c +++ b/src/util.c @@ -32,7 +32,9 @@ static int log_fd = 0; struct FacName { const char *name; int code; }; static struct FacName facility_names [] = { { "auth", LOG_AUTH }, - { "authpriv", LOG_AUTHPRIV }, +#ifdef LOG_AUTHPRIV + { "authpriv", LOG_AUTHPRIV }, +#endif { "daemon", LOG_DAEMON }, { "user", LOG_USER }, { "local0", LOG_LOCAL0 }, -- 2.40.0