[PATCH] makedumpfile: Support line mode terminals

Michael Holzheu holzheu at linux.vnet.ibm.com
Mon Aug 15 09:24:26 EDT 2011


From: Michael Holzheu <holzheu at linux.vnet.ibm.com>

On S390 we have line mode terminals that do not have the ability to
position the cursor. When using kdump the output of makedumpfile will be shown
on such terminals. Currently the output looks very strange because the '\r'
control character is ignored. It looks like the following:

 Checking for memory holes          : [  0 %]  Checking for memory holes        
  : [100 %]  Copying data                       : [ 33 %]  Copying data         
              : [ 65 %]  Copying data                       : [ 96 %]  Copying d
ata                       : [100 %]   

For those line mode terminals the TERM environment variable is set to "dumb".
With this patch makedumpfile checks the TERM variable and in case of "dumb"
instead of using '\r' each progress message is printed into a separate line.
The output will then look like the following:

Checking for memory holes          : [  0 %]
Checking for memory holes          : [100 %]
Copying data                       : [ 11 %]
Copying data                       : [ 44 %]
Copying data                       : [ 75 %]
Copying data                       : [100 %]

Signed-off-by: Michael Holzheu <holzheu at linux.vnet.ibm.com>
---
 makedumpfile.c |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -29,6 +29,7 @@ struct DumpInfo		*info = NULL;
 
 char filename_stdout[] = FILENAME_STDOUT;
 int message_level;
+static int dumb_term;
 
 /*
  * Forward declarations
@@ -5661,9 +5662,14 @@ print_progress(const char *msg, unsigned
 		progress = current * 100 / end;
 	} else
 		progress = 100;
-
-	PROGRESS_MSG("\r");
-	PROGRESS_MSG("%-" PROGRESS_MAXLEN "s: [%3d %%] ", msg, progress);
+	if (dumb_term) {
+		PROGRESS_MSG("%-" PROGRESS_MAXLEN "s: [%3d %%]\n",
+			     msg, progress);
+	} else {
+		PROGRESS_MSG("\r");
+		PROGRESS_MSG("%-" PROGRESS_MAXLEN "s: [%3d %%] ",
+			     msg, progress);
+	}
 }
 
 unsigned long long
@@ -7825,11 +7831,21 @@ static struct option longopts[] = {
 	{0, 0, 0, 0}
 };
 
+static void setup_term(void)
+{
+	char *term_str = getenv("TERM");
+
+	if (term_str && strcmp(term_str, "dumb") == 0)
+		dumb_term = 1;
+}
+
 int
 main(int argc, char *argv[])
 {
 	int i, opt, flag_debug = FALSE;
 
+	setup_term();
+
 	if ((info = calloc(1, sizeof(struct DumpInfo))) == NULL) {
 		ERRMSG("Can't allocate memory for the pagedesc cache. %s.\n",
 		    strerror(errno));





More information about the kexec mailing list