]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
fix building on Solaris
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 18 Sep 2015 08:10:50 +0000 (10:10 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 18 Sep 2015 14:42:28 +0000 (16:42 +0200)
- 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
configure
main.c

index 2fbc549ffa763d090b37549e98b875fca1ec64c0..39b5d448af4f199a9bfe98bdf090bcac966a854d 100644 (file)
--- 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;
     }
index 92ee06374494edd7a5a97fcf6de7fd47ece86d0d..699375ba41488df9a32a5448aa55743522f1adde 100755 (executable)
--- a/configure
+++ b/configure
@@ -390,9 +390,13 @@ case $OPERATINGSYSTEM in
         # Doug Woodward <dougw@whistler.com> 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>' '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 5626e86b10a642b4e4deb646a29d34f48da76ed8..63bb32cf93b0b3b052219788790e408608c12885 100644 (file)
--- 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);
   }
 }