cgroup_add_value_string() is the fundamental building block for adding a name/value pair to a cgroup_controller struct. Add support for a NULL value field.
Currently it only supports adding a valid value, but in a subsequent commit, cgget will utilize this function to build up a hierarchy of cgroups, controllers, and setting names. The values are NULL at the time the struct are populated and will be read from sysfs at a later time. Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com> --- src/wrapper.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/wrapper.c b/src/wrapper.c index b7932545ebfa..35f5dbd8afa5 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -195,18 +195,22 @@ int cgroup_add_value_string(struct cgroup_controller *controller, if (!cntl_value) return ECGCONTROLLERCREATEFAILED; - if (strlen(value) >= sizeof(cntl_value->value)) { - fprintf(stderr, "value exceeds the maximum of %d characters\n", - sizeof(cntl_value->value) - 1); - free(cntl_value); - return ECGCONFIGPARSEFAIL; - } - strncpy(cntl_value->name, name, sizeof(cntl_value->name)); cntl_value->name[sizeof(cntl_value->name)-1] = '\0'; - strncpy(cntl_value->value, value, sizeof(cntl_value->value)); - cntl_value->value[sizeof(cntl_value->value)-1] = '\0'; - cntl_value->dirty = true; + + if (value) { + if (strlen(value) >= sizeof(cntl_value->value)) { + fprintf(stderr, "value exceeds the maximum of %d characters\n", + sizeof(cntl_value->value) - 1); + free(cntl_value); + return ECGCONFIGPARSEFAIL; + } + + strncpy(cntl_value->value, value, sizeof(cntl_value->value)); + cntl_value->value[sizeof(cntl_value->value)-1] = '\0'; + cntl_value->dirty = true; + } + controller->values[controller->index] = cntl_value; controller->index++; -- 2.26.2 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel