Do code cleanup use duff device linenoise i/o

This commit is contained in:
Justine Tunney 2022-04-22 18:55:28 -07:00
parent 6ff46ca373
commit 2f56ebfe78
79 changed files with 1393 additions and 1484 deletions

View file

@ -19,7 +19,6 @@
#include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/fmt/conv.h"
#include "libc/log/check.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/goodsocket.internal.h"
@ -91,7 +90,7 @@ char *SendHttpRequest(const char *s) {
bool Matches(const char *regex, const char *str) {
bool r;
regex_t re;
CHECK_EQ(REG_OK, regcomp(&re, regex, 0));
EXPECT_EQ(REG_OK, regcomp(&re, regex, 0));
r = regexec(&re, str, 0, 0, 0) == REG_OK;
regfree(&re);
return r;
@ -103,15 +102,22 @@ TEST(redbean, testOptions) {
int pid, pipefds[2];
sigset_t chldmask, savemask;
sigaddset(&chldmask, SIGCHLD);
CHECK_NE(-1, sigprocmask(SIG_BLOCK, &chldmask, &savemask));
EXPECT_NE(-1, sigprocmask(SIG_BLOCK, &chldmask, &savemask));
ASSERT_NE(-1, pipe(pipefds));
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
setpgrp();
close(0);
open("/dev/null", O_RDWR);
close(1);
dup(0);
close(2);
open("log", O_CREAT | O_TRUNC | O_WRONLY | O_APPEND, 0644);
close(pipefds[0]);
dup2(pipefds[1], 1);
sigprocmask(SIG_SETMASK, &savemask, NULL);
execv("bin/redbean.com",
(char *const[]){"bin/redbean.com", "-szp0", "-l127.0.0.1", 0});
(char *const[]){"bin/redbean.com", "-vvszp0", "-l127.0.0.1", 0});
_exit(127);
}
EXPECT_NE(-1, close(pipefds[1]));
@ -129,7 +135,8 @@ TEST(redbean, testOptions) {
EXPECT_EQ(0, close(pipefds[0]));
EXPECT_NE(-1, kill(pid, SIGTERM));
EXPECT_NE(-1, wait(0));
CHECK_NE(-1, sigprocmask(SIG_SETMASK, &savemask, 0));
EXPECT_NE(-1, sigprocmask(SIG_SETMASK, &savemask, 0));
if (g_testlib_failed) fputs(gc(xslurp("log", 0)), stderr);
}
TEST(redbean, testPipeline) {
@ -138,15 +145,20 @@ TEST(redbean, testPipeline) {
int pid, pipefds[2];
sigset_t chldmask, savemask;
sigaddset(&chldmask, SIGCHLD);
CHECK_NE(-1, sigprocmask(SIG_BLOCK, &chldmask, &savemask));
EXPECT_NE(-1, sigprocmask(SIG_BLOCK, &chldmask, &savemask));
ASSERT_NE(-1, pipe(pipefds));
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
setpgrp();
close(0);
open("/dev/null", O_RDWR);
close(2);
open("log", O_CREAT | O_TRUNC | O_WRONLY | O_APPEND, 0644);
close(pipefds[0]);
dup2(pipefds[1], 1);
sigprocmask(SIG_SETMASK, &savemask, NULL);
execv("bin/redbean.com",
(char *const[]){"bin/redbean.com", "-szp0", "-l127.0.0.1", 0});
(char *const[]){"bin/redbean.com", "-vvszp0", "-l127.0.0.1", 0});
_exit(127);
}
EXPECT_NE(-1, close(pipefds[1]));
@ -173,5 +185,6 @@ TEST(redbean, testPipeline) {
EXPECT_EQ(0, close(pipefds[0]));
EXPECT_NE(-1, kill(pid, SIGTERM));
EXPECT_NE(-1, wait(0));
CHECK_NE(-1, sigprocmask(SIG_SETMASK, &savemask, 0));
EXPECT_NE(-1, sigprocmask(SIG_SETMASK, &savemask, 0));
if (g_testlib_failed) fputs(gc(xslurp("log", 0)), stderr);
}