From 6330eb5a8a526ee88eb0e91c86e26ce18c213080 Mon Sep 17 00:00:00 2001 From: chegJH Date: Tue, 15 Feb 2022 17:22:35 +0800 Subject: [PATCH 1/2] changes for compile in andorid env Signed-off-by: chegJH --- 0036-compile-in-android-env.patch | 199 ++++++++++++++++++++++++++++++ lxc.spec | 9 +- series.conf | 1 + 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 0036-compile-in-android-env.patch diff --git a/0036-compile-in-android-env.patch b/0036-compile-in-android-env.patch new file mode 100644 index 0000000..3f72427 --- /dev/null +++ b/0036-compile-in-android-env.patch @@ -0,0 +1,199 @@ +From 8ff75016bcb3becdb9ccaa4ef13d989328fb886d Mon Sep 17 00:00:00 2001 +From: chegJH +Date: Tue, 15 Feb 2022 16:13:56 +0800 +Subject: [PATCH] changes for compile in android env + +Signed-off-by: chegJH +--- + configure.ac | 2 +- + src/lxc/Makefile.am | 3 ++- + src/lxc/commands_utils.c | 8 +++++++- + src/lxc/confile.c | 6 +++--- + src/lxc/json/read-file.c | 2 +- + src/lxc/log.c | 2 +- + src/lxc/lxclock.c | 1 + + src/lxc/syscall_wrappers.h | 2 +- + src/lxc/utils.c | 21 +++++++-------------- + 9 files changed, 24 insertions(+), 23 deletions(-) + +diff --git a/configure.ac b/configure.ac +index d1d793b..4cc8ad7 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -771,7 +771,7 @@ 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"],,[]) + +-CFLAGS="$CFLAGS -Wvla -std=gnu11 -D_FORTIFY_SOURCE=2 -Wall -fPIC -fPIE -pie" ++CFLAGS="$CFLAGS -Wvla -std=gnu11 -D_FORTIFY_SOURCE=2 -Wall -fPIC -fPIE" + if test "x$enable_werror" = "xyes"; then + CFLAGS="$CFLAGS -Werror" + fi +diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am +index dc49c7e..2686e24 100644 +--- a/src/lxc/Makefile.am ++++ b/src/lxc/Makefile.am +@@ -361,7 +361,8 @@ LDADD = liblxc.la \ + @OPENSSL_LIBS@ \ + @SECCOMP_LIBS@ \ + @SELINUX_LIBS@ \ +- @DLOG_LIBS@ ++ @DLOG_LIBS@ \ ++ @YAJL_LIBS@ + + if ENABLE_TOOLS + lxc_attach_SOURCES = tools/lxc_attach.c \ +diff --git a/src/lxc/commands_utils.c b/src/lxc/commands_utils.c +index 7dfefa5..54ba26e 100644 +--- a/src/lxc/commands_utils.c ++++ b/src/lxc/commands_utils.c +@@ -141,9 +141,15 @@ int lxc_make_abstract_socket_name(char *path, size_t pathlen, + char *generate_named_unix_sock_dir(const char *name) + { + __do_free char *exec_sock_dir = NULL; ++ __do_free char *rundir = NULL; + +- if (asprintf(&exec_sock_dir, "/var/run/lxc/%s", name) < 0) ++ rundir = get_rundir(); ++ if (!rundir) ++ rundir = strdup("/var/run"); ++ ++ if (asprintf(&exec_sock_dir, "%s/lxc/%s", rundir, name) < 0) { + return log_error_errno(NULL, errno, "Failed to allocate memory"); ++ } + + return move_ptr(exec_sock_dir); + } +diff --git a/src/lxc/confile.c b/src/lxc/confile.c +index e298ce9..cc53148 100644 +--- a/src/lxc/confile.c ++++ b/src/lxc/confile.c +@@ -6239,21 +6239,21 @@ 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; ++ char **tmp = NULL; + char *new_value = NULL; + + ret = set_config_string_item(&new_value, value); + if (ret || !new_value) + return ret; + +- tmp = realloc(lxc_conf->init_argv, (lxc_conf->init_argc + 1) * sizeof(char *)); ++ tmp = (char **)realloc(lxc_conf->init_argv, (lxc_conf->init_argc + 1) * sizeof(char *)); + if (!tmp) { + ERROR("Out of memory"); + free(new_value); + return -1; + } + +- lxc_conf->init_argv = (char **)tmp; ++ lxc_conf->init_argv = tmp; + + lxc_conf->init_argv[lxc_conf->init_argc] = new_value; + lxc_conf->init_argc++; +diff --git a/src/lxc/json/read-file.c b/src/lxc/json/read-file.c +index 70e73e5..34ebeed 100644 +--- a/src/lxc/json/read-file.c ++++ b/src/lxc/json/read-file.c +@@ -76,7 +76,7 @@ char *read_file(const char *path, size_t *length) + return NULL; + } + +- fd = open(rpath, O_RDONLY | O_CLOEXEC, 0640); ++ fd = open(rpath, O_RDONLY | O_CLOEXEC); + if (fd < 0) { + return NULL; + } +diff --git a/src/lxc/log.c b/src/lxc/log.c +index 79caa2c..a04f78e 100644 +--- a/src/lxc/log.c ++++ b/src/lxc/log.c +@@ -71,7 +71,7 @@ static int isulad_open_fifo(const char *file_path) + #define LOG_FIFO_SIZE (1024 * 1024) + int fd; + +- fd = lxc_unpriv(open(file_path, O_RDWR | O_NONBLOCK | O_CLOEXEC, 0640)); ++ fd = lxc_unpriv(open(file_path, O_RDWR | O_NONBLOCK | O_CLOEXEC)); + if (fd == -1) { + fprintf(stderr, "Open fifo %s failed: %s\n", file_path, strerror(errno)); + return -1; +diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c +index bb0dca0..d65c614 100644 +--- a/src/lxc/lxclock.c ++++ b/src/lxc/lxclock.c +@@ -179,6 +179,7 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name) + l->u.f.fd = -1; + + on_error: ++ fprintf(stderr, "Failed to create lock for %s, path %s\n", name, lxcpath); + return l; + } + +diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h +index 1cef215..1c8e652 100644 +--- a/src/lxc/syscall_wrappers.h ++++ b/src/lxc/syscall_wrappers.h +@@ -62,7 +62,7 @@ extern int memfd_create(const char *name, unsigned int flags); + #endif + + #ifndef HAVE_PIVOT_ROOT +-static int pivot_root(const char *new_root, const char *put_old) ++static inline int pivot_root(const char *new_root, const char *put_old) + { + return syscall(__NR_pivot_root, new_root, put_old); + } +diff --git a/src/lxc/utils.c b/src/lxc/utils.c +index 95c00cf..b39b6a8 100644 +--- a/src/lxc/utils.c ++++ b/src/lxc/utils.c +@@ -2081,7 +2081,10 @@ void lxc_write_error_message(int errfd, const char *format, ...) + return; + + va_start(argp, format); ++#pragma GCC diagnostic push ++#pragma GCC diagnostic ignored "-Wformat-nonliteral" + ret = vsnprintf(errbuf, BUFSIZ, format, argp); ++#pragma GCC diagnostic pop + va_end(argp); + if (ret < 0 || ret >= BUFSIZ) + SYSERROR("Failed to call vsnprintf"); +@@ -2210,30 +2213,20 @@ out: + // isulad: set env home in container + int lxc_setup_env_home(uid_t uid) + { +-#define __PASSWD_FILE__ "/etc/passwd" + char *homedir = "/"; // default home dir is / +- FILE *stream = NULL; + struct passwd pw, *pwbufp = NULL; + char buf[BUFSIZ]; ++ int ret; + +- stream = fopen_cloexec(__PASSWD_FILE__, "r"); +- if (stream == NULL) { +- SYSWARN("Failed to open %s", __PASSWD_FILE__); ++ ret = getpwuid_r(uid, &pw, buf, sizeof(buf), &pwbufp); ++ if ((ret == 0) && (pwbufp != NULL) && (pwbufp->pw_uid == uid)) { ++ homedir = pwbufp->pw_dir; + goto set_env; + } + +- while (fgetpwent_r(stream, &pw, buf, sizeof(buf), &pwbufp) == 0 && pwbufp != NULL) { +- if (pwbufp->pw_uid == uid) { +- homedir = pwbufp->pw_dir; +- goto set_env; +- } +- } + WARN("User invalid, can not find user '%u'", uid); + + set_env: +- if (stream) +- fclose(stream); +- + // if we didn't configure HOME, set it based on uid + if (setenv("HOME", homedir, 0) < 0) { + SYSERROR("Unable to set env 'HOME'"); +-- +2.32.0 (Apple Git-132) + diff --git a/lxc.spec b/lxc.spec index 37a3012..e906587 100644 --- a/lxc.spec +++ b/lxc.spec @@ -1,4 +1,4 @@ -%global _release 2021122701 +%global _release 2022021501 Name: lxc Version: 4.0.3 @@ -43,6 +43,7 @@ Patch0032: 0032-disable-lxc_keep-with-oci-image.patch Patch0033: 0033-conf-ensure-that-the-idmap-pointer-itself-is-freed.patch Patch0034: 0034-cgfsng-fix-cgroup-attach-cgroup-creation.patch Patch0035: 0035-adapt-upstream-compiler-settings.patch +Patch0036: 0036-compile-in-android-env.patch BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath BuildRequires: pkgconfig(libseccomp) @@ -214,6 +215,12 @@ make check %{_mandir}/*/man7/%{name}* %changelog +* Tue Feb 15 2022 chegJH - 4.0.3-2022021501 +- Type:improve +- ID:NA +- SUG:NA +- DESC:changes for compile in android env + * Mon Dec 27 2021 haozi007 - 4.0.3-2021122701 - Type:improve - ID:NA diff --git a/series.conf b/series.conf index 86c71d5..b2cb785 100644 --- a/series.conf +++ b/series.conf @@ -33,3 +33,4 @@ 0033-conf-ensure-that-the-idmap-pointer-itself-is-freed.patch 0034-cgfsng-fix-cgroup-attach-cgroup-creation.patch 0035-adapt-upstream-compiler-settings.patch +0036-compile-in-android-env.patch -- Gitee From 147b19baca99d6334b94094e0703bb4e8563099f Mon Sep 17 00:00:00 2001 From: chegJH Date: Mon, 21 Feb 2022 19:24:24 +0800 Subject: [PATCH 2/2] fix always print and len Signed-off-by: chegJH --- 0037-fix-always-print-and-temp-len.patch | 39 ++++++++++++++++++++++++ lxc.spec | 9 +++++- series.conf | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 0037-fix-always-print-and-temp-len.patch diff --git a/0037-fix-always-print-and-temp-len.patch b/0037-fix-always-print-and-temp-len.patch new file mode 100644 index 0000000..b9ccdf5 --- /dev/null +++ b/0037-fix-always-print-and-temp-len.patch @@ -0,0 +1,39 @@ +From 178d09524a346cab9ca1f9eb939e35945b7bfbb0 Mon Sep 17 00:00:00 2001 +From: chegJH +Date: Mon, 21 Feb 2022 19:14:56 +0800 +Subject: [PATCH] fix always print and temp len + +Signed-off-by: chegJH +--- + src/lxc/confile_utils.h | 2 +- + src/lxc/lxclock.c | 1 + + 2 files changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h +index 62990e9..3655ec4 100644 +--- a/src/lxc/confile_utils.h ++++ b/src/lxc/confile_utils.h +@@ -13,7 +13,7 @@ + if (str) \ + len = snprintf(str, inlen, ##__VA_ARGS__); \ + else \ +- len = snprintf((char *){""}, 0, ##__VA_ARGS__); \ ++ len = 0; \ + if (len < 0) { \ + SYSERROR("failed to create string"); \ + return -1; \ +diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c +index d65c614..9c9b57c 100644 +--- a/src/lxc/lxclock.c ++++ b/src/lxc/lxclock.c +@@ -177,6 +177,7 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name) + } + + l->u.f.fd = -1; ++ return l; + + on_error: + fprintf(stderr, "Failed to create lock for %s, path %s\n", name, lxcpath); +-- +2.32.0 (Apple Git-132) + diff --git a/lxc.spec b/lxc.spec index e906587..35807a5 100644 --- a/lxc.spec +++ b/lxc.spec @@ -1,4 +1,4 @@ -%global _release 2022021501 +%global _release 2022022101 Name: lxc Version: 4.0.3 @@ -44,6 +44,7 @@ Patch0033: 0033-conf-ensure-that-the-idmap-pointer-itself-is-freed.patch Patch0034: 0034-cgfsng-fix-cgroup-attach-cgroup-creation.patch Patch0035: 0035-adapt-upstream-compiler-settings.patch Patch0036: 0036-compile-in-android-env.patch +Patch0037: 0037-fix-always-print-and-temp-len.patch BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath BuildRequires: pkgconfig(libseccomp) @@ -215,6 +216,12 @@ make check %{_mandir}/*/man7/%{name}* %changelog +* Mon Feb 21 2022 chegJH - 4.0.3-2022022101 +- Type:improv +- ID:NA +- SUG:NA +- DESC: fix alwasy print and len + * Tue Feb 15 2022 chegJH - 4.0.3-2022021501 - Type:improve - ID:NA diff --git a/series.conf b/series.conf index b2cb785..89a1d80 100644 --- a/series.conf +++ b/series.conf @@ -34,3 +34,4 @@ 0034-cgfsng-fix-cgroup-attach-cgroup-creation.patch 0035-adapt-upstream-compiler-settings.patch 0036-compile-in-android-env.patch +0037-fix-always-print-and-temp-len.patch -- Gitee