diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index c399f679..2974c242 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -28,8 +28,6 @@ luna_app(stat.cpp stat) luna_app(uname.cpp uname) luna_app(base64.cpp base64) luna_app(login.cpp login) -luna_app(ipc-test.cpp ipc-test) -luna_app(signal-test.cpp signal-test) luna_app(mount.cpp mount) luna_app(umount.cpp umount) luna_app(ps.cpp ps) @@ -41,10 +39,5 @@ luna_app(pivot_root.cpp pivot_root) luna_app(cp.cpp cp) luna_app(kill.cpp kill) luna_app(gol.cpp gol) -luna_app(buffer-test.cpp buffer-test) -luna_app(socket-test.cpp socket-test) -luna_app(socket-client.cpp socket-client) -luna_app(input.cpp input) -luna_app(shmem-test.cpp shmem-test) luna_app(touch.cpp touch) luna_app(free.cpp free) diff --git a/apps/buffer-test.cpp b/apps/buffer-test.cpp deleted file mode 100644 index 09319c73..00000000 --- a/apps/buffer-test.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -int main() -{ - fprintf(stderr, "Writing incomplete line to stdout (_IOLBF=%d)...\n", stdout->_buf.mode); - fputs("hi!", stdout); - sleep(3); - putchar('\n'); - fprintf(stderr, "Incomplete line should have been written.\n"); - - FILE* f = fopen("/dev/console", "w+"); - assert(f); - assert(setvbuf(f, NULL, _IOFBF, 0) == 0); - - fprintf(stderr, "Writing long text to file (_IOFBF=%d)...\n", f->_buf.mode); - - fputs("Hello world!\nHow are you doing!\nThis is a test for many lines of buffering.\n", f); - - sleep(3); - fflush(f); - - fprintf(stderr, "Long text should have been written.\n"); - - fclose(f); -} diff --git a/apps/input.cpp b/apps/input.cpp deleted file mode 100644 index 6893f847..00000000 --- a/apps/input.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -Result process_mouse_packet(const moon::MousePacket& packet) -{ - bool right = packet.buttons & moon::MouseButton::Right; - bool left = packet.buttons & moon::MouseButton::Left; - bool middle = packet.buttons & moon::MouseButton::Middle; - - Vector buttons; - if (right) TRY(buttons.try_append("RIGHT"_sv)); - if (left) TRY(buttons.try_append("LEFT"_sv)); - if (middle) TRY(buttons.try_append("MIDDLE"_sv)); - - String button_string; - if (!buttons.size()) button_string = TRY(String::from_cstring("NONE")); - else - button_string = TRY(String::join(buttons, " | "_sv)); - - os::println("Mouse packet: xdelta=%d, ydelta=%d, buttons=(%s)", packet.xdelta, packet.ydelta, - button_string.chars()); - - return {}; -} - -Result luna_main(int, char**) -{ - auto mouse = TRY(os::File::open("/dev/mouse", os::File::ReadOnly)); - mouse->set_buffer(os::File::NotBuffered); - - auto keyboard = TRY(os::File::open("/dev/kbd", os::File::ReadOnly)); - keyboard->set_buffer(os::File::NotBuffered); - - ioctl(STDIN_FILENO, TTYSETGFX, 1); - - while (1) - { - struct pollfd fds[] = { - { .fd = mouse->fd(), .events = POLLIN, .revents = 0 }, - { .fd = keyboard->fd(), .events = POLLIN, .revents = 0 }, - }; - - int rc = poll(fds, 2, 1000); - if (!rc) continue; - if (rc < 0) { os::println("poll: error: %s", strerror(errno)); } - - if (fds[0].revents & POLLIN) - { - moon::MousePacket packet; - TRY(mouse->read_typed(packet)); - TRY(process_mouse_packet(packet)); - } - if (fds[1].revents & POLLIN) - { - moon::KeyboardPacket packet; - TRY(keyboard->read_typed(packet)); - os::println("Keyboard packet: %s key %u", packet.released ? "released" : "pressed", packet.key); - } - } - - return 0; -} diff --git a/apps/ipc-test.cpp b/apps/ipc-test.cpp deleted file mode 100644 index 41311e44..00000000 --- a/apps/ipc-test.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include - -int main() -{ - int pfds[2]; - - if (pipe(pfds) < 0) - { - perror("pipe"); - return 1; - } - - pid_t child = fork(); - if (child == 0) - { - close(pfds[1]); - - char buffer[4096]; - size_t nread = read(pfds[0], buffer, sizeof(buffer) - 1); - buffer[nread] = 0; - close(pfds[0]); - - puts(buffer); - - return 0; - } - else if (child == -1) - { - perror("fork"); - return 1; - } - - close(pfds[0]); - - const char* string = "Hello from a child process who just received this message from its parent!"; - write(pfds[1], string, strlen(string)); - close(pfds[1]); - - wait(NULL); - - return 0; -} diff --git a/apps/shmem-test.cpp b/apps/shmem-test.cpp deleted file mode 100644 index 4e9db300..00000000 --- a/apps/shmem-test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include -#include - -int main() -{ - pledge("stdio rpath wpath cpath proc", nullptr); - - int fd = shm_open("/shared", O_CREAT | O_RDWR, 0666); - if (fd < 0) - { - perror("shm_open"); - return 1; - } - - ftruncate(fd, PAGE_SIZE); - - void* address = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (address == MAP_FAILED) - { - perror("mmap"); - return 1; - } - - char* ptr = (char*)address; - - printf("the value is %c\n", *ptr); - - *ptr = 'a'; - - pid_t child = fork(); - if (child < 0) - { - perror("fork"); - return 1; - } - if (child == 0) - { - *ptr = 'e'; - _exit(0); - } - - waitpid(child, NULL, 0); - - printf("the value is %c\n", *ptr); - - return 0; -} diff --git a/apps/signal-test.cpp b/apps/signal-test.cpp deleted file mode 100644 index b9f6df9a..00000000 --- a/apps/signal-test.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -void handler(int) -{ - puts("I caught a segfault!"); -} - -int main() -{ - struct sigaction sa; - sa.sa_handler = handler; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESETHAND; - sigaction(SIGSEGV, &sa, NULL); - -#pragma GCC diagnostic ignored "-Wnonnull" - char* str = nullptr; - memset(str, 0, 2); - - return 0; -} diff --git a/apps/socket-client.cpp b/apps/socket-client.cpp deleted file mode 100644 index 9ea4fd29..00000000 --- a/apps/socket-client.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include -#include - -Result luna_main(int argc, char** argv) -{ - StringView message; - - os::ArgumentParser parser; - parser.add_description("A UNIX domain socket client, to test said sockets."); - parser.add_system_program_info("socket-client"_sv); - parser.add_positional_argument(message, "message"_sv, "exit"_sv); - parser.parse(argc, argv); - - int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (sockfd < 0) - { - perror("socket"); - return 0; - } - - struct sockaddr_un un; - un.sun_family = AF_UNIX; - strncpy(un.sun_path, "/tmp/local.sock", sizeof(un.sun_path)); - - if (connect(sockfd, (struct sockaddr*)&un, sizeof(un)) < 0) - { - perror("connect"); - return 1; - } - - char buf[4096]; - ssize_t nread = read(sockfd, buf, sizeof(buf) - 1); - if (nread > 0) - { - buf[nread] = 0; - printf("Message from server: %s\n", buf); - } - - write(sockfd, message.chars(), message.length()); - - close(sockfd); - - return 0; -} diff --git a/apps/socket-test.cpp b/apps/socket-test.cpp deleted file mode 100644 index b4279c17..00000000 --- a/apps/socket-test.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -int main() -{ - setgid(1000); - setuid(1000); - - remove("/tmp/local.sock"); - - int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (sockfd < 0) - { - perror("socket"); - return 0; - } - - struct sockaddr_un un; - un.sun_family = AF_UNIX; - strncpy(un.sun_path, "/tmp/local.sock", sizeof(un.sun_path)); - - if (bind(sockfd, (struct sockaddr*)&un, sizeof(un)) < 0) - { - perror("bind"); - return 1; - } - - if (listen(sockfd, 10) < 0) - { - perror("listen"); - return 1; - } - - while (1) - { - int fd = accept(sockfd, NULL, NULL); - if (fd < 0) - { - perror("accept"); - return 1; - } - - puts("New connection from client, sending hello"); - - const char* message = "Hello, client!"; - write(fd, message, strlen(message)); - - puts("Now waiting for client to message back"); - - char buf[4096]; - ssize_t nread = read(fd, buf, sizeof(buf) - 1); - if (nread >= 0) - { - buf[nread] = 0; - printf("Message from client: %s\n", buf); - if (!strcasecmp(buf, "exit")) - { - close(fd); - close(sockfd); - remove("/tmp/local.sock"); - return 0; - } - } - else { printf("Error reading from client: %s\n", strerror(errno)); } - - puts("Transmission ended, closing connection"); - - close(fd); - } -} diff --git a/base/etc/init/98-listen b/base/etc/init/98-listen deleted file mode 100644 index a27cf204..00000000 --- a/base/etc/init/98-listen +++ /dev/null @@ -1,6 +0,0 @@ -Name=listen -Description=Start a Unix domain socket test server. -Command=/usr/bin/socket-test -StandardOutput=/dev/uart0 -StandardError=/dev/uart0 -Restart=true