Skip to content

Commit 9e7c7e2

Browse files
author
Tom
committed
daemon mode means fb won't exit even pgsql err
1 parent a07d45a commit 9e7c7e2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

plugins/out_pgsql/pgsql.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
5454
char *temp = NULL;
5555
const char *tmp = NULL;
5656
int ret;
57+
int daemon;
5758

5859
/* set default network configuration */
5960
flb_output_net_default(FLB_PGSQL_HOST, FLB_PGSQL_PORT, ins);
@@ -171,8 +172,20 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
171172
ctx->cockroachdb = FLB_FALSE;
172173
}
173174

175+
/* daemon mode so that fluenbit will not exit if pgsql error */
176+
tmp = flb_output_get_property("daemon", ins);
177+
if (tmp && flb_utils_bool(tmp)) {
178+
daemon = FLB_TRUE;
179+
}
180+
else {
181+
daemon = FLB_FALSE;
182+
}
183+
174184
ret = pgsql_start_connections(ctx);
175185
if (ret) {
186+
if (daemon) {
187+
return 0;
188+
}
176189
return -1;
177190
}
178191

@@ -187,6 +200,9 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
187200
flb_plg_error(ctx->ins, "failed to parse table name: %s",
188201
PQerrorMessage(ctx->conn_current->conn));
189202
pgsql_conf_destroy(ctx);
203+
if (daemon) {
204+
return 0;
205+
}
190206
return -1;
191207
}
192208

@@ -197,6 +213,9 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
197213
if (!ctx->db_table) {
198214
flb_errno();
199215
pgsql_conf_destroy(ctx);
216+
if (daemon) {
217+
return 0;
218+
}
200219
return -1;
201220
}
202221

@@ -209,6 +228,9 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
209228
if (query == NULL) {
210229
flb_errno();
211230
pgsql_conf_destroy(ctx);
231+
if (daemon) {
232+
return 0;
233+
}
212234
return -1;
213235
}
214236

@@ -227,6 +249,9 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
227249
flb_plg_error(ctx->ins, "%s",
228250
PQerrorMessage(ctx->conn_current->conn));
229251
pgsql_conf_destroy(ctx);
252+
if (daemon) {
253+
return 0;
254+
}
230255
return -1;
231256
}
232257

@@ -250,6 +275,9 @@ static void cb_pgsql_flush(struct flb_event_chunk *event_chunk,
250275
flb_sds_t tag_escaped = NULL;
251276
size_t str_len;
252277

278+
if (ctx ==NULL) {
279+
FLB_OUTPUT_RETURN(FLB_RETRY);
280+
}
253281

254282
if (pgsql_next_connection(ctx) == 1) {
255283
FLB_OUTPUT_RETURN(FLB_RETRY);

plugins/out_pgsql/pgsql_connections.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ int pgsql_next_connection(struct flb_pgsql_config *ctx)
143143
struct mk_list *head;
144144
int ret_conn = 1;
145145

146+
if (ctx ==NULL) {
147+
return 1;
148+
}
149+
146150
if (PQconsumeInput(ctx->conn_current->conn) == 1) {
147151
if (PQisBusy(ctx->conn_current->conn) == 0) {
148152
res = PQgetResult(ctx->conn_current->conn);

0 commit comments

Comments
 (0)