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
b5e39501
Commit
b5e39501
authored
Nov 24, 2016
by
Stéphane Graber
Committed by
GitHub
Nov 24, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1318 from brauner/2016-11-25/fix_logging_race
log: use thread-safe localtime_r()
parents
81f466d0
b4c42474
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
log.c
src/lxc/log.c
+7
-5
No files found.
src/lxc/log.c
View file @
b5e39501
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
* License along with this library; if not, write to the Free Software
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#define _GNU_SOURCE
#include <assert.h>
#include <assert.h>
#include <stdio.h>
#include <stdio.h>
#include <errno.h>
#include <errno.h>
...
@@ -31,8 +33,6 @@
...
@@ -31,8 +33,6 @@
#include <pthread.h>
#include <pthread.h>
#include <time.h>
#include <time.h>
#define __USE_GNU
/* for *_CLOEXEC */
#include <syslog.h>
#include <syslog.h>
#include <stdio.h>
#include <stdio.h>
...
@@ -139,7 +139,7 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
...
@@ -139,7 +139,7 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
{
{
char
date
[
LXC_LOG_DATEFOMAT_SIZE
]
=
"20150427012246"
;
char
date
[
LXC_LOG_DATEFOMAT_SIZE
]
=
"20150427012246"
;
char
buffer
[
LXC_LOG_BUFFER_SIZE
];
char
buffer
[
LXC_LOG_BUFFER_SIZE
];
const
struct
tm
*
t
;
struct
tm
newtime
;
int
n
;
int
n
;
int
ms
;
int
ms
;
int
fd_to_use
=
-
1
;
int
fd_to_use
=
-
1
;
...
@@ -155,8 +155,10 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
...
@@ -155,8 +155,10 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
if
(
fd_to_use
==
-
1
)
if
(
fd_to_use
==
-
1
)
return
0
;
return
0
;
t
=
localtime
(
&
event
->
timestamp
.
tv_sec
);
if
(
!
localtime_r
(
&
event
->
timestamp
.
tv_sec
,
&
newtime
))
strftime
(
date
,
sizeof
(
date
),
"%Y%m%d%H%M%S"
,
t
);
return
0
;
strftime
(
date
,
sizeof
(
date
),
"%Y%m%d%H%M%S"
,
&
newtime
);
ms
=
event
->
timestamp
.
tv_usec
/
1000
;
ms
=
event
->
timestamp
.
tv_usec
/
1000
;
n
=
snprintf
(
buffer
,
sizeof
(
buffer
),
n
=
snprintf
(
buffer
,
sizeof
(
buffer
),
"%15s%s%s %10s.%03d %-8s %s - %s:%s:%d - "
,
"%15s%s%s %10s.%03d %-8s %s - %s:%s:%d - "
,
...
...
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