Fix the problem described in https://bugzilla.redhat.com/show_bug.cgi?id=667968
cgclassify accepts invalid non-numeric arguments, testcase:
$ cgclassify -g cpu:/ xxx; echo $?
0
Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
int flag = 0;
struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
int c;
+ char *endptr;
if (argc < 2) {
}
for (i = optind; i < argc; i++) {
- pid = (uid_t) atoi(argv[i]);
+ pid = (uid_t) strtol(argv[i], &endptr, 10);
+ if (endptr[0] != '\0') {
+ /* the input argument was not a number */
+ fprintf(stderr, "Error: %s is not valid pid.\n",
+ argv[i]);
+ exit_code = 2;
+ continue;
+ }
if (flag)
ret = cgroup_register_unchanged_process(pid, flag);