Luna/apps/src/init.c

61 lines
1.1 KiB
C

#include <errno.h>
#include <luna.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
typedef long ssize_t;
int main()
{
if (gettid() == 0) // why are we the idle task?
{
__luna_abort("SHENANIGANS! init is tid 0 (which is reserved for the idle task)\n");
}
printf("Welcome to Luna!\n");
printf("Running as tid %ld\n\n", gettid());
sleep(1);
char version[40];
syscall(SYS_getversion, version, sizeof(version));
printf("Your kernel version is %s\n\n", version);
sleep(2);
const char* filename = "/sys/config";
printf("Opening %s for reading...\n", filename);
FILE* config = fopen(filename, "r");
if (!config)
{
perror("fopen");
return 1;
}
char buf[4096];
size_t nread = fread(buf, sizeof(buf), 1, config);
if (ferror(config)) { perror("fread"); }
else
{
buf[nread] = 0;
printf("Read %zd bytes\n\n", nread);
printf("%s", buf);
}
if (fclose(config) < 0) { perror("fclose"); }
printf("\n\nPress any key to restart.\n");
return 0;
}