Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
522bbc79
Unverified
Commit
522bbc79
authored
Feb 20, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgroups: simplify current cgroup retrieval on pure unified cgroup layouts
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
c41ab8e4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
26 deletions
+24
-26
cgfsng.c
src/lxc/cgroups/cgfsng.c
+24
-26
No files found.
src/lxc/cgroups/cgfsng.c
View file @
522bbc79
...
...
@@ -3417,41 +3417,39 @@ static int cg_hybrid_init(struct cgroup_ops *ops, bool relative, bool unprivileg
}
/* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */
static
char
*
c
g_unified_get_current_cgroup
(
bool
relative
)
static
char
*
c
urrent_cgroup_unified
(
bool
relative
)
{
__do_free
char
*
basecginfo
=
NULL
,
*
copy
=
NULL
;
char
*
base_cgroup
;
__do_free
char
*
cgroup_info
=
NULL
;
char
*
it
;
if
(
!
relative
&&
(
geteuid
()
==
0
))
basecg
info
=
read_file_at
(
-
EBADF
,
"/proc/1/cgroup"
,
PROTECT_OPEN
,
0
);
cgroup_
info
=
read_file_at
(
-
EBADF
,
"/proc/1/cgroup"
,
PROTECT_OPEN
,
0
);
else
basecg
info
=
read_file_at
(
-
EBADF
,
"/proc/self/cgroup"
,
PROTECT_OPEN
,
0
);
if
(
!
basecg
info
)
cgroup_
info
=
read_file_at
(
-
EBADF
,
"/proc/self/cgroup"
,
PROTECT_OPEN
,
0
);
if
(
!
cgroup_
info
)
return
NULL
;
base_cgroup
=
strstr
(
basecginfo
,
"0::/"
);
if
(
!
base_cgroup
)
return
NULL
;
lxc_iterate_parts
(
it
,
cgroup_info
,
"
\n
"
)
{
if
(
*
it
!=
'0'
)
continue
;
base_cgroup
=
base_cgroup
+
3
;
copy
=
copy_to_eol
(
base_cgroup
);
if
(
!
copy
)
return
NULL
;
trim
(
copy
);
it
+=
STRLITERALLEN
(
"0::"
);
if
(
!
relative
)
{
base_cgroup
=
prune_init_scope
(
copy
);
if
(
!
base_cgroup
)
return
NULL
;
}
else
{
base_cgroup
=
copy
;
}
if
(
!
abspath
(
it
))
return
log_error
(
NULL
,
"Corrupt cgroup info for %s process"
,
relative
?
"current"
:
"init"
);
if
(
abspath
(
base_cgroup
))
base_cgroup
=
deabs
(
base_cgroup
);
/* remove init.scope */
if
(
!
relative
)
it
=
prune_init_scope
(
it
);
/* create a relative path */
it
=
deabs
(
it
);
return
strdup
(
it
);
}
/* We're allowing base_cgroup to be "". */
return
strdup
(
base_cgroup
);
return
log_error
(
NULL
,
"Failed to retrieve current cgroup for %s process"
,
relative
?
"current"
:
"init"
);
}
static
int
cg_unified_init
(
struct
cgroup_ops
*
ops
,
bool
relative
,
...
...
@@ -3460,7 +3458,7 @@ static int cg_unified_init(struct cgroup_ops *ops, bool relative,
__do_free
char
*
base_cgroup
=
NULL
;
int
ret
;
base_cgroup
=
c
g_unified_get_current_cgroup
(
relative
);
base_cgroup
=
c
urrent_cgroup_unified
(
relative
);
if
(
!
base_cgroup
)
return
ret_errno
(
EINVAL
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment