syslog-ng source
journald-subsystem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2014 Balabit
3  * Copyright (c) 2010-2014 Viktor Juhasz <viktor.juhasz@balabit.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 
24 #ifndef JOURNAL_SOURCE_INTERFACE_H_
25 #define JOURNAL_SOURCE_INTERFACE_H_
26 
27 #include "syslog-ng-config.h"
28 
29 #if SYSLOG_NG_SYSTEMD_JOURNAL_MODE == SYSLOG_NG_JOURNALD_SYSTEM
30 #include <systemd/sd-journal.h>
31 
32 static inline int
33 load_journald_subsystem(void)
34 {
35  return 1;
36 }
37 
38 #else
39 
40 #include <stddef.h>
41 #include <stdint.h>
42 
43 /* Open flags */
44 enum
45 {
46  SD_JOURNAL_LOCAL_ONLY = 1,
47  SD_JOURNAL_RUNTIME_ONLY = 2,
48  SD_JOURNAL_SYSTEM = 4,
49  SD_JOURNAL_CURRENT_USER = 8,
50  SD_JOURNAL_OS_ROOT = 16,
51  SD_JOURNAL_ALL_NAMESPACES = 32,
52  SD_JOURNAL_INCLUDE_DEFAULT_NAMESPACE = 64
53 };
54 
55 typedef union sd_id128 sd_id128_t;
56 
57 union sd_id128
58 {
59  uint8_t bytes[16];
60  uint64_t qwords[2];
61 };
62 
63 #define SD_ID128_STRING_MAX 33
64 
65 
66 typedef struct sd_journal sd_journal;
67 
68 /*
69  * attribute((visibility("hidden")) is needed to avoid these variables to be
70  * overridden with symbols of the same name from libsystemd.so.
71  *
72  * It may happen that libsyslog-ng.so itself is linked against libsystemd.so
73  * (due to service management being used). In this case these names would
74  * map to actual functions in libsystemd.so, resulting in a nasty crash
75  * whenever we try to use these as pointers to functions.
76  *
77  * By using "hidden" visibility, we tell the linker that these symbols are
78  * internal to the current .so, meaning that any code that references these
79  * from this module will happily use these as pointers while other modules
80  * of syslog-ng can still use them as functions.
81  *
82  * See https://github.com/syslog-ng/syslog-ng/issues/4300 for more details.
83  */
84 
85 #define VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
86 
87 VISIBILITY_HIDDEN extern int (*sd_journal_open)(sd_journal **ret, int flags);
88 #if SYSLOG_NG_HAVE_JOURNAL_NAMESPACES
89 VISIBILITY_HIDDEN extern int (*sd_journal_open_namespace)(sd_journal **ret, const char *namespace, int flags);
90 #endif
91 VISIBILITY_HIDDEN extern void (*sd_journal_close)(sd_journal *j);
92 VISIBILITY_HIDDEN extern int (*sd_journal_seek_head)(sd_journal *j);
93 VISIBILITY_HIDDEN extern int (*sd_journal_seek_tail)(sd_journal *j);
94 VISIBILITY_HIDDEN extern int (*sd_journal_get_cursor)(sd_journal *j, char **cursor);
95 VISIBILITY_HIDDEN extern int (*sd_journal_next)(sd_journal *j);
96 VISIBILITY_HIDDEN extern void (*sd_journal_restart_data)(sd_journal *j);
97 VISIBILITY_HIDDEN extern int (*sd_journal_enumerate_data)(sd_journal *j, const void **data, size_t *length);
98 VISIBILITY_HIDDEN extern int (*sd_journal_seek_cursor)(sd_journal *j, const char *cursor);
99 VISIBILITY_HIDDEN extern int (*sd_journal_test_cursor)(sd_journal *j, const char *cursor);
100 VISIBILITY_HIDDEN extern int (*sd_journal_get_fd)(sd_journal *j);
101 VISIBILITY_HIDDEN extern int (*sd_journal_process)(sd_journal *j);
102 VISIBILITY_HIDDEN extern int (*sd_journal_get_realtime_usec)(sd_journal *j, uint64_t *usec);
103 VISIBILITY_HIDDEN extern int (*sd_journal_add_match)(sd_journal *j, const void *data, size_t size);
104 VISIBILITY_HIDDEN extern char *(*sd_id128_to_string)(sd_id128_t id, char s[SD_ID128_STRING_MAX]);
105 VISIBILITY_HIDDEN extern int (*sd_id128_get_boot)(sd_id128_t *ret);
106 
107 int load_journald_subsystem(void);
108 
109 #endif
110 
111 #endif /* JOURNAL_SOURCE_INTERFACE_H_ */
MOCK_STATIC void MOCK_FUNC() sd_journal_close(sd_journal *s)
Definition: journald-mock.c:161
MOCK_STATIC int MOCK_FUNC() sd_journal_open(sd_journal **s, int flags)
Definition: journald-mock.c:146
MOCK_STATIC int MOCK_FUNC() sd_journal_get_realtime_usec(sd_journal *s, guint64 *usec)
Definition: journald-mock.c:307
MOCK_STATIC int MOCK_FUNC() sd_journal_enumerate_data(sd_journal *s, const void **data, gsize *length)
Definition: journald-mock.c:230
MOCK_STATIC int MOCK_FUNC() sd_journal_get_cursor(sd_journal *s, gchar **cursor)
Definition: journald-mock.c:194
MOCK_STATIC int MOCK_FUNC() sd_journal_get_fd(sd_journal *s)
Definition: journald-mock.c:280
MOCK_STATIC int MOCK_FUNC() sd_journal_seek_tail(sd_journal *s)
Definition: journald-mock.c:184
MOCK_STATIC void MOCK_FUNC() sd_journal_restart_data(sd_journal *s)
Definition: journald-mock.c:220
MOCK_STATIC int MOCK_FUNC() sd_id128_get_boot(sd_id128_t *ret)
Definition: journald-mock.c:326
MOCK_STATIC int MOCK_FUNC() sd_journal_process(sd_journal *s)
Definition: journald-mock.c:288
MOCK_STATIC int MOCK_FUNC() sd_journal_next(sd_journal *s)
Definition: journald-mock.c:205
MOCK_STATIC int MOCK_FUNC() sd_journal_seek_head(sd_journal *s)
Definition: journald-mock.c:174
MOCK_STATIC int MOCK_FUNC() sd_journal_seek_cursor(sd_journal *s, const gchar *cursor)
Definition: journald-mock.c:255
MOCK_STATIC int MOCK_FUNC() sd_journal_add_match(sd_journal *s, const void *match, size_t match_len)
Definition: journald-mock.c:314
MOCK_STATIC int MOCK_FUNC() sd_journal_test_cursor(sd_journal *self, const gchar *cursor)
Definition: journald-mock.c:274
MOCK_STATIC int MOCK_FUNC() sd_journal_open_namespace(sd_journal **s, const gchar *namespace, int flags)
Definition: journald-mock.c:155