Since the file targets append one anyway, save them some extra work.
syslog can use `%.*s` since it's "forced" printf by API anyway.
Signed-off-by: David Lamparter <equinox@diac24.net>
return len;
}
-static int search_buf(const char *buf)
+static int search_buf(const char *buf, size_t len)
{
char *found = NULL;
frr_with_mutex(&logfilterlock) {
for (int i = 0; i < zlog_filter_count; i++) {
- found = strstr(buf, zlog_filters[i]);
+ found = memmem(buf, len, zlog_filters[i],
+ strlen(zlog_filters[i]));
if (found != NULL)
return 0;
}
{
struct zlog_msg *msgfilt[nmsgs];
size_t i, o = 0;
+ const char *text;
+ size_t text_len;
for (i = 0; i < nmsgs; i++) {
- if (zlog_msg_prio(msgs[i]) >= LOG_DEBUG
- && search_buf(zlog_msg_text(msgs[i], NULL)) < 0)
- continue;
-
+ if (zlog_msg_prio(msgs[i]) >= LOG_DEBUG) {
+ text = zlog_msg_text(msgs[i], &text_len);
+ if (search_buf(text, text_len) < 0)
+ continue;
+ }
msgfilt[o++] = msgs[i];
}
va_end(args);
msg->textlen = need;
- need += bputch(&fb, '\0');
+ need += bputch(&fb, '\n');
if (need <= msg->stackbufsz)
msg->text = msg->stackbuf;
vbprintfrr(&fb, msg->fmt, args);
va_end(args);
- bputch(&fb, '\0');
+ bputch(&fb, '\n');
}
msg->n_argpos = fb.outpos_i;
extern int zlog_msg_prio(struct zlog_msg *msg);
extern const struct xref_logmsg *zlog_msg_xref(struct zlog_msg *msg);
-/* pass NULL as textlen if you don't need it. */
+/* text is NOT \0 terminated; instead there is a \n after textlen since the
+ * logging targets would jump extra hoops otherwise for a single byte. (the
+ * \n is not included in textlen)
+ *
+ * calling this with NULL textlen is likely wrong.
+ * use "%.*s", (int)textlen, text when passing to printf-like functions
+ */
extern const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen);
extern void zlog_msg_args(struct zlog_msg *msg, size_t *hdrlen,
int prio = zlog_msg_prio(msg);
if (prio <= zt->prio_min) {
- iov[iovpos].iov_base = ts_pos;
- if (iovpos > 0)
- *ts_pos++ = '\n';
-
struct fbuf fbuf = {
.buf = ts_buf,
.pos = ts_pos,
.len = sizeof(ts_buf),
};
+
+ iov[iovpos].iov_base = ts_pos;
zlog_msg_ts(msg, &fbuf,
ZLOG_TS_LEGACY | zte->ts_subsec);
ts_pos = fbuf.pos;
iov[iovpos].iov_base =
(char *)zlog_msg_text(msg, &textlen);
- iov[iovpos].iov_len = textlen;
+ iov[iovpos].iov_len = textlen + 1;
iovpos++;
}
if (iovpos > 0 && (ts_buf + sizeof(ts_buf) - ts_pos < TS_LEN
|| i + 1 == nmsgs
|| array_size(iov) - iovpos < 5)) {
- iov[iovpos].iov_base = (char *)"\n";
- iov[iovpos].iov_len = 1;
-
- iovpos++;
-
writev(fd, iov, iovpos);
iovpos = 0;
{
size_t i;
struct zlt_syslog *zte = container_of(zt, struct zlt_syslog, zt);
+ const char *text;
+ size_t text_len;
for (i = 0; i < nmsgs; i++) {
if (zlog_msg_prio(msgs[i]) > zt->prio_min)
continue;
- syslog(zlog_msg_prio(msgs[i]) | zte->syslog_facility, "%s",
- zlog_msg_text(msgs[i], NULL));
+ text = zlog_msg_text(msgs[i], &text_len);
+ syslog(zlog_msg_prio(msgs[i]) | zte->syslog_facility, "%.*s",
+ (int)text_len, text);
}
}