while ((c = getopt_long(argc, argv, "+g:s", longopts, NULL)) > 0) {
switch (c) {
case 'g':
- if (parse_cgroup_spec(cgroup_list, optarg)) {
+ ret = parse_cgroup_spec(cgroup_list, optarg,
+ CG_HIER_MAX);
+ if (ret) {
fprintf(stderr, "cgroup controller and path"
"parsing failed\n");
return -1;
}
break;
case 'g':
- if (parse_cgroup_spec(cgroup_list, optarg)) {
+ ret = parse_cgroup_spec(cgroup_list, optarg,
+ CG_HIER_MAX);
+ if (ret) {
fprintf(stderr, "%s: "
"cgroup controller and path"
"parsing failed (%s)\n",
/* parse groups on command line */
for (i = optind; i < argc; i++) {
- ret = parse_cgroup_spec(cgroup_list, argv[i]);
+ ret = parse_cgroup_spec(cgroup_list, argv[i], CG_HIER_MAX);
if (ret != 0) {
fprintf(stderr, "%s: error parsing cgroup '%s'\n",
argv[0], argv[i]);
while ((c = getopt_long(argc, argv, "+g:s", longopts, NULL)) > 0) {
switch (c) {
case 'g':
- if (parse_cgroup_spec(cgroup_list, optarg)) {
+ ret = parse_cgroup_spec(cgroup_list, optarg,
+ CG_HIER_MAX);
+ if (ret) {
fprintf(stderr, "cgroup controller and path"
"parsing failed\n");
return -1;
/* read the list of controllers */
while (optind < argc) {
- if (parse_cgroup_spec(cgroup_list, argv[optind])) {
+ ret = parse_cgroup_spec(cgroup_list, optarg,
+ CG_HIER_MAX);
+ if (ret) {
fprintf(stderr, "%s: cgroup controller"
" and path parsing failed (%s)\n",
argv[0], argv[optind]);
#include <libcgroup.h>
#include "tools-common.h"
-int parse_cgroup_spec(struct cgroup_group_spec *cdptr[], char *optarg)
+int parse_cgroup_spec(struct cgroup_group_spec **cdptr, char *optarg,
+ int capacity)
{
struct cgroup_group_spec *ptr;
int i, j;
ptr = *cdptr;
/* Find first free entry inside the cgroup data array */
- for (i = 0; i < CG_HIER_MAX; i++, ptr++) {
+ for (i = 0; i < capacity; i++, ptr++) {
if (!cdptr[i])
break;
}
- if (i == CG_HIER_MAX) {
+ if (i == capacity) {
/* No free slot found */
fprintf(stderr, "Max allowed hierarchies %d reached\n",
- CG_HIER_MAX);
+ capacity);
return -1;
}
* The option must have form of 'controller1,controller2,..:group_name'.
*
* The parsed list of controllers and group name is added at the end of
- * provided cdptr.
+ * provided cdptr, i.e. on place of first NULL cgroup_group_spec*.
*
* @param cdptr Target data structure to fill. New item is allocated and added
* at the end.
* @param optarg Argument to parse.
+ * @param capacity Capacity of the cdptr array.
* @return 0 on success, != 0 on error.
*/
-int parse_cgroup_spec(struct cgroup_group_spec *cdptr[], char *optarg);
+int parse_cgroup_spec(struct cgroup_group_spec **cdptr, char *optarg,
+ int capacity);
/**
* Free a single cgroup_group_spec structure.