]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgsnapshot: Close tags in output file on errors
authorTom Hromatka <tom.hromatka@oracle.com>
Wed, 21 Dec 2022 21:00:21 +0000 (14:00 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 6 Jan 2023 15:07:41 +0000 (08:07 -0700)
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 <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
src/tools/cgsnapshot.c

index 79183db2a2d3cc17c9ce1622e1d04f4b6656549b..1aea9b79bd8c9d09d5118511194b0fcdb0b23f1b 100644 (file)
@@ -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;
                }