From: Sebastien GODARD Date: Sun, 5 Feb 2017 09:52:09 +0000 (+0100) Subject: SVG: Properly terminate SVG file when no data have been found X-Git-Tag: v11.5.5~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1cf1a62f5177284603255e24e11bfdf1c64fae00;p=sysstat SVG: Properly terminate SVG file when no data have been found When a data file contains only a Linux Restart message with no statistics, trying to create SVG graphs with sadf -g resulted in an error ("XML Parsing Error: no element found"). This patch fixes that and display "No data!" instead. Signed-off-by: Sebastien GODARD --- diff --git a/sadf.c b/sadf.c index ff9fec3..7a9a223 100644 --- a/sadf.c +++ b/sadf.c @@ -1326,8 +1326,11 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst, __nr_t cpu_ if (read_next_sample(ifd, IGNORE_RESTART | IGNORE_COMMENT, 0, file, &rtype, 0, file_magic, file_actlst, rectime, loctime)) - /* End of sa data file */ - return; + { + /* End of sa data file: No views displayed */ + parm.graph_nr = 0; + goto close_svg; + } } while ((rtype == R_RESTART) || (rtype == R_COMMENT) || (tm_start.use && (datecmp(loctime, &tm_start) < 0)) || @@ -1379,11 +1382,12 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst, __nr_t cpu_ } /* Real number of graphs that have been displayed */ - graph_nr = g_nr; + parm.graph_nr = g_nr; +close_svg: /* Print SVG trailer */ if (*fmt[f_position]->f_header) { - (*fmt[f_position]->f_header)(&graph_nr, F_END, file, file_magic, + (*fmt[f_position]->f_header)(&parm, F_END, file, file_magic, &file_hdr, cpu_nr, act, id_seq); } } diff --git a/sadf_misc.c b/sadf_misc.c index 12e27d4..5a47233 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -942,6 +942,11 @@ __printf_funct_t print_svg_header(void *parm, int action, char *dfile, if (action & F_END) { if (!(action & F_BEGIN)) { + if (!hdr_parm->graph_nr) { + /* No views displayed */ + printf(""); + printf("No data!\n"); + } /* Give actual SVG height */ printf("\n", SVG_H_YSIZE + SVG_T_YSIZE * (hdr_parm->graph_nr));