]> git.ipfire.org Git - pakfire.git/commitdiff
jail: setgroups: Use pakfire_file_write
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Nov 2023 17:50:35 +0000 (17:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Nov 2023 17:50:35 +0000 (17:50 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index ece668eca6a2e63e1c5163bee7e0ac30c3ef5e9b..e47fe7e8845beba8e473c4d9f6fdbd59d468253b 100644 (file)
@@ -1634,38 +1634,19 @@ static int pakfire_jail_setup_gid_mapping(struct pakfire_jail* jail, pid_t pid)
 
 static int pakfire_jail_setgroups(struct pakfire_jail* jail, pid_t pid) {
        char path[PATH_MAX];
-       int r = 1;
+       int r;
 
        // Make path
        r = pakfire_string_format(path, "/proc/%d/setgroups", pid);
        if (r)
                return r;
 
-       // Open file for writing
-       FILE* f = fopen(path, "w");
-       if (!f) {
-               ERROR(jail->pakfire, "Could not open %s for writing: %m\n", path);
-               goto ERROR;
-       }
-
-       // Write content
-       int bytes_written = fprintf(f, "deny\n");
-       if (bytes_written <= 0) {
-               ERROR(jail->pakfire, "Could not write to %s: %m\n", path);
-               goto ERROR;
-       }
-
-       r = fclose(f);
-       f = NULL;
+       r = pakfire_file_write(jail->pakfire, path, 0, 0, 0, "deny\n");
        if (r) {
-               ERROR(jail->pakfire, "Could not close %s: %m\n", path);
-               goto ERROR;
+               CTX_ERROR(jail->ctx, "Could not set setgroups to deny: %s\n", strerror(errno));
+               r = -errno;
        }
 
-ERROR:
-       if (f)
-               fclose(f);
-
        return r;
 }