]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: add a target type instead of hacking the address family
authorWilly Tarreau <w@1wt.eu>
Fri, 30 Aug 2019 12:18:44 +0000 (14:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 30 Aug 2019 13:07:25 +0000 (15:07 +0200)
Instead of detecting an AF_UNSPEC address family for a log server and
to deduce a file descriptor, let's create a target type field and
explicitly mention that the socket is of type FD.

include/types/log.h
src/log.c

index affcd92d29b302818dca9b0b99259095a0ebae31..dbbd73bf70d843283a029429ffb8f4c2d8b8ee6a 100644 (file)
@@ -47,6 +47,12 @@ enum {
        LOG_FORMATS,          /* number of supported log formats, must always be last */
 };
 
+/* log target types */
+enum log_tgt {
+       LOG_TARGET_DGRAM = 0, // datagram address (udp, unix socket)
+       LOG_TARGET_FD,        // file descriptor
+};
+
 /* lists of fields that can be logged */
 enum {
 
@@ -197,6 +203,7 @@ struct logsrv {
        struct list list;
        struct sockaddr_storage addr;
        struct smp_info lb;
+       enum log_tgt type;
        int format;
        int facility;
        int level;
index 9011724df2a08dc3e38042426468463aed931bff..1b34c637e23687c6920dbd183c3603f42a2886a9 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -999,6 +999,10 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
        }
 
        /* now, back to the address */
+       logsrv->type = LOG_TARGET_DGRAM;
+       if (strncmp(args[1], "fd@", 3) == 0)
+               logsrv->type = LOG_TARGET_FD;
+
        sk = str2sa_range(args[1], NULL, &port1, &port2, err, NULL, NULL, 1);
        if (!sk)
                goto error;
@@ -1502,7 +1506,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
 
        dataptr = message;
 
-       if (logsrv->addr.ss_family == AF_UNSPEC) {
+       if (logsrv->type == LOG_TARGET_FD) {
                /* the socket's address is a file descriptor */
                plogfd = (int *)&((struct sockaddr_in *)&logsrv->addr)->sin_addr.s_addr;
        }