2022-10-10 21:08:57 +02:00
|
|
|
#include <errno.h>
|
2022-10-02 18:10:53 +02:00
|
|
|
#include <luna.h>
|
2022-10-03 19:00:10 +02:00
|
|
|
#include <stdio.h>
|
2022-10-02 17:25:56 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-10-10 20:21:39 +02:00
|
|
|
typedef long ssize_t;
|
|
|
|
|
2022-10-02 17:25:56 +02:00
|
|
|
int main()
|
|
|
|
{
|
2022-10-02 18:10:53 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-03 19:00:10 +02:00
|
|
|
printf("Welcome to Luna!\n");
|
2022-10-02 17:25:56 +02:00
|
|
|
|
2022-10-03 19:00:10 +02:00
|
|
|
printf("Running as tid %ld\n\n", gettid());
|
2022-10-02 17:25:56 +02:00
|
|
|
|
2022-10-03 19:00:10 +02:00
|
|
|
sleep(1);
|
2022-10-02 17:25:56 +02:00
|
|
|
|
|
|
|
char version[40];
|
|
|
|
syscall(SYS_getversion, version, sizeof(version));
|
|
|
|
|
2022-10-03 19:00:10 +02:00
|
|
|
printf("Your kernel version is %s\n\n", version);
|
2022-10-02 17:25:56 +02:00
|
|
|
|
2022-10-02 18:10:53 +02:00
|
|
|
sleep(2);
|
2022-10-02 17:25:56 +02:00
|
|
|
|
2022-10-10 20:21:39 +02:00
|
|
|
const char* filename = "/sys/config";
|
|
|
|
|
|
|
|
printf("Opening %s for reading...\n", filename);
|
|
|
|
|
2022-10-10 21:08:57 +02:00
|
|
|
FILE* config = fopen(filename, "r");
|
|
|
|
if (!config)
|
2022-10-10 20:21:39 +02:00
|
|
|
{
|
2022-10-10 21:08:57 +02:00
|
|
|
perror("fopen");
|
2022-10-11 16:57:08 +02:00
|
|
|
return 1;
|
2022-10-10 20:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char buf[4096];
|
|
|
|
|
2022-10-10 21:08:57 +02:00
|
|
|
size_t nread = fread(buf, sizeof(buf), 1, config);
|
2022-10-11 16:57:08 +02:00
|
|
|
if (ferror(config)) { perror("fread"); }
|
2022-10-10 20:21:39 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[nread] = 0;
|
|
|
|
|
|
|
|
printf("Read %zd bytes\n\n", nread);
|
|
|
|
|
|
|
|
printf("%s", buf);
|
|
|
|
}
|
|
|
|
|
2022-10-11 16:57:08 +02:00
|
|
|
if (fclose(config) < 0) { perror("fclose"); }
|
2022-10-02 20:45:04 +02:00
|
|
|
|
2022-10-10 20:21:39 +02:00
|
|
|
printf("\n\nPress any key to restart.\n");
|
2022-10-02 17:25:56 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|