pty: set VERASE character to backspace during setup
authorDavid Herrmann <dh.herrmann@googlemail.com>
Wed, 19 Sep 2012 19:13:48 +0000 (21:13 +0200)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Wed, 19 Sep 2012 19:13:48 +0000 (21:13 +0200)
Some crazy guy decided to set VERASE to DEL by default in the kernel. So
when starting an application which does not initialize the terminal on
startup, they may not notice that we actually send BACKSPACE as
erase-character (like /bin/login). Therefore, initialize VERASE to 010 so
everyone is happy.

Thanks to Etam for reporting this!

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/pty.c

index b20a3f8..98c9283 100644 (file)
--- a/src/pty.c
+++ b/src/pty.c
@@ -184,6 +184,7 @@ static void setup_child(int master, struct winsize *ws)
        pid_t pid;
        char slave_name[128];
        int slave = -1;
+       struct termios attr;
 
        /* The child should not inherit our signal mask. */
        sigemptyset(&sigset);
@@ -223,6 +224,21 @@ static void setup_child(int master, struct winsize *ws)
                goto err_out;
        }
 
+       /* get terminal attributes */
+       if (tcgetattr(slave, &attr) < 0) {
+               log_err("cannot get terminal attributes: %m");
+               goto err_out;
+       }
+
+       /* erase character should be normal backspace */
+       attr.c_cc[VERASE] = 010;
+
+       /* set changed terminal attributes */
+       if (tcsetattr(slave, TCSANOW, &attr) < 0) {
+               log_warn("cannot set terminal attributes: %m");
+               goto err_out;
+       }
+
        if (ws) {
                ret = ioctl(slave, TIOCSWINSZ, ws);
                if (ret)