Browse Source

Fix UNIX_PATH_MAX portability problem. Thanks to S.Galabov

Serj Kalichev 11 years ago
parent
commit
21e5c5ae08
3 changed files with 8 additions and 17 deletions
  1. 0 5
      bin/konf.c
  2. 4 7
      bin/konfd.c
  3. 4 5
      konf/net/net.c

+ 0 - 5
bin/konf.c

@@ -22,11 +22,6 @@
 #include "konf/buf.h"
 #include "lub/string.h"
 
-#ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX 108
-#endif
-#define MAXMSG 1024
-
 #ifndef VERSION
 #define VERSION 1.2.2
 #endif

+ 4 - 7
bin/konfd.c

@@ -50,17 +50,14 @@
 #define KONFD_PIDFILE "/var/run/konfd.pid"
 
 /* UNIX socket path */
-#ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX 108
-#endif
+/* Don't use UNIX_PATH_MAX due to portability issues */
+#define USOCK_PATH_MAX sizeof(((struct sockaddr_un *)0)->sun_path)
 
 /* OpenBSD has no MSG_NOSIGNAL flag */
 #ifndef MSG_NOSIGNAL
 #define MSG_NOSIGNAL 0
 #endif
 
-#define MAXMSG 1024
-
 /* Global signal vars */
 static volatile int sigterm = 0;
 static void sighandler(int signo);
@@ -151,8 +148,8 @@ int main(int argc, char **argv)
 		goto err;
 	}
 	laddr.sun_family = AF_UNIX;
-	strncpy(laddr.sun_path, opts->socket_path, UNIX_PATH_MAX);
-	laddr.sun_path[UNIX_PATH_MAX - 1] = '\0';
+	strncpy(laddr.sun_path, opts->socket_path, USOCK_PATH_MAX);
+	laddr.sun_path[USOCK_PATH_MAX - 1] = '\0';
 	if (bind(sock, (struct sockaddr *)&laddr, sizeof(laddr))) {
 		syslog(LOG_ERR, "Can't bind socket: %s\n",
 			strerror(errno));

+ 4 - 5
konf/net/net.c

@@ -15,9 +15,8 @@
 #include "private.h"
 
 /* UNIX socket name in filesystem */
-#ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX 108
-#endif
+/* Don't use UNIX_PATH_MAX due to portability issues */
+#define USOCK_PATH_MAX sizeof(((struct sockaddr_un *)0)->sun_path)
 
 /* OpenBSD has no MSG_NOSIGNAL flag.
  * The SIGPIPE must be ignored in application.
@@ -67,8 +66,8 @@ int konf_client_connect(konf_client_t *this)
 		return this->sock;
 
 	raddr.sun_family = AF_UNIX;
-	strncpy(raddr.sun_path, this->path, UNIX_PATH_MAX);
-	raddr.sun_path[UNIX_PATH_MAX - 1] = '\0';
+	strncpy(raddr.sun_path, this->path, USOCK_PATH_MAX);
+	raddr.sun_path[USOCK_PATH_MAX - 1] = '\0';
 	if (connect(this->sock, (struct sockaddr *)&raddr, sizeof(raddr))) {
 		close(this->sock);
 		this->sock = -1;