#include #include #include #include // #include #ifdef __linux__ # include #elifdef __OpenBSD__ # include # include # include #else # error "sorry, unknown platform. please hack." #endif #include void nonblock(int p) { int v = fcntl(p, F_GETFL); fcntl(p, F_SETFL, v|O_NONBLOCK); } word prim_custom(int op, word a, word b, word c) { switch (op) { case 400: { /* openbash → fd */ int m, s; openpty(&m, &s, NULL, NULL, NULL); nonblock(m); nonblock(s); if (fork() == 0) { setsid(); ioctl(s, TIOCSCTTY, 0); dup2(s, STDIN_FILENO); dup2(s, STDOUT_FILENO); dup2(s, STDERR_FILENO); close(m); close(s); execlp("bash", "-i", NULL); exit(42); } else { close(s); return mkport(m); } } default: return IFALSE; } }