From f444561a106ac73d7de7b6a1949df73c739d8bf2 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 18 Sep 2015 10:10:50 +0200 Subject: [PATCH] fix building on Solaris - a feature test macro is needed to get msg_control in struct msghdr - variables must not be named sun to avoid conflict with a macro - res_init() needs -lresolv - configure tests for IPv6 and getaddrinfo need -lsocket -lnsl - pid_t is defined as long and needs to be cast for %d format --- client.c | 14 +++++++------- configure | 12 ++++++++---- main.c | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/client.c b/client.c index 2fbc549..39b5d44 100644 --- a/client.c +++ b/client.c @@ -215,28 +215,28 @@ prepare_socket(union sockaddr_all *addr) } if (addr->sa.sa_family == AF_UNIX) { - struct sockaddr_un sun; + struct sockaddr_un sa_un; /* Construct path of our socket. Use the same directory as the server socket and include our process ID to allow multiple chronyc instances running at the same time. */ dir = UTI_PathToDir(addr->un.sun_path); - if (snprintf(sun.sun_path, sizeof (sun.sun_path), - "%s/chronyc.%d.sock", dir, getpid()) >= sizeof (sun.sun_path)) + if (snprintf(sa_un.sun_path, sizeof (sa_un.sun_path), + "%s/chronyc.%d.sock", dir, (int)getpid()) >= sizeof (sa_un.sun_path)) LOG_FATAL(LOGF_Client, "Unix socket path too long"); Free(dir); - sun.sun_family = AF_UNIX; - unlink(sun.sun_path); + sa_un.sun_family = AF_UNIX; + unlink(sa_un.sun_path); /* Bind the socket to the path */ - if (bind(sock_fd, (struct sockaddr *)&sun, sizeof (sun)) < 0) { + if (bind(sock_fd, (struct sockaddr *)&sa_un, sizeof (sa_un)) < 0) { DEBUG_LOG(LOGF_Client, "Could not bind socket : %s", strerror(errno)); return 0; } /* Allow server without root privileges to send replies to our socket */ - if (chmod(sun.sun_path, 0666) < 0) { + if (chmod(sa_un.sun_path, 0666) < 0) { DEBUG_LOG(LOGF_Client, "Could not change socket permissions : %s", strerror(errno)); return 0; } diff --git a/configure b/configure index 92ee063..699375b 100755 --- a/configure +++ b/configure @@ -390,9 +390,13 @@ case $OPERATINGSYSTEM in # Doug Woodward reported that this configuration # works for Solaris 2.8 / SunOS 5.8 on x86 platforms EXTRA_OBJECTS="sys_solaris.o" - EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf" - EXTRA_CLI_LIBS="-lsocket -lnsl" + EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf -lresolv" + EXTRA_CLI_LIBS="-lsocket -lnsl -lresolv" add_def SOLARIS + # These are needed to have msg_control in struct msghdr + add_def __EXTENSIONS__ + add_def _XOPEN_SOURCE 1 + add_def _XOPEN_SOURCE_EXTENDED 1 echo "Configuring for Solaris (" $SYSTEM "SunOS version" $VERSION ")" ;; * ) @@ -513,7 +517,7 @@ if test_code '' 'inttypes.h' '' '' ''; then fi if [ $feat_ipv6 = "1" ] && \ - test_code 'IPv6 support' 'arpa/inet.h sys/socket.h netinet/in.h' '' '' ' + test_code 'IPv6 support' 'arpa/inet.h sys/socket.h netinet/in.h' '' "$EXTRA_LIBS" ' struct sockaddr_in6 n; char p[100]; n.sin6_addr = in6addr_any; @@ -534,7 +538,7 @@ then fi fi -if test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' '' \ +if test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' "$EXTRA_LIBS" \ 'return getaddrinfo(0, 0, 0, 0);' then add_def HAVE_GETADDRINFO diff --git a/main.c b/main.c index 5626e86..63bb32c 100644 --- a/main.c +++ b/main.c @@ -265,7 +265,7 @@ write_lockfile(void) if (!out) { LOG_FATAL(LOGF_Main, "could not open lockfile %s for writing", pidfile); } else { - fprintf(out, "%d\n", getpid()); + fprintf(out, "%d\n", (int)getpid()); fclose(out); } }