* Written by Ivana Hutarova Varekova <varekova@redhat.com>
*/
+#include "tools-common.h"
+
#include <libcgroup.h>
#include <libcgroup-internal.h>
static void usage(int status, const char *program_name)
{
if (status != 0) {
- fprintf(stderr, "Wrong input parameters,");
- fprintf(stderr, " try %s -h' for more information.\n",
- program_name);
+ err("Wrong input parameters, ");
+ err("try %s -h' for more information.\n", program_name);
return;
}
- printf("Usage: %s [-h] [-s] [-b FILE] [-w FILE] [-f FILE] ",
- program_name);
- printf("[controller] [...]\n");
- printf("Generate the configuration file for given controllers\n");
- printf(" -b, --blacklist=FILE Set the blacklist");
- printf(" configuration file (default %s)\n", BLACKLIST_CONF);
- printf(" -f, --file=FILE Redirect the output");
- printf(" to output_file\n");
- printf(" -h, --help Display this help\n");
- printf(" -s, --silent Ignore all warnings\n");
- printf(" -t, --strict Don't show variables ");
- printf("which are not on the whitelist\n");
- printf(" -w, --whitelist=FILE Set the whitelist");
- printf(" configuration file (don't used by default)\n");
+
+ info("Usage: %s [-h] [-s] [-b FILE] [-w FILE] [-f FILE] ",
+ program_name);
+ info("[controller] [...]\n");
+ info("Generate the configuration file for given controllers\n");
+ info(" -b, --blacklist=FILE Set the blacklist");
+ info(" configuration file (default %s)\n", BLACKLIST_CONF);
+ info(" -f, --file=FILE Redirect the output ");
+ info("to output_file\n");
+ info(" -h, --help Display this help\n");
+ info(" -s, --silent Ignore all warnings\n");
+ info(" -t, --strict Don't show variables ");
+ info("which are not on the whitelist\n");
+ info(" -w, --whitelist=FILE Set the whitelist ");
+ info("configuration file (don't used by default)\n");
}
/* cache values from blacklist file to the list structure */
fw = fopen(filename, "r");
if (fw == NULL) {
- fprintf(stderr, "ERROR: Failed to open file %s: %s\n",
- filename, strerror(errno));
+ err("ERROR: Failed to open file %s: %s\n", filename,
+ strerror(errno));
*p_list = NULL;
return 1;
}
new = (struct black_list_type *)
malloc(sizeof(struct black_list_type));
if (new == NULL) {
- fprintf(stderr, "ERROR: Memory allocation problem ");
- fprintf(stderr, "(%s)\n", strerror(errno));
+ err("ERROR: Memory allocation problem (%s)\n",
+ strerror(errno));
ret = 1;
goto err;
}
new->name = strdup(name);
if (new->name == NULL) {
- fprintf(stderr, "ERROR: Memory allocation problem ");
- fprintf(stderr, "(%s)\n", strerror(errno));
+ err("ERROR: Memory allocation problem (%s)\n",
+ strerror(errno));
ret = 1;
free(new);
goto err;
/* get the directory statistic */
ret = stat(path, &sba);
if (ret) {
- fprintf(stderr, "ERROR: can't read statistics about %s\n",
- path);
+ err("ERROR: can't read statistics about %s\n", path);
return -1;
}
ret = cgroup_build_tasks_procs_path(tasks_path, sizeof(tasks_path),
cg_name, ctrl_name);
if (ret) {
- fprintf(stderr, "ERROR: can't build tasks/procs path: %d\n",
- ret);
+ err("ERROR: can't build tasks/procs path: %d\n", ret);
return -1;
}
ret = stat(tasks_path, &sbt);
if (ret) {
- fprintf(stderr, "ERROR: can't read statistics about %s\n",
- tasks_path);
+ err("ERROR: can't read statistics about %s\n", tasks_path);
return -1;
}
/* find out the user and group name */
pw = getpwuid(sba.st_uid);
if (pw == NULL) {
- fprintf(stderr, "ERROR: can't get %d user name\n",
- sba.st_uid);
+ err("ERROR: can't get %d user name\n", sba.st_uid);
return -1;
}
gr = getgrgid(sba.st_gid);
if (gr == NULL) {
- fprintf(stderr, "ERROR: can't get %d group name\n",
- sba.st_gid);
+ err("ERROR: can't get %d group name\n", sba.st_gid);
return -1;
}
/* find out the user and group name */
pw = getpwuid(sbt.st_uid);
if (pw == NULL) {
- fprintf(stderr, "ERROR: can't get %d user name\n",
- sbt.st_uid);
+ err("ERROR: can't get %d user name\n", sbt.st_uid);
return -1;
}
gr = getgrgid(sbt.st_gid);
if (gr == NULL) {
- fprintf(stderr, "ERROR: can't get %d group name\n",
- sbt.st_gid);
+ err("ERROR: can't get %d group name\n", sbt.st_gid);
return -1;
}
group_controller = cgroup_get_controller(group, controller[i]);
if (group_controller == NULL) {
- printf("cannot find controller '%s' in group '%s'\n",
- controller[i], group->name);
+ info("cannot find controller '%s' in group '%s'\n",
+ controller[i], group->name);
i++;
ret = -1;
continue;
* used write an warning
*/
if ((!wl) && !(flags & FL_SILENT) && (first)) {
- fprintf(stderr, "WARNING: variable %s is ",
- name);
- fprintf(stderr, "neither blacklisted nor ");
- fprintf(stderr, "whitelisted\n");
+ err("WARNING: variable %s is neither ", name);
+ err("blacklisted nor whitelisted\n");
}
output_name = name;
/* variable can not be read */
if (ret != 0) {
ret = 0;
- fprintf(stderr, "ERROR: Value of ");
- fprintf(stderr, "variable %s can be read\n",
- name);
+ err("ERROR: Value of variable %s can be read\n",
+ name);
goto err;
}
fprintf(output_f, "\t\t%s=\"%s\";\n", output_name, value);
/* start to grab data about the new group */
group = cgroup_new_cgroup(cgroup_name);
if (group == NULL) {
- printf("cannot create group '%s'\n",
+ info("cannot create group '%s'\n",
cgroup_name);
ret = ECGFAIL;
goto err;
ret = cgroup_get_cgroup(group);
if (ret != 0) {
- printf("cannot read group '%s': %s\n",
+ info("cannot read group '%s': %s\n",
cgroup_name, cgroup_strerror(ret));
goto err;
}
if (!(flags & FL_LIST)) {
if (show_mountpoints(name)) {
/* the controller is not mounted */
- if ((flags & FL_SILENT) == 0) {
- fprintf(stderr, "ERROR: %s hierarchy ", name);
- fprintf(stderr, "not mounted\n");
- }
+ if ((flags & FL_SILENT) == 0)
+ err("ERROR: %s hierarchy not mounted\n", name);
}
return;
}
if (show_mountpoints(name)) {
/* the controller is not mounted */
if ((flags & FL_SILENT) == 0) {
- fprintf(stderr, "ERROR: %s ", name);
- fprintf(stderr, "hierarchy not ");
- fprintf(stderr, "mounted\n");
+ err("ERROR: %s hierarchy not mounted\n",
+ name);
}
break;
}
if (ret != ECGEOF) {
if ((flags & FL_SILENT) != 0) {
- fprintf(stderr,
- "E: in get next controller %s\n",
- cgroup_strerror(ret));
+ err("E: in get next controller %s\n",
+ cgroup_strerror(ret));
}
final_ret = ret;
}
if (ret != ECGEOF) {
if ((flags & FL_SILENT) != 0) {
- fprintf(stderr,
- "E: in get next controller %s\n",
- cgroup_strerror(ret));
+ err("E: in get next controller %s\n",
+ cgroup_strerror(ret));
}
final_ret = ret;
}
flags |= FL_OUTPUT;
output_f = fopen(optarg, "w");
if (output_f == NULL) {
- fprintf(stderr, "%s: Failed to open file %s\n",
- argv[0], optarg);
+ err("%s: Failed to open file %s\n", argv[0],
+ optarg);
return ECGOTHER;
}
break;
c_number++;
optind++;
if (optind == CG_CONTROLLER_MAX-1) {
- fprintf(stderr, "too many parameters\n");
+ err("too many parameters\n");
break;
}
}