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.
This commit is contained in:
Willy Tarreau 2019-08-30 14:18:44 +02:00
parent d52a7f8c8d
commit f3dc30f6de
2 changed files with 12 additions and 1 deletions

View 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;

View File

@ -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;
}