Browse Source

splash-log: support for submessages with :

K. Lange 2 years ago
parent
commit
7f51afb3f2
2 changed files with 23 additions and 7 deletions
  1. 10 2
      apps/migrate.c
  2. 13 5
      apps/splash-log.c

+ 10 - 2
apps/migrate.c

@@ -26,11 +26,15 @@
 #include <toaru/hashmap.h>
 #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");

+ 13 - 5
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);
 			}
 		}