]> git.mdlowis.com Git - projs/tide.git/commitdiff
sketched out pseudotty logic for term
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 30 May 2017 02:50:45 +0000 (22:50 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 30 May 2017 02:50:45 +0000 (22:50 -0400)
term.c

diff --git a/term.c b/term.c
index c8eb02b79d6cd725d22103062b94674632eadad8..14b8c3e8e059b20275126645df4f3778010f5a4b 100644 (file)
--- a/term.c
+++ b/term.c
@@ -5,6 +5,8 @@
 #include <ctype.h>
 #include <win.h>
 
+static int ShellFD;
+
 #define INCLUDE_DEFS
 #include "config.h"
 
@@ -37,11 +39,42 @@ void onerror(char* msg) {
 }
 
 #ifndef TEST
+#include <unistd.h>
+#include <util.h>
+#include <sys/ioctl.h>
+
+void spawn_shell(int master, int slave) {
+       static char* shell[] = { "/bin/sh", "-l", NULL };
+    dup2(slave, 0);
+    dup2(slave, 1);
+    dup2(slave, 2);
+    if (ioctl(slave, TIOCSCTTY, NULL) < 0)
+        die("ioctl(TIOSCTTY) failed");
+    close(slave);
+    close(master);
+    execvp(shell[0], shell);
+}
+
 int main(int argc, char** argv) {
+    int pid, m, s;
+       if (openpty(&m, &s, NULL, NULL, NULL) < 0)
+               die("openpty failed: %s\n", strerror(errno));
+    if ((pid = fork()))
+        die("fork failed");
+
+    if (pid == 0) {
+       spawn_shell(m, s);
+    } else {
+        close(s);
+        ShellFD = m;
+        //signal(SIGCHLD, sigchld);
+    }
+
     win_window("term", onerror);
     //win_setkeys(&Bindings);
     //win_setmouse(&MouseHandlers);
     win_loop();
+
     return 0;
 }
 #endif