Whamcloud - gitweb
e2fsck: fix XML validity problem with the problem log
authorTheodore Ts'o <tytso@mit.edu>
Fri, 10 May 2019 17:20:59 +0000 (13:20 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 10 May 2019 22:36:46 +0000 (18:36 -0400)
Also fix a gcc warning.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/e2fsck.c
e2fsck/problem.c
e2fsck/unix.c

index 2af6105..3770bfc 100644 (file)
@@ -218,9 +218,10 @@ void e2fsck_free_context(e2fsck_t ctx)
        if (ctx->problem_log_fn)
                free(ctx->problem_log_fn);
 
-       if (ctx->problem_logf)
+       if (ctx->problem_logf) {
+               fputs("</problem_log>\n", ctx->problem_logf);
                fclose(ctx->problem_logf);
-
+       }
        ext2fs_free_mem(&ctx);
 }
 
index 01f0867..360eb33 100644 (file)
@@ -2196,7 +2196,7 @@ static void print_problem(FILE *f, problem_t code, int answer, int fixed,
                          struct problem_context *pctx)
 {
        if (ptr->flags & PR_HEADER) {
-               fprintf(f, "<header code=\"0x%06x\">\n", code);
+               fprintf(f, "<header code=\"0x%06x\"/>\n", code);
                return;
        }
        fprintf(f, "<problem code=\"0x%06x\" answer=\"%d\"", code, answer);
@@ -2317,7 +2317,8 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
                if (ptr->count == ptr->max_count + 1) {
                        if (ctx->problem_logf)
                                fprintf(ctx->problem_logf,
-                                       "<suppressed code=\"0x%06x\">\n", code);
+                                       "<suppressed code=\"0x%06x\"/>\n",
+                                       code);
                        printf("...problem 0x%06x suppressed\n",
                               ptr->e2p_code);
                        fflush(stdout);
index f8c4983..68f4987 100644 (file)
@@ -1438,11 +1438,13 @@ int main (int argc, char *argv[])
 
                fputs("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
                      ctx->problem_logf);
+               fprintf(ctx->problem_logf, "<problem_log time=\"%lu\">\n",
+                       ctx->now);
                fprintf(ctx->problem_logf, "<invocation prog=\"%s\"",
                        argv[0]);
                for (i = 1; i < argc; i++)
-                       fprintf(ctx->problem_logf, " arg=\"%s\"", argv[i]);
-               fputs(">\n", ctx->problem_logf);
+                       fprintf(ctx->problem_logf, " arg%d=\"%s\"", i, argv[i]);
+               fputs("/>\n", ctx->problem_logf);
        }
 
        init_resource_track(&ctx->global_rtrack, NULL);
@@ -1712,11 +1714,10 @@ failure:
                }
                if (sb->s_volume_name[0]) {
                        memset(buf, 0, sizeof(buf));
-                       strncpy(buf, sb->s_volume_name,
-                               sizeof(sb->s_volume_name));
+                       strncpy(buf, sb->s_volume_name, sizeof(buf));
                        fprintf(ctx->problem_logf, " label=\"%s\"", buf);
                }
-               fputs(">\n", ctx->problem_logf);
+               fputs("/>\n", ctx->problem_logf);
        }
 
        ehandler_init(fs->io);