From b69fbd46bfd3e26b9cc7046203a5e8bb2a65cb99 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 20 Oct 2022 19:27:37 +0200 Subject: [PATCH] init: Add a Message of the Day --- apps/src/init.c | 29 ++++++++++++++++++++++++++++- initrd/etc/motd | 3 +++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 initrd/etc/motd diff --git a/apps/src/init.c b/apps/src/init.c index 41ee2020..dae78ecb 100644 --- a/apps/src/init.c +++ b/apps/src/init.c @@ -1,8 +1,35 @@ +#include #include #include #include #include +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); diff --git a/initrd/etc/motd b/initrd/etc/motd new file mode 100644 index 00000000..21960418 --- /dev/null +++ b/initrd/etc/motd @@ -0,0 +1,3 @@ +Welcome to Luna! + +Tip of the day: Type 'help' to get started! \ No newline at end of file