File dmesg_adjust.patch of Package firmwarekit

---
 dmesg.c         |   74 ++++++++++++++++++++++++++++++--------------------------
 libstandalone.c |    9 +++++-
 2 files changed, 47 insertions(+), 36 deletions(-)

Index: firmwarekit/dmesg.c
===================================================================
--- firmwarekit.orig/dmesg.c
+++ firmwarekit/dmesg.c
@@ -44,17 +44,37 @@ void get_dmesg_buffer(void)
 {
 	char *dmesg;
 	char *c1, *c2;
-	int linecount = 0;
+	int linecount = 0, ret;
 	dmesg = malloc(DMESG_SIZE);
 	assert(dmesg!=NULL);
+	c1 = malloc(4096);
+	assert(dmesg!=NULL && c1!=NULL);
 
 	system("/bin/dmesg -s 256000 > "DMESG_FILE);
+	FILE *f_dmesg;
 
 	/* don't printk to the console; newt hates that */
 	klogctl (6, NULL, 0);
 
+	if (access(DMESG_FILE, R_OK)){
+		system("/bin/dmesg -s 256000 > "DMESG_FILE);
+	}
 	memset(dmesg, 0, DMESG_SIZE);
-	klogctl (4, dmesg, DMESG_SIZE);
+	memset(c1, 0, 4096);
+
+	/* Clear ring buffer, we only want to get up to date messages
+	   in further calls... */
+	klogctl (5, NULL, 0);
+
+	f_dmesg = fopen (DMESG_FILE, "r");
+	if (f_dmesg == NULL){
+		fprintf (stderr, "WARN: Could not open "DMESG_FILE);
+		free(dmesg);
+		free(c1);
+		return;
+	}
+	ret = fread(dmesg, 1, DMESG_SIZE-1, f_dmesg);
+	dmesg[ret]='\0';
 
 	/* Add to our resource list that we keep. The user
 	 * will have access to this when they look at the 
@@ -62,32 +82,22 @@ void get_dmesg_buffer(void)
 	 * see uri.c for implementation */
 	announce_resource("dmesg://", dmesg, NULL);
 
-	c1 = dmesg;
-	while (c1) {
-		/* get next line from dmesg before '\n' 
-		 * and put into 'c1' */
-		c2 = strchr(c1, '\n');
-		
-		/* break if we're at the end of dmesg */
-		if (c2==NULL)
-			break;
-		
-		/* take out extra \n from beginning */
-		*c2 = 0;
-		c2++;
-		
-		/* skip the <4> that is in front of each line */
-		if (strlen(c1)>3 && c1[0]=='<')
-			c1+=3;
-
-		/* now append the cleaned-up line to boot_dmesg */
-		boot_dmesg = g_list_append(boot_dmesg, strdup(c1));
-		linecount ++;
-		
-		/* put what's left of dmesg back into c1 */
-		c1 = c2;
+	rewind(f_dmesg);
+	while (fgets(c1, 4095, f_dmesg)) {
+		/* skip the <4> that is in front of each line
+		   We only need lines with <4>, rest is later appended stuff in
+		   ordinary booted system
+		*/
+		c2=c1;
+		if (strlen(c1)>3 && c1[0]=='<' && c1[2]=='>'){
+			c2+=3;
+			boot_dmesg = g_list_append(boot_dmesg, strdup(c2));
+			linecount ++;
+		}
 	}
 	
+	fclose(f_dmesg);
+	free(c1);
 	free(dmesg);
 
 }
openSUSE Build Service is sponsored by