ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Alexey Gladkov <legion@altlinux.ru>
To: ALT Devel discussion list <devel@lists.altlinux.org>
Subject: [devel] [PATCH 4/6] syslogd: no need to try to substitute a field in a record if it's not in the log_format
Date: Tue, 27 Oct 2020 12:33:49 +0100
Message-ID: <20201027113351.3373843-5-legion@altlinux.ru> (raw)
In-Reply-To: <20201027113351.3373843-1-legion@altlinux.ru>

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
---
 syslogd.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/syslogd.c b/syslogd.c
index 214c4e9..4c3c85f 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -314,6 +314,7 @@ struct log_format {
 	struct iovec *iov;
 	size_t iovec_nr;
 
+	unsigned int f_mask;
 	struct log_format_field *fields;
 	size_t fields_nr;
 };
@@ -1491,6 +1492,9 @@ finish:
 
 char *get_record_field(struct log_format *log_fmt, enum log_format_type name)
 {
+	if (!(log_fmt->f_mask | (1 << name)))
+		return NULL;
+
 	for (int i = 0; i < LOG_FORMAT_FIELDS_MAX && log_fmt->fields[i].f_iov; i++) {
 		if (log_fmt->fields[i].f_type == name)
 			return log_fmt->fields[i].f_iov->iov_base;
@@ -1501,7 +1505,12 @@ char *get_record_field(struct log_format *log_fmt, enum log_format_type name)
 void set_record_field(struct log_format *log_fmt,
 		enum log_format_type name, char *value, ssize_t len)
 {
-	size_t iov_len = len == -1 ? strlen(value) : len;
+	size_t iov_len;
+
+	if (!(log_fmt->f_mask | (1 << name)))
+		return;
+
+	iov_len = len == -1 ? strlen(value) : len;
 
 	for (int i = 0; i < LOG_FORMAT_FIELDS_MAX && log_fmt->fields[i].f_iov; i++) {
 		if (log_fmt->fields[i].f_type == name) {
@@ -2666,6 +2675,7 @@ int set_log_format_field(struct log_format *log_fmt, size_t i,
 			return -1;
 		}
 
+		log_fmt->f_mask |= (1 << t);
 		log_fmt->fields[log_fmt->fields_nr].f_type = t;
 		log_fmt->fields[log_fmt->fields_nr].f_iov = log_fmt->iov + i;
 		log_fmt->fields_nr++;
-- 
2.25.4



  parent reply	other threads:[~2020-10-27 11:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-27 11:33 [devel] [PATCH 0/6] sysklogd: implement checkum chains for log entries Alexey Gladkov
2020-10-27 11:33 ` [devel] [PATCH 1/6] Optimize the filling of the record fields Alexey Gladkov
2020-10-27 11:33 ` [devel] [PATCH 2/6] syslogd: make logerror is printf-like Alexey Gladkov
2020-10-27 11:33 ` [devel] [PATCH 3/6] syslogd: Implement customization of log file records Alexey Gladkov
2020-10-27 11:33 ` Alexey Gladkov [this message]
2020-10-27 11:33 ` [devel] [PATCH 5/6] Makefile: use make variables instead of a hardcoded list Alexey Gladkov
2020-10-27 11:33 ` [devel] [PATCH 6/6] syslogd: implement checksum chains for log entries Alexey Gladkov
2020-10-27 11:44 ` [devel] [PATCH 0/6] sysklogd: implement checkum " Alexey V. Vissarionov
2020-10-27 12:13   ` Alexey Gladkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201027113351.3373843-5-legion@altlinux.ru \
    --to=legion@altlinux.ru \
    --cc=devel@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git