From d41119b1a3744181666ba1132c3da9a418adeba0 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 16 Feb 2014 11:55:26 +0800 Subject: [PATCH] CLIShell - PTY signal support (and kernel fixes) --- KernelLand/Kernel/drv/pty.c | 6 ++++-- KernelLand/Kernel/threads.c | 2 +- Usermode/Applications/CLIShell_src/main.c | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/KernelLand/Kernel/drv/pty.c b/KernelLand/Kernel/drv/pty.c index 3a8499b6..3b30b996 100644 --- a/KernelLand/Kernel/drv/pty.c +++ b/KernelLand/Kernel/drv/pty.c @@ -308,7 +308,8 @@ int PTY_SetAttrib(tPTY *PTY, const struct ptydims *Dims, const struct ptymode *M else { // SIGWINSZ to client - Threads_SignalGroup(PTY->ControllingProcGroup, SIGWINCH); + if( PTY->ControllingProcGroup > 0 ) + Threads_SignalGroup(PTY->ControllingProcGroup, SIGWINCH); } LOG("PTY %p dims set to %ix%i", PTY, Dims->W, Dims->H); PTY->Dims = *Dims; @@ -391,7 +392,8 @@ size_t PTY_int_SendInput(tPTY *PTY, const char *Input, size_t Length) { case 3: // INTR - ^C // Send SIGINT - Threads_SignalGroup(PTY->ControllingProcGroup, SIGINT); + if( PTY->ControllingProcGroup > 0 ) + Threads_SignalGroup(PTY->ControllingProcGroup, SIGINT); print = 0; break; case 4: // EOF - ^D diff --git a/KernelLand/Kernel/threads.c b/KernelLand/Kernel/threads.c index 12613a24..73a2b58f 100644 --- a/KernelLand/Kernel/threads.c +++ b/KernelLand/Kernel/threads.c @@ -355,7 +355,7 @@ tThread *Threads_CloneTCB(Uint Flags) if(Flags & CLONE_VM) { tProcess *newproc, *oldproc; oldproc = cur->Process; - new->Process = malloc( sizeof(struct sProcess) ); + new->Process = calloc( sizeof(struct sProcess), 1 ); newproc = new->Process; newproc->PID = new->TID; if( Flags & CLONE_PGID ) diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 8cea3648..6de92df4 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -9,6 +9,7 @@ #include "header.h" #include #include +#include #define _stdin 0 #define _stdout 1 @@ -213,14 +214,28 @@ void CallCommand(char **Args) // Create new process int fds[] = {0, 1, 2}; + int status; pid = _SysSpawn(sTmpBuffer, (const char **)Args, (const char **)gasEnvironment, 3, fds, NULL); if(pid <= 0) { printf("Unable to create process: `%s'\n", sTmpBuffer); // Error Message + status = 0; } else { - int status; + _SysIOCtl(0, PTY_IOCTL_SETPGRP, &pid); _SysWaitTID(pid, &status); } + + // Return terminal to a sane state + { + int zero = 0; + _SysIOCtl(0, PTY_IOCTL_SETPGRP, &zero); + printf("\x1b[0m"); + } + // Print a status message if termination was non-clean + if( status ) + { + printf("[%i] exited %i\n", pid, status); + } } /** -- 2.20.1