CLIShell - PTY signal support (and kernel fixes)
authorJohn Hodge <[email protected]>
Sun, 16 Feb 2014 03:55:26 +0000 (11:55 +0800)
committerJohn Hodge <[email protected]>
Sun, 16 Feb 2014 03:55:26 +0000 (11:55 +0800)
KernelLand/Kernel/drv/pty.c
KernelLand/Kernel/threads.c
Usermode/Applications/CLIShell_src/main.c

index 3a8499b..3b30b99 100644 (file)
@@ -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
index 12613a2..73a2b58 100644 (file)
@@ -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 )
index 8cea364..6de92df 100644 (file)
@@ -9,6 +9,7 @@
 #include "header.h"\r
 #include <readline.h>\r
 #include <errno.h>\r
+#include <acess/devices/pty.h>\r
 \r
 #define _stdin 0\r
 #define _stdout        1\r
@@ -213,14 +214,28 @@ void CallCommand(char **Args)
        \r
        // Create new process\r
        int fds[] = {0, 1, 2};\r
+        int    status;\r
        pid = _SysSpawn(sTmpBuffer, (const char **)Args, (const char **)gasEnvironment, 3, fds, NULL);\r
        if(pid <= 0) {\r
                printf("Unable to create process: `%s'\n", sTmpBuffer); // Error Message\r
+               status = 0;\r
        }\r
        else {\r
-                int    status;\r
+               _SysIOCtl(0, PTY_IOCTL_SETPGRP, &pid);\r
                _SysWaitTID(pid, &status);\r
        }\r
+       \r
+       // Return terminal to a sane state\r
+       {\r
+               int zero = 0;\r
+               _SysIOCtl(0, PTY_IOCTL_SETPGRP, &zero);\r
+               printf("\x1b[0m");\r
+       }\r
+       // Print a status message if termination was non-clean\r
+       if( status )\r
+       {\r
+               printf("[%i] exited %i\n", pid, status);\r
+       }\r
 }\r
 \r
 /**\r

UCC git Repository :: git.ucc.asn.au