Luna/apps/src/init.c

69 lines
1.2 KiB
C
Raw Normal View History

#include <fcntl.h>
#include <luna.h>
#include <stdio.h>
2022-10-02 17:25:56 +02:00
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
typedef long ssize_t;
2022-10-02 17:25:56 +02:00
int main()
{
if (gettid() == 0) // why are we the idle task?
2022-10-02 17:25:56 +02:00
{
2022-10-02 18:16:27 +02:00
__luna_abort("SHENANIGANS! init is tid 0 (which is reserved for the idle task)\n");
2022-10-02 17:25:56 +02:00
}
printf("Welcome to Luna!\n");
2022-10-02 17:25:56 +02:00
printf("Running as tid %ld\n\n", gettid());
2022-10-02 17:25:56 +02:00
sleep(1);
2022-10-02 17:25:56 +02:00
char version[40];
syscall(SYS_getversion, version, sizeof(version));
printf("Your kernel version is %s\n\n", version);
2022-10-02 17:25:56 +02:00
sleep(2);
2022-10-02 17:25:56 +02:00
const char* filename = "/sys/config";
printf("Opening %s for reading...\n", filename);
int fd = open(filename, O_RDONLY);
if (fd < 0)
{
perror("open");
// return 1;
}
char buf[4096];
ssize_t nread = read(fd, buf, sizeof(buf));
if (nread < 0)
{
perror("read");
// return 1;
}
else
{
buf[nread] = 0;
printf("Read %zd bytes\n\n", nread);
printf("%s", buf);
}
if (close(fd) < 0)
{
perror("close");
// return 1;
}
printf("\n\nPress any key to restart.\n");
2022-10-02 17:25:56 +02:00
return 0;
}