mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-18 20:55:24 +00:00
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:
parent
69c3910d15
commit
8b92dc3ab6
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user