Skip to content

Commit

Permalink
Merge pull request #1214 from alessandrocarminati/ac-serial-terminal-…
Browse files Browse the repository at this point in the history
…issue_3

Refactor: Restore serial settings for incorrect serial
  • Loading branch information
giuseppe authored May 15, 2023
2 parents 00bcc1f + 1ad17f8 commit ec06899
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/libcrun/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ libcrun_new_terminal (char **pty, libcrun_error_t *err)
}

static int
set_raw (int fd, libcrun_error_t *err)
set_raw (int fd, void **current_status, libcrun_error_t *err)
{
int ret;
struct termios termios;
Expand All @@ -71,6 +71,14 @@ set_raw (int fd, libcrun_error_t *err)
if (UNLIKELY (ret < 0))
return crun_make_error (err, errno, "tcgetattr");

if (current_status)
{
struct terminal_status_s *s = xmalloc (sizeof (*s));
s->fd = fd;
memcpy (&(s->termios), &termios, sizeof (termios));
*current_status = s;
}

cfmakeraw (&termios);

termios.c_iflag &= OPOST;
Expand Down Expand Up @@ -116,19 +124,11 @@ libcrun_setup_terminal_ptmx (int fd, void **current_status, libcrun_error_t *err
if (UNLIKELY (ret < 0))
return crun_make_error (err, errno, "tcgetattr");

if (current_status)
{
struct terminal_status_s *s = xmalloc (sizeof (*s));
s->fd = 0;
memcpy (&(s->termios), &termios, sizeof (termios));
*current_status = s;
}

ret = tcsetattr (fd, TCSANOW, &termios);
if (UNLIKELY (ret < 0))
return crun_make_error (err, errno, "tcsetattr");

return set_raw (0, err);
return set_raw (0, current_status, err);
}

void
Expand Down

0 comments on commit ec06899

Please sign in to comment.