cgroup-show: drop unnecessary call of cg_mangle_path()

As the caller already dropped controller part.
This commit is contained in:
Yu Watanabe
2025-08-30 09:52:14 +09:00
parent a8156588fa
commit 6a8ab5f062
4 changed files with 6 additions and 33 deletions

View File

@@ -687,25 +687,6 @@ int cg_split_spec(const char *spec, char **ret_controller, char **ret_path) {
return 0;
}
int cg_mangle_path(const char *path, char **ret) {
_cleanup_free_ char *p = NULL;
int r;
assert(path);
assert(ret);
/* First, check if it already is a filesystem path */
if (path_startswith(path, "/sys/fs/cgroup"))
return path_simplify_alloc(path, ret);
/* Otherwise, treat it as cg spec */
r = cg_split_spec(path, /* ret_controller = */ NULL, &p);
if (r < 0)
return r;
return cg_get_path(p, /* suffix = */ NULL, ret);
}
int cg_get_root_path(char **ret_path) {
char *p, *e;
int r;

View File

@@ -162,7 +162,6 @@ int cg_kill_kernel_sigkill(const char *path);
int cg_kill_recursive(const char *path, int sig, CGroupFlags flags, Set *killed_pids, cg_kill_log_func_t log_kill, void *userdata);
int cg_split_spec(const char *spec, char **ret_controller, char **ret_path);
int cg_mangle_path(const char *path, char **ret);
int cg_get_path(const char *path, const char *suffix, char **ret);

View File

@@ -244,7 +244,7 @@ static int run(int argc, char *argv[]) {
printf("Unit %s (%s):\n", unit_name, cgroup);
fflush(stdout);
q = show_cgroup_by_path(cgroup, NULL, 0, arg_output_flags);
q = show_cgroup(cgroup, NULL, 0, arg_output_flags);
} else if (path_startswith(*name, "/sys/fs/cgroup")) {

View File

@@ -87,16 +87,13 @@ static int show_cgroup_one_by_path(
_cleanup_free_ pid_t *pids = NULL;
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
size_t n = 0;
char *fn;
int r;
r = cg_mangle_path(path, &p);
if (r < 0)
return r;
assert(path);
fn = strjoina(p, "/cgroup.procs");
fn = strjoina(path, "/cgroup.procs");
f = fopen(fn, "re");
if (!f)
return -errno;
@@ -225,7 +222,7 @@ int show_cgroup_by_path(
size_t n_columns,
OutputFlags flags) {
_cleanup_free_ char *fn = NULL, *p1 = NULL, *last = NULL, *p2 = NULL;
_cleanup_free_ char *p1 = NULL, *last = NULL, *p2 = NULL;
_cleanup_closedir_ DIR *d = NULL;
bool shown_pids = false;
char *gn = NULL;
@@ -238,18 +235,14 @@ int show_cgroup_by_path(
prefix = strempty(prefix);
r = cg_mangle_path(path, &fn);
if (r < 0)
return r;
d = opendir(fn);
d = opendir(path);
if (!d)
return -errno;
while ((r = cg_read_subgroup(d, &gn)) > 0) {
_cleanup_free_ char *k = NULL;
k = path_join(fn, gn);
k = path_join(path, gn);
free(gn);
if (!k)
return -ENOMEM;