#include <unistd.h>
#include <stdio.h>
-#define MODE_SHOW_HEADERS 1
-#define MODE_SHOW_NAMES 2
+#define MODE_SHOW_HEADERS 1
+#define MODE_SHOW_NAMES 2
-#define LL_MAX 100
+#define LL_MAX 100
static const struct option long_options[] = {
{"variable", required_argument, NULL, 'r'},
static void usage(int status, const char *program_name)
{
if (status != 0) {
- err("Wrong input parameters,");
- err(" try %s -h' for more information.\n", program_name);
+ err("Wrong input parameters, try %s -h' for more information.\n", program_name);
return;
}
- info("Usage: %s [-nv] [-r <name>] [-g <controllers>] ", program_name);
- info("[-a] <path> ...\n");
- info(" or: %s [-nv] [-r <name>] -g <controllers>:<path> ...\n",
- program_name);
+ info("Usage: %s [-nv] [-r <name>] [-g <controllers>] [-a] <path> ...\n", program_name);
info("Print parameter(s) of given group(s).\n");
- info(" -a, --all Print info about all relevant ");
- info("controllers\n");
- info(" -g <controllers> Controller which info should ");
- info("be displayed\n");
- info(" -g <controllers>:<path> Control group which info ");
- info("should be displayed\n");
+ info(" -a, --all Print info about all relevant controllers\n");
+ info(" -g <controllers> Controller which info should be displayed\n");
+ info(" -g <controllers>:<path> Control group which info should be displayed\n");
info(" -h, --help Display this help\n");
info(" -n Do not print headers\n");
info(" -r, --variable <name> Define parameter to display\n");
info("parameter names\n");
}
-static int get_controller_from_name(const char * const name,
- char **controller)
+static int get_controller_from_name(const char * const name, char **controller)
{
char *dot;
dot = strchr(*controller, '.');
if (dot == NULL) {
- err("cgget: error parsing parameter name\n");
- err( " '%s'", name);
+ err("cgget: error parsing parameter name '%s'", name);
return ECGINVAL;
}
-
*dot = '\0';
+
return 0;
}
static int create_cg(struct cgroup **cg_list[], int * const cg_list_len)
{
- *cg_list = realloc(*cg_list,
- ((*cg_list_len) + 1) * sizeof(struct cgroup *));
+ *cg_list = realloc(*cg_list, ((*cg_list_len) + 1) * sizeof(struct cgroup *));
if ((*cg_list) == NULL)
return ECGCONTROLLERCREATEFAILED;
return ECGCONTROLLERCREATEFAILED;
(*cg_list_len)++;
+
return 0;
}
}
/*
- * if "-r" was provided, then we know that the cgroup(s) will be an
- * optarg at the end with no flag. Let's temporarily populate the
- * first cgroup with the requested control values.
+ * if "-r" was provided, then we know that the cgroup(s) will be
+ * an optarg at the end with no flag. Let's temporarily populate
+ * the first cgroup with the requested control values.
*/
cg = (*cg_list)[0];
if (!cgc) {
cgc = cgroup_add_controller(cg, controller.name);
if (!cgc) {
- err("cgget: cannot find controller '%s'\n",
- controller.name);
+ err("cgget: cannot find controller '%s'\n", controller.name);
ret = ECGOTHER;
goto out;
}
}
-
ret = cgroup_get_controller_next(&handle, &controller);
}
if (ret == ECGEOF)
cgroup_get_controller_end(&handle);
return ret;
+
out:
cgroup_get_controller_end(&handle);
+
return ret;
}
}
/*
- * if "-r" was provided, then we know that the cgroup(s) will be an
- * optarg at the end with no flag. Let's temporarily populate the
- * first cgroup with the requested control values.
+ * if "-r" was provided, then we know that the cgroup(s) will be
+ * an optarg at the end with no flag. Let's temporarily populate
+ * the first cgroup with the requested control values.
*/
cg = (*cg_list)[0];
if (!cgc) {
cgc = cgroup_add_controller(cg, cntl_value_controller);
if (!cgc) {
- err("cgget: cannot find controller '%s'\n",
- cntl_value_controller);
+ err("cgget: cannot find controller '%s'\n", cntl_value_controller);
ret = ECGOTHER;
goto out;
}
out:
if (cntl_value_controller)
free(cntl_value_controller);
+
return ret;
}
-static int parse_g_flag_no_colon(struct cgroup **cg_list[],
- int * const cg_list_len,
+static int parse_g_flag_no_colon(struct cgroup **cg_list[], int * const cg_list_len,
const char * const ctrl_str)
{
struct cgroup_controller *cgc;
return 0;
}
-static int split_controllers(const char * const in,
- char **ctrl[], int * const ctrl_len)
+static int split_controllers(const char * const in, char **ctrl[], int * const ctrl_len)
{
char *copy, *tok, *colon, *saveptr = NULL;
int ret = 0;
out:
if (saveptr)
free(saveptr);
+
return ret;
}
-static int parse_g_flag_with_colon(struct cgroup **cg_list[],
- int * const cg_list_len,
+static int parse_g_flag_with_colon(struct cgroup **cg_list[], int * const cg_list_len,
const char * const ctrl_str)
{
struct cgroup_controller *cgc;
if (!cgc) {
cgc = cgroup_add_controller(cg, controllers[i]);
if (!cgc) {
- err("cgget: cannot find controller '%s'\n",
- controllers[i]);
+ err("cgget: cannot find controller '%s'\n", controllers[i]);
ret = ECGOTHER;
goto out;
}
out:
for (i = 0; i < controllers_len; i++)
free(controllers[i]);
+
return ret;
}
int ret = 0;
/*
- * The first cgroup was temporarily populated and requires
- * the user to provide a cgroup name as an opt
+ * The first cgroup was temporarily populated and requires the
+ * user to provide a cgroup name as an opt
*/
if (argv[optind] == NULL && first_cg_is_dummy) {
usage(1, argv[0]);
/*
* The user has provided a cgroup and controller via the
- * -g <controller>:<cgroup> flag and has also provided a cgroup via
- * the optind. This was not supported by the previous cgget
+ * -g <controller>:<cgroup> flag and has also provided a cgroup
+ * via the optind. This was not supported by the previous cgget
* implementation. Continue that approach.
*
* Example of a command that will hit this code:
if (ret)
goto out;
- strncpy((*cg_list)[(*cg_list_len) - 1]->name,
- argv[optind],
+ strncpy((*cg_list)[(*cg_list_len) - 1]->name, argv[optind],
sizeof((*cg_list)[(*cg_list_len) - 1]->name) - 1);
} else if (cg != NULL && strlen(cg->name) == 0) {
/*
* this cgroup was created based upon control/value
* pairs or with a -g <controller> option. we'll
- * populate it with the parameter provided by the
- * user
+ * populate it with the parameter provided by the user
*/
strncpy(cg->name, argv[optind], sizeof(cg->name) - 1);
} else {
if (ret)
goto out;
- strncpy((*cg_list)[(*cg_list_len) - 1]->name,
- argv[optind],
+ strncpy((*cg_list)[(*cg_list_len) - 1]->name, argv[optind],
sizeof((*cg_list)[(*cg_list_len) - 1]->name) - 1);
}
-
optind++;
}
return ret;
}
-static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[],
- int * const cg_list_len, int * const mode)
+static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * const cg_list_len,
+ int * const mode)
{
bool do_not_fill_controller = false;
bool first_cgroup_is_dummy = false;
int c;
/* Parse arguments. */
- while ((c = getopt_long(argc, argv, "r:hnvg:a", long_options,
- NULL)) > 0) {
+ while ((c = getopt_long(argc, argv, "r:hnvg:a", long_options, NULL)) > 0) {
switch (c) {
case 'h':
usage(0, argv[0]);
fill_controller = true;
if (strchr(optarg, ':') == NULL) {
first_cgroup_is_dummy = true;
- ret = parse_g_flag_no_colon(cg_list,
- cg_list_len, optarg);
+ ret = parse_g_flag_no_colon(cg_list, cg_list_len, optarg);
if (ret)
goto err;
} else {
- ret = parse_g_flag_with_colon(cg_list,
- cg_list_len, optarg);
+ ret = parse_g_flag_with_colon(cg_list, cg_list_len, optarg);
if (ret)
goto err;
}
exit(1);
}
- ret = parse_opt_args(argc, argv, cg_list, cg_list_len,
- first_cgroup_is_dummy);
+ ret = parse_opt_args(argc, argv, cg_list, cg_list_len, first_cgroup_is_dummy);
if (ret)
goto err;
return ret;
}
-static int get_cv_value(struct control_value * const cv,
- const char * const cg_name,
+static int get_cv_value(struct control_value * const cv, const char * const cg_name,
const char * const controller_name)
{
bool is_multiline = false;
void *handle, *tmp;
int ret;
- ret = cgroup_read_value_begin(controller_name, cg_name, cv->name,
- &handle, tmp_line, LL_MAX);
+ ret = cgroup_read_value_begin(controller_name, cg_name, cv->name, &handle, tmp_line,
+ LL_MAX);
if (ret == ECGEOF)
goto read_end;
if (ret != 0) {
*/
tmp_ret = cgroup_test_subsys_mounted(controller_name);
if (tmp_ret == 0) {
- err("cgget: cannot find controller '%s' ",
- controller_name);
- err("in group '%s'\n", cg_name);
+ err("cgget: cannot find controller '%s' in group '%s'\n",
+ controller_name, cg_name);
} else {
- err("variable file read failed %s\n",
- cgroup_strerror(ret));
+ err("variable file read failed %s\n", cgroup_strerror(ret));
}
}
cgroup_read_value_end(&handle);
if (ret == ECGEOF)
ret = 0;
-
end:
if (is_multiline == false && cv->multiline_value) {
free(cv->multiline_value);
return 0;
}
-static int fill_empty_controller(struct cgroup * const cg,
- struct cgroup_controller * const cgc)
+static int fill_empty_controller(struct cgroup * const cg, struct cgroup_controller * const cgc)
{
struct dirent *ctrl_dir = NULL;
bool found_mount = false;
pthread_rwlock_rdlock(&cg_mount_table_lock);
- for (i = 0; i < CG_CONTROLLER_MAX && cg_mount_table[i].name[0] != '\0';
- i++) {
+ for (i = 0; i < CG_CONTROLLER_MAX && cg_mount_table[i].name[0] != '\0'; i++) {
if (strlen(cgc->name) == strlen(cg_mount_table[i].name) &&
- strncmp(cgc->name, cg_mount_table[i].name,
- strlen(cgc->name)) == 0) {
+ strncmp(cgc->name, cg_mount_table[i].name, strlen(cgc->name)) == 0) {
found_mount = true;
break;
}
if (found_mount == false)
goto out;
- if (!cg_build_path_locked(NULL, path,
- cg_mount_table[i].name)) {
+ if (!cg_build_path_locked(NULL, path, cg_mount_table[i].name))
goto out;
- }
path_len = strlen(path);
strncat(path, cg->name, FILENAME_MAX - path_len - 1);
if (access(path, F_OK))
goto out;
- if (!cg_build_path_locked(cg->name, path,
- cg_mount_table[i].name))
+ if (!cg_build_path_locked(cg->name, path, cg_mount_table[i].name))
goto out;
dir = opendir(path);
cgc->values[cgc->index - 1]->dirty = false;
/*
- * previous versions of cgget indented the second and
- * all subsequent lines. continue that behavior
+ * previous versions of cgget indented the second
+ * and all subsequent lines. Continue that behavior
*/
if (strchr(cgc->values[cgc->index - 1]->value, '\n')) {
ret = indent_multiline_value(
closedir(dir);
pthread_rwlock_unlock(&cg_mount_table_lock);
+
return ret;
}
-static int get_controller_values(struct cgroup * const cg,
- struct cgroup_controller * const cgc)
+static int get_controller_values(struct cgroup * const cg, struct cgroup_controller * const cgc)
{
int ret = 0;
int i;
ret = cgroup_init();
if (ret) {
- err("%s: libcgroup initialization failed: %s\n", argv[0],
- cgroup_strerror(ret));
+ err("%s: libcgroup initialization failed: %s\n", argv[0], cgroup_strerror(ret));
goto err;
}