Hi guys,

On Fri, Nov 03, 2017 at 11:08:03PM +0100, Willy Tarreau wrote:
> > I get an error which doesn't let me compile this version of HAProxy:
> > 
> >     src/haproxy.c: In function 'get_old_sockets':
> >     src/haproxy.c:971:31: error: 'NAME_MAX' undeclared (first use in
> >     this function)
> >     ? tmpbuf = malloc(fd_nb * (1 + NAME_MAX + 1 + IFNAMSIZ + sizeof(int)));
> >     ?????????????????????????????? ^
> >     src/haproxy.c:971:31: note: each undeclared identifier is reported
> >     only once for each function it appears in
> >     gmake: *** [src/haproxy.o] Error 1
> 
> Oh too bad, we've already dealt with this a long time ago but now it
> reappeared in new code. CCing Olivier. Olivier, in 2012 we already
> faced this issue and addressed it in commit ee2663b ("BUILD: ssl:
> NAME_MAX is not portable, use MAXPATHLEN instead") but resorting to
> MAXPATHLEN.
> 

The attached patch should fix that.
Sorry about that, I remember trying to figure out what the right spelling was,
quite obviously I was wrong :)
But shouldn't it be PATH_MAX, which seems to be defined by POSIX ?

Regards,

Olivier
>From 02b1a8886d80814ebcb3eb02b2f635fb780ee14e Mon Sep 17 00:00:00 2001
From: Olivier Houchard <[email protected]>
Date: Sat, 4 Nov 2017 15:13:01 +0100
Subject: [PATCH] BUILD: use MAXPATHLEN instead of NAME_MAX.

This fixes building on at least Solaris, where NAME_MAX doesn't exist.
---
 src/cli.c     | 2 +-
 src/haproxy.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/cli.c b/src/cli.c
index b546fd02b..9c7794945 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -1354,7 +1354,7 @@ static int _getsocks(char **args, struct appctx *appctx, 
void *private)
        /* We will send sockets MAX_SEND_FD per MAX_SEND_FD, allocate a
         * buffer big enough to store the socket informations.
         */
-       tmpbuf = malloc(MAX_SEND_FD * (1 + NAME_MAX + 1 + IFNAMSIZ + 
sizeof(int)));
+       tmpbuf = malloc(MAX_SEND_FD * (1 + MAXPATHLEN + 1 + IFNAMSIZ + 
sizeof(int)));
        if (tmpbuf == NULL) {
                Warning("Failed to allocate memory to transfer socket 
informations\n");
                goto out;
diff --git a/src/haproxy.c b/src/haproxy.c
index d3db264ee..68b5e427b 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -968,7 +968,7 @@ static int get_old_sockets(const char *unixsocket)
                ret = 0;
                goto out;
        }
-       tmpbuf = malloc(fd_nb * (1 + NAME_MAX + 1 + IFNAMSIZ + sizeof(int)));
+       tmpbuf = malloc(fd_nb * (1 + MAXPATHLEN + 1 + IFNAMSIZ + sizeof(int)));
        if (tmpbuf == NULL) {
                Warning("Failed to allocate memory while receiving sockets\n");
                goto out;
@@ -980,7 +980,7 @@ static int get_old_sockets(const char *unixsocket)
        }
        msghdr.msg_control = cmsgbuf;
        msghdr.msg_controllen = CMSG_SPACE(sizeof(int)) * MAX_SEND_FD;
-       iov.iov_len = MAX_SEND_FD * (1 + NAME_MAX + 1 + IFNAMSIZ + sizeof(int));
+       iov.iov_len = MAX_SEND_FD * (1 + MAXPATHLEN + 1 + IFNAMSIZ + 
sizeof(int));
        do {
                int ret3;
 
-- 
2.13.5

Reply via email to