]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
jail: Use common function to write files
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Aug 2022 10:07:57 +0000 (10:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Aug 2022 10:07:57 +0000 (10:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index c4b19833f91d250605fcbf77e5c27a1d4276ea6e..06b664be32b6e406440a83eb80e5ee07736b9f62 100644 (file)
@@ -982,39 +982,8 @@ static int pakfire_jail_mount(struct pakfire_jail* jail) {
 
 static int pakfire_jail_write_uidgid_mapping(struct pakfire_jail* jail,
                const char* path, const struct pakfire_subid* subid) {
-       int r = 1;
-
-       // 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 configuration
-       int bytes_written = fprintf(f, "%d %u %lu\n", 0, subid->id, subid->length);
-       if (bytes_written <= 0) {
-               ERROR(jail->pakfire, "Could not write UID/GID mapping: %m\n");
-               goto ERROR;
-       }
-
-       // Close the file
-       r = fclose(f);
-       f = NULL;
-       if (r) {
-               ERROR(jail->pakfire, "Could not write UID/GID mapping: %m\n");
-
-               goto ERROR;
-       }
-
-       // Success
-       r = 0;
-
-ERROR:
-       if (f)
-               fclose(f);
-
-       return r;
+       return pakfire_file_write(jail->pakfire, path, 0, 0, 0,
+               "%d %u %lu\n", 0, subid->id, subid->length);
 }
 
 static int pakfire_jail_setup_uid_mapping(struct pakfire_jail* jail, pid_t pid) {