-
Notifications
You must be signed in to change notification settings - Fork 30
/
logdststdout.c
62 lines (52 loc) · 1.07 KB
/
logdststdout.c
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
/*-
* xnumon - monitor macOS for malicious activity
* https://www.roe.ch/xnumon
*
* Copyright (c) 2017-2019, Daniel Roethlisberger <daniel@roe.ch>.
* All rights reserved.
*
* Licensed under the Open Software License version 3.0.
*/
#include "logdststdout.h"
#include "config.h"
#include "attrib.h"
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
#include <assert.h>
static config_t *config;
static bool do_flush;
static FILE *
logdststdout_open(void) {
return stdout;
}
static int
logdststdout_close(UNUSED FILE *f) {
/*
* Need to flush if stdout refers to a file in order to prevent
* committing incomplete events to disk. If stdout refers to a TTY,
* assume the TTY is line-buffered anyway.
*/
if (do_flush)
fflush(f);
return 0;
}
static int
logdststdout_init(config_t *cfg) {
config = cfg;
do_flush = !isatty(fileno(stdout));
return 0;
}
static void
logdststdout_fini(void) {
config = NULL;
}
logdst_t logdststdout = {
"-", false, true, true, false,
logdststdout_init,
NULL,
logdststdout_fini,
NULL,
logdststdout_open,
logdststdout_close
};