Skip to content

Commit 9959b0f

Browse files
committed
Engine: implement shutdown routine to release resources
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 5c09ad5 commit 9959b0f

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

include/fluent-bit/flb_engine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@
3636
int flb_engine_start(struct flb_config *config);
3737
int flb_engine_flush(struct flb_config *config,
3838
struct flb_input_plugin *in_force);
39+
int flb_engine_shutdown(struct flb_config *config);
40+
3941
#endif

src/flb_engine.c

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,7 @@ int flb_engine_start(struct flb_config *config)
256256
if (event->type == FLB_ENGINE_EV_CORE) {
257257
ret = flb_engine_handle_event(event->fd, event->mask, config);
258258
if (ret == -1) {
259-
/* Inputs exit */
260-
flb_input_exit_all(config);
261-
/* Outputs exit */
262-
flb_output_exit(config);
259+
flb_engine_shutdown(config);
263260
return 0;
264261
}
265262
}
@@ -281,3 +278,44 @@ int flb_engine_start(struct flb_config *config)
281278
}
282279
}
283280
}
281+
282+
/* Release all resources associated to the engine */
283+
int flb_engine_shutdown(struct flb_config *config)
284+
{
285+
/* cleanup plugins */
286+
flb_input_exit_all(config);
287+
flb_output_exit(config);
288+
289+
/* release resources */
290+
if (config->ch_event.fd) {
291+
close(config->ch_event.fd);
292+
}
293+
294+
/* Pipe */
295+
if (config->ch_data[0]) {
296+
close(config->ch_data[0]);
297+
close(config->ch_data[1]);
298+
}
299+
300+
/* Channel manager */
301+
if (config->ch_manager[0] > 0) {
302+
close(config->ch_manager[0]);
303+
if (config->ch_manager[0] != config->ch_manager[1]) {
304+
close(config->ch_manager[1]);
305+
}
306+
}
307+
308+
/* Channel notifications */
309+
if (config->ch_notif[0] > 0) {
310+
close(config->ch_notif[0]);
311+
if (config->ch_notif[0] != config->ch_notif[1]) {
312+
close(config->ch_notif[1]);
313+
}
314+
}
315+
316+
close(config->flush_fd);
317+
mk_event_loop_destroy(config->evl);
318+
free(config);
319+
320+
return 0;
321+
}

0 commit comments

Comments
 (0)