-
Notifications
You must be signed in to change notification settings - Fork 30
/
logdstsyslog.c
70 lines (58 loc) · 1.21 KB
/
logdstsyslog.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
62
63
64
65
66
67
68
69
/*-
* 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 "logdstsyslog.h"
#include "config.h"
#include "attrib.h"
#include "memstream.h"
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <assert.h>
static config_t *config;
static char *msg;
static size_t sz;
static FILE *
logdstsyslog_open(void) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
return open_memstream(&msg, &sz);
#pragma clang diagnostic pop
}
static int
logdstsyslog_close(FILE *f) {
fclose(f);
if (!msg)
return -1;
syslog(LOG_NOTICE, "%s", msg);
free(msg);
return 0;
}
static int
logdstsyslog_init(config_t *cfg) {
config = cfg;
assert(cfg->logoneline);
setlogmask(LOG_UPTO(LOG_NOTICE));
openlog("xnumon", LOG_CONS|LOG_PID|LOG_NDELAY, LOG_LOCAL1);
return 0;
}
static void
logdstsyslog_fini(void) {
closelog();
config = NULL;
}
logdst_t logdstsyslog = {
"syslog", false, true, false, true,
logdstsyslog_init,
NULL,
logdstsyslog_fini,
NULL,
logdstsyslog_open,
logdstsyslog_close
};