mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-13 16:59:33 +00:00
cgmanager: fix obvious braindeadnesses
1. don't return bools for int-return functions 2. copy the filename to controller before using it 3. use full filename not just the key to pass to cgmanager Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
c5afb6e455
commit
c0e0d2b299
@ -249,31 +249,28 @@ int cgm_get(const char *filename, char *value, size_t len, const char *name, con
|
|||||||
char *result, *controller, *key, *cgroup;
|
char *result, *controller, *key, *cgroup;
|
||||||
|
|
||||||
controller = alloca(strlen(filename)+1);
|
controller = alloca(strlen(filename)+1);
|
||||||
|
strcpy(controller, filename);
|
||||||
key = strchr(controller, '.');
|
key = strchr(controller, '.');
|
||||||
if (!key)
|
if (!key)
|
||||||
return false;
|
return -1;
|
||||||
*key = '\0';
|
*key = '\0';
|
||||||
key++;
|
|
||||||
|
|
||||||
/* use the command interface to look for the cgroup */
|
/* use the command interface to look for the cgroup */
|
||||||
cgroup = lxc_cmd_get_cgroup_path(name, lxcpath, controller);
|
cgroup = lxc_cmd_get_cgroup_path(name, lxcpath, controller);
|
||||||
if (!cgroup) {
|
if (!cgroup)
|
||||||
ERROR("Failed to get cgroup for controller %s for %s:%s",
|
return -1;
|
||||||
controller, lxcpath, name);
|
if (cgmanager_get_value_sync(NULL, cgroup_manager, controller, cgroup, filename, &result) != 0) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (cgmanager_get_value_sync(NULL, cgroup_manager, controller, cgroup, key, &result) != 0) {
|
|
||||||
ERROR("Error getting value for %s from cgmanager for cgroup %s (%s:%s)",
|
ERROR("Error getting value for %s from cgmanager for cgroup %s (%s:%s)",
|
||||||
filename, cgroup, lxcpath, name);
|
filename, cgroup, lxcpath, name);
|
||||||
free(cgroup);
|
free(cgroup);
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
free(cgroup);
|
free(cgroup);
|
||||||
strncpy(value, result, len);
|
strncpy(value, result, len);
|
||||||
if (strlen(result) >= len)
|
if (strlen(result) >= len)
|
||||||
value[len-1] = '\0';
|
value[len-1] = '\0';
|
||||||
free(result);
|
free(result);
|
||||||
return true;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cgm_set(const char *filename, const char *value, const char *name, const char *lxcpath)
|
int cgm_set(const char *filename, const char *value, const char *name, const char *lxcpath)
|
||||||
@ -281,27 +278,27 @@ int cgm_set(const char *filename, const char *value, const char *name, const cha
|
|||||||
char *controller, *key, *cgroup;
|
char *controller, *key, *cgroup;
|
||||||
|
|
||||||
controller = alloca(strlen(filename)+1);
|
controller = alloca(strlen(filename)+1);
|
||||||
|
strcpy(controller, filename);
|
||||||
key = strchr(controller, '.');
|
key = strchr(controller, '.');
|
||||||
if (!key)
|
if (!key)
|
||||||
return false;
|
return -1;
|
||||||
*key = '\0';
|
*key = '\0';
|
||||||
key++;
|
|
||||||
|
|
||||||
/* use the command interface to look for the cgroup */
|
/* use the command interface to look for the cgroup */
|
||||||
cgroup = lxc_cmd_get_cgroup_path(name, lxcpath, controller);
|
cgroup = lxc_cmd_get_cgroup_path(name, lxcpath, controller);
|
||||||
if (!cgroup) {
|
if (!cgroup) {
|
||||||
ERROR("Failed to get cgroup for controller %s for %s:%s",
|
ERROR("Failed to get cgroup for controller %s for %s:%s",
|
||||||
controller, lxcpath, name);
|
controller, lxcpath, name);
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
if (cgmanager_set_value_sync(NULL, cgroup_manager, controller, cgroup, key, value) != 0) {
|
if (cgmanager_set_value_sync(NULL, cgroup_manager, controller, cgroup, filename, value) != 0) {
|
||||||
ERROR("Error setting value for %s from cgmanager for cgroup %s (%s:%s)",
|
ERROR("Error setting value for %s from cgmanager for cgroup %s (%s:%s)",
|
||||||
filename, cgroup, lxcpath, name);
|
filename, cgroup, lxcpath, name);
|
||||||
free(cgroup);
|
free(cgroup);
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
free(cgroup);
|
free(cgroup);
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -365,9 +362,9 @@ static int cgm_unfreeze_fromhandler(struct lxc_handler *handler)
|
|||||||
if (cgmanager_set_value_sync(NULL, cgroup_manager, "freezer", d->cgroup_path,
|
if (cgmanager_set_value_sync(NULL, cgroup_manager, "freezer", d->cgroup_path,
|
||||||
"freezer.state", "THAWED") != 0) {
|
"freezer.state", "THAWED") != 0) {
|
||||||
ERROR("Error unfreezing %s", d->cgroup_path);
|
ERROR("Error unfreezing %s", d->cgroup_path);
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cgroup_ops cgmanager_ops = {
|
static struct cgroup_ops cgmanager_ops = {
|
||||||
|
Loading…
Reference in New Issue
Block a user