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
1a4b9d44
Unverified
Commit
1a4b9d44
authored
Dec 07, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgroups/cgfsng: rework cgroup attach
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
75bb976e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
cgfsng.c
src/lxc/cgroups/cgfsng.c
+15
-13
No files found.
src/lxc/cgroups/cgfsng.c
View file @
1a4b9d44
...
@@ -2176,39 +2176,41 @@ static inline char *build_full_cgpath_from_monitorpath(struct hierarchy *h,
...
@@ -2176,39 +2176,41 @@ static inline char *build_full_cgpath_from_monitorpath(struct hierarchy *h,
static
int
cgroup_attach_leaf
(
int
unified_fd
,
int64_t
pid
)
static
int
cgroup_attach_leaf
(
int
unified_fd
,
int64_t
pid
)
{
{
int
idx
=
0
;
int
idx
=
1
;
int
ret
;
int
ret
;
char
pidstr
[
INTTYPE_TO_STRLEN
(
int64_t
)
+
1
];
char
pidstr
[
INTTYPE_TO_STRLEN
(
int64_t
)
+
1
];
char
attach_cgroup
[
STRLITERALLEN
(
"lxc-1000/cgroup.procs"
)
+
1
];
size_t
pidstr_len
;
size_t
pidstr_len
;
/* Create leaf cgroup. */
ret
=
mkdirat
(
unified_fd
,
"lxc"
,
0755
);
if
(
ret
<
0
&&
errno
!=
EEXIST
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to create leaf cgroup
\"
lxc
\"
"
);
pidstr_len
=
sprintf
(
pidstr
,
INT64_FMT
,
pid
);
pidstr_len
=
sprintf
(
pidstr
,
INT64_FMT
,
pid
);
ret
=
lxc_writeat
(
unified_fd
,
"cgroup.procs"
,
pidstr
,
pidstr_len
);
ret
=
lxc_writeat
(
unified_fd
,
"lxc/cgroup.procs"
,
pidstr
,
pidstr_len
);
if
(
ret
<
0
)
ret
=
lxc_writeat
(
unified_fd
,
"cgroup.procs"
,
pidstr
,
pidstr_len
);
if
(
ret
==
0
)
if
(
ret
==
0
)
return
0
;
return
0
;
/* this is a non-leaf node */
/* this is a non-leaf node */
if
(
errno
!=
EBUSY
)
if
(
errno
!=
EBUSY
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to attach to unified cgroup"
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to attach to unified cgroup"
);
do
{
do
{
char
*
slash
;
char
*
slash
;
char
attach_cgroup
[
STRLITERALLEN
(
"lxc-1000/cgroup.procs"
)
+
1
];
if
(
idx
)
ret
=
snprintf
(
attach_cgroup
,
sizeof
(
attach_cgroup
),
"lxc-%d/cgroup.procs"
,
idx
);
else
ret
=
snprintf
(
attach_cgroup
,
sizeof
(
attach_cgroup
),
"lxc/cgroup.procs"
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
attach_cgroup
))
return
-
1
;
sprintf
(
attach_cgroup
,
"lxc-%d/cgroup.procs"
,
idx
);
slash
=
&
attach_cgroup
[
ret
]
-
STRLITERALLEN
(
"/cgroup.procs"
);
slash
=
&
attach_cgroup
[
ret
]
-
STRLITERALLEN
(
"/cgroup.procs"
);
*
slash
=
'\0'
;
*
slash
=
'\0'
;
ret
=
mkdirat
(
unified_fd
,
attach_cgroup
,
0755
);
ret
=
mkdirat
(
unified_fd
,
attach_cgroup
,
0755
);
if
(
ret
<
0
&&
errno
!=
EEXIST
)
if
(
ret
<
0
&&
errno
!=
EEXIST
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to create cgroup %s"
,
attach_cgroup
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to create cgroup %s"
,
attach_cgroup
);
*
slash
=
'/'
;
*
slash
=
'/'
;
ret
=
lxc_writeat
(
unified_fd
,
attach_cgroup
,
pidstr
,
pidstr_len
);
ret
=
lxc_writeat
(
unified_fd
,
attach_cgroup
,
pidstr
,
pidstr_len
);
if
(
ret
==
0
)
if
(
ret
==
0
)
return
0
;
return
0
;
...
@@ -2220,7 +2222,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid)
...
@@ -2220,7 +2222,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid)
idx
++
;
idx
++
;
}
while
(
idx
<
1000
);
}
while
(
idx
<
1000
);
return
-
1
;
return
log_error_errno
(
-
1
,
errno
,
"Failed to attach to unified cgroup"
)
;
}
}
int
cgroup_attach
(
const
char
*
name
,
const
char
*
lxcpath
,
int64_t
pid
)
int
cgroup_attach
(
const
char
*
name
,
const
char
*
lxcpath
,
int64_t
pid
)
...
...
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