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
6137f654
Unverified
Commit
6137f654
authored
Feb 11, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor: convert to strnprintf()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
272707bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
14 deletions
+10
-14
monitor.c
src/lxc/monitor.c
+10
-14
No files found.
src/lxc/monitor.c
View file @
6137f654
...
@@ -50,8 +50,8 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
...
@@ -50,8 +50,8 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
return
-
1
;
return
-
1
;
if
(
do_mkdirp
)
{
if
(
do_mkdirp
)
{
ret
=
snprintf
(
fifo_path
,
fifo_path_sz
,
"%s/lxc/%s"
,
rundir
,
lxcpath
);
ret
=
s
tr
nprintf
(
fifo_path
,
fifo_path_sz
,
"%s/lxc/%s"
,
rundir
,
lxcpath
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
fifo_path_sz
)
{
if
(
ret
<
0
)
{
ERROR
(
"rundir/lxcpath (%s/%s) too long for monitor fifo"
,
rundir
,
lxcpath
);
ERROR
(
"rundir/lxcpath (%s/%s) too long for monitor fifo"
,
rundir
,
lxcpath
);
free
(
rundir
);
free
(
rundir
);
return
-
1
;
return
-
1
;
...
@@ -63,8 +63,8 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
...
@@ -63,8 +63,8 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
return
ret
;
return
ret
;
}
}
}
}
ret
=
snprintf
(
fifo_path
,
fifo_path_sz
,
"%s/lxc/%s/monitor-fifo"
,
rundir
,
lxcpath
);
ret
=
s
tr
nprintf
(
fifo_path
,
fifo_path_sz
,
"%s/lxc/%s/monitor-fifo"
,
rundir
,
lxcpath
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
fifo_path_sz
)
{
if
(
ret
<
0
)
{
ERROR
(
"rundir/lxcpath (%s/%s) too long for monitor fifo"
,
rundir
,
lxcpath
);
ERROR
(
"rundir/lxcpath (%s/%s) too long for monitor fifo"
,
rundir
,
lxcpath
);
free
(
rundir
);
free
(
rundir
);
return
-
1
;
return
-
1
;
...
@@ -163,27 +163,23 @@ int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr)
...
@@ -163,27 +163,23 @@ int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr)
/* strlen("lxc/") + strlen("/monitor-sock") + 1 = 18 */
/* strlen("lxc/") + strlen("/monitor-sock") + 1 = 18 */
len
=
strlen
(
lxcpath
)
+
18
;
len
=
strlen
(
lxcpath
)
+
18
;
path
=
must_realloc
(
NULL
,
len
);
path
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
path
,
len
,
"lxc/%s/monitor-sock"
,
lxcpath
);
ret
=
s
tr
nprintf
(
path
,
len
,
"lxc/%s/monitor-sock"
,
lxcpath
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to create name for monitor socket"
);
ERROR
(
"Failed to create name for monitor socket"
);
return
-
1
;
return
-
1
;
}
}
/* Note: snprintf() will \0-terminate addr->sun_path on the 106th byte
/* Note: s
tr
nprintf() will \0-terminate addr->sun_path on the 106th byte
* and so the abstract socket name has 105 "meaningful" characters. This
* and so the abstract socket name has 105 "meaningful" characters. This
* is absolutely intentional. For further info read the comment for this
* is absolutely intentional. For further info read the comment for this
* function above!
* function above!
*/
*/
len
=
sizeof
(
addr
->
sun_path
)
-
1
;
len
=
sizeof
(
addr
->
sun_path
)
-
1
;
hash
=
fnv_64a_buf
(
path
,
ret
,
FNV1A_64_INIT
);
hash
=
fnv_64a_buf
(
path
,
ret
,
FNV1A_64_INIT
);
ret
=
snprintf
(
addr
->
sun_path
,
len
,
"@lxc/%016"
PRIx64
"/%s"
,
hash
,
lxcpath
);
ret
=
s
tr
nprintf
(
addr
->
sun_path
,
len
,
"@lxc/%016"
PRIx64
"/%s"
,
hash
,
lxcpath
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to create hashed name for monitor socket"
);
ERROR
(
"Failed to create hashed name for monitor socket"
);
goto
on_error
;
goto
on_error
;
}
else
if
((
size_t
)
ret
>=
len
)
{
errno
=
ENAMETOOLONG
;
SYSERROR
(
"The name of monitor socket too long (%d bytes)"
,
ret
);
goto
on_error
;
}
}
/* replace @ with \0 */
/* replace @ with \0 */
...
@@ -353,8 +349,8 @@ int lxc_monitord_spawn(const char *lxcpath)
...
@@ -353,8 +349,8 @@ int lxc_monitord_spawn(const char *lxcpath)
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
ret
=
snprintf
(
pipefd_str
,
sizeof
(
pipefd_str
),
"%d"
,
pipefd
[
1
]);
ret
=
s
tr
nprintf
(
pipefd_str
,
sizeof
(
pipefd_str
),
"%d"
,
pipefd
[
1
]);
if
(
ret
<
0
||
ret
>=
sizeof
(
pipefd_str
)
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to create pid argument to pass to monitord"
);
ERROR
(
"Failed to create pid argument to pass to monitord"
);
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
...
...
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