Skip to content

Commit

Permalink
in_serial: Restore termios before exiting.
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi HASEGAWA <[email protected]>
  • Loading branch information
hasegaw committed Sep 2, 2015
1 parent 7719138 commit 46367d8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins/in_serial/in_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
};

0 comments on commit 46367d8

Please sign in to comment.