2018-12-18 06:12:17 +03:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
2021-06-07 16:00:20 +03:00
|
|
|
* Copyright (C) 2018-2021 K. Lange
|
2018-12-18 06:12:17 +03:00
|
|
|
*
|
|
|
|
* splash-log - Display startup messages before UI has started.
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2021-07-19 13:43:57 +03:00
|
|
|
#include <signal.h>
|
2018-12-18 06:12:17 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
2021-06-07 16:00:20 +03:00
|
|
|
#include <sys/utsname.h>
|
2018-12-18 06:12:17 +03:00
|
|
|
|
|
|
|
#include <kernel/video.h>
|
|
|
|
#include <toaru/pex.h>
|
|
|
|
|
|
|
|
#include "terminal-font.h"
|
|
|
|
|
2021-10-20 12:49:58 +03:00
|
|
|
static FILE * console;
|
2018-12-18 06:12:17 +03:00
|
|
|
|
2021-10-20 12:49:58 +03:00
|
|
|
static void update_message(char * c) {
|
|
|
|
fprintf(console, "%s\n", c);
|
2018-12-18 06:12:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static FILE * pex_endpoint = NULL;
|
|
|
|
static void open_socket(void) {
|
|
|
|
pex_endpoint = pex_bind("splash");
|
|
|
|
if (!pex_endpoint) exit(1);
|
|
|
|
}
|
|
|
|
|
2021-06-07 16:00:20 +03:00
|
|
|
static void say_hello(void) {
|
|
|
|
/* Get our release version */
|
|
|
|
struct utsname u;
|
|
|
|
uname(&u);
|
|
|
|
/* Strip git tag */
|
|
|
|
char * tmp = strstr(u.release, "-");
|
|
|
|
if (tmp) *tmp = '\0';
|
|
|
|
/* Setup hello message */
|
|
|
|
char hello_msg[512];
|
|
|
|
snprintf(hello_msg, 511, "ToaruOS %s is starting up...", u.release);
|
|
|
|
/* Add it to the log */
|
2021-10-20 12:49:58 +03:00
|
|
|
update_message(hello_msg);
|
2021-06-07 16:00:20 +03:00
|
|
|
}
|
|
|
|
|
2018-12-18 06:12:17 +03:00
|
|
|
int main(int argc, char * argv[]) {
|
|
|
|
if (getuid() != 0) {
|
|
|
|
fprintf(stderr, "%s: only root should run this\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
open_socket();
|
2021-10-20 12:49:58 +03:00
|
|
|
console = fopen("/dev/console","a");
|
2018-12-18 06:12:17 +03:00
|
|
|
|
|
|
|
if (!fork()) {
|
2021-06-07 16:00:20 +03:00
|
|
|
say_hello();
|
2018-12-18 06:12:17 +03:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
pex_packet_t * p = calloc(PACKET_SIZE, 1);
|
|
|
|
pex_listen(pex_endpoint, p);
|
|
|
|
|
|
|
|
if (p->size < 4) continue; /* Ignore blank messages, erroneous line feeds, etc. */
|
|
|
|
if (p->size > 80) continue; /* Ignore overly large messages */
|
|
|
|
|
|
|
|
if (!strncmp((char*)p->data, "!quit", 5)) {
|
|
|
|
/* Use the special message !quit to exit. */
|
|
|
|
fclose(pex_endpoint);
|
|
|
|
return 0;
|
2018-12-21 11:47:19 +03:00
|
|
|
} else if (p->data[0] == ':') {
|
|
|
|
/* Make sure message is nil terminated (it should be...) */
|
|
|
|
char * tmp = malloc(p->size + 1);
|
|
|
|
memcpy(tmp, p->data, p->size);
|
|
|
|
tmp[p->size] = '\0';
|
2021-10-20 12:49:58 +03:00
|
|
|
update_message(tmp+1);
|
2018-12-21 11:47:19 +03:00
|
|
|
free(tmp);
|
2018-12-18 06:12:17 +03:00
|
|
|
} else {
|
|
|
|
/* Make sure message is nil terminated (it should be...) */
|
|
|
|
char * tmp = malloc(p->size + 1);
|
|
|
|
memcpy(tmp, p->data, p->size);
|
|
|
|
tmp[p->size] = '\0';
|
2021-10-20 12:49:58 +03:00
|
|
|
update_message(tmp);
|
2018-12-18 06:12:17 +03:00
|
|
|
free(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|