From: Tom Hromatka Date: Wed, 21 Dec 2022 21:00:21 +0000 (-0700) Subject: cgsnapshot: Close tags in output file on errors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5bcbbcebf466433f1b87c770a403869c5818b2b;p=thirdparty%2Flibcgroup.git 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 --- 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; }