2022-04-16 17:40:23 +00:00
|
|
|
#if 0
|
|
|
|
/*─────────────────────────────────────────────────────────────────╗
|
|
|
|
│ To the extent possible under law, Justine Tunney has waived │
|
|
|
|
│ all copyright and related or neighboring rights to this file, │
|
|
|
|
│ as it is written in the following disclaimers: │
|
|
|
|
│ • http://unlicense.org/ │
|
|
|
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
|
|
|
╚─────────────────────────────────────────────────────────────────*/
|
|
|
|
#endif
|
2023-09-10 15:12:43 +00:00
|
|
|
#include "third_party/linenoise/linenoise.h"
|
|
|
|
#include "libc/calls/calls.h"
|
|
|
|
#include "libc/calls/struct/sigset.h"
|
|
|
|
#include "libc/intrin/kprintf.h"
|
2022-04-16 17:40:23 +00:00
|
|
|
#include "libc/mem/mem.h"
|
2023-09-10 15:12:43 +00:00
|
|
|
#include "libc/runtime/runtime.h"
|
|
|
|
#include "libc/stdio/posix_spawn.h"
|
2022-04-16 17:40:23 +00:00
|
|
|
#include "libc/stdio/stdio.h"
|
2023-09-10 15:12:43 +00:00
|
|
|
#include "libc/str/str.h"
|
|
|
|
#include "libc/sysv/consts/sig.h"
|
2022-04-16 17:40:23 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2023-09-10 15:12:43 +00:00
|
|
|
int ws;
|
2022-04-16 17:40:23 +00:00
|
|
|
char *line;
|
2023-09-10 15:12:43 +00:00
|
|
|
char ps1[100];
|
|
|
|
sigset_t mask, om;
|
|
|
|
posix_spawnattr_t attr;
|
|
|
|
ShowCrashReports();
|
|
|
|
sigemptyset(&mask);
|
|
|
|
sigaddset(&mask, SIGINT);
|
|
|
|
sigaddset(&mask, SIGQUIT);
|
|
|
|
sigaddset(&mask, SIGCHLD);
|
|
|
|
sigprocmask(SIG_BLOCK, &mask, &om);
|
|
|
|
posix_spawnattr_init(&attr);
|
|
|
|
posix_spawnattr_setsigmask(&attr, &om);
|
|
|
|
for (ws = 0;;) {
|
|
|
|
if (WIFSIGNALED(ws)) {
|
|
|
|
ksnprintf(ps1, sizeof(ps1), "\e[1;31m%G\e[0m :> ", ws, WTERMSIG(ws));
|
|
|
|
} else {
|
|
|
|
ksnprintf(ps1, sizeof(ps1), "%d :> ", ws, WEXITSTATUS(ws));
|
|
|
|
}
|
|
|
|
if (!(line = linenoiseWithHistory(ps1, "unbourne"))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*line) {
|
|
|
|
int i = 0;
|
|
|
|
char *args[64];
|
|
|
|
args[i++] = strtok(line, " \t\v\r\n");
|
|
|
|
while ((args[i++] = strtok(0, " \t\v\r\n"))) {
|
|
|
|
}
|
|
|
|
int pid;
|
|
|
|
posix_spawnp(&pid, args[0], 0, &attr, args, environ);
|
|
|
|
wait(&ws);
|
|
|
|
}
|
2022-04-16 17:40:23 +00:00
|
|
|
free(line);
|
|
|
|
}
|
2023-09-10 15:12:43 +00:00
|
|
|
posix_spawnattr_destroy(&attr);
|
2022-04-16 17:40:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|