From f3dc30f6de28820a35d670a27959365a493d43a7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 30 Aug 2019 14:18:44 +0200 Subject: [PATCH] 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. --- include/types/log.h | 7 +++++++ src/log.c | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/types/log.h b/include/types/log.h index affcd92d2..dbbd73bf7 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 9011724df..1b34c637e 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; } -- 2.47.3