+// SPDX-License-Identifier: ISC
/*
* Copyright (c) 2015-19 David Lamparter, for NetDEF, Inc.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "zebra.h"
* absolute end.
*/
-DECLARE_MGROUP(LOG);
DEFINE_MGROUP_ACTIVEATEXIT(LOG, "logging subsystem");
DEFINE_MTYPE_STATIC(LOG, LOG_FD, "log file target");
int prio = zlog_msg_prio(msg);
if (prio <= zt->prio_min) {
+ struct fbuf fbuf = {
+ .buf = ts_buf,
+ .pos = ts_pos,
+ .len = sizeof(ts_buf),
+ };
+
iov[iovpos].iov_base = ts_pos;
- if (iovpos > 0)
- *ts_pos++ = '\n';
- ts_pos += zlog_msg_ts(msg, ts_pos,
- sizeof(ts_buf) - 1
- - (ts_pos - ts_buf),
- ZLOG_TS_LEGACY | zte->ts_subsec);
+ zlog_msg_ts(msg, &fbuf,
+ ZLOG_TS_LEGACY | zte->ts_subsec);
+ ts_pos = fbuf.pos;
+
*ts_pos++ = ' ';
iov[iovpos].iov_len =
ts_pos - (char *)iov[iovpos].iov_base;
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;
void zlog_file_set_other(struct zlog_cfg_file *zcf)
{
- frr_with_mutex(&zcf->cfg_mtx) {
+ frr_with_mutex (&zcf->cfg_mtx) {
zlog_file_cycle(zcf);
}
}
bool zlog_file_set_filename(struct zlog_cfg_file *zcf, const char *filename)
{
- frr_with_mutex(&zcf->cfg_mtx) {
+ frr_with_mutex (&zcf->cfg_mtx) {
XFREE(MTYPE_LOG_FD_NAME, zcf->filename);
zcf->filename = XSTRDUP(MTYPE_LOG_FD_NAME, filename);
zcf->fd = -1;
return zlog_file_cycle(zcf);
}
assert(0);
+ return false;
}
bool zlog_file_set_fd(struct zlog_cfg_file *zcf, int fd)
{
- frr_with_mutex(&zcf->cfg_mtx) {
+ frr_with_mutex (&zcf->cfg_mtx) {
if (zcf->fd == fd)
return true;
return zlog_file_cycle(zcf);
}
assert(0);
+ return false;
}
struct rcu_close_rotate {
struct rcu_close_rotate *rcr;
int fd;
- frr_with_mutex(&zcf->cfg_mtx) {
+ frr_with_mutex (&zcf->cfg_mtx) {
if (!zcf->active || !zcf->filename)
return true;
{
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);
}
}
struct zlog_target *newztc;
struct zlt_syslog *newzt;
- frr_with_mutex(&syslog_cfg_mutex) {
+ frr_with_mutex (&syslog_cfg_mutex) {
if (facility == syslog_facility)
return;
syslog_facility = facility;
int zlog_syslog_get_facility(void)
{
- frr_with_mutex(&syslog_cfg_mutex) {
+ frr_with_mutex (&syslog_cfg_mutex) {
return syslog_facility;
}
assert(0);
+ return 0;
}
void zlog_syslog_set_prio_min(int prio_min)
struct zlog_target *newztc;
struct zlt_syslog *newzt = NULL;
- frr_with_mutex(&syslog_cfg_mutex) {
+ frr_with_mutex (&syslog_cfg_mutex) {
if (prio_min == syslog_prio_min)
return;
syslog_prio_min = prio_min;
int zlog_syslog_get_prio_min(void)
{
- frr_with_mutex(&syslog_cfg_mutex) {
+ frr_with_mutex (&syslog_cfg_mutex) {
return syslog_prio_min;
}
assert(0);
+ return 0;
}