static int pakfire_cgroup_fprintf(Pakfire pakfire,
const char* group, const char* file, const char* format, ...) {
+ char buffer[64];
+ size_t length;
int r;
va_list args;
if (!f)
return 1;
- // Write to file
+ // Format what we have to write
va_start(args, format);
- r = vfprintf(f, format, args);
+ length = vsnprintf(buffer, sizeof(buffer) - 1, format, args);
va_end(args);
+ // Use write(2) instead of fprintf/fwrite because we want to know
+ // if the operation was successful.
+ r = write(fileno(f), buffer, length);
+
fclose(f);
return r;
"+%s", controller);
// fprintf might set errno when there was a problem, although the write itself was ok
- if (errno) {
+ if (r < 0) {
// The parent group does not seem to have this controller enabled
if (errno == ENOENT) {
char* parent = pakfire_cgroup_parent_name(group);