mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-10 06:32:28 +00:00
Greatly expand system() shell code features
The cosmopolitan command interpreter now has 13 builtin commands, variable support, support for ; / && / || syntax, asynchronous support, and plenty of unit tests with bug fixes. This change fixes a bug in posix_spawn() with null envp arg. strace logging now uses atomic writes for scatter functions. Breaking change renaming GetCpuCount() to _getcpucount(). TurfWar is now updated to use the new token bucket algorithm. WIN32 affinity masks now inherit across fork() and execve().
This commit is contained in:
parent
e7329b7cba
commit
b41f91c658
80 changed files with 1370 additions and 344 deletions
|
@ -29,20 +29,18 @@
|
|||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
void SetUpOnce(void) {
|
||||
__enable_threads();
|
||||
}
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
__attribute__((__constructor__)) static void init(void) {
|
||||
if (atoi(nulltoempty(getenv("THE_DOGE"))) == 42) {
|
||||
exit(42);
|
||||
switch (atoi(nulltoempty(getenv("THE_DOGE")))) {
|
||||
case 42:
|
||||
exit(42);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(spawn, test) {
|
||||
if (atoi(nulltoempty(getenv("THE_DOGE"))) == 42) {
|
||||
exit(42);
|
||||
}
|
||||
int rc, ws, pid;
|
||||
char *prog = GetProgramExecutableName();
|
||||
char *args[] = {program_invocation_name, NULL};
|
||||
|
@ -53,6 +51,25 @@ TEST(spawn, test) {
|
|||
EXPECT_EQ(42, WEXITSTATUS(ws));
|
||||
}
|
||||
|
||||
TEST(spawn, pipe) {
|
||||
char buf[10];
|
||||
int p[2], pid, status;
|
||||
const char *pn = "./echo.com";
|
||||
posix_spawn_file_actions_t fa;
|
||||
testlib_extract("/zip/echo.com", "echo.com", 0755);
|
||||
ASSERT_SYS(0, 0, pipe(p));
|
||||
ASSERT_EQ(0, posix_spawn_file_actions_init(&fa));
|
||||
ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, p[0]));
|
||||
ASSERT_EQ(0, posix_spawn_file_actions_adddup2(&fa, p[1], 1));
|
||||
ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, p[1]));
|
||||
ASSERT_EQ(0, posix_spawnp(&pid, pn, &fa, 0, (char *[]){pn, "hello", 0}, 0));
|
||||
ASSERT_SYS(0, 0, close(p[1]));
|
||||
ASSERT_SYS(0, pid, waitpid(pid, &status, 0));
|
||||
ASSERT_SYS(0, 6, read(p[0], buf, sizeof(buf)));
|
||||
ASSERT_SYS(0, 0, close(p[0]));
|
||||
ASSERT_EQ(0, posix_spawn_file_actions_destroy(&fa));
|
||||
}
|
||||
|
||||
/*
|
||||
* BEST LINUX FORK+EXEC+EXIT+WAIT PERFORMANCE
|
||||
* The fastest it can go with fork() is 40µs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue