Skip to content

Commit 36e50e2

Browse files
committed
in_systemd: validate if FLB_SQLDB is set
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 92ef906 commit 36e50e2

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

plugins/in_systemd/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
set(src
22
systemd_config.c
3-
systemd_db.c
43
systemd.c)
54

5+
if(FLB_SQLDB)
6+
set(src
7+
${src}
8+
systemd_db.c)
9+
endif()
10+
611
FLB_PLUGIN(in_systemd "${src}" ${JOURNALD_LIBRARIES})

plugins/in_systemd/systemd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ static int in_systemd_collect(struct flb_input_instance *i_ins,
8686
const char *key;
8787
const char *val;
8888
char *tmp;
89+
#ifdef FLB_HAVE_SQLDB
8990
char *cursor = NULL;
91+
#endif
9092
char *tag;
9193
char new_tag[PATH_MAX];
9294
char last_tag[PATH_MAX];
@@ -260,6 +262,7 @@ static int in_systemd_collect(struct flb_input_instance *i_ins,
260262
}
261263
}
262264

265+
#ifdef FLB_HAVE_SQLDB
263266
/* Save cursor */
264267
if (ctx->db) {
265268
sd_journal_get_cursor(ctx->j, &cursor);
@@ -268,6 +271,7 @@ static int in_systemd_collect(struct flb_input_instance *i_ins,
268271
flb_free(cursor);
269272
}
270273
}
274+
#endif
271275

272276
/* Write any pending data into the buffer */
273277
if (mp_sbuf.size > 0) {

plugins/in_systemd/systemd_config.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
#include <sys/stat.h>
2929
#include <unistd.h>
3030

31+
#ifdef FLB_HAVE_SQLDB
3132
#include "systemd_db.h"
33+
#endif
34+
3235
#include "systemd_config.h"
3336

3437
struct flb_systemd_config *flb_systemd_config_create(struct flb_input_instance *i_ins,
@@ -107,6 +110,7 @@ struct flb_systemd_config *flb_systemd_config_create(struct flb_input_instance *
107110
ctx->dynamic_tag = FLB_FALSE;
108111
}
109112

113+
#ifdef FLB_HAVE_SQLDB
110114
/* Database file */
111115
tmp = flb_input_get_property("db", i_ins);
112116
if (tmp) {
@@ -115,6 +119,7 @@ struct flb_systemd_config *flb_systemd_config_create(struct flb_input_instance *
115119
flb_error("[in_systemd] could not open/create database");
116120
}
117121
}
122+
#endif
118123

119124
/* Max number of fields per record/entry */
120125
tmp = flb_input_get_property("max_fields", i_ins);
@@ -186,6 +191,7 @@ struct flb_systemd_config *flb_systemd_config_create(struct flb_input_instance *
186191
sd_journal_seek_head(ctx->j);
187192
}
188193

194+
#ifdef FLB_HAVE_SQLDB
189195
/* Check if we have a cursor in our database */
190196
if (ctx->db) {
191197
cursor = flb_systemd_db_get_cursor(ctx);
@@ -203,6 +209,7 @@ struct flb_systemd_config *flb_systemd_config_create(struct flb_input_instance *
203209
flb_free(cursor);
204210
}
205211
}
212+
#endif
206213

207214
tmp = flb_input_get_property("strip_underscores", i_ins);
208215
if (tmp != NULL && flb_utils_bool(tmp)) {
@@ -229,9 +236,11 @@ int flb_systemd_config_destroy(struct flb_systemd_config *ctx)
229236
flb_free(ctx->path);
230237
}
231238

239+
#ifdef FLB_HAVE_SQLDB
232240
if (ctx->db) {
233241
flb_systemd_db_close(ctx->db);
234242
}
243+
#endif
235244

236245
close(ctx->ch_manager[0]);
237246
close(ctx->ch_manager[1]);

plugins/in_systemd/systemd_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ struct flb_systemd_config {
5959
int max_fields; /* max number of fields per record */
6060
int max_entries; /* max number of records per iteration */
6161
int strip_underscores;
62+
63+
#ifdef FLB_HAVE_SQLDB
6264
struct flb_sqldb *db;
65+
#endif
6366
struct flb_input_instance *i_ins;
6467
};
6568

0 commit comments

Comments
 (0)