From: Willy Tarreau Date: Fri, 30 Aug 2019 12:18:44 +0000 (+0200) Subject: MINOR: log: add a target type instead of hacking the address family X-Git-Tag: v2.1-dev2~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3dc30f6de28820a35d670a27959365a493d43a7;p=thirdparty%2Fhaproxy.git MINOR: log: add a target type instead of hacking the address family 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. --- diff --git a/include/types/log.h b/include/types/log.h index affcd92d29..dbbd73bf70 100644 --- a/include/types/log.h +++ b/include/types/log.h @@ -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; diff --git a/src/log.c b/src/log.c index 9011724df2..1b34c637e2 100644 --- 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; }