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
This commit is contained in:
Miroslav Lichvar 2015-09-18 10:10:50 +02:00
parent 046f219a0e
commit f444561a10
3 changed files with 16 additions and 12 deletions

View file

@ -215,28 +215,28 @@ prepare_socket(union sockaddr_all *addr)
} }
if (addr->sa.sa_family == AF_UNIX) { 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 /* Construct path of our socket. Use the same directory as the server
socket and include our process ID to allow multiple chronyc instances socket and include our process ID to allow multiple chronyc instances
running at the same time. */ running at the same time. */
dir = UTI_PathToDir(addr->un.sun_path); dir = UTI_PathToDir(addr->un.sun_path);
if (snprintf(sun.sun_path, sizeof (sun.sun_path), if (snprintf(sa_un.sun_path, sizeof (sa_un.sun_path),
"%s/chronyc.%d.sock", dir, getpid()) >= sizeof (sun.sun_path)) "%s/chronyc.%d.sock", dir, (int)getpid()) >= sizeof (sa_un.sun_path))
LOG_FATAL(LOGF_Client, "Unix socket path too long"); LOG_FATAL(LOGF_Client, "Unix socket path too long");
Free(dir); Free(dir);
sun.sun_family = AF_UNIX; sa_un.sun_family = AF_UNIX;
unlink(sun.sun_path); unlink(sa_un.sun_path);
/* Bind the socket to the 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)); DEBUG_LOG(LOGF_Client, "Could not bind socket : %s", strerror(errno));
return 0; return 0;
} }
/* Allow server without root privileges to send replies to our socket */ /* 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)); DEBUG_LOG(LOGF_Client, "Could not change socket permissions : %s", strerror(errno));
return 0; return 0;
} }

12
configure vendored
View file

@ -390,9 +390,13 @@ case $OPERATINGSYSTEM in
# Doug Woodward <dougw@whistler.com> reported that this configuration # Doug Woodward <dougw@whistler.com> reported that this configuration
# works for Solaris 2.8 / SunOS 5.8 on x86 platforms # works for Solaris 2.8 / SunOS 5.8 on x86 platforms
EXTRA_OBJECTS="sys_solaris.o" EXTRA_OBJECTS="sys_solaris.o"
EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf" EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf -lresolv"
EXTRA_CLI_LIBS="-lsocket -lnsl" EXTRA_CLI_LIBS="-lsocket -lnsl -lresolv"
add_def SOLARIS 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 ")" echo "Configuring for Solaris (" $SYSTEM "SunOS version" $VERSION ")"
;; ;;
* ) * )
@ -513,7 +517,7 @@ if test_code '<inttypes.h>' 'inttypes.h' '' '' ''; then
fi fi
if [ $feat_ipv6 = "1" ] && \ 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; struct sockaddr_in6 n;
char p[100]; char p[100];
n.sin6_addr = in6addr_any; n.sin6_addr = in6addr_any;
@ -534,7 +538,7 @@ then
fi fi
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);' 'return getaddrinfo(0, 0, 0, 0);'
then then
add_def HAVE_GETADDRINFO add_def HAVE_GETADDRINFO

2
main.c
View file

@ -265,7 +265,7 @@ write_lockfile(void)
if (!out) { if (!out) {
LOG_FATAL(LOGF_Main, "could not open lockfile %s for writing", pidfile); LOG_FATAL(LOGF_Main, "could not open lockfile %s for writing", pidfile);
} else { } else {
fprintf(out, "%d\n", getpid()); fprintf(out, "%d\n", (int)getpid());
fclose(out); fclose(out);
} }
} }