From 7f51afb3f23f8d1f92356d6231e0d15421ef2fe3 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Fri, 21 Dec 2018 17:47:19 +0900 Subject: [PATCH] splash-log: support for submessages with : --- apps/migrate.c | 12 ++++++++++-- apps/splash-log.c | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/apps/migrate.c b/apps/migrate.c index b6f4068a..c685dee0 100644 --- a/apps/migrate.c +++ b/apps/migrate.c @@ -26,11 +26,15 @@ #include #define TRACE_APP_NAME "migrate" -#define TRACE_(...) do { if (_debug) { TRACE(__VA_ARGS__); } } while (0) +#define TRACE_(...) do { \ + if (_splash) { char tmp[512]; sprintf(tmp, __VA_ARGS__); fprintf(_splash, ":%s", tmp); fflush(_splash); } \ + if (_debug) { TRACE(__VA_ARGS__); } \ +} while (0) #define CHUNK_SIZE 4096 static int _debug = 0; +static FILE * _splash = NULL; int tokenize(char * str, char * sep, char **buf) { char * pch_i; @@ -58,6 +62,7 @@ void copy_link(char * source, char * dest, int mode, int uid, int gid) { void copy_file(char * source, char * dest, int mode,int uid, int gid) { //fprintf(stderr, "need to copy file %s to %s %x\n", source, dest, mode); + TRACE_("Copying %s...", dest); int d_fd = open(dest, O_WRONLY | O_CREAT, mode); int s_fd = open(source, O_RDONLY); @@ -92,6 +97,7 @@ void copy_directory(char * source, char * dest, int mode, int uid, int gid) { return; } + TRACE_("Creating %s/...", dest); //fprintf(stderr, "Creating %s\n", dest); if (!strcmp(dest, "/")) { dest = ""; @@ -191,8 +197,10 @@ int main(int argc, char * argv[]) { _debug = 1; } + _splash = fopen("/dev/pex/splash","r+"); + if (hashmap_has(cmdline, "root")) { - TRACE_("Original root was %s", hashmap_get(cmdline, "root")); + TRACE_("Original root was %s", (char*)hashmap_get(cmdline, "root")); } else if (hashmap_has(cmdline,"init") && !strcmp(hashmap_get(cmdline,"init"),"/dev/ram0")) { TRACE_("Init is ram0, so this is probably a netboot image, going to assume root is /tmp/netboot.img"); hashmap_set(cmdline,"root","/tmp/netboot.img"); diff --git a/apps/splash-log.c b/apps/splash-log.c index 8df40810..e5fcab14 100644 --- a/apps/splash-log.c +++ b/apps/splash-log.c @@ -64,10 +64,10 @@ static void write_char(int x, int y, int val, uint32_t color) { } } -static void update_message(char * c) { +static void update_message(char * c, int line) { if (framebuffer_fd != -1) { int x = 20; - int y = 20; + int y = 20 + char_height * line; while (*c) { write_char(x, y, *c, FG_COLOR); c++; @@ -79,7 +79,7 @@ static void update_message(char * c) { } } else { int x = 2; - int y = 2; + int y = 2 + line; while (*c) { placech(*c, x, y, 0x7); c++; @@ -140,7 +140,7 @@ int main(int argc, char * argv[]) { if (!fork()) { check_framebuffer(); clear_screen(); - update_message("ToaruOS is starting up..."); + update_message("ToaruOS is starting up...", 0); while (1) { pex_packet_t * p = calloc(PACKET_SIZE, 1); @@ -153,12 +153,20 @@ int main(int argc, char * argv[]) { /* Use the special message !quit to exit. */ fclose(pex_endpoint); return 0; + } 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'; + update_message(tmp+1, 1); + free(tmp); } 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'; - update_message(tmp); + update_message(tmp, 0); + update_message("", 1); free(tmp); } }