Commit 490caf5d authored by Petr Baudis's avatar Petr Baudis
Browse files

cgroup_add_task(), cgroup_set_mem_limit*(): More careful error detection

parent c40fc4df
......@@ -66,8 +66,15 @@ cgroup_add_task(const char *chier, const char *cgroup, pid_t pid)
cgroup_perror(tasksfile);
return -1;
}
fprintf(tasks, "%d\n", pid);
fclose(tasks);
if (fprintf(tasks, "%d\n", pid) < 0) {
cgroup_perror(tasksfile);
fclose(tasks);
return -1;
}
if (fclose(tasks) < 0) {
cgroup_perror(tasksfile);
return -1;
}
return 1;
}
......@@ -144,8 +151,15 @@ cgroup_set_mem_limit_do(const char *chier, const char *cgroup, size_t nlimit, ch
cgroup_perror(limitfile);
return -1;
}
fprintf(limit, "%zu\n", nlimit);
fclose(limit);
if (fprintf(limit, "%zu\n", nlimit) < 0) {
cgroup_perror(limitfile);
fclose(limit);
return -1;
}
if (fclose(limit) < 0) {
cgroup_perror(limitfile);
return -1;
}
return 1;
}
......@@ -156,8 +170,10 @@ cgroup_set_mem_limit(const char *chier, const char *cgroup, size_t nlimit)
* since normal <= memsw must hold. */
int ret = cgroup_set_mem_limit_do(chier, cgroup, nlimit, "");
#if SWAP_LIMIT
if (ret >= 0)
ret |= cgroup_set_mem_limit_do(chier, cgroup, nlimit, MEMSW);
if (ret >= 0) {
int ret2 = cgroup_set_mem_limit_do(chier, cgroup, nlimit, MEMSW);
ret = ret2 < 0 ? ret2 : (ret || ret2);
}
#endif
return ret;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment