]> git.tue.mpg.de Git - micoforia.git/commitdiff
enter: Save and restore the terminal settings.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 5 May 2021 16:48:13 +0000 (18:48 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 5 May 2021 16:50:28 +0000 (18:50 +0200)
On some systems, the backspace key no longer worked the
enter subcommand exited.

micoforia.c

index 6e10a0c8aab3ef96d9710e69100f0b47d965319e..b09f352b8c5c9b800809c79b4452627478fe5bb4 100644 (file)
@@ -1929,6 +1929,8 @@ static bool com_enter(void)
        bool success;
        int ret, pid;
        char *errctx;
+       struct termios tios;
+       bool tty;
 
        ret = lls_check_arg_count(sublpr, 1, INT_MAX, &errctx);
        if (ret < 0)
@@ -1951,7 +1953,21 @@ static bool com_enter(void)
                        : dflt_cmd[n];
        argv[N - 1] = NULL;
        clean_env();
+       tty = false;
+       if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
+               if (tcgetattr(STDIN_FILENO, &tios) >= 0)
+                       tty = true;
+       }
        success = xexec(argv, NULL);
+       if (tty) { /* reset terminal settings */
+               /*
+                * First give up the controlling terminal. Without this, the
+                * command gets SIGSTOP and goes to the background. We ignore
+                * errors here because nobody cares about a messed up terminal.
+                */
+               ioctl(STDIN_FILENO, TIOCNOTTY);
+               tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios);
+       }
        free(argv);
        return success;
 }