blob: 34717227f13cd18faf44529bd4316e6876287779 (
plain) (
blame)
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
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
struct liblog_output *
liblog_use_output(struct liblog_context *ctx, const struct liblog_output *output)
{
void *new;
if (!ctx || !output)
goto einval;
if (output->lowest_verbosity_unlimited && output->highest_verbosity_unlimited)
if (output->lowest_verbosity > output->highest_verbosity)
goto einval;
if (output->sink_type == LIBLOG_STREAM) {
if (!output->sink.stream.stream)
goto einval;
} else if (output->sink_type != LIBLOG_SYSLOG && output->sink_type != LIBLOG_FILE) {
/*
* We do not want to validate syslog level,
* nor do we want to validate file descriptor,
* indeed the user may want to output to a negative
* file descriptor so that it only visible during
* system call tracing
*/
einval:
errno = EINVAL;
return NULL;
}
if (ctx->noutputs > SIZE_MAX / sizeof(*ctx->outputs) - 1)
goto enomem;
new = realloc(ctx->outputs, (ctx->noutputs + 1) * sizeof(*ctx->outputs));
if (!new) {
enomem:
errno = ENOMEM;
return NULL;
}
memcpy(&ctx->outputs[ctx->noutputs], output, sizeof(*output));
if (!ctx->outputs[ctx->noutputs].prefixfmt)
ctx->outputs[ctx->noutputs].prefixfmt = DEFAULT_PREFIXFMT;
return &ctx->outputs[ctx->noutputs++];
}
#else
int main(void) {return 0;} /* TODO test */
#endif
|