Bug: file: Should reset file context when tty exit

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2021-02-01 12:12:30 +08:00
parent 048c0d3c95
commit 83af75e0e7
3 changed files with 13 additions and 4 deletions
+9 -4
View File
@@ -63,14 +63,21 @@ static int send_file_control_msg(int fd, int type, void *buf, int len)
return 0;
}
static void file_context_reset(struct file_context *ctx)
void file_context_reset(struct file_context *ctx)
{
struct rtty *rtty = container_of(ctx, struct rtty, file_context);
ev_io_stop(rtty->loop, &ctx->iof);
if (ctx->fd > 0) {
close(ctx->fd);
ctx->fd = -1;
}
close(ctx->ctlfd);
if (ctx->ctlfd > 0) {
close(ctx->ctlfd);
ctx->ctlfd = -1;
}
ctx->busy = false;
}
@@ -125,7 +132,6 @@ static void on_file_read(struct ev_loop *loop, struct ev_io *w, int revents)
ev_io_start(rtty->loop, &rtty->iow);
if (ret == 0) {
ev_io_stop(loop, w);
file_context_reset(ctx);
return;
}
@@ -136,7 +142,6 @@ static void on_file_read(struct ev_loop *loop, struct ev_io *w, int revents)
return;
err:
ev_io_stop(loop, w);
notify_user_canceled(rtty);
file_context_reset(ctx);
}
+2
View File
@@ -65,5 +65,7 @@ bool detect_file_operation(uint8_t *buf, int len, int sid, struct file_context *
void parse_file_msg(struct file_context *ctx, struct buffer *data, int len);
void file_context_reset(struct file_context *ctx);
#endif
+2
View File
@@ -56,6 +56,8 @@ static void del_tty(struct tty *tty)
rtty->ttys[tty->sid] = NULL;
file_context_reset(&rtty->file_context);
log_info("delete tty: %d\n", tty->sid);
free(tty);