From: Michael Tremer Date: Sun, 5 Nov 2023 17:50:35 +0000 (+0000) Subject: jail: setgroups: Use pakfire_file_write X-Git-Tag: 0.9.30~1304 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe30bb0ac1026c9670b4a32a8607b5f19f2e14a5;p=pakfire.git jail: setgroups: Use pakfire_file_write Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index ece668eca..e47fe7e88 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -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; }