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
76ae4ba2
Unverified
Commit
76ae4ba2
authored
Feb 11, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgroups: convert to strnprintf()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
f13e60db
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
21 deletions
+31
-21
cgfsng.c
src/lxc/cgroups/cgfsng.c
+31
-21
No files found.
src/lxc/cgroups/cgfsng.c
View file @
76ae4ba2
...
@@ -266,8 +266,8 @@ static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
...
@@ -266,8 +266,8 @@ static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
if
(
!
is_set
(
i
,
bitarr
))
if
(
!
is_set
(
i
,
bitarr
))
continue
;
continue
;
ret
=
snprintf
(
numstr
,
sizeof
(
numstr
),
"%zu"
,
i
);
ret
=
s
tr
nprintf
(
numstr
,
sizeof
(
numstr
),
"%zu"
,
i
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
numstr
)
)
if
(
ret
<
0
)
return
NULL
;
return
NULL
;
ret
=
lxc_append_string
(
&
cpulist
,
numstr
);
ret
=
lxc_append_string
(
&
cpulist
,
numstr
);
...
@@ -1053,8 +1053,8 @@ __cgfsng_ops static void cgfsng_monitor_destroy(struct cgroup_ops *ops,
...
@@ -1053,8 +1053,8 @@ __cgfsng_ops static void cgfsng_monitor_destroy(struct cgroup_ops *ops,
}
}
conf
=
handler
->
conf
;
conf
=
handler
->
conf
;
len
=
snprintf
(
pidstr
,
sizeof
(
pidstr
),
"%d"
,
handler
->
monitor_pid
);
len
=
s
tr
nprintf
(
pidstr
,
sizeof
(
pidstr
),
"%d"
,
handler
->
monitor_pid
);
if
(
len
<
0
||
(
size_t
)
len
>=
sizeof
(
pidstr
)
)
if
(
len
<
0
)
return
;
return
;
for
(
int
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
for
(
int
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
...
@@ -1470,9 +1470,15 @@ __cgfsng_ops static bool cgfsng_monitor_enter(struct cgroup_ops *ops,
...
@@ -1470,9 +1470,15 @@ __cgfsng_ops static bool cgfsng_monitor_enter(struct cgroup_ops *ops,
if
(
!
handler
||
!
handler
->
conf
)
if
(
!
handler
||
!
handler
->
conf
)
return
ret_set_errno
(
false
,
EINVAL
);
return
ret_set_errno
(
false
,
EINVAL
);
monitor_len
=
snprintf
(
monitor
,
sizeof
(
monitor
),
"%d"
,
handler
->
monitor_pid
);
monitor_len
=
strnprintf
(
monitor
,
sizeof
(
monitor
),
"%d"
,
handler
->
monitor_pid
);
if
(
handler
->
transient_pid
>
0
)
if
(
monitor_len
<
0
)
transient_len
=
snprintf
(
transient
,
sizeof
(
transient
),
"%d"
,
handler
->
transient_pid
);
return
false
;
if
(
handler
->
transient_pid
>
0
)
{
transient_len
=
strnprintf
(
transient
,
sizeof
(
transient
),
"%d"
,
handler
->
transient_pid
);
if
(
transient_len
<
0
)
return
false
;
}
for
(
int
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
for
(
int
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
struct
hierarchy
*
h
=
ops
->
hierarchies
[
i
];
struct
hierarchy
*
h
=
ops
->
hierarchies
[
i
];
...
@@ -1525,7 +1531,9 @@ __cgfsng_ops static bool cgfsng_payload_enter(struct cgroup_ops *ops,
...
@@ -1525,7 +1531,9 @@ __cgfsng_ops static bool cgfsng_payload_enter(struct cgroup_ops *ops,
if
(
!
handler
||
!
handler
->
conf
)
if
(
!
handler
||
!
handler
->
conf
)
return
ret_set_errno
(
false
,
EINVAL
);
return
ret_set_errno
(
false
,
EINVAL
);
len
=
snprintf
(
pidstr
,
sizeof
(
pidstr
),
"%d"
,
handler
->
pid
);
len
=
strnprintf
(
pidstr
,
sizeof
(
pidstr
),
"%d"
,
handler
->
pid
);
if
(
len
<
0
)
return
false
;
for
(
int
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
for
(
int
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
struct
hierarchy
*
h
=
ops
->
hierarchies
[
i
];
struct
hierarchy
*
h
=
ops
->
hierarchies
[
i
];
...
@@ -2282,9 +2290,9 @@ static int cgroup_attach_leaf(const struct lxc_conf *conf, int unified_fd, pid_t
...
@@ -2282,9 +2290,9 @@ static int cgroup_attach_leaf(const struct lxc_conf *conf, int unified_fd, pid_t
if
(
ret
<
0
&&
errno
!=
EEXIST
)
if
(
ret
<
0
&&
errno
!=
EEXIST
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create leaf cgroup
\"
.lxc
\"
"
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create leaf cgroup
\"
.lxc
\"
"
);
pidstr_len
=
snprintf
(
pidstr
,
sizeof
(
pidstr
),
INT64_FMT
,
(
int64_t
)
pid
);
pidstr_len
=
s
tr
nprintf
(
pidstr
,
sizeof
(
pidstr
),
INT64_FMT
,
(
int64_t
)
pid
);
if
(
pidstr_len
<
0
||
(
size_t
)
pidstr_len
>=
sizeof
(
pidstr
)
)
if
(
pidstr_len
<
0
)
return
ret_errno
(
EIO
)
;
return
pidstr_len
;
ret
=
lxc_writeat
(
unified_fd
,
".lxc/cgroup.procs"
,
pidstr
,
pidstr_len
);
ret
=
lxc_writeat
(
unified_fd
,
".lxc/cgroup.procs"
,
pidstr
,
pidstr_len
);
if
(
ret
<
0
)
if
(
ret
<
0
)
...
@@ -2301,9 +2309,9 @@ static int cgroup_attach_leaf(const struct lxc_conf *conf, int unified_fd, pid_t
...
@@ -2301,9 +2309,9 @@ static int cgroup_attach_leaf(const struct lxc_conf *conf, int unified_fd, pid_t
char
attach_cgroup
[
STRLITERALLEN
(
".lxc-/cgroup.procs"
)
+
INTTYPE_TO_STRLEN
(
int
)
+
1
];
char
attach_cgroup
[
STRLITERALLEN
(
".lxc-/cgroup.procs"
)
+
INTTYPE_TO_STRLEN
(
int
)
+
1
];
char
*
slash
=
attach_cgroup
;
char
*
slash
=
attach_cgroup
;
ret
=
snprintf
(
attach_cgroup
,
sizeof
(
attach_cgroup
),
".lxc-%d/cgroup.procs"
,
idx
);
ret
=
s
tr
nprintf
(
attach_cgroup
,
sizeof
(
attach_cgroup
),
".lxc-%d/cgroup.procs"
,
idx
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
attach_cgroup
)
)
if
(
ret
<
0
)
return
ret
_errno
(
EIO
)
;
return
ret
;
/*
/*
* This shouldn't really happen but the compiler might complain
* This shouldn't really happen but the compiler might complain
...
@@ -2509,8 +2517,8 @@ __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops,
...
@@ -2509,8 +2517,8 @@ __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops,
if
(
!
ops
->
hierarchies
)
if
(
!
ops
->
hierarchies
)
return
true
;
return
true
;
len
=
snprintf
(
pidstr
,
sizeof
(
pidstr
),
"%d"
,
pid
);
len
=
s
tr
nprintf
(
pidstr
,
sizeof
(
pidstr
),
"%d"
,
pid
);
if
(
len
<
0
||
(
size_t
)
len
>=
sizeof
(
pidstr
)
)
if
(
len
<
0
)
return
false
;
return
false
;
for
(
int
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
for
(
int
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
...
@@ -2826,11 +2834,13 @@ static int convert_devpath(const char *invalue, char *dest)
...
@@ -2826,11 +2834,13 @@ static int convert_devpath(const char *invalue, char *dest)
if
(
ret
<
0
)
if
(
ret
<
0
)
return
-
1
;
return
-
1
;
ret
=
snprintf
(
dest
,
50
,
"%c %d:%d %s"
,
device
.
type
,
device
.
major
,
ret
=
strnprintf
(
dest
,
50
,
"%c %d:%d %s"
,
device
.
type
,
device
.
major
,
device
.
minor
,
device
.
access
);
device
.
minor
,
device
.
access
);
if
(
ret
<
0
||
ret
>=
50
)
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
ENAMETOOLONG
,
"Error on configuration value
\"
%c %d:%d %s
\"
(max 50 chars)"
,
return
log_error_errno
(
ret
,
-
ret
,
device
.
type
,
device
.
major
,
device
.
minor
,
device
.
access
);
"Error on configuration value
\"
%c %d:%d %s
\"
(max 50 chars)"
,
device
.
type
,
device
.
major
,
device
.
minor
,
device
.
access
);
return
0
;
return
0
;
}
}
...
...
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