splash-log: support for submessages with :

This commit is contained in:
K. Lange 2018-12-21 17:47:19 +09:00
parent 536d25567b
commit 7f51afb3f2
2 changed files with 23 additions and 7 deletions

View File

@ -26,11 +26,15 @@
#include <toaru/hashmap.h> #include <toaru/hashmap.h>
#define TRACE_APP_NAME "migrate" #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 #define CHUNK_SIZE 4096
static int _debug = 0; static int _debug = 0;
static FILE * _splash = NULL;
int tokenize(char * str, char * sep, char **buf) { int tokenize(char * str, char * sep, char **buf) {
char * pch_i; 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) { 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); //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 d_fd = open(dest, O_WRONLY | O_CREAT, mode);
int s_fd = open(source, O_RDONLY); 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; return;
} }
TRACE_("Creating %s/...", dest);
//fprintf(stderr, "Creating %s\n", dest); //fprintf(stderr, "Creating %s\n", dest);
if (!strcmp(dest, "/")) { if (!strcmp(dest, "/")) {
dest = ""; dest = "";
@ -191,8 +197,10 @@ int main(int argc, char * argv[]) {
_debug = 1; _debug = 1;
} }
_splash = fopen("/dev/pex/splash","r+");
if (hashmap_has(cmdline, "root")) { 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")) { } 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"); 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"); hashmap_set(cmdline,"root","/tmp/netboot.img");

View File

@ -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) { if (framebuffer_fd != -1) {
int x = 20; int x = 20;
int y = 20; int y = 20 + char_height * line;
while (*c) { while (*c) {
write_char(x, y, *c, FG_COLOR); write_char(x, y, *c, FG_COLOR);
c++; c++;
@ -79,7 +79,7 @@ static void update_message(char * c) {
} }
} else { } else {
int x = 2; int x = 2;
int y = 2; int y = 2 + line;
while (*c) { while (*c) {
placech(*c, x, y, 0x7); placech(*c, x, y, 0x7);
c++; c++;
@ -140,7 +140,7 @@ int main(int argc, char * argv[]) {
if (!fork()) { if (!fork()) {
check_framebuffer(); check_framebuffer();
clear_screen(); clear_screen();
update_message("ToaruOS is starting up..."); update_message("ToaruOS is starting up...", 0);
while (1) { while (1) {
pex_packet_t * p = calloc(PACKET_SIZE, 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. */ /* Use the special message !quit to exit. */
fclose(pex_endpoint); fclose(pex_endpoint);
return 0; 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 { } else {
/* Make sure message is nil terminated (it should be...) */ /* Make sure message is nil terminated (it should be...) */
char * tmp = malloc(p->size + 1); char * tmp = malloc(p->size + 1);
memcpy(tmp, p->data, p->size); memcpy(tmp, p->data, p->size);
tmp[p->size] = '\0'; tmp[p->size] = '\0';
update_message(tmp); update_message(tmp, 0);
update_message("", 1);
free(tmp); free(tmp);
} }
} }