lxc/0115-fix-compile-error-on-ubuntu.patch
2019-12-25 15:57:42 +08:00

372 lines
9.1 KiB
Diff

From b1f801be29895369ae393b334005ad3bf87e371f Mon Sep 17 00:00:00 2001
From: liuhao <liuhao27@huawei.com>
Date: Thu, 11 Jul 2019 17:42:00 +0800
Subject: [PATCH 115/131] fix compile error on ubuntu
fix compile error on ubuntu
Signed-off-by: liuhao <liuhao27@huawei.com>
Signed-off-by: LiFeng <lifeng68@huawei.com>
---
configure.ac | 1 -
src/lxc/Makefile.am | 10 ++++-
src/lxc/conf.c | 2 +-
src/lxc/confile.c | 2 +-
src/lxc/isulad_utils.c | 87 ++++++++++++++++++++++++++++++++++++++++++
src/lxc/isulad_utils.h | 13 +++++++
src/lxc/path.c | 2 +-
src/lxc/utils.c | 82 +--------------------------------------
src/lxc/utils.h | 6 +--
9 files changed, 113 insertions(+), 92 deletions(-)
create mode 100644 src/lxc/isulad_utils.c
create mode 100644 src/lxc/isulad_utils.h
diff --git a/configure.ac b/configure.ac
index 5963fab1..dc85f746 100644
--- a/configure.ac
+++ b/configure.ac
@@ -706,7 +706,6 @@ AX_CHECK_LINK_FLAG([-z relro], [LDFLAGS="$LDFLAGS -z relro"],,[])
AX_CHECK_LINK_FLAG([-z now], [LDFLAGS="$LDFLAGS -z now"],,[])
AX_CHECK_LINK_FLAG([-z noexecstack], [LDFLAGS="$LDFLAGS -z noexecstack"],,[])
-LDFLAGS="$LDFLAGS -fPIE -pie"
CFLAGS="$CFLAGS -Wvla -std=gnu11 -D_FORTIFY_SOURCE=2 -Wall -fPIC -fPIE -pie"
if test "x$enable_werror" = "xyes"; then
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index b24fcfdb..27240cc4 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -50,6 +50,7 @@ noinst_HEADERS = attach.h \
json/oci_runtime_spec.h \
json/logger_json_file.h \
json/read-file.h \
+ isulad_utils.h \
utils.h
if IS_BIONIC
@@ -146,6 +147,7 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \
sync.c sync.h \
syscall_wrappers.h \
terminal.c \
+ isulad_utils.c isulad_utils.h \
utils.c utils.h \
version.h \
json/json_common.c json/json_common.h \
@@ -232,14 +234,14 @@ AM_CFLAGS += -DUSE_CONFIGPATH_LOGS
endif
# build the shared library
-liblxc_la_CFLAGS = -fPIC \
- -fPIE -pie \
+liblxc_la_CFLAGS = \
-DPIC \
-D_FORTIFY_SOURCE=2 -Wall \
$(AM_CFLAGS) \
-pthread
liblxc_la_LDFLAGS = -pthread \
+ -fPIC \
-Wl,-no-undefined \
-Wl,-z,relro \
-Wl,-z,now \
@@ -375,6 +377,7 @@ lxc_monitord_SOURCES = cmd/lxc_monitord.c \
mainloop.c mainloop.h \
monitor.c monitor.h \
raw_syscalls.c raw_syscalls.h \
+ isulad_utils.c isulad_utils.h \
utils.c utils.h
lxc_user_nic_SOURCES = cmd/lxc_user_nic.c \
../include/netns_ifaddrs.c ../include/netns_ifaddrs.h \
@@ -391,6 +394,7 @@ lxc_usernsexec_SOURCES = cmd/lxc_usernsexec.c \
file_utils.c file_utils.h \
string_utils.c string_utils.h \
syscall_wrappers.h \
+ isulad_utils.c isulad_utils.h \
utils.c utils.h
endif
@@ -411,6 +415,8 @@ init_lxc_static_SOURCES = cmd/lxc_init.c \
initutils.c initutils.h \
file_utils.c file_utils.h \
log.c log.h \
+ path.c path.h \
+ isulad_utils.c isulad_utils.h \
macro.h \
namespace.c namespace.h \
string_utils.c string_utils.h
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index e22e13e8..d9a7aae1 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -4934,7 +4934,7 @@ static int do_run_oci_hooks(const char *name, const char *lxcpath, struct lxc_co
work_conf.ocihook = lc->ocihooks->poststart[i];
nret = run_ocihook_script_argv(name, "lxc", &work_conf, lxcpath, rootpath);
if (nret != 0)
- WARN("running poststart hook %ld failed, ContainerId: %s", i, name);
+ WARN("running poststart hook %zu failed, ContainerId: %s", i, name);
}
break;
case OCI_HOOK_POSTSTOP:
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 0537ebcf..01fc9443 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -2212,7 +2212,7 @@ static int set_config_init_args(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
int ret = 0;
- char *tmp = NULL;
+ void *tmp = NULL;
char *new_value = NULL;
ret = set_config_string_item(&new_value, value);
diff --git a/src/lxc/isulad_utils.c b/src/lxc/isulad_utils.c
new file mode 100644
index 00000000..66516a80
--- /dev/null
+++ b/src/lxc/isulad_utils.c
@@ -0,0 +1,87 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "isulad_utils.h"
+#include "log.h"
+#include "path.h"
+
+lxc_log_define(isulad_utils, lxc);
+
+void *lxc_common_calloc_s(size_t size)
+{
+ if (size == 0 || size > SIZE_MAX) {
+ return NULL;
+ }
+
+ return calloc((size_t)1, size);
+}
+
+int lxc_mem_realloc(void **newptr, size_t newsize, void *oldptr, size_t oldsize)
+{
+ void *tmp = NULL;
+
+ if (newsize == 0) {
+ goto err_out;
+ }
+
+ tmp = lxc_common_calloc_s(newsize);
+ if (tmp == NULL) {
+ ERROR("Failed to malloc memory");
+ goto err_out;
+ }
+
+ if (oldptr != NULL) {
+ memcpy(tmp, oldptr, (newsize < oldsize) ? newsize : oldsize);
+
+ memset(oldptr, 0, oldsize);
+
+ free(oldptr);
+ }
+
+ *newptr = tmp;
+ return 0;
+
+err_out:
+ return -1;
+}
+
+char *safe_strdup(const char *src)
+{
+ char *dst = NULL;
+
+ if (src == NULL) {
+ return NULL;
+ }
+
+ dst = strdup(src);
+ if (dst == NULL) {
+ abort();
+ }
+
+ return dst;
+}
+
+int lxc_open(const char *filename, int flags, mode_t mode)
+{
+ char rpath[PATH_MAX] = {0x00};
+
+ if (cleanpath(filename, rpath, sizeof(rpath)) == NULL) {
+ return -1;
+ }
+ if (mode) {
+ return open(rpath, (int)((unsigned int)flags | O_CLOEXEC), mode);
+ } else {
+ return open(rpath, (int)((unsigned int)flags | O_CLOEXEC));
+ }
+}
+
+FILE *lxc_fopen(const char *filename, const char *mode)
+{
+ char rpath[PATH_MAX] = {0x00};
+
+ if (cleanpath(filename, rpath, sizeof(rpath)) == NULL) {
+ return NULL;
+ }
+
+ return fopen_cloexec(rpath, mode);
+}
diff --git a/src/lxc/isulad_utils.h b/src/lxc/isulad_utils.h
new file mode 100644
index 00000000..852d9562
--- /dev/null
+++ b/src/lxc/isulad_utils.h
@@ -0,0 +1,13 @@
+#ifndef __LXC_MEM_UTILS_H
+#define __LXC_MEM_UTILS_H
+
+#include <stdio.h>
+
+extern int lxc_mem_realloc(void **newptr, size_t newsize, void *oldptr, size_t oldsize);
+extern void *lxc_common_calloc_s(size_t size);
+extern char *safe_strdup(const char *src);
+
+extern int lxc_open(const char *filename, int flags, mode_t mode);
+extern FILE *lxc_fopen(const char *filename, const char *mode);
+
+#endif
diff --git a/src/lxc/path.c b/src/lxc/path.c
index df285f54..7a5dce95 100644
--- a/src/lxc/path.c
+++ b/src/lxc/path.c
@@ -10,7 +10,7 @@
#include "path.h"
#include "log.h"
-#include "utils.h"
+#include "isulad_utils.h"
lxc_log_define(lxc_path_ui, lxc);
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 656df4a3..1d2e9ee4 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -57,6 +57,7 @@
#include "syscall_wrappers.h"
#include "utils.h"
#include "path.h"
+#include "isulad_utils.h"
#ifndef HAVE_STRLCPY
#include "include/strlcpy.h"
@@ -2092,84 +2093,3 @@ bool is_non_negative_num(const char *s)
}
return true;
}
-
-void *lxc_common_calloc_s(size_t size)
-{
- if (size == 0 || size > SIZE_MAX) {
- return NULL;
- }
-
- return calloc((size_t)1, size);
-}
-
-
-int lxc_mem_realloc(void **newptr, size_t newsize, void *oldptr, size_t oldsize)
-{
- void *tmp = NULL;
-
- if (newsize == 0) {
- goto err_out;
- }
-
- tmp = lxc_common_calloc_s(newsize);
- if (tmp == NULL) {
- ERROR("Failed to malloc memory");
- goto err_out;
- }
-
- if (oldptr != NULL) {
- memcpy(tmp, oldptr, (newsize < oldsize) ? newsize : oldsize);
-
- memset(oldptr, 0, oldsize);
-
- free(oldptr);
- }
-
- *newptr = tmp;
- return 0;
-
-err_out:
- return -1;
-}
-
-int lxc_open(const char *filename, int flags, mode_t mode)
-{
- char rpath[PATH_MAX] = {0x00};
-
- if (cleanpath(filename, rpath, sizeof(rpath)) == NULL) {
- return -1;
- }
- if (mode) {
- return open(rpath, (int)((unsigned int)flags | O_CLOEXEC), mode);
- } else {
- return open(rpath, (int)((unsigned int)flags | O_CLOEXEC));
- }
-}
-
-FILE *lxc_fopen(const char *filename, const char *mode)
-{
- char rpath[PATH_MAX] = {0x00};
-
- if (cleanpath(filename, rpath, sizeof(rpath)) == NULL) {
- return NULL;
- }
-
- return fopen_cloexec(rpath, mode);
-}
-
-char *safe_strdup(const char *src)
-{
- char *dst = NULL;
-
- if (src == NULL) {
- return NULL;
- }
-
- dst = strdup(src);
- if (dst == NULL) {
- abort();
- }
-
- return dst;
-}
-
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 0b33f690..1c9bf418 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -42,6 +42,7 @@
#include "macro.h"
#include "raw_syscalls.h"
#include "string_utils.h"
+#include "isulad_utils.h"
/* isulad: replace space with SPACE_MAGIC_STR */
#define SPACE_MAGIC_STR "[#)"
@@ -324,10 +325,5 @@ extern bool lxc_process_alive(pid_t pid, unsigned long long start_time);
extern bool is_non_negative_num(const char *s);
extern int lxc_file2str(const char *filename, char ret[], int cap);
-extern int lxc_mem_realloc(void **newptr, size_t newsize, void *oldptr, size_t oldsize);
-extern void *lxc_common_calloc_s(size_t size);
-extern int lxc_open(const char *filename, int flags, mode_t mode);
-extern FILE *lxc_fopen(const char *filename, const char *mode);
-extern char *safe_strdup(const char *src);
#endif /* __LXC_UTILS_H */
--
2.23.0