From 46367d8f1e2bc3c09895e320690c438a476c4703 Mon Sep 17 00:00:00 2001 From: Takeshi HASEGAWA Date: Thu, 3 Sep 2015 03:12:50 +0900 Subject: [PATCH] in_serial: Restore termios before exiting. Signed-off-by: Takeshi HASEGAWA --- plugins/in_serial/in_serial.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/in_serial/in_serial.c b/plugins/in_serial/in_serial.c index 324a17ce974..4337448c7fa 100644 --- a/plugins/in_serial/in_serial.c +++ b/plugins/in_serial/in_serial.c @@ -131,6 +131,15 @@ int in_serial_collect(struct flb_config *config, void *in_context) } } +/* Cleanup serial input */ +int in_serial_exit(void *in_context, struct flb_config *config) +{ + struct flb_in_serial_config *ctx = in_context; + + flb_debug("[in_serial] Restoring original termios..."); + tcsetattr(ctx->fd, TCSANOW, &ctx->tio_orig); +} + /* Init serial input */ int in_serial_init(struct flb_config *config) { @@ -166,6 +175,7 @@ int in_serial_init(struct flb_config *config) msgpack_sbuffer_init(&ctx->mp_sbuf); msgpack_packer_init(&ctx->mp_pck, &ctx->mp_sbuf, msgpack_sbuffer_write); + tcgetattr(fd, &ctx->tio_orig); memset(&ctx->tio, 0, sizeof(ctx->tio)); ctx->tio.c_cflag = ctx->tio.c_ispeed = ctx->tio.c_ospeed = atoi(ctx->bitrate); ctx->tio.c_cflag |= CRTSCTS | CS8 | CLOCAL | CREAD; @@ -209,5 +219,6 @@ struct flb_input_plugin in_serial_plugin = { .cb_init = in_serial_init, .cb_pre_run = NULL, .cb_collect = in_serial_collect, - .cb_flush_buf = in_serial_flush + .cb_flush_buf = in_serial_flush, + .cb_exit = in_serial_exit };