init: Add a Message of the Day

This commit is contained in:
apio 2022-10-20 19:27:37 +02:00
parent bd4c587409
commit b69fbd46bf
2 changed files with 31 additions and 1 deletions

View File

@ -1,8 +1,35 @@
#include <errno.h>
#include <luna.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
void show_motd()
{
FILE* fp = fopen("/etc/motd", "r");
if (!fp)
{
if (errno != ENOENT) { perror("fopen"); }
return;
}
char buf[4096];
size_t nread = fread(buf, sizeof(buf) - 1, 1, fp);
if (ferror(fp))
{
perror("fread");
fclose(fp);
return;
}
buf[nread] = 0;
puts(buf);
fclose(fp);
putchar('\n');
}
int main()
{
if (getpid() != 1)
@ -11,7 +38,7 @@ int main()
return 1;
}
printf("Welcome to Luna!\n\n");
show_motd();
msleep(200);

3
initrd/etc/motd Normal file
View File

@ -0,0 +1,3 @@
Welcome to Luna!
Tip of the day: Type 'help' to get started!