Make improvements

- Improved async signal safety of read() particularly for longjmp()
- Started adding cancel cleanup handlers for locks / etc on Windows
- Make /dev/tty work better particularly for uses like `foo | less`
- Eagerly read console input into a linked list, so poll can signal
- Fix some libc definitional bugs, which configure scripts detected
This commit is contained in:
Justine Tunney 2023-09-21 07:30:39 -07:00
parent d6c2830850
commit 0c5dd7b342
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
85 changed files with 1062 additions and 671 deletions

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/atomic.h"
#include "libc/calls/calls.h"
#include "libc/calls/cp.internal.h"
#include "libc/calls/internal.h"
@ -26,12 +27,14 @@
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/internal.h"
#include "libc/sysv/consts/nr.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"
void SetUpOnce(void) {
testlib_enable_tmp_setup_teardown();
@ -82,6 +85,57 @@ TEST(read_directory, eisdir) {
ASSERT_SYS(0, 0, close(3));
}
int fds[2];
jmp_buf jb;
pthread_t th;
atomic_bool isdone;
void *GenerateSignals(void *arg) {
while (!isdone) {
usleep(123);
pthread_kill(th, SIGINT);
}
return 0;
}
void *GenerateData(void *arg) {
for (;;) {
usleep(223);
int rc = write(fds[1], "hi", 2);
if (rc == -1 && errno == EPIPE) break;
ASSERT_EQ(2, rc);
}
return 0;
}
void OnSig(int sig) {
char buf[8];
ASSERT_SYS(0, 2, read(fds[0], buf, 8));
longjmp(jb, 1);
}
TEST(read, whatEmacsDoes) {
pthread_t sigth;
sighandler_t sh1 = signal(SIGINT, SIG_IGN);
sighandler_t sh2 = signal(SIGPIPE, SIG_IGN);
ASSERT_SYS(0, 0, pipe(fds));
ASSERT_EQ(0, pthread_create(&th, 0, GenerateData, 0));
ASSERT_EQ(0, pthread_create(&sigth, 0, GenerateSignals, 0));
for (int i = 0; i < 100; ++i) {
if (!setjmp(jb)) {
char buf[8];
ASSERT_GE(read(fds[0], buf, 8), 2);
}
}
isdone = true;
ASSERT_SYS(0, 0, close(fds[0]));
ASSERT_EQ(0, pthread_join(sigth, 0));
ASSERT_EQ(0, pthread_join(th, 0));
ASSERT_SYS(0, 0, close(fds[1]));
signal(SIGPIPE, sh2);
signal(SIGINT, sh1);
}
////////////////////////////////////////////////////////////////////////////////
BENCH(read, bench) {