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
ed6988d9
Unverified
Commit
ed6988d9
authored
Feb 11, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log: convert to strnprintf()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
efcfb360
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
7 deletions
+11
-7
log.c
src/lxc/log.c
+11
-7
No files found.
src/lxc/log.c
View file @
ed6988d9
...
...
@@ -280,19 +280,19 @@ static int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespe
seconds
=
(
time
->
tv_sec
-
d_in_s
-
h_in_s
-
(
minutes
*
60
));
/* Make string from nanoseconds. */
ret
=
snprintf
(
nanosec
,
sizeof
(
nanosec
),
"%"
PRId64
,
(
int64_t
)
time
->
tv_nsec
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
nanosec
)
)
ret
=
s
tr
nprintf
(
nanosec
,
sizeof
(
nanosec
),
"%"
PRId64
,
(
int64_t
)
time
->
tv_nsec
);
if
(
ret
<
0
)
return
ret_errno
(
EIO
);
/*
* Create final timestamp for the log and shorten nanoseconds to 3
* digit precision.
*/
ret
=
snprintf
(
buf
,
bufsize
,
ret
=
s
tr
nprintf
(
buf
,
bufsize
,
"%"
PRId64
"%02"
PRId64
"%02"
PRId64
"%02"
PRId64
"%02"
PRId64
"%02"
PRId64
".%.3s"
,
year
,
month
,
day
,
hours
,
minutes
,
seconds
,
nanosec
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
bufsize
)
if
(
ret
<
0
)
return
ret_errno
(
EIO
);
return
0
;
...
...
@@ -346,6 +346,10 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
if
(
ret
)
return
ret
;
/*
* We allow truncation here which is why we use snprintf() directly
* instead of strnprintf().
*/
n
=
snprintf
(
buffer
,
sizeof
(
buffer
),
"%s%s%s %s %-8s %s - %s:%s:%d - "
,
log_prefix
,
...
...
@@ -572,10 +576,10 @@ static char *build_log_path(const char *name, const char *lxcpath)
return
ret_set_errno
(
NULL
,
ENOMEM
);
if
(
use_dir
)
ret
=
snprintf
(
p
,
len
,
"%s/%s/%s.log"
,
lxcpath
,
name
,
name
);
ret
=
s
tr
nprintf
(
p
,
len
,
"%s/%s/%s.log"
,
lxcpath
,
name
,
name
);
else
ret
=
snprintf
(
p
,
len
,
"%s/%s.log"
,
lxcpath
,
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
ret
=
s
tr
nprintf
(
p
,
len
,
"%s/%s.log"
,
lxcpath
,
name
);
if
(
ret
<
0
)
return
ret_set_errno
(
NULL
,
EIO
);
return
move_ptr
(
p
);
...
...
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