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
cea0552e
Commit
cea0552e
authored
Sep 11, 2013
by
Serge Hallyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgroup: address some style+safety issues
three issues raised by Christian Seiler: use pid_t, use snprintf, and use const. Signed-off-by:
Serge Hallyn
<
serge.hallyn@ubuntu.com
>
parent
9e60f51d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
9 deletions
+21
-9
cgroup.c
src/lxc/cgroup.c
+21
-9
No files found.
src/lxc/cgroup.c
View file @
cea0552e
...
...
@@ -542,11 +542,11 @@ struct cgroup_process_info *lxc_cgroup_process_info_get_self(struct cgroup_meta_
* name is c1. . We want to rename the cgroup directory to /sys/fs/cgroup/lxc/c1,
* and return the string /sys/fs/cgroup/lxc/c1.
*/
static
char
*
cgroup_rename_nsgroup
(
c
har
*
mountpath
,
const
char
*
oldname
,
in
t
pid
,
const
char
*
name
)
static
char
*
cgroup_rename_nsgroup
(
c
onst
char
*
mountpath
,
const
char
*
oldname
,
pid_
t
pid
,
const
char
*
name
)
{
char
*
dir
,
*
fulloldpath
;
char
*
newname
,
*
fullnewpath
;
int
len
;
int
len
,
newlen
,
ret
;
/*
* if cgroup is mounted at /cgroup and task is in cgroup /ab/, pid 2375 and
...
...
@@ -559,8 +559,11 @@ static char *cgroup_rename_nsgroup(char *mountpath, const char *oldname, int pid
dir
=
alloca
(
strlen
(
oldname
)
+
1
);
strcpy
(
dir
,
oldname
);
fulloldpath
=
alloca
(
strlen
(
oldname
)
+
strlen
(
mountpath
)
+
22
);
sprintf
(
fulloldpath
,
"%s/%s/%d"
,
mountpath
,
oldname
,
pid
);
len
=
strlen
(
oldname
)
+
strlen
(
mountpath
)
+
22
;
fulloldpath
=
alloca
(
len
);
ret
=
snprintf
(
fulloldpath
,
len
,
"%s/%s/%ld"
,
mountpath
,
oldname
,
(
unsigned
long
)
pid
);
if
(
ret
<
0
||
ret
>=
len
)
return
NULL
;
len
=
strlen
(
dir
)
+
strlen
(
name
)
+
2
;
newname
=
malloc
(
len
);
...
...
@@ -568,10 +571,19 @@ static char *cgroup_rename_nsgroup(char *mountpath, const char *oldname, int pid
SYSERROR
(
"Out of memory"
);
return
NULL
;
}
sprintf
(
newname
,
"%s/%s"
,
dir
,
name
);
ret
=
snprintf
(
newname
,
len
,
"%s/%s"
,
dir
,
name
);
if
(
ret
<
0
||
ret
>=
len
)
{
free
(
newname
);
return
NULL
;
}
fullnewpath
=
alloca
(
strlen
(
mountpath
)
+
len
+
2
);
sprintf
(
fullnewpath
,
"%s/%s"
,
mountpath
,
newname
);
newlen
=
strlen
(
mountpath
)
+
len
+
2
;
fullnewpath
=
alloca
(
newlen
);
ret
=
snprintf
(
fullnewpath
,
newlen
,
"%s/%s"
,
mountpath
,
newname
);
if
(
ret
<
0
||
ret
>=
newlen
)
{
free
(
newname
);
return
NULL
;
}
if
(
access
(
fullnewpath
,
F_OK
)
==
0
)
{
if
(
rmdir
(
fullnewpath
)
!=
0
)
{
...
...
@@ -592,7 +604,7 @@ static char *cgroup_rename_nsgroup(char *mountpath, const char *oldname, int pid
}
/* create a new cgroup */
extern
struct
cgroup_process_info
*
lxc_cgroup_create
(
const
char
*
name
,
const
char
*
path_pattern
,
struct
cgroup_meta_data
*
meta_data
,
const
char
*
sub_pattern
,
in
t
pid
)
extern
struct
cgroup_process_info
*
lxc_cgroup_create
(
const
char
*
name
,
const
char
*
path_pattern
,
struct
cgroup_meta_data
*
meta_data
,
const
char
*
sub_pattern
,
pid_
t
pid
)
{
char
**
cgroup_path_components
=
NULL
;
char
**
p
=
NULL
;
...
...
@@ -820,7 +832,7 @@ extern struct cgroup_process_info *lxc_cgroup_create(const char *name, const cha
* the cgroup name and record that.
*/
if
(
lxc_string_in_array
(
"ns"
,
(
const
char
**
)
info_ptr
->
hierarchy
->
subsystems
))
{
char
*
tmp
=
cgroup_rename_nsgroup
(
info_ptr
->
designated_mount_point
->
mount_point
,
char
*
tmp
=
cgroup_rename_nsgroup
(
(
const
char
*
)
info_ptr
->
designated_mount_point
->
mount_point
,
info_ptr
->
cgroup_path
,
pid
,
name
);
if
(
!
tmp
)
goto
out_initial_error
;
...
...
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