lkml.org 
[lkml]   [2020]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 07/10] perf record: Support synthesizing cgroup events
On Mon, Feb 24, 2020 at 01:37:46PM +0900, Namhyung Kim wrote:

SNIP

> + d = opendir(path);
> + if (d == NULL) {
> + pr_debug("failed to open directory: %s\n", path);
> + return -1;
> + }
> +
> + while ((dent = readdir(d)) != NULL) {
> + if (dent->d_type != DT_DIR)
> + continue;
> + if (!strcmp(dent->d_name, ".") ||
> + !strcmp(dent->d_name, ".."))
> + continue;
> +
> + /* any sane path should be less than PATH_MAX */
> + if (strlen(path) + strlen(dent->d_name) + 1 >= PATH_MAX)
> + continue;
> +
> + if (path[pos - 1] != '/')
> + strcat(path, "/");
> + strcat(path, dent->d_name);
> +
> + ret = perf_event__walk_cgroup_tree(tool, event, path,
> + mount_len, process, machine);
> + if (ret < 0)
> + break;
> +
> + path[pos] = '\0';
> + }
> +
> + closedir(d);
> + return ret;
> +}
> +
> +int perf_event__synthesize_cgroups(struct perf_tool *tool,
> + perf_event__handler_t process,
> + struct machine *machine)
> +{
> + union perf_event event;
> + char cgrp_root[PATH_MAX];
> + size_t mount_len; /* length of mount point in the path */
> +
> + if (cgroupfs__mountpoint(cgrp_root, PATH_MAX, "perf_event") < 0) {
> + pr_debug("cannot find cgroup mount point\n");
> + return -1;
> + }
> +
> + mount_len = strlen(cgrp_root);
> + /* make sure the path starts with a slash (after mount point) */
> + strcat(cgrp_root, "/");

the code above checks on this and seems to add '/' if needed,
is this strcat necessary?

jirka

\
 
 \ /
  Last update: 2020-03-06 15:15    [W:0.124 / U:3.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site