apps: add a new example app which does all kinds of stdio misbehaving >.<

This commit is contained in:
apio 2022-10-11 17:31:06 +02:00
parent 667d308fc3
commit 7a097f16ea
3 changed files with 28 additions and 2 deletions

View File

@ -1,4 +1,4 @@
APPS := init fib leap art memeater
APPS := init fib leap art memeater quota
APPS_DIR := $(LUNA_ROOT)/apps
APPS_SRC := $(APPS_DIR)/src

22
apps/src/quota.c Normal file
View File

@ -0,0 +1,22 @@
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
if (open("/file/that/does/not/exist", O_RDONLY) < 0) { perror("open"); }
int sys = open("/sys", O_RDONLY);
if (sys < 0) { perror("open"); }
if (read(sys, NULL, 20) < 0) { perror("read"); }
char buf[20];
if (read(sys, buf, 20) < 0) { perror("read"); }
if (close(sys) < 0) { perror("close"); }
for (int i = 0; i < 10; i++)
{
if (open("/", O_RDONLY) < 0) { perror("open"); }
}
int exec;
if ((exec = open("/bin/quota", O_RDONLY)) < 0) { perror("open"); }
if (read(exec, buf, 20) < 0) { perror("read"); }
if (close(exec) < 0) { perror("close"); }
}

View File

@ -123,7 +123,7 @@ extern "C" void _start()
}
});
uint64_t demo = Mersenne::get() % 5;
uint64_t demo = Mersenne::get() % 6;
switch (demo)
{
@ -147,6 +147,10 @@ extern "C" void _start()
kinfoln("Loading demo: memory eating program");
Scheduler::load_user_task("bin/memeater");
break;
case 5:
kinfoln("Loading demo: misbehaving program");
Scheduler::load_user_task("bin/quota");
break;
default: break;
}