diff --git a/kernel-src/include/kernel/tty.h b/kernel-src/include/kernel/tty.h index 9b8a0880..8a69e40d 100644 --- a/kernel-src/include/kernel/tty.h +++ b/kernel-src/include/kernel/tty.h @@ -34,5 +34,6 @@ void tty_init(); tty_t *tty_create(char *name, ttydevicewritefn_t writefn, ttyinactivefn_t inactivefn, void *internal); void tty_process(tty_t *tty, char c); void tty_unregister(tty_t *tty); +int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result); #endif diff --git a/kernel-src/include/termios.h b/kernel-src/include/termios.h index 7811f73c..495d9344 100644 --- a/kernel-src/include/termios.h +++ b/kernel-src/include/termios.h @@ -22,6 +22,7 @@ typedef unsigned int tcflag_t; #define TCGETS 0x5401 #define TCSETS 0x5402 #define TIOCGWINSZ 0x5413 +#define TIOCSWINSZ 0x5414 typedef struct { unsigned short ws_row; diff --git a/kernel-src/io/pty.c b/kernel-src/io/pty.c index 84b5e09c..ec8b529c 100644 --- a/kernel-src/io/pty.c +++ b/kernel-src/io/pty.c @@ -198,14 +198,13 @@ static int ioctl(int minor, unsigned long request, void *_arg, int *result) { return ENODEV; switch (request) { - case TIOCGPTN: - { + case TIOCGPTN: { int *arg = _arg; *arg = pty->minor; break; } default: - return ENOTTY; + return tty_ioctl(pty->tty, request, _arg, result); } return 0; diff --git a/kernel-src/io/tty.c b/kernel-src/io/tty.c index 3753f2e2..b6185493 100644 --- a/kernel-src/io/tty.c +++ b/kernel-src/io/tty.c @@ -25,7 +25,7 @@ void tty_process(tty_t *tty, char c) { char echoc = (tty->termios.c_lflag & ECHO) ? c : '\0'; // echo control characters - if ((tty->termios.c_lflag & ECHOCTL) && c < 32 && c != '\n' && c != '\r' && c != '\b' && c != '\t') { + if ((tty->termios.c_lflag & ECHOCTL) && c < 32 && c != '\n' && c != '\r' && c != '\b' && c != '\t' && c != '\e') { char tmp[2] = {'^', c + 0x40}; tty->writetodevice(tty->deviceinternal, tmp, 2); } @@ -231,22 +231,27 @@ static int poll(int minor, polldata_t *data, int events) { return internalpoll(tty, data, events); } -static int ioctl(int minor, unsigned long req, void *arg, int *result) { - tty_t *tty = ttyget(minor); - if (tty == NULL) - return ENODEV; - +int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result) { switch (req) { - case TIOCGWINSZ: + case TIOCGWINSZ: { winsize_t *w = arg; *w = tty->winsize; break; - case TCGETS: + } + case TIOCSWINSZ: { + winsize_t *w = arg; + tty->winsize = *w; + // TODO send signal to foreground process group + break; + } + case TCGETS: { *(termios_t *)arg = tty->termios; break; - case TCSETS: + } + case TCSETS: { tty->termios = *(termios_t *)arg; break; + } default: return ENOTTY; } @@ -254,6 +259,14 @@ static int ioctl(int minor, unsigned long req, void *arg, int *result) { return 0; } +static int ioctl(int minor, unsigned long req, void *arg, int *result) { + tty_t *tty = ttyget(minor); + if (tty == NULL) + return ENODEV; + + return tty_ioctl(tty, req, arg, result); +} + static int isatty(int minor) { return 0; }