[systemd-devel] [PATCH 2/2] ptyfwd: Don't set the output prop of stdin, nor the input props of stdout.

Lennart Poettering lennart at poettering.net
Tue Dec 10 17:04:46 PST 2013


On Sat, 23.11.13 04:57, Luke Shumaker (LukeShu at sbcglobal.net) wrote:

> It was calling cfmakeraw(3) on the properties for STDIN_FILENO; cfmakeraw
> sets both input and output properties.  If (and only if) stdin and stdout
> are the same device is this correct.  Otherwise, we must change only the
> input properties of stdin, and only the output properties of stdout.

Makes sense! Applied! Thanks!

> ---
>  src/shared/ptyfwd.c | 35 +++++++++++++++++++++++------------
>  1 file changed, 23 insertions(+), 12 deletions(-)
> 
> diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c
> index 85a0ddc..72aa59e 100644
> --- a/src/shared/ptyfwd.c
> +++ b/src/shared/ptyfwd.c
> @@ -341,29 +341,40 @@ static int process_pty_loop(int master, sigset_t *mask, pid_t kill_pid, int sign
>  }
>  
>  int process_pty(int master, sigset_t *mask, pid_t kill_pid, int signo) {
> -        struct termios saved_attr;
> -        bool saved = false;
> +        struct termios saved_stdin_attr, raw_stdin_attr;
> +        struct termios saved_stdout_attr, raw_stdout_attr;
> +        bool saved_stdin = false;
> +        bool saved_stdout = false;
>          struct winsize ws;
>          int r;
>  
>          if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) >= 0)
>                  ioctl(master, TIOCSWINSZ, &ws);
>  
> -        if (tcgetattr(STDIN_FILENO, &saved_attr) >= 0) {
> -                struct termios raw_attr;
> -                saved = true;
> +        if (tcgetattr(STDIN_FILENO, &saved_stdin_attr) >= 0) {
> +                saved_stdin = true;
>  
> -                raw_attr = saved_attr;
> -                cfmakeraw(&raw_attr);
> -                raw_attr.c_lflag &= ~ECHO;
> -
> -                tcsetattr(STDIN_FILENO, TCSANOW, &raw_attr);
> +                raw_stdin_attr = saved_stdin_attr;
> +                cfmakeraw(&raw_stdin_attr);
> +                raw_stdin_attr.c_oflag = saved_stdin_attr.c_oflag;
> +                tcsetattr(STDIN_FILENO, TCSANOW, &raw_stdin_attr);
> +        }
> +        if (tcgetattr(STDOUT_FILENO, &saved_stdout_attr) >= 0) {
> +                saved_stdout = true;
> +
> +                raw_stdout_attr = saved_stdout_attr;
> +                cfmakeraw(&raw_stdout_attr);
> +                raw_stdout_attr.c_iflag = saved_stdout_attr.c_iflag;
> +                raw_stdout_attr.c_lflag = saved_stdout_attr.c_lflag;
> +                tcsetattr(STDOUT_FILENO, TCSANOW, &raw_stdout_attr);
>          }
>  
>          r = process_pty_loop(master, mask, kill_pid, signo);
>  
> -        if (saved)
> -                tcsetattr(STDIN_FILENO, TCSANOW, &saved_attr);
> +        if (saved_stdout)
> +                tcsetattr(STDOUT_FILENO, TCSANOW, &saved_stdout_attr);
> +        if (saved_stdin)
> +                tcsetattr(STDIN_FILENO, TCSANOW, &saved_stdin_attr);
>  
>          return r;
>  


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list