Make greenbean web server better

- Remove misguided __assert_disabled variable
- Change EPROCLIM to be EAGAIN on BSD distros
- Improve quality of greenbean with cancellations
- Fix thread race condition crash with file descriptors
This commit is contained in:
Justine Tunney 2023-09-07 03:24:46 -07:00
parent 6cff3137c5
commit 0e087143fd
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
14 changed files with 247 additions and 149 deletions

View file

@ -164,11 +164,22 @@ static bool __sig_deliver(int sigops, int sig, int si_code, ucontext_t *ctx) {
* Returns true if signal default action is to end process.
*/
static textwindows bool __sig_is_fatal(int sig) {
if (sig == SIGCHLD || sig == SIGURG || sig == SIGWINCH) {
return false;
} else {
return true;
}
return !(sig == SIGURG || //
sig == SIGCHLD || //
sig == SIGWINCH);
}
/**
* Returns true if signal is so fatal it should dump core.
*/
static textwindows bool __sig_is_core(int sig) {
return sig == SIGSYS || //
sig == SIGBUS || //
sig == SIGSEGV || //
sig == SIGQUIT || //
sig == SIGTRAP || //
sig == SIGXCPU || //
sig == SIGXFSZ;
}
/**
@ -186,11 +197,10 @@ textwindows bool __sig_handle(int sigops, int sig, int si_code,
char *end, sigbuf[21], output[22];
signame = strsignal_r(sig, sigbuf);
STRACE("terminating due to uncaught %s", signame);
hStderr = GetStdHandle(kNtStdErrorHandle);
end = stpcpy(stpcpy(output, signame), "\n");
WriteFile(hStderr, output, end - output, 0, 0);
if (_weaken(__restore_console_win32)) {
_weaken(__restore_console_win32)();
if (__sig_is_core(sig)) {
hStderr = GetStdHandle(kNtStdErrorHandle);
end = stpcpy(stpcpy(output, signame), "\n");
WriteFile(hStderr, output, end - output, 0, 0);
}
ExitProcess(sig);
}

View file

@ -26,9 +26,7 @@
*/
void __assert_fail(const char *expr, const char *file, int line) {
char ibuf[12];
if (!__assert_disable) {
FormatInt32(ibuf, line);
tinyprint(2, file, ":", ibuf, ": assert(", expr, ") failed\n", NULL);
abort();
}
FormatInt32(ibuf, line);
tinyprint(2, "\n", file, ":", ibuf, ": assert(", expr, ") failed\n", NULL);
abort();
}

View file

@ -68,10 +68,6 @@ int raise(int sig) {
rc = sys_tkill(gettid(), sig, 0);
} else if (IsWindows() || IsMetal()) {
if (IsWindows() && sig == SIGKILL) {
// TODO(jart): Isn't this implemented by __sig_raise()?
if (_weaken(__restore_console_win32)) {
_weaken(__restore_console_win32)();
}
ExitProcess(sig);
} else {
rc = __sig_raise(sig, SI_TKILL);

View file

@ -39,10 +39,12 @@ static volatile size_t mapsize;
* @asyncsignalsafe
*/
int __ensurefds_unlocked(int fd) {
size_t n;
if (fd < g_fds.n) return fd;
g_fds.n = fd + 1;
g_fds.e = _extend(g_fds.p, g_fds.n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE,
n = fd + 1;
g_fds.e = _extend(g_fds.p, n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE,
kMemtrackFdsStart + kMemtrackFdsSize);
g_fds.n = n;
return fd;
}