1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/* logging, for libreswan
*
* Copyright (C) 2022 Andrew Cagney
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <https://www.gnu.org/licenses/gpl2.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
*/
#include <stdlib.h> /* for abort() */
#include "logjam.h"
#include "lswlog.h"
struct jambuf *jambuf_from_logjam(struct logjam *logjam,
const struct logger *logger,
enum pluto_exit_code pluto_exit_code,
where_t where,
lset_t rc_flags)
{
/*
* Note: don't initialize entire logjam; as that would zero
* the very large array[LOG_WIDTH].
*/
logjam->barf = (struct barf) {
.rc_flags = rc_flags,
.jambuf = ARRAY_AS_JAMBUF(logjam->array),
.logger = logger,
.where = where,
.pluto_exit_code = pluto_exit_code,
};
jam_logger_rc_prefix(&logjam->barf.jambuf, logger, rc_flags);
return &logjam->barf.jambuf;
}
void logjam_to_logger(struct logjam *logjam)
{
if (logjam->barf.where != NULL) {
jam_string(&logjam->barf.jambuf, " ");
jam_where(&logjam->barf.jambuf, logjam->barf.where);
}
jambuf_to_logger(&logjam->barf.jambuf, logjam->barf.logger, logjam->barf.rc_flags);
if ((logjam->barf.rc_flags & STREAM_MASK) == PASSERT_STREAM) {
abort();
}
}
void barf(lset_t rc_flags, struct logger *logger,
enum pluto_exit_code pluto_exit_code, where_t where,
const char *fmt, ...)
{
BARF_JAMBUF(rc_flags, logger, pluto_exit_code, where, buf) {
va_list ap;
va_start(ap, fmt);
jam_va_list(buf, fmt, ap);
va_end(ap);
}
}
|