[lxc-devel] [lxc/master] fix thread-safe issue (localtime => localtime_r)
2xsec on Github
lxc-bot at linuxcontainers.org
Mon Aug 13 07:55:49 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 349 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180813/2c505724/attachment.bin>
-------------- next part --------------
From f9572e9f18ef7fbaa9116937f92e40f7bb2fd3e8 Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Mon, 13 Aug 2018 16:52:24 +0900
Subject: [PATCH 1/2] macro: remove duplicated define
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/macro.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/src/lxc/macro.h b/src/lxc/macro.h
index 3ef0ab4c2..75c63c7c1 100644
--- a/src/lxc/macro.h
+++ b/src/lxc/macro.h
@@ -43,10 +43,6 @@
#define PR_CAPBSET_DROP 24
#endif
-#ifndef LO_FLAGS_AUTOCLEAR
-#define LO_FLAGS_AUTOCLEAR 4
-#endif
-
#ifndef CAP_SETUID
#define CAP_SETUID 7
#endif
From df05fa0f04ff63429b3014f98415498944c2b4e0 Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Mon, 13 Aug 2018 16:53:30 +0900
Subject: [PATCH 2/2] fix thread safe issue(localtime => localtime_r)
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/log.c | 1 -
src/lxc/lxccontainer.c | 27 +++++++++++++++------------
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/src/lxc/log.c b/src/lxc/log.c
index 781295e5c..d944273b6 100644
--- a/src/lxc/log.c
+++ b/src/lxc/log.c
@@ -33,7 +33,6 @@
#include <sys/stat.h>
#include <string.h>
#include <pthread.h>
-#include <time.h>
#include <syslog.h>
#include <stdio.h>
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 1b9c0fb6d..2e8674723 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -4121,15 +4121,19 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
{
int i, flags, ret;
+ time_t timer;
+ struct tm tm_info;
struct lxc_container *c2;
char snappath[MAXPATHLEN], newname[20];
+ char buffer[25];
+ FILE *f;
if (!c || !lxcapi_is_defined(c))
return -1;
if (!storage_can_backup(c->lxc_conf)) {
- ERROR("%s's backing store cannot be backed up.", c->name);
- ERROR("Your container must use another backing store type.");
+ ERROR("%s's backing store cannot be backed up", c->name);
+ ERROR("Your container must use another backing store type");
return -1;
}
@@ -4154,31 +4158,30 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_KEEPMACADDR | LXC_CLONE_KEEPNAME |
LXC_CLONE_KEEPBDEVTYPE | LXC_CLONE_MAYBE_SNAPSHOT;
if (storage_is_dir(c->lxc_conf)) {
- ERROR("Snapshot of directory-backed container requested.");
+ ERROR("Snapshot of directory-backed container requested");
ERROR("Making a copy-clone. If you do want snapshots, then");
ERROR("please create overlay clone first, snapshot that");
- ERROR("and keep the original container pristine.");
+ ERROR("and keep the original container pristine");
flags &= ~LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT;
}
c2 = do_lxcapi_clone(c, newname, snappath, flags, NULL, NULL, 0, NULL);
if (!c2) {
- ERROR("clone of %s:%s failed", c->config_path, c->name);
+ ERROR("Failed to clone of %s:%s", c->config_path, c->name);
return -1;
}
lxc_container_put(c2);
/* Now write down the creation time. */
- time_t timer;
- char buffer[25];
- struct tm* tm_info;
- FILE *f;
-
time(&timer);
- tm_info = localtime(&timer);
- strftime(buffer, 25, "%Y:%m:%d %H:%M:%S", tm_info);
+ if (!localtime_r(&timer, &tm_info)) {
+ ERROR("Failed to get localtime");
+ return -1;
+ }
+
+ strftime(buffer, 25, "%Y:%m:%d %H:%M:%S", &tm_info);
char *dfnam = alloca(strlen(snappath) + strlen(newname) + 5);
sprintf(dfnam, "%s/%s/ts", snappath, newname);
More information about the lxc-devel
mailing list