apps: Add more simple apps

Now that we can start them at will from the command line, bring them on!!
This commit is contained in:
apio 2022-10-19 21:11:38 +02:00
parent 47bdfecedb
commit 2c813f5901
5 changed files with 62 additions and 41 deletions

View File

@ -1,4 +1,4 @@
APPS := init sym sh APPS := init sym sh crash uname uptime
APPS_DIR := $(LUNA_ROOT)/apps APPS_DIR := $(LUNA_ROOT)/apps
APPS_SRC := $(APPS_DIR)/src APPS_SRC := $(APPS_DIR)/src

5
apps/src/crash.c Normal file
View File

@ -0,0 +1,5 @@
int main()
{
int* ptr = (int*)0xdeadbeef;
*ptr = 6;
}

View File

@ -1,43 +1,8 @@
#include <luna.h> #include <luna.h>
#include <setjmp.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
int print_version()
{
char version[4096];
FILE* fp = fopen("/dev/version", "r");
if (!fp)
{
perror("fopen");
return 1;
}
size_t nread = fread(version, 4096, 1, fp);
if (ferror(fp))
{
perror("fread");
return 1;
}
version[nread] = 0;
if (fclose(fp) < 0)
{
perror("fclose");
return 1;
}
printf("Your kernel version is %s\n\n", version);
return 0;
}
int main() int main()
{ {
if (getpid() != 1) if (getpid() != 1)
@ -46,11 +11,7 @@ int main()
return 1; return 1;
} }
printf("Welcome to Luna!\n"); printf("Welcome to Luna!\n\n");
printf("Running as PID %ld\n", getpid());
if (print_version()) return 1;
msleep(200); msleep(200);

26
apps/src/uname.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
int main()
{
FILE* fp = fopen("/dev/version", "r");
if (!fp)
{
perror("fopen");
return 1;
}
char buf[4096];
size_t nread = fread(buf, sizeof(buf) - 1, 1, fp);
if (ferror(fp))
{
perror("fread");
return 1;
}
buf[nread] = 0; // null terminate it :)
printf("%s\n", buf);
fclose(fp);
}

29
apps/src/uptime.c Normal file
View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* fp = fopen("/dev/uptime", "r");
if (!fp)
{
perror("fopen");
return 1;
}
char buf[4096];
size_t nread = fread(buf, sizeof(buf) - 1, 1, fp);
if (ferror(fp))
{
perror("fread");
return 1;
}
buf[nread] = 0; // null terminate it :)
long ms_uptime = atol(buf);
printf("up for %ld seconds\n", ms_uptime / 1000);
fclose(fp);
}