Commit 8b92dc3a by Michel Normand Committed by Daniel Lezcano

change lxc_cgroup_set/get functions to return -1

and report error message as soon as detected error in these two functions Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com>
parent 69c3910d
......@@ -108,17 +108,21 @@ int lxc_unlink_nsgroup(const char *name)
int lxc_cgroup_set(const char *name, const char *subsystem, const char *value)
{
int fd, ret = -LXC_ERROR_INTERNAL;;
int fd, ret = -1;
char path[MAXPATHLEN];
snprintf(path, MAXPATHLEN, LXCPATH "/%s/nsgroup/%s", name, subsystem);
fd = open(path, O_WRONLY);
if (fd < 0)
if (fd < 0) {
ERROR("open %s : %s", path, strerror(errno));
return -1;
}
if (write(fd, value, strlen(value)) < 0)
if (write(fd, value, strlen(value)) < 0) {
ERROR("write %s : %s", path, strerror(errno));
goto out;
}
ret = 0;
out:
......@@ -129,17 +133,21 @@ out:
int lxc_cgroup_get(const char *name, const char *subsystem,
char *value, size_t len)
{
int fd, ret = -LXC_ERROR_INTERNAL;
int fd, ret = -1;
char path[MAXPATHLEN];
snprintf(path, MAXPATHLEN, LXCPATH "/%s/nsgroup/%s", name, subsystem);
fd = open(path, O_RDONLY);
if (fd < 0)
if (fd < 0) {
ERROR("open %s : %s", path, strerror(errno));
return -1;
}
if (read(fd, value, len) < 0)
if (read(fd, value, len) < 0) {
ERROR("read %s : %s", path, strerror(errno));
goto out;
}
ret = 0;
out:
......
......@@ -982,7 +982,7 @@ static int setup_cgroup_cb(void* buffer, void *data)
ret = lxc_cgroup_set(name, key, value);
if (ret)
SYSERROR("failed to set cgroup '%s' = '%s' for '%s'",
ERROR("failed to set cgroup '%s' = '%s' for '%s'",
key, value, name);
return ret;
}
......
Markdown is supported
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