From d5bcbbcebf466433f1b87c770a403869c5818b2b Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 21 Dec 2022 14:00:21 -0700 Subject: [PATCH] cgsnapshot: Close tags in output file on errors Close tags in the output file when cgsnapshot encounters an error. For example, if cgsnapshot cannot translate a uid to a username, the "perm {" tag still needs a closing "}". Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- src/tools/cgsnapshot.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/cgsnapshot.c b/src/tools/cgsnapshot.c index 79183db2..1aea9b79 100644 --- a/src/tools/cgsnapshot.c +++ b/src/tools/cgsnapshot.c @@ -236,12 +236,14 @@ static int display_permissions(const char *path, const char * const cg_name, pw = getpwuid(sba.st_uid); if (pw == NULL) { err("ERROR: can't get %d user name\n", sba.st_uid); + fprintf(output_f, "}\n}\n"); return -1; } gr = getgrgid(sba.st_gid); if (gr == NULL) { err("ERROR: can't get %d group name\n", sba.st_gid); + fprintf(output_f, "}\n}\n"); return -1; } @@ -255,12 +257,14 @@ static int display_permissions(const char *path, const char * const cg_name, pw = getpwuid(sbt.st_uid); if (pw == NULL) { err("ERROR: can't get %d user name\n", sbt.st_uid); + fprintf(output_f, "}\n}\n"); return -1; } gr = getgrgid(sbt.st_gid); if (gr == NULL) { err("ERROR: can't get %d group name\n", sbt.st_gid); + fprintf(output_f, "}\n}\n"); return -1; } -- 2.47.2