chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update TODO
[elogind.git]
/
src
/
shared
/
cgroup-util.c
diff --git
a/src/shared/cgroup-util.c
b/src/shared/cgroup-util.c
index be00b40fa2346afb2ebf43ab6847d4d61a025f6f..c17e1d4d1bde18080cd82a7ebb2b1bd6778a384f 100644
(file)
--- a/
src/shared/cgroup-util.c
+++ b/
src/shared/cgroup-util.c
@@
-677,9
+677,9
@@
int cg_delete(const char *controller, const char *path) {
}
int cg_attach(const char *controller, const char *path, pid_t pid) {
}
int cg_attach(const char *controller, const char *path, pid_t pid) {
- char *fs;
+ _cleanup_free_ char *fs = NULL;
+ char c[DECIMAL_STR_MAX(pid_t) + 2];
int r;
int r;
- char c[32];
assert(controller);
assert(path);
assert(controller);
assert(path);
@@
-693,16
+693,18
@@
int cg_attach(const char *controller, const char *path, pid_t pid) {
pid = getpid();
snprintf(c, sizeof(c), "%lu\n", (unsigned long) pid);
pid = getpid();
snprintf(c, sizeof(c), "%lu\n", (unsigned long) pid);
- char_array_0(c);
-
- r = write_one_line_file(fs, c);
- free(fs);
- return
r
;
+ return
write_string_file(fs, c)
;
}
}
-int cg_set_group_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid) {
- char *fs;
+int cg_set_group_access(
+ const char *controller,
+ const char *path,
+ mode_t mode,
+ uid_t uid,
+ gid_t gid) {
+
+ _cleanup_free_ char *fs = NULL;
int r;
assert(controller);
int r;
assert(controller);
@@
-715,14
+717,18
@@
int cg_set_group_access(const char *controller, const char *path, mode_t mode, u
if (r < 0)
return r;
if (r < 0)
return r;
- r = chmod_and_chown(fs, mode, uid, gid);
- free(fs);
-
- return r;
+ return chmod_and_chown(fs, mode, uid, gid);
}
}
-int cg_set_task_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid, int sticky) {
- char *fs;
+int cg_set_task_access(
+ const char *controller,
+ const char *path,
+ mode_t mode,
+ uid_t uid,
+ gid_t gid,
+ int sticky) {
+
+ _cleanup_free_ char *fs = NULL, *procs = NULL;
int r;
assert(controller);
int r;
assert(controller);
@@
-749,10
+755,8
@@
int cg_set_task_access(const char *controller, const char *path, mode_t mode, ui
* mode from the file itself */
r = lstat(fs, &st);
* mode from the file itself */
r = lstat(fs, &st);
- if (r < 0) {
- free(fs);
+ if (r < 0)
return -errno;
return -errno;
- }
if (mode == (mode_t) -1)
/* No mode set, we just shall set the sticky bit */
if (mode == (mode_t) -1)
/* No mode set, we just shall set the sticky bit */
@@
-763,9
+767,15
@@
int cg_set_task_access(const char *controller, const char *path, mode_t mode, ui
}
r = chmod_and_chown(fs, mode, uid, gid);
}
r = chmod_and_chown(fs, mode, uid, gid);
- free(fs);
+ if (r < 0)
+ return r;
- return r;
+ /* Always keep values for "cgroup.procs" in sync with "tasks" */
+ r = cg_get_path(controller, path, "cgroup.procs", &procs);
+ if (r < 0)
+ return r;
+
+ return chmod_and_chown(procs, mode, uid, gid);
}
int cg_get_by_pid(const char *controller, pid_t pid, char **path) {
}
int cg_get_by_pid(const char *controller, pid_t pid, char **path) {
@@
-857,7
+867,8
@@
int cg_install_release_agent(const char *controller, const char *agent) {
goto finish;
}
goto finish;
}
- if ((r = write_one_line_file(fs, line)) < 0)
+ r = write_string_file(fs, line);
+ if (r < 0)
goto finish;
} else if (!streq(sc, agent)) {
goto finish;
} else if (!streq(sc, agent)) {
@@
-878,7
+889,7
@@
int cg_install_release_agent(const char *controller, const char *agent) {
sc = strstrip(contents);
if (streq(sc, "0")) {
sc = strstrip(contents);
if (streq(sc, "0")) {
- if ((r = write_
one_line
_file(fs, "1\n")) < 0)
+ if ((r = write_
string
_file(fs, "1\n")) < 0)
goto finish;
r = 1;
goto finish;
r = 1;