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: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Michel Normand <normand@fr.ibm.com>
This commit is contained in:
Michel Normand 2009-05-14 16:27:29 +02:00 committed by Daniel Lezcano
parent 69c3910d15
commit 8b92dc3ab6
2 changed files with 15 additions and 7 deletions

View File

@ -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:

View File

@ -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;
}