From 58db1a61c88a41eec7e0dffe656d9ece53d899cc Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 09:25:56 +0200 Subject: [PATCH 01/62] build: add src/include to build and simplify header inclusions Signed-off-by: Christian Brauner --- hooks/unmount-namespace.c | 2 +- src/lxc/Makefile.am | 1 + src/lxc/af_unix.c | 2 +- src/lxc/cgroups/cgfsng.c | 4 ++-- src/lxc/cgroups/cgroup2_devices.h | 4 ++-- src/lxc/cmd/lxc_user_nic.c | 2 +- src/lxc/conf.c | 12 ++++++------ src/lxc/confile.c | 6 +++--- src/lxc/confile_utils.c | 2 +- src/lxc/criu.c | 4 ++-- src/lxc/initutils.c | 2 +- src/lxc/log.c | 2 +- src/lxc/lxccontainer.c | 2 +- src/lxc/monitor.c | 2 +- src/lxc/network.c | 4 ++-- src/lxc/pam/pam_cgfs.c | 4 ++-- src/lxc/rexec.c | 2 +- src/lxc/start.c | 2 +- src/lxc/storage/btrfs.c | 4 ++-- src/lxc/storage/nbd.c | 2 +- src/lxc/storage/rbd.c | 2 +- src/lxc/storage/storage.c | 2 +- src/lxc/storage/storage.h | 2 +- src/lxc/storage/storage_utils.c | 2 +- src/lxc/string_utils.c | 4 ++-- src/lxc/string_utils.h | 6 +++--- src/lxc/terminal.c | 2 +- src/lxc/tools/include/getsubopt.c | 2 +- src/lxc/tools/lxc_copy.c | 2 +- src/lxc/tools/lxc_device.c | 2 +- src/lxc/utils.c | 4 ++-- src/lxc/utils.h | 2 +- src/tests/Makefile.am | 1 + src/tests/api_reboot.c | 2 +- src/tests/arch_parse.c | 2 +- src/tests/attach.c | 2 +- src/tests/cgpath.c | 2 +- src/tests/device_add_remove.c | 2 +- src/tests/get_item.c | 2 +- src/tests/shortlived.c | 2 +- 40 files changed, 57 insertions(+), 55 deletions(-) diff --git a/hooks/unmount-namespace.c b/hooks/unmount-namespace.c index 99b284481..c0c8b191c 100644 --- a/hooks/unmount-namespace.c +++ b/hooks/unmount-namespace.c @@ -40,7 +40,7 @@ #include <../src/config.h> #if IS_BIONIC -#include <../src/include/lxcmntent.h> +#include "lxcmntent.h" #else #include #endif diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index d13cbc160..3c1f0a3dd 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -230,6 +230,7 @@ AM_CFLAGS += -DLXCROOTFSMOUNT=\"$(LXCROOTFSMOUNT)\" \ -DSBINDIR=\"$(SBINDIR)\" \ -DAPPARMOR_CACHE_DIR=\"$(APPARMOR_CACHE_DIR)\" \ -I $(top_srcdir)/src \ + -I $(top_srcdir)/src/include \ -I $(top_srcdir)/src/lxc \ -I $(top_srcdir)/src/lxc/storage \ -I $(top_srcdir)/src/lxc/cgroups diff --git a/src/lxc/af_unix.c b/src/lxc/af_unix.c index 92debcf6c..4f8e2fad6 100644 --- a/src/lxc/af_unix.c +++ b/src/lxc/af_unix.c @@ -23,7 +23,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(af_unix, lxc); diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 1f8080241..0e9cbcec6 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -54,11 +54,11 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef HAVE_STRLCAT -#include "include/strlcat.h" +#include "strlcat.h" #endif lxc_log_define(cgfsng, cgroup); diff --git a/src/lxc/cgroups/cgroup2_devices.h b/src/lxc/cgroups/cgroup2_devices.h index c8a1606a1..31896d292 100644 --- a/src/lxc/cgroups/cgroup2_devices.h +++ b/src/lxc/cgroups/cgroup2_devices.h @@ -24,8 +24,8 @@ #include "memory_utils.h" #include "syscall_numbers.h" -#include "include/bpf.h" -#include "include/bpf_common.h" +#include "bpf.h" +#include "bpf_common.h" #ifndef HAVE_BPF static inline int bpf_lxc(int cmd, union bpf_attr *attr, size_t size) diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c index 6ead30b64..16ee4651d 100644 --- a/src/lxc/cmd/lxc_user_nic.c +++ b/src/lxc/cmd/lxc_user_nic.c @@ -43,7 +43,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #define usernic_debug_stream(stream, format, ...) \ diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 86ad68b52..be9d3072b 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -75,7 +75,7 @@ #if HAVE_OPENPTY #include #else -#include <../include/openpty.h> +#include "openpty.h" #endif #if HAVE_LIBCAP @@ -83,25 +83,25 @@ #endif #ifndef HAVE_STRLCAT -#include "include/strlcat.h" +#include "strlcat.h" #endif #if IS_BIONIC -#include <../include/lxcmntent.h> +#include "lxcmntent.h" #else #include #endif #if !defined(HAVE_PRLIMIT) && defined(HAVE_PRLIMIT64) -#include <../include/prlimit.h> +#include "prlimit.h" #endif #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef HAVE_STRCHRNUL -#include "include/strchrnul.h" +#include "strchrnul.h" #endif lxc_log_define(conf, lxc); diff --git a/src/lxc/confile.c b/src/lxc/confile.c index a5f7249b7..9a2fcc3fc 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -29,7 +29,7 @@ #include "config.h" #include "confile.h" #include "confile_utils.h" -#include "../include/netns_ifaddrs.h" +#include "netns_ifaddrs.h" #include "log.h" #include "lxcseccomp.h" #include "macro.h" @@ -40,11 +40,11 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef HAVE_STRLCAT -#include "include/strlcat.h" +#include "strlcat.h" #endif lxc_log_define(confile, lxc); diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index fff20375c..77627513c 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -25,7 +25,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(confile_utils, lxc); diff --git a/src/lxc/criu.c b/src/lxc/criu.c index 4452d0b0c..9143100fa 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -29,13 +29,13 @@ #include "utils.h" #if IS_BIONIC -#include <../include/lxcmntent.h> +#include "lxcmntent.h" #else #include #endif #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #define CRIU_VERSION "2.0" diff --git a/src/lxc/initutils.c b/src/lxc/initutils.c index 5f2a42454..397e94692 100644 --- a/src/lxc/initutils.c +++ b/src/lxc/initutils.c @@ -20,7 +20,7 @@ #include "process_utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif static char *copy_global_config_value(char *p) diff --git a/src/lxc/log.c b/src/lxc/log.c index be3a16fcc..9c5053ec9 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -27,7 +27,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #if HAVE_DLOG diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 3b18d00ff..9ed50894b 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -25,7 +25,7 @@ #include #include -#include "../include/netns_ifaddrs.h" +#include "netns_ifaddrs.h" #include "af_unix.h" #include "api_extensions.h" #include "attach.h" diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index 26f1ec04b..1c1d7039a 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -33,7 +33,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(monitor, lxc); diff --git a/src/lxc/network.c b/src/lxc/network.c index 15ed81bd5..32963a0ea 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -26,7 +26,7 @@ #include #include -#include "../include/netns_ifaddrs.h" +#include "netns_ifaddrs.h" #include "af_unix.h" #include "conf.h" #include "config.h" @@ -42,7 +42,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(network, lxc); diff --git a/src/lxc/pam/pam_cgfs.c b/src/lxc/pam/pam_cgfs.c index 74d10a760..91efe5c80 100644 --- a/src/lxc/pam/pam_cgfs.c +++ b/src/lxc/pam/pam_cgfs.c @@ -34,11 +34,11 @@ #include #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef HAVE_STRLCAT -#include "include/strlcat.h" +#include "strlcat.h" #endif #define pam_cgfs_debug_stream(stream, format, ...) \ diff --git a/src/lxc/rexec.c b/src/lxc/rexec.c index 060df680e..2d6345651 100644 --- a/src/lxc/rexec.c +++ b/src/lxc/rexec.c @@ -19,7 +19,7 @@ #include "syscall_wrappers.h" #if IS_BIONIC -#include "../include/fexecve.h" +#include "fexecve.h" #endif #define LXC_MEMFD_REXEC_SEALS \ diff --git a/src/lxc/start.c b/src/lxc/start.c index 7f0903f1b..a96aa27d8 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -63,7 +63,7 @@ #endif #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(start, lxc); diff --git a/src/lxc/storage/btrfs.c b/src/lxc/storage/btrfs.c index b115e10bb..22ba1484c 100644 --- a/src/lxc/storage/btrfs.c +++ b/src/lxc/storage/btrfs.c @@ -26,11 +26,11 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef HAVE_STRLCAT -#include "include/strlcat.h" +#include "strlcat.h" #endif lxc_log_define(btrfs, lxc); diff --git a/src/lxc/storage/nbd.c b/src/lxc/storage/nbd.c index ba4207380..06515b833 100644 --- a/src/lxc/storage/nbd.c +++ b/src/lxc/storage/nbd.c @@ -22,7 +22,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(nbd, lxc); diff --git a/src/lxc/storage/rbd.c b/src/lxc/storage/rbd.c index 7a8a8b8be..f387ac21a 100644 --- a/src/lxc/storage/rbd.c +++ b/src/lxc/storage/rbd.c @@ -18,7 +18,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(rbd, lxc); diff --git a/src/lxc/storage/storage.c b/src/lxc/storage/storage.c index a8c4be5f3..e40ecee1f 100644 --- a/src/lxc/storage/storage.c +++ b/src/lxc/storage/storage.c @@ -43,7 +43,7 @@ #include "zfs.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef BLKGETSIZE64 diff --git a/src/lxc/storage/storage.h b/src/lxc/storage/storage.h index 91e08b7fc..0f14fd260 100644 --- a/src/lxc/storage/storage.h +++ b/src/lxc/storage/storage.h @@ -9,7 +9,7 @@ #include #if IS_BIONIC -#include <../include/lxcmntent.h> +#include "lxcmntent.h" #else #include #endif diff --git a/src/lxc/storage/storage_utils.c b/src/lxc/storage/storage_utils.c index 2839f0ce7..de82e4d41 100644 --- a/src/lxc/storage/storage_utils.c +++ b/src/lxc/storage/storage_utils.c @@ -31,7 +31,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef BLKGETSIZE64 diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c index b1d6dc9bc..372d660cb 100644 --- a/src/lxc/string_utils.c +++ b/src/lxc/string_utils.c @@ -35,11 +35,11 @@ #include "string_utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef HAVE_STRLCAT -#include "include/strlcat.h" +#include "strlcat.h" #endif char **lxc_va_arg_list_to_argv(va_list ap, size_t skip, int do_strdup) diff --git a/src/lxc/string_utils.h b/src/lxc/string_utils.h index ac916c6b6..2c1af4a88 100644 --- a/src/lxc/string_utils.h +++ b/src/lxc/string_utils.h @@ -11,15 +11,15 @@ #include "macro.h" #ifndef HAVE_STRLCAT -#include "include/strlcat.h" +#include "strlcat.h" #endif #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef HAVE_STRCHRNUL -#include "include/strchrnul.h" +#include "strchrnul.h" #endif /* convert variadic argument lists to arrays (for execl type argument lists) */ diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index 7327893b3..543e947bb 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -32,7 +32,7 @@ #if HAVE_OPENPTY #include #else -#include <../include/openpty.h> +#include "openpty.h" #endif #define LXC_TERMINAL_BUFFER_SIZE 1024 diff --git a/src/lxc/tools/include/getsubopt.c b/src/lxc/tools/include/getsubopt.c index c01131a70..96d582ac0 100644 --- a/src/lxc/tools/include/getsubopt.c +++ b/src/lxc/tools/include/getsubopt.c @@ -7,7 +7,7 @@ #include "config.h" #ifndef HAVE_STRCHRNUL -#include "../../../include/strchrnul.h" +#include "strchrnul.h" #endif /* Parse comma separated suboption from *OPTIONP and match against diff --git a/src/lxc/tools/lxc_copy.c b/src/lxc/tools/lxc_copy.c index a786a300c..94b339f63 100644 --- a/src/lxc/tools/lxc_copy.c +++ b/src/lxc/tools/lxc_copy.c @@ -27,7 +27,7 @@ #include "utils.h" #ifndef HAVE_GETSUBOPT -#include "include/getsubopt.h" +#include "getsubopt.h" #endif lxc_log_define(lxc_copy, lxc); diff --git a/src/lxc/tools/lxc_device.c b/src/lxc/tools/lxc_device.c index c6641f45a..62d5ac86e 100644 --- a/src/lxc/tools/lxc_device.c +++ b/src/lxc/tools/lxc_device.c @@ -12,7 +12,7 @@ #include -#include "../../include/netns_ifaddrs.h" +#include "netns_ifaddrs.h" #include "arguments.h" #include "config.h" #include "log.h" diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 55995405c..c2cfecf88 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -40,11 +40,11 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef HAVE_STRLCAT -#include "include/strlcat.h" +#include "strlcat.h" #endif #ifndef O_PATH diff --git a/src/lxc/utils.h b/src/lxc/utils.h index 272e2dbef..51fb8874b 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -35,7 +35,7 @@ __hidden extern char *get_rundir(void); /* Define getline() if missing from the C library */ #ifndef HAVE_GETLINE #ifdef HAVE_FGETLN -#include <../include/getline.h> +#include "getline.h" #endif #endif diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index ef8330efd..a64d61302 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -1288,6 +1288,7 @@ AM_CFLAGS += -DLXCROOTFSMOUNT=\"$(LXCROOTFSMOUNT)\" \ -DRUNTIME_PATH=\"$(RUNTIME_PATH)\" \ -DSBINDIR=\"$(SBINDIR)\" \ -I $(top_srcdir)/src \ + -I $(top_srcdir)/src/include \ -I $(top_srcdir)/src/lxc \ -I $(top_srcdir)/src/lxc/cgroups \ -I $(top_srcdir)/src/lxc/tools \ diff --git a/src/tests/api_reboot.c b/src/tests/api_reboot.c index 91ba9f656..bf051b8b5 100644 --- a/src/tests/api_reboot.c +++ b/src/tests/api_reboot.c @@ -32,7 +32,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #define TSTNAME "lxc-api-reboot" diff --git a/src/tests/arch_parse.c b/src/tests/arch_parse.c index 47a2518da..95792ddd1 100644 --- a/src/tests/arch_parse.c +++ b/src/tests/arch_parse.c @@ -31,7 +31,7 @@ #include "../lxc/memory_utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif static const char *const arches[] = { diff --git a/src/tests/attach.c b/src/tests/attach.c index 3e43c7b06..f4ff5efbb 100644 --- a/src/tests/attach.c +++ b/src/tests/attach.c @@ -33,7 +33,7 @@ #include #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #define TSTNAME "lxc-attach-test" diff --git a/src/tests/cgpath.c b/src/tests/cgpath.c index b1e5ffc74..81b2162fe 100644 --- a/src/tests/cgpath.c +++ b/src/tests/cgpath.c @@ -36,7 +36,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #define MYNAME "lxctest1" diff --git a/src/tests/device_add_remove.c b/src/tests/device_add_remove.c index dd5c5d3ec..a03f7d19a 100644 --- a/src/tests/device_add_remove.c +++ b/src/tests/device_add_remove.c @@ -25,7 +25,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #define NAME "device_add_remove_test" diff --git a/src/tests/get_item.c b/src/tests/get_item.c index 111fc4af9..5ebe5508d 100644 --- a/src/tests/get_item.c +++ b/src/tests/get_item.c @@ -32,7 +32,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #define MYNAME "lxctest1" diff --git a/src/tests/shortlived.c b/src/tests/shortlived.c index 5c3d27548..c66e97ede 100644 --- a/src/tests/shortlived.c +++ b/src/tests/shortlived.c @@ -32,7 +32,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #define MYNAME "shortlived" From 4ee86fdad6b66b96b75f3df1345422b4e2ca461a Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 09:31:50 +0200 Subject: [PATCH 02/62] syscall_wrapper: fix pivot_root() declaration Signed-off-by: Christian Brauner --- src/lxc/syscall_wrappers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h index 7d62b7c5b..b545b0365 100644 --- a/src/lxc/syscall_wrappers.h +++ b/src/lxc/syscall_wrappers.h @@ -67,7 +67,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); } From 45ef2e0c690f38a460765290c576ab5a6b1a50c5 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 09:34:59 +0200 Subject: [PATCH 03/62] cgroups: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/cgroups/cgfsng.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 0e9cbcec6..3103263b3 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -163,7 +163,7 @@ int prepare_cgroup_fd(const struct cgroup_ops *ops, struct cgroup_fd *fd, bool l * The client requested that the controller must be in a specific * cgroup version. */ - if (fd->type != 0 && fd->type != h->fs_type) + if (fd->type != 0 && (cgroupfs_type_magic_t)fd->type != h->fs_type) return ret_errno(EINVAL); if (limit) @@ -2132,7 +2132,7 @@ static int cgroup_attach_leaf(const struct lxc_conf *conf, int unified_fd, pid_t * that a short write would cause a buffer overrun. So be on * the safe side. */ - if (ret < STRLITERALLEN(".lxc-/cgroup.procs")) + if ((size_t)ret < STRLITERALLEN(".lxc-/cgroup.procs")) return log_error_errno(-EINVAL, EINVAL, "Unexpected short write would cause buffer-overrun"); slash += (ret - STRLITERALLEN("/cgroup.procs")); @@ -2208,11 +2208,11 @@ static int cgroup_attach_move_into_leaf(const struct lxc_conf *conf, pidstr_len = sprintf(pidstr, INT64_FMT, (int64_t)pid); ret = lxc_write_nointr(target_fd0, pidstr, pidstr_len); - if (ret > 0 && ret == pidstr_len) + if (ret > 0 && (size_t)ret == pidstr_len) return log_debug(0, "Moved process into target cgroup via fd %d", target_fd0); ret = lxc_write_nointr(target_fd1, pidstr, pidstr_len); - if (ret > 0 && ret == pidstr_len) + if (ret > 0 && (size_t)ret == pidstr_len) return log_debug(0, "Moved process into target cgroup via fd %d", target_fd1); return log_debug_errno(-1, errno, "Failed to move process into target cgroup via fd %d and %d", @@ -2437,7 +2437,8 @@ static int device_cgroup_parse_access(struct device_item *device, const char *va static int device_cgroup_rule_parse(struct device_item *device, const char *key, const char *val) { - int count, ret; + size_t count; + int ret; char temp[50]; if (strequal("devices.allow", key)) From 15b9e2b099421b17a7afdfe0a0cd24f18a125ef4 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 09:35:34 +0200 Subject: [PATCH 04/62] confile: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/confile.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 9a2fcc3fc..6b1cfd4be 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "af_unix.h" @@ -47,6 +47,10 @@ #include "strlcat.h" #endif +#if HAVE_SYS_RESOURCE_H +#include +#endif + lxc_log_define(confile, lxc); #define lxc_config_define(name) \ @@ -2540,7 +2544,7 @@ static int set_config_console_buffer_size(const char *key, const char *value, if (buffer_size == 0) return ret_errno(EINVAL); - if (buffer_size != size) + if (buffer_size != (uint64_t)size) NOTICE("Passed size was not a power of 2. Rounding log size to next power of two: %" PRIu64 " bytes", buffer_size); lxc_conf->console.buffer_size = buffer_size; @@ -2585,7 +2589,7 @@ static int set_config_console_size(const char *key, const char *value, if (log_size == 0) return ret_errno(EINVAL); - if (log_size != size) + if (log_size != (uint64_t)size) NOTICE("Passed size was not a power of 2. Rounding log size to next power of two: %" PRIu64 " bytes", log_size); lxc_conf->console.log_size = log_size; @@ -3216,7 +3220,7 @@ int lxc_config_parse_arch(const char *arch, signed long *persona) { "x86_64", PER_LINUX }, }; - for (int i = 0; i < ARRAY_SIZE(pername); i++) { + for (size_t i = 0; i < ARRAY_SIZE(pername); i++) { if (!strequal(pername[i].name, arch)) continue; @@ -4508,7 +4512,7 @@ static int get_config_init_groups(const char *key, char *retv, int inlen, if (c->init_groups.size == 0) return 0; - for (int i = 0; i < c->init_groups.size; i++) + for (size_t i = 0; i < c->init_groups.size; i++) strprint(retv, inlen, "%s%d", (i > 0) ? "," : "", c->init_groups.list[i]); From 2048ac1a8e75816e41d745888a3b190596086ea1 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 09:42:11 +0200 Subject: [PATCH 05/62] storage: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/storage/btrfs.c | 10 +++++----- src/lxc/storage/lvm.c | 4 ++-- src/lxc/storage/overlay.c | 4 ++-- src/lxc/storage/storage_utils.c | 5 ++++- src/lxc/storage/zfs.c | 8 ++++---- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/lxc/storage/btrfs.c b/src/lxc/storage/btrfs.c index 22ba1484c..e0b7586c3 100644 --- a/src/lxc/storage/btrfs.c +++ b/src/lxc/storage/btrfs.c @@ -687,11 +687,11 @@ static void free_btrfs_tree(struct my_btrfs_tree *tree) static bool do_remove_btrfs_children(struct my_btrfs_tree *tree, u64 root_id, const char *path) { - int i, ret; + int ret; char *newpath; size_t len; - for (i = 0; i < tree->num; i++) { + for (int i = 0; i < tree->num; i++) { if (tree->nodes[i].parentid == root_id) { if (!tree->nodes[i].dirname) { WARN("Odd condition: child objid with no name under %s", path); @@ -706,7 +706,7 @@ static bool do_remove_btrfs_children(struct my_btrfs_tree *tree, u64 root_id, } ret = snprintf(newpath, len, "%s/%s", path, tree->nodes[i].dirname); - if (ret < 0 || ret >= len) { + if (ret < 0 || (size_t)ret >= len) { free(newpath); return false; } @@ -739,7 +739,7 @@ static int btrfs_lxc_rm_rf(const char *path) struct btrfs_ioctl_search_header sh; struct btrfs_root_ref *ref; struct my_btrfs_tree *tree; - int ret, e, i; + int ret, e; unsigned long off = 0; u16 name_len; u64 dir_id; @@ -802,7 +802,7 @@ static int btrfs_lxc_rm_rf(const char *path) break; off = 0; - for (i = 0; i < sk->nr_items; i++) { + for (size_t i = 0; i < sk->nr_items; i++) { memcpy(&sh, args.buf + off, sizeof(sh)); off += sizeof(sh); diff --git a/src/lxc/storage/lvm.c b/src/lxc/storage/lvm.c index 9c79565e2..ed53bd086 100644 --- a/src/lxc/storage/lvm.c +++ b/src/lxc/storage/lvm.c @@ -275,10 +275,10 @@ int lvm_compare_lv_attr(const char *path, int pos, const char expected) return 0; len = strlen(output); - while (start < len && output[start] == ' ') + while ((size_t)start < len && output[start] == ' ') start++; - if (start + pos < len && output[start + pos] == expected) + if ((size_t)(start + pos) < len && output[start + pos] == expected) return 1; return 0; diff --git a/src/lxc/storage/overlay.c b/src/lxc/storage/overlay.c index 410b4ff5a..c00ebc344 100644 --- a/src/lxc/storage/overlay.c +++ b/src/lxc/storage/overlay.c @@ -116,7 +116,7 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char return log_error_errno(-ENOMEM, ENOMEM, "Failed to allocate memory"); ret = snprintf(new->src, len, "overlay:%s:%s", src, delta); - if (ret < 0 || (size_t)ret >= len) + if (ret < 0 || ret >= len) return log_error_errno(-EIO, EIO, "Failed to create string"); } else if (!strcmp(orig->type, "overlayfs") || !strcmp(orig->type, "overlay")) { @@ -467,7 +467,7 @@ int ovl_mount(struct lxc_storage *bdev) lower, work); } - if (ret < 0 || ret >= len || ret2 < 0 || ret2 >= len2) { + if (ret < 0 || (size_t)ret >= len || ret2 < 0 || (size_t)ret2 >= len2) { ERROR("Failed to create string"); free(mntdata); free(dup); diff --git a/src/lxc/storage/storage_utils.c b/src/lxc/storage/storage_utils.c index de82e4d41..d3548d21b 100644 --- a/src/lxc/storage/storage_utils.c +++ b/src/lxc/storage/storage_utils.c @@ -184,6 +184,8 @@ int detect_fs(struct lxc_storage *bdev, char *type, int len) _exit(EXIT_FAILURE); while (getline(&line, &linelen, f) != -1) { + ssize_t nbytes; + sp1 = strchr(line, ' '); if (!sp1) _exit(EXIT_FAILURE); @@ -203,7 +205,8 @@ int detect_fs(struct lxc_storage *bdev, char *type, int len) *sp3 = '\0'; sp2++; - if (write(p[1], sp2, strlen(sp2)) != strlen(sp2)) + nbytes = write(p[1], sp2, strlen(sp2)); + if (nbytes < 0 || (size_t)nbytes != strlen(sp2)) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); diff --git a/src/lxc/storage/zfs.c b/src/lxc/storage/zfs.c index b209d79e0..6e3c739af 100644 --- a/src/lxc/storage/zfs.c +++ b/src/lxc/storage/zfs.c @@ -380,7 +380,7 @@ bool zfs_snapshot(struct lxc_conf *conf, struct lxc_storage *orig, len -= snapshot_len; ret = snprintf(snapshot + snapshot_len, len, "@%s", snap_name); - if (ret < 0 || ret >= len) { + if (ret < 0 || (size_t)ret >= len) { ERROR("Failed to create string"); free(snapshot); return false; @@ -514,7 +514,7 @@ int zfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, len -= dataset_len - 4; ret = snprintf(new->src + dataset_len + 4, len, "/%s", cname); - if (ret < 0 || ret >= len) { + if (ret < 0 || (size_t)ret >= len) { ERROR("Failed to create string"); return -1; } @@ -539,7 +539,7 @@ int zfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, } ret = snprintf(new->dest, len, "%s/%s/rootfs", lxcpath, cname); - if (ret < 0 || ret >= len) { + if (ret < 0 || (size_t)ret >= len) { ERROR("Failed to create string \"%s/%s/rootfs\"", lxcpath, cname); return -1; } @@ -717,7 +717,7 @@ int zfs_create(struct lxc_storage *bdev, const char *dest, const char *n, } ret = snprintf(bdev->src, len, "zfs:%s/%s", zfsroot, n); - if (ret < 0 || ret >= len) { + if (ret < 0 || (size_t)ret >= len) { ERROR("Failed to create string"); return -1; } From 7e5a9e11e45160c15e0f0ef2d9618900a3a88926 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 09:51:17 +0200 Subject: [PATCH 06/62] attach: fix helper declarations Signed-off-by: Christian Brauner --- src/lxc/attach.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 5668fd035..9c22931d5 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -163,7 +163,7 @@ static inline bool sync_wait_fd(int fd, int *fd_recv) return lxc_abstract_unix_recv_one_fd(fd, fd_recv, NULL, 0) > 0; } -static bool attach_lsm(lxc_attach_options_t *options) +static inline bool attach_lsm(lxc_attach_options_t *options) { return (options->attach_flags & (LXC_ATTACH_LSM | LXC_ATTACH_LSM_LABEL)); } @@ -1797,7 +1797,7 @@ int lxc_attach_run_shell(void* payload) struct passwd pwent; struct passwd *pwentp = NULL; char *user_shell; - size_t bufsize; + ssize_t bufsize; int ret; /* Ignore payload parameter. */ @@ -1806,7 +1806,7 @@ int lxc_attach_run_shell(void* payload) uid = getuid(); bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); - if (bufsize == -1) + if (bufsize < 0) bufsize = 1024; buf = malloc(bufsize); From 961878dac19af1ab6723d05c08bd461eaf4d9b64 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 10:01:51 +0200 Subject: [PATCH 07/62] lsm: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/lsm/apparmor.c | 7 +++---- src/lxc/lsm/selinux.c | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c index 0667526d4..2d81acdc8 100644 --- a/src/lxc/lsm/apparmor.c +++ b/src/lxc/lsm/apparmor.c @@ -406,7 +406,7 @@ static int __apparmor_process_label_open(struct lsm_ops *ops, pid_t pid, int o_f /* first try the apparmor subdir */ ret = snprintf(path, LXC_LSMATTRLEN, "/proc/%d/attr/apparmor/current", pid); - if (ret < 0 || ret >= LXC_LSMATTRLEN) + if (ret < 0 || (size_t)ret >= LXC_LSMATTRLEN) return -1; labelfd = open(path, o_flags); @@ -417,7 +417,7 @@ static int __apparmor_process_label_open(struct lsm_ops *ops, pid_t pid, int o_f /* fallback to legacy global attr directory */ ret = snprintf(path, LXC_LSMATTRLEN, "/proc/%d/attr/current", pid); - if (ret < 0 || ret >= LXC_LSMATTRLEN) + if (ret < 0 || (size_t)ret >= LXC_LSMATTRLEN) return -1; labelfd = open(path, o_flags); @@ -721,13 +721,12 @@ static void append_all_remount_rules(char **profile, size_t *size) const size_t buf_append_pos = strlen(buf); const size_t opt_count = ARRAY_SIZE(REMOUNT_OPTIONS); - size_t opt_bits; must_append_sized(profile, size, "# allow various ro-bind-*re*mounts\n", sizeof("# allow various ro-bind-*re*mounts\n")-1); - for (opt_bits = 0; opt_bits != 1 << opt_count; ++opt_bits) { + for (size_t opt_bits = 0; opt_bits != (size_t)1 << opt_count; ++opt_bits) { size_t at = buf_append_pos; unsigned bit = 1; size_t o; diff --git a/src/lxc/lsm/selinux.c b/src/lxc/lsm/selinux.c index 34987a6c7..e0833f1b7 100644 --- a/src/lxc/lsm/selinux.c +++ b/src/lxc/lsm/selinux.c @@ -136,7 +136,7 @@ static int selinux_process_label_fd_get(struct lsm_ops *ops, pid_t pid, bool on_ ret = snprintf(path, LXC_LSMATTRLEN, "/proc/%d/attr/exec", pid); else ret = snprintf(path, LXC_LSMATTRLEN, "/proc/%d/attr/current", pid); - if (ret < 0 || ret >= LXC_LSMATTRLEN) + if (ret < 0 || (size_t)ret >= LXC_LSMATTRLEN) return -1; labelfd = open(path, O_RDWR); From 02d477ccc6392bf1c9e64d295cb4ce7f6d4a82fd Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 10:14:44 +0200 Subject: [PATCH 08/62] conf: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/conf.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index be9d3072b..1c3cfc3b3 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -2803,7 +2803,7 @@ FILE *make_anonymous_mount_file(const struct list_head *mount_entries, len = strlen(entry->val); ret = lxc_write_nointr(fd, entry->val, len); - if (ret != len) + if (ret < 0 || (size_t)ret != len) return NULL; ret = lxc_write_nointr(fd, "\n", 1); @@ -3438,7 +3438,7 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, return log_error_errno(-1, errno, "Failed to open \"%s\"", path); ret = lxc_write_nointr(fd, buf, buf_size); - if (ret != buf_size) + if (ret < 0 || (size_t)ret != buf_size) return log_error_errno(-1, errno, "Failed to write %cid mapping to \"%s\"", idtype == ID_TYPE_UID ? 'u' : 'g', path); @@ -3509,7 +3509,9 @@ static struct id_map *find_mapped_hostid_entry(const struct list_head *idmap, int lxc_map_ids(struct list_head *idmap, pid_t pid) { - int hostuid, hostgid, fill, left; + int fill, left; + uid_t hostuid; + gid_t hostgid; char u_or_g; char *pos; char cmd_output[PATH_MAX]; @@ -3718,7 +3720,7 @@ static int lxc_transient_proc(struct lxc_rootfs *rootfs) return log_error_errno(-errno, errno, "Failed to create %d(proc)", rootfs->dfd_mnt); goto domount; - } else if (link_len >= sizeof(link)) { + } else if ((size_t)link_len >= sizeof(link)) { return log_error_errno(-EIO, EIO, "Truncated link target"); } link[link_len] = '\0'; @@ -4116,14 +4118,14 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler) if (!info_new->tty) return ret_errno(ENOMEM); - for (int i = 0; i < ttys_max; i++) { + for (size_t i = 0; i < ttys_max; i++) { terminal_info = &info_new->tty[i]; terminal_info->busy = -1; terminal_info->ptx = -EBADF; terminal_info->pty = -EBADF; } - for (int i = 0; i < ttys_max; i++) { + for (size_t i = 0; i < ttys_max; i++) { int ptx = -EBADF, pty = -EBADF; ret = lxc_abstract_unix_recv_two_fds(sock, &ptx, &pty); @@ -5521,11 +5523,11 @@ static char *getuname(void) __do_free char *buf = NULL; struct passwd pwent; struct passwd *pwentp = NULL; - size_t bufsize; + ssize_t bufsize; int ret; bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); - if (bufsize == -1) + if (bufsize < 0) bufsize = 1024; buf = zalloc(bufsize); @@ -5549,11 +5551,11 @@ static char *getgname(void) __do_free char *buf = NULL; struct group grent; struct group *grentp = NULL; - size_t bufsize; + ssize_t bufsize; int ret; bufsize = sysconf(_SC_GETGR_R_SIZE_MAX); - if (bufsize == -1) + if (bufsize < 0) bufsize = 1024; buf = zalloc(bufsize); From a5e92f5dff3cd3e3c62677294f04225016bd105f Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 10:14:55 +0200 Subject: [PATCH 09/62] string_utils: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/string_utils.c | 3 +-- src/lxc/string_utils.h | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c index 372d660cb..95f3f59a3 100644 --- a/src/lxc/string_utils.c +++ b/src/lxc/string_utils.c @@ -1000,10 +1000,9 @@ char *lxc_trim_whitespace_in_place(char *buffer) int lxc_is_line_empty(const char *line) { - int i; size_t len = strlen(line); - for (i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) if (line[i] != ' ' && line[i] != '\t' && line[i] != '\n' && line[i] != '\r' && line[i] != '\f' && line[i] != '\0') diff --git a/src/lxc/string_utils.h b/src/lxc/string_utils.h index 2c1af4a88..7bf4f585a 100644 --- a/src/lxc/string_utils.h +++ b/src/lxc/string_utils.h @@ -151,13 +151,13 @@ static inline char *deabs(char *str) return str + strspn(str, "/"); } -#define strnprintf(buf, buf_size, ...) \ - ({ \ - int __ret_strnprintf; \ - __ret_strnprintf = snprintf(buf, buf_size, ##__VA_ARGS__); \ - if (__ret_strnprintf < 0 || (size_t)__ret_strnprintf >= buf_size) \ - __ret_strnprintf = ret_errno(EIO); \ - __ret_strnprintf; \ +#define strnprintf(buf, buf_size, ...) \ + ({ \ + int __ret_strnprintf; \ + __ret_strnprintf = snprintf(buf, buf_size, ##__VA_ARGS__); \ + if (__ret_strnprintf < 0 || (size_t)__ret_strnprintf >= (size_t)buf_size) \ + __ret_strnprintf = ret_errno(EIO); \ + __ret_strnprintf; \ }) static inline const char *proc_self_fd(int fd) From 1e03cbb1a72934ffdf6cd776059f383010ef9f7c Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 10:21:18 +0200 Subject: [PATCH 10/62] conf: fix struct mount_attr initalization Signed-off-by: Christian Brauner --- src/lxc/conf.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 1c3cfc3b3..8d2be1301 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -885,7 +885,7 @@ static const struct dev_symlinks dev_symlinks[] = { static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs) { - for (int i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) { + for (size_t i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) { int ret; struct stat s; const struct dev_symlinks *d = &dev_symlinks[i]; @@ -974,7 +974,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf) if (!conf->rootfs.path) return 0; - for (int i = 0; i < ttys->max; i++) { + for (size_t i = 0; i < ttys->max; i++) { __do_close int fd_to = -EBADF; struct lxc_terminal_info *tty = &ttys->tty[i]; @@ -982,7 +982,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf) char *tty_name, *tty_path; ret = strnprintf(rootfs->buf, sizeof(rootfs->buf), - "/dev/%s/tty%d", ttydir, i + 1); + "/dev/%s/tty%zu", ttydir, i + 1); if (ret < 0) return ret_errno(-EIO); @@ -1028,7 +1028,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf) rootfs->dfd_dev, tty_name, rootfs->dfd_dev, tty_path); } else { - ret = strnprintf(rootfs->buf, sizeof(rootfs->buf), "tty%d", i + 1); + ret = strnprintf(rootfs->buf, sizeof(rootfs->buf), "tty%zu", i + 1); if (ret < 0) return ret_errno(-EIO); @@ -1107,7 +1107,7 @@ void lxc_delete_tty(struct lxc_tty_info *ttys) if (!ttys || !ttys->tty) return; - for (int i = 0; i < ttys->max; i++) { + for (size_t i = 0; i < ttys->max; i++) { struct lxc_terminal_info *tty = &ttys->tty[i]; close_prot_errno_disarm(tty->ptx); close_prot_errno_disarm(tty->pty); @@ -1118,7 +1118,6 @@ void lxc_delete_tty(struct lxc_tty_info *ttys) static int __lxc_send_ttys_to_parent(struct lxc_handler *handler) { - int i; int ret = -1; struct lxc_conf *conf = handler->conf; struct lxc_tty_info *ttys = &conf->ttys; @@ -1127,7 +1126,7 @@ static int __lxc_send_ttys_to_parent(struct lxc_handler *handler) if (ttys->max == 0) return 0; - for (i = 0; i < ttys->max; i++) { + for (size_t i = 0; i < ttys->max; i++) { int ttyfds[2]; struct lxc_terminal_info *tty = &ttys->tty[i]; @@ -1298,7 +1297,7 @@ enum { static int lxc_fill_autodev(struct lxc_rootfs *rootfs) { - int i, ret; + int ret; mode_t cmask; int use_mknod = LXC_DEVNODE_MKNOD; @@ -1308,7 +1307,7 @@ static int lxc_fill_autodev(struct lxc_rootfs *rootfs) INFO("Populating \"/dev\""); cmask = umask(S_IXUSR | S_IXGRP | S_IXOTH); - for (i = 0; i < sizeof(lxc_devices) / sizeof(lxc_devices[0]); i++) { + for (size_t i = 0; i < sizeof(lxc_devices) / sizeof(lxc_devices[0]); i++) { const struct lxc_device_node *device = &lxc_devices[i]; if (use_mknod >= LXC_DEVNODE_MKNOD) { @@ -2247,7 +2246,7 @@ static int parse_vfs_attr(struct lxc_mount_options *opts, char *opt, size_t size return 0; } - if (mo->flag == ~0) + if (mo->flag == (__u64)~0) return log_info(0, "Ignoring %s mount option", mo->name); if (mo->clear) { @@ -2979,7 +2978,7 @@ static int __lxc_idmapped_mounts_child(struct lxc_handler *handler, FILE *f) /* Set propagation mount options. */ if (opts.attr.propagation) { attr = (struct lxc_mount_attr) { - attr.propagation = opts.attr.propagation, + .propagation = opts.attr.propagation, }; ret = mount_setattr(fd_from, From 622d344d178fbe41a0564c154aa90ab2fe7dabd3 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 10:25:01 +0200 Subject: [PATCH 11/62] conf: fix array initalization Signed-off-by: Christian Brauner --- src/lxc/conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 8d2be1301..c11306dbc 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -185,7 +185,7 @@ static struct mount_opt propagation_opt[] = { { "rshared", 0, true, MS_SHARED, MS_SHARED | MS_REC }, { "rslave", 0, true, MS_SLAVE, MS_SLAVE | MS_REC }, { "runbindable", 0, true, MS_UNBINDABLE, MS_UNBINDABLE | MS_REC }, - { NULL, 0, 0 }, + { NULL, 0, false, 0, 0 }, }; static struct caps_opt caps_opt[] = { From 5eac34d508764b8636842088142f590863b17fb3 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 10:30:16 +0200 Subject: [PATCH 12/62] tree-wide: fix attach header inclusion Signed-off-by: Christian Brauner --- src/lxc/attach.c | 1 + src/lxc/criu.c | 2 ++ src/lxc/start.c | 1 + 3 files changed, 4 insertions(+) diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 9c22931d5..50d2b34ef 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -23,6 +23,7 @@ #include #include +#include #include "af_unix.h" #include "attach.h" diff --git a/src/lxc/criu.c b/src/lxc/criu.c index 9143100fa..f93cfa6be 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -14,6 +14,8 @@ #include #include +#include + #include "cgroup.h" #include "commands.h" #include "conf.h" diff --git a/src/lxc/start.c b/src/lxc/start.c index a96aa27d8..5b7be5130 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -26,6 +26,7 @@ #include #include "af_unix.h" +#include "attach_options.h" #include "caps.h" #include "cgroups/cgroup.h" #include "cgroups/cgroup_utils.h" From 6c7c4a01ab20e7031e46f29a7a699064fd6f67b5 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 10:49:34 +0200 Subject: [PATCH 13/62] confile_utils: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/confile_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index 77627513c..07aabd2de 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -799,7 +799,7 @@ int lxc_get_conf_str(char *retv, int inlen, const char *value) return 0; value_len = strlen(value); - if (retv && inlen >= value_len + 1) + if (retv && (size_t)inlen >= value_len + 1) memcpy(retv, value, value_len + 1); return value_len; From 402770b630533b7a02f3bb662f8e18b1bcd1b637 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 11:03:07 +0200 Subject: [PATCH 14/62] criu: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/criu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxc/criu.c b/src/lxc/criu.c index f93cfa6be..ea21640e5 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -337,7 +337,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, WARN("No cgroup controllers configured in container's cgroup %s", cgroup_base_path); ret = sprintf(buf, "%s", cgroup_base_path); } - if (ret < 0 || ret >= sizeof(buf)) + if (ret < 0 || (size_t)ret >= sizeof(buf)) return log_error_errno(-EIO, EIO, "sprintf of cgroup root arg failed"); DECLARE_ARG("--cgroup-root"); @@ -445,7 +445,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, char ghost_limit[32]; ret = sprintf(ghost_limit, "%"PRIu64, opts->user->ghost_limit); - if (ret < 0 || ret >= sizeof(ghost_limit)) + if (ret < 0 || (size_t)ret >= sizeof(ghost_limit)) return log_error_errno(-EIO, EIO, "Failed to print ghost limit %"PRIu64, opts->user->ghost_limit); DECLARE_ARG("--ghost-limit"); From fd80f8c0fd52998f9e8ee338d2be9e9bd1ea665a Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 11:04:58 +0200 Subject: [PATCH 15/62] commands: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/commands.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 535242f10..4c2f77ada 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -253,14 +253,14 @@ static ssize_t lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) case LXC_CMD_GET_CGROUP_FD: /* data */ __fallthrough; case LXC_CMD_GET_LIMIT_CGROUP_FD: /* data */ - if (rsp->datalen > sizeof(struct cgroup_fd)) + if ((size_t)rsp->datalen > sizeof(struct cgroup_fd)) return syserror_set(-EINVAL, "Invalid response size from server for \"%s\"", cur_cmdstr); /* Don't pointlessly allocate. */ rsp->data = (void *)cmd->req.data; break; case LXC_CMD_GET_CGROUP_CTX: /* data */ - if (rsp->datalen > sizeof(struct cgroup_ctx)) + if ((size_t)rsp->datalen > sizeof(struct cgroup_ctx)) return syserror_set(-EINVAL, "Invalid response size from server for \"%s\"", cur_cmdstr); /* Don't pointlessly allocate. */ @@ -1489,7 +1489,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req, if (log->read) rsp.data = lxc_ringbuf_get_read_addr(buf); - if (log->read_max > 0 && (log->read_max <= rsp.datalen)) + if (log->read_max > 0 && (log->read_max <= (uint64_t)rsp.datalen)) rsp.datalen = log->read_max; /* there's nothing to read */ From cdb4f412ff248f53f6719dfd0af6e0fde54c47e5 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 11:09:02 +0200 Subject: [PATCH 16/62] tree-wide: fix public lxc header inclusions Signed-off-by: Christian Brauner --- src/lxc/attach.c | 3 +-- src/lxc/attach.h | 3 ++- src/lxc/commands_utils.c | 1 + src/lxc/conf.c | 2 +- src/lxc/confile.h | 4 ++-- src/lxc/criu.c | 2 +- src/lxc/freezer.c | 1 + src/tests/rootfs_options.c | 4 ++-- src/tests/sys_mixed.c | 4 ++-- 9 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 50d2b34ef..a1b16607a 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -22,8 +22,7 @@ #include #include -#include -#include +#include "attach.h" #include "af_unix.h" #include "attach.h" diff --git a/src/lxc/attach.h b/src/lxc/attach.h index 66b9796a3..6556bab40 100644 --- a/src/lxc/attach.h +++ b/src/lxc/attach.h @@ -4,9 +4,10 @@ #define __LXC_ATTACH_H #include -#include #include +#include "lxccontainer.h" +#include "attach_options.h" #include "compiler.h" #include "namespace.h" diff --git a/src/lxc/commands_utils.c b/src/lxc/commands_utils.c index b2957b007..6a62d2fcb 100644 --- a/src/lxc/commands_utils.c +++ b/src/lxc/commands_utils.c @@ -13,6 +13,7 @@ #include #include +#include "attach_options.h" #include "af_unix.h" #include "commands.h" #include "commands_utils.h" diff --git a/src/lxc/conf.c b/src/lxc/conf.c index c11306dbc..60ed9aa9e 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -34,11 +34,11 @@ #include #include +#include "conf.h" #include "af_unix.h" #include "caps.h" #include "cgroups/cgroup.h" #include "compiler.h" -#include "conf.h" #include "config.h" #include "confile.h" #include "confile_utils.h" diff --git a/src/lxc/confile.h b/src/lxc/confile.h index 999dc1648..73935a858 100644 --- a/src/lxc/confile.h +++ b/src/lxc/confile.h @@ -6,8 +6,8 @@ #include #include -#include -#include +#include "lxccontainer.h" +#include "attach_options.h" #include "compiler.h" diff --git a/src/lxc/criu.c b/src/lxc/criu.c index ea21640e5..3d61bea6d 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -14,7 +14,7 @@ #include #include -#include +#include "attach_options.h" #include "cgroup.h" #include "commands.h" diff --git a/src/lxc/freezer.c b/src/lxc/freezer.c index 5d2d48978..ef6afa046 100644 --- a/src/lxc/freezer.c +++ b/src/lxc/freezer.c @@ -12,6 +12,7 @@ #include #include +#include "attach_options.h" #include "cgroups/cgroup.h" #include "cgroups/cgroup_utils.h" #include "commands.h" diff --git a/src/tests/rootfs_options.c b/src/tests/rootfs_options.c index c103cbc11..05cb3dda6 100644 --- a/src/tests/rootfs_options.c +++ b/src/tests/rootfs_options.c @@ -32,8 +32,8 @@ #include #include -#include -#include +#include "lxccontainer.h" +#include "attach_options.h" #ifdef HAVE_STATVFS #include diff --git a/src/tests/sys_mixed.c b/src/tests/sys_mixed.c index 785f6e867..9716ac3d0 100644 --- a/src/tests/sys_mixed.c +++ b/src/tests/sys_mixed.c @@ -32,8 +32,8 @@ #include #include -#include -#include +#include "lxccontainer.h" +#include "attach_options.h" #ifdef HAVE_STATVFS #include From 9a064678605777c561251577c6993a7010f9114f Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 11:25:56 +0200 Subject: [PATCH 17/62] network: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxc/network.c b/src/lxc/network.c index 32963a0ea..6c6715d57 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -2518,7 +2518,7 @@ static int ifa_get_local_ip(int family, struct nlmsghdr *msg, void **res) * the address length is correct, but check here just in * case. */ - if (RTA_PAYLOAD(rta) != addrlen) + if (RTA_PAYLOAD(rta) != (unsigned int)addrlen) return -1; /* We might have found an IFA_ADDRESS before, which we @@ -2621,7 +2621,7 @@ static int ip_addr_get(int family, int ifindex, void **res) return ret_errno(EINVAL); ifa = (struct ifaddrmsg *)NLMSG_DATA(msg); - if (ifa->ifa_index == ifindex) { + if (ifa->ifa_index == (__u32)ifindex) { if (ifa_get_local_ip(family, msg, res) < 0) return ret_errno(EINVAL); From 652a1f4ba521f044811fe04c2293fbd3a34ec9c2 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 11:30:01 +0200 Subject: [PATCH 18/62] lxccontainer: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/lxccontainer.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 9ed50894b..401288986 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -1625,13 +1625,12 @@ static bool create_run_template(struct lxc_container *c, char *tpath, static bool prepend_lxc_header(char *path, const char *t, char *const argv[]) { - long flen; - size_t len; + ssize_t len, flen; char *contents; FILE *f; int ret = -1; + ssize_t nbytes; #if HAVE_OPENSSL - int i; unsigned int md_len = 0; unsigned char md_value[EVP_MAX_MD_SIZE]; char *tpath; @@ -1709,7 +1708,7 @@ static bool prepend_lxc_header(char *path, const char *t, char *const argv[]) #if HAVE_OPENSSL fprintf(f, "# Template script checksum (SHA-1): "); - for (i=0; iifa_addr)->sin6_scope_id != scope) + if (((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_scope_id != (uint32_t)scope) continue; address_ptr_tmp = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; @@ -4268,8 +4268,11 @@ static char *get_timestamp(char* snappath, char *name) if (len > 0) { s = malloc(len+1); if (s) { + ssize_t nbytes; + s[len] = '\0'; - if (fread(s, 1, len, fin) != len) + nbytes = fread(s, 1, len, fin); + if (nbytes < 0 || nbytes != (ssize_t)len) return log_error_errno(NULL, errno, "reading timestamp"); } } @@ -5471,13 +5474,13 @@ int list_defined_containers(const char *lxcpath, char ***names, free_bad: if (names && *names) { - for (int i = 0; i < name_array_len; i++) + for (size_t i = 0; i < name_array_len; i++) free((*names)[i]); free(*names); } if (cret && *cret) { - for (int i = 0; i < ct_array_len; i++) + for (size_t i = 0; i < ct_array_len; i++) lxc_container_put((*cret)[i]); free(*cret); } From 8703bf5bdbe6e13311e7cf33220211049343b3e9 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 11:41:25 +0200 Subject: [PATCH 19/62] terminal: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/terminal.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index 543e947bb..a1f974be0 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -270,7 +270,7 @@ static int lxc_terminal_write_log_file(struct lxc_terminal *terminal, char *buf, if (ret < 0) return ret; - if (bytes_read <= terminal->log_size) + if ((uint64_t)bytes_read <= terminal->log_size) return lxc_write_nointr(terminal->log_fd, buf, bytes_read); /* Write as much as we can into the buffer and loose the rest. */ @@ -301,7 +301,7 @@ static int lxc_terminal_write_log_file(struct lxc_terminal *terminal, char *buf, if (ret < 0) return ret; - if (terminal->log_size < bytes_read) { + if (terminal->log_size < (uint64_t)bytes_read) { /* Well, this is unfortunate because it means that there is more * to write than the user has granted us space. There are * multiple ways to handle this but let's use the simplest one: @@ -615,7 +615,7 @@ on_error: int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) { - int ttynum; + size_t ttynum; int ptxfd = -1; struct lxc_tty_info *ttys = &conf->ttys; struct lxc_terminal *terminal = &conf->console; @@ -632,7 +632,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) } if (*ttyreq > 0) { - if (*ttyreq > ttys->max) + if ((size_t)*ttyreq > ttys->max) goto out; if (ttys->tty[*ttyreq - 1].busy >= 0) @@ -652,7 +652,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) if (ttynum > ttys->max) goto out; - *ttyreq = ttynum; + *ttyreq = (int)ttynum; out_tty: ttys->tty[ttynum - 1].busy = sockfd; @@ -664,11 +664,10 @@ out: void lxc_terminal_free(struct lxc_conf *conf, int fd) { - int i; struct lxc_tty_info *ttys = &conf->ttys; struct lxc_terminal *terminal = &conf->console; - for (i = 0; i < ttys->max; i++) + for (size_t i = 0; i < ttys->max; i++) if (ttys->tty[i].busy == fd) ttys->tty[i].busy = -1; From 8f76aa9766de595a319aba5478d61aae8ce7d059 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 11:43:05 +0200 Subject: [PATCH 20/62] utils: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lxc/utils.c b/src/lxc/utils.c index c2cfecf88..aab0dda23 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -356,7 +356,8 @@ int sha1sum_file(char *fnam, unsigned char *digest, unsigned int *md_len) __do_free char *buf = NULL; __do_fclose FILE *f = NULL; int ret; - long flen; + ssize_t flen; + ssize_t nbytes; if (!fnam) return -1; @@ -379,7 +380,8 @@ int sha1sum_file(char *fnam, unsigned char *digest, unsigned int *md_len) if (!buf) return log_error_errno(-1, ENOMEM, "Out of memory"); - if (fread(buf, 1, flen, f) != flen) + nbytes = fread(buf, 1, flen, f); + if (nbytes < 0 || nbytes != flen) return log_error_errno(-1, errno, "Failed to read template"); buf[flen] = '\0'; @@ -1815,7 +1817,7 @@ int fix_stdio_permissions(uid_t uid) if (ret) return log_trace_errno(-errno, errno, "Failed to stat \"/dev/null\""); - for (int i = 0; i < ARRAY_SIZE(std_fds); i++) { + for (size_t i = 0; i < ARRAY_SIZE(std_fds); i++) { ret = fstat(std_fds[i], &st); if (ret) { SYSWARN("Failed to stat standard I/O file descriptor %d", std_fds[i]); @@ -1846,13 +1848,13 @@ int fix_stdio_permissions(uid_t uid) bool multiply_overflow(int64_t base, uint64_t mult, int64_t *res) { - if (base > 0 && base > (INT64_MAX / mult)) + if (base > 0 && base > (int64_t)(INT64_MAX / mult)) return false; - if (base < 0 && base < (INT64_MIN / mult)) + if (base < 0 && base < (int64_t)(INT64_MIN / mult)) return false; - *res = base * mult; + *res = (int64_t)(base * mult); return true; } From a15c3609493356fabc5c9875602ce4890a0d5001 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 11:58:55 +0200 Subject: [PATCH 21/62] start: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/start.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lxc/start.c b/src/lxc/start.c index 5b7be5130..58c4136ea 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -317,7 +317,7 @@ restart: #endif - if (fd <= listen_fds_max) { + if ((size_t)fd <= listen_fds_max) { INFO("Inheriting fd %d (using the LISTEN_FDS environment variable)", fd); continue; } @@ -355,7 +355,7 @@ static int setup_signal_fd(sigset_t *oldmask) if (ret < 0) return -EBADF; - for (int sig = 0; sig < (sizeof(signals) / sizeof(signals[0])); sig++) { + for (size_t sig = 0; sig < (sizeof(signals) / sizeof(signals[0])); sig++) { ret = sigdelset(&mask, signals[sig]); if (ret < 0) return -EBADF; @@ -446,7 +446,7 @@ static int signal_handler(int fd, uint32_t events, void *data, /* More robustness, protect ourself from a SIGCHLD sent * by a process different from the container init. */ - if (siginfo.ssi_pid != hdlr->pid) { + if ((__u64)siginfo.ssi_pid != (__u64)hdlr->pid) { NOTICE("Received %d from pid %d instead of container init %d", siginfo.ssi_signo, siginfo.ssi_pid, hdlr->pid); return hdlr->init_died ? LXC_MAINLOOP_CLOSE From 49bdee73fc66744428b0eaedb0c82778cded1f32 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 12:11:43 +0200 Subject: [PATCH 22/62] netns_ifaddrs: fix integer comparisons Signed-off-by: Christian Brauner --- src/include/netns_ifaddrs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/netns_ifaddrs.c b/src/include/netns_ifaddrs.c index 7ac80e3d6..30040b2b7 100644 --- a/src/include/netns_ifaddrs.c +++ b/src/include/netns_ifaddrs.c @@ -31,7 +31,7 @@ #define __NETLINK_ALIGN(len) (((len) + 3) & ~3) #define __NLMSG_OK(nlh, end) \ - ((char *)(end) - (char *)(nlh) >= sizeof(struct nlmsghdr)) + ((size_t)((char *)(end) - (char *)(nlh)) >= sizeof(struct nlmsghdr)) #define __NLMSG_NEXT(nlh) \ (struct nlmsghdr *)((char *)(nlh) + __NETLINK_ALIGN((nlh)->nlmsg_len)) @@ -50,7 +50,7 @@ (struct rtattr *)((char *)(rta) + __NETLINK_ALIGN((rta)->rta_len)) #define __RTA_OK(nlh, end) \ - ((char *)(end) - (char *)(rta) >= sizeof(struct rtattr)) + ((size_t)((char *)(end) - (char *)(rta)) >= sizeof(struct rtattr)) #define __NLMSG_RTAOK(rta, nlh) __RTA_OK(rta, __NLMSG_DATAEND(nlh)) From 360df02a57c0fda22e5da026429ba9b290b5762a Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 12:12:24 +0200 Subject: [PATCH 23/62] lxcmntent: fix fallthrough Signed-off-by: Christian Brauner --- src/include/lxcmntent.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/include/lxcmntent.c b/src/include/lxcmntent.c index 3d527a963..9661235d4 100644 --- a/src/include/lxcmntent.c +++ b/src/include/lxcmntent.c @@ -125,8 +125,10 @@ struct mntent *getmntent_r(FILE *stream, struct mntent *mp, char *buffer, int bu switch (ret) { case 0: mp->mnt_freq = 0; + break; case 1: mp->mnt_passno = 0; + break; case 2: break; } From 14551c8c82d1173ccc29a7bb8a3b5e8b7006044c Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 12:50:28 +0200 Subject: [PATCH 24/62] seccomp: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/seccomp.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lxc/seccomp.c b/src/lxc/seccomp.c index ff1d6e04e..c2c0928bd 100644 --- a/src/lxc/seccomp.c +++ b/src/lxc/seccomp.c @@ -93,9 +93,9 @@ static const char *get_action_name(uint32_t action) return "invalid action"; } -static uint32_t get_v2_default_action(char *line) +static int32_t get_v2_default_action(char *line) { - uint32_t ret_action = -1; + int32_t ret_action = -1; while (*line == ' ') line++; @@ -129,7 +129,7 @@ static uint32_t get_v2_default_action(char *line) return ret_action; } -static uint32_t get_v2_action(char *line, uint32_t def_action) +static int32_t get_v2_action(char *line, uint32_t def_action) { char *p; uint32_t ret; @@ -264,13 +264,14 @@ static int parse_v2_rules(char *line, uint32_t def_action, return -1; /* read optional action which follows the syscall */ - rules->action = get_v2_action(tmp, def_action); - if (rules->action == -1) { + ret = get_v2_action(tmp, def_action); + if (ret == -1) { ERROR("Failed to interpret action"); - ret = -1; goto on_error; } + rules->action = ret; + ret = 0; rules->args_num = 0; if (!strchr(tmp, '[')) @@ -496,7 +497,7 @@ enum lxc_seccomp_rule_status_t { static enum lxc_seccomp_rule_status_t do_resolve_add_rule(uint32_t arch, char *line, scmp_filter_ctx ctx, struct seccomp_v2_rule *rule) { - int i, nr, ret; + int nr, ret; struct scmp_arg_cmp arg_cmp[6]; ret = seccomp_arch_exist(ctx, arch); @@ -543,8 +544,8 @@ static enum lxc_seccomp_rule_status_t do_resolve_add_rule(uint32_t arch, char *l } memset(&arg_cmp, 0, sizeof(arg_cmp)); - for (i = 0; i < rule->args_num; i++) { - INFO("arg_cmp[%d]: SCMP_CMP(%u, %llu, %llu, %llu)", i, + for (size_t i = 0; i < rule->args_num; i++) { + INFO("arg_cmp[%zu]: SCMP_CMP(%u, %llu, %llu, %llu)", i, rule->args_value[i].index, (long long unsigned int)rule->args_value[i].op, (long long unsigned int)rule->args_value[i].mask, @@ -618,7 +619,7 @@ static int parse_config_v2(FILE *f, char *line, size_t *line_bufsz, struct lxc_c char *p; enum lxc_hostarch_t cur_rule_arch, native_arch; bool denylist = false; - uint32_t default_policy_action = -1, default_rule_action = -1; + int32_t default_policy_action = -1, default_rule_action = -1; struct seccomp_v2_rule rule; struct scmp_ctx_info { uint32_t architectures[3]; From 59366a6156fea45ae9be758598f3830291c5092d Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 12:51:17 +0200 Subject: [PATCH 25/62] uuid: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/uuid.c b/src/lxc/uuid.c index 256225b8f..df8d816fb 100644 --- a/src/lxc/uuid.c +++ b/src/lxc/uuid.c @@ -47,7 +47,7 @@ static int get_random_bytes(void *p, size_t n) return -1; bytes = read(fd, p, n); - if (bytes != n) + if ((size_t)bytes != n) return -1; return 0; From b608dc2f9318a13f771f5a22d849d8e868a3382a Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 12:53:54 +0200 Subject: [PATCH 26/62] nl: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/nl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lxc/nl.c b/src/lxc/nl.c index 81e9cbab4..27f62c50b 100644 --- a/src/lxc/nl.c +++ b/src/lxc/nl.c @@ -42,7 +42,7 @@ static int nla_put(struct nlmsg *nlmsg, int attr, size_t rtalen = RTA_LENGTH(len); size_t tlen = NLMSG_ALIGN(nlmsg->nlmsghdr->nlmsg_len) + RTA_ALIGN(rtalen); - if (tlen > nlmsg->cap) + if (tlen > (size_t)nlmsg->cap) return ret_errno(ENOMEM); rta = NLMSG_TAIL(nlmsg->nlmsghdr); @@ -122,7 +122,7 @@ void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len) size_t nlmsg_len = nlmsg->nlmsghdr->nlmsg_len; size_t tlen = NLMSG_ALIGN(len); - if (nlmsg_len + tlen > nlmsg->cap) + if (nlmsg_len + tlen > (size_t)nlmsg->cap) return ret_set_errno(NULL, ENOMEM); buf = ((char *)(nlmsg->nlmsghdr)) + nlmsg_len; @@ -188,7 +188,7 @@ again: if (!ret) return 0; - if (msg.msg_flags & MSG_TRUNC && (ret == nlmsghdr->nlmsg_len)) + if (msg.msg_flags & MSG_TRUNC && ((__u32)ret == nlmsghdr->nlmsg_len)) return ret_errno(EMSGSIZE); return ret; From d535a483c90373b3395e0eee0fa15b5bb8182cbb Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 12:54:57 +0200 Subject: [PATCH 27/62] monitor: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/monitor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index 1c1d7039a..b01355168 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -224,7 +224,6 @@ int lxc_monitor_open(const char *lxcpath) int lxc_monitor_read_fdset(struct pollfd *fds, nfds_t nfds, struct lxc_msg *msg, int timeout) { - long i; int ret; ret = poll(fds, nfds, timeout * 1000); @@ -236,7 +235,7 @@ int lxc_monitor_read_fdset(struct pollfd *fds, nfds_t nfds, struct lxc_msg *msg, /* Only read from the first ready fd, the others will remain ready for * when this routine is called again. */ - for (i = 0; i < nfds; i++) { + for (size_t i = 0; i < nfds; i++) { if (fds[i].revents != 0) { fds[i].revents = 0; ret = recv(fds[i].fd, msg, sizeof(*msg), 0); @@ -327,8 +326,9 @@ int lxc_monitord_spawn(const char *lxcpath) * synced with the child process. the if-empty-statement * construct is to quiet the warn-unused-result warning. */ - if (lxc_read_nointr(pipefd[0], &c, 1)) + if (lxc_read_nointr(pipefd[0], &c, 1)) { ; + } close(pipefd[0]); From 5e0e7af42adcb8ca5b3d5fe01568e2204bdaee9c Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 12:56:43 +0200 Subject: [PATCH 28/62] file_utils: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/file_utils.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lxc/file_utils.c b/src/lxc/file_utils.c index eaa9a5a40..f7e4fb378 100644 --- a/src/lxc/file_utils.c +++ b/src/lxc/file_utils.c @@ -259,14 +259,19 @@ bool file_exists(const char *f) int print_to_file(const char *file, const char *content) { __do_fclose FILE *f = NULL; - int ret = 0; + int ret; + size_t len; f = fopen(file, "we"); if (!f) return -1; - if (fprintf(f, "%s", content) != strlen(content)) + len = strlen(content); + ret = fprintf(f, "%s", content); + if (ret < 0 || (size_t)ret != len) ret = -1; + else + ret = 0; return ret; } @@ -593,8 +598,7 @@ FILE *fdopen_at(int dfd, const char *path, const char *mode, int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset) { __do_close int fd = -EBADF; - int ret; - ssize_t len; + ssize_t len, ret; char buf[INTTYPE_TO_STRLEN(int) + STRLITERALLEN(" ") + INTTYPE_TO_STRLEN(int64_t) + STRLITERALLEN(" ") + INTTYPE_TO_STRLEN(int64_t) + 1]; @@ -611,7 +615,7 @@ int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset) return ret_errno(EFBIG); ret = lxc_write_nointr(fd, buf, len); - if (ret < 0 || (size_t)ret != len) + if (ret < 0 || ret != len) return -EIO; return 0; From 60a8b99b8971eb80f2cf3e8ca0bf423dfd0fa0cb Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 12:57:07 +0200 Subject: [PATCH 29/62] commands_utils: fix integer comparisons Signed-off-by: Christian Brauner --- src/lxc/commands_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/commands_utils.c b/src/lxc/commands_utils.c index 6a62d2fcb..8f77880e6 100644 --- a/src/lxc/commands_utils.c +++ b/src/lxc/commands_utils.c @@ -130,7 +130,7 @@ int lxc_make_abstract_socket_name(char *path, size_t pathlen, * ret >= len. This means lxcpath and name are too long. We need to * hash both. */ - if (ret >= len) { + if ((size_t)ret >= len) { tmplen = strlen(name) + strlen(lxcpath) + 2; tmppath = must_realloc(NULL, tmplen); ret = strnprintf(tmppath, tmplen, "%s/%s", lxcpath, name); From b53f80d4dee9b5f9ffc932bae1f31db0a507aec9 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:09:43 +0200 Subject: [PATCH 30/62] arguments: fix includes Signed-off-by: Christian Brauner --- src/lxc/tools/arguments.c | 10 ++++------ src/lxc/tools/arguments.h | 5 +++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/lxc/tools/arguments.c b/src/lxc/tools/arguments.c index 447031fc0..eb0336367 100644 --- a/src/lxc/tools/arguments.c +++ b/src/lxc/tools/arguments.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -13,11 +12,10 @@ #include #include -#include -#include +#include "lxccontainer.h" +#include "version.h" #include "arguments.h" -#include "compiler.h" #include "config.h" #include "initutils.h" #include "namespace.h" diff --git a/src/lxc/tools/arguments.h b/src/lxc/tools/arguments.h index 0af6f3332..e49913740 100644 --- a/src/lxc/tools/arguments.h +++ b/src/lxc/tools/arguments.h @@ -3,14 +3,15 @@ #ifndef __LXC_ARGUMENTS_H #define __LXC_ARGUMENTS_H +#include "config.h" + #include #include #include #include #include -#include - +#include "lxccontainer.h" #include "compiler.h" struct lxc_arguments; From b4e5e90b8ba9c5b3b124f20cf900903c6fcce04d Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:09:56 +0200 Subject: [PATCH 31/62] string_utils: fix includes Signed-off-by: Christian Brauner --- src/lxc/string_utils.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c index 95f3f59a3..e2bc9fe48 100644 --- a/src/lxc/string_utils.c +++ b/src/lxc/string_utils.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */ +#include "config.h" + #include #include #include @@ -26,13 +24,9 @@ #include #include -#include "config.h" -#include "lxclock.h" +#include "string_utils.h" #include "macro.h" #include "memory_utils.h" -#include "namespace.h" -#include "parse.h" -#include "string_utils.h" #ifndef HAVE_STRLCPY #include "strlcpy.h" From 481f03ef254e745dd1a162fa26d94f5e8b676066 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:10:16 +0200 Subject: [PATCH 32/62] conf: fix includes Signed-off-by: Christian Brauner --- src/lxc/conf.c | 6 ++---- src/lxc/conf.h | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 60ed9aa9e..aecd94228 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -39,7 +38,6 @@ #include "caps.h" #include "cgroups/cgroup.h" #include "compiler.h" -#include "config.h" #include "confile.h" #include "confile_utils.h" #include "error.h" diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 24bf1b71b..636b9017d 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -3,9 +3,8 @@ #ifndef __LXC_CONF_H #define __LXC_CONF_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -18,7 +17,6 @@ #include "attach_options.h" #include "caps.h" #include "compiler.h" -#include "config.h" #include "hlist.h" #include "list.h" #include "lxcseccomp.h" From 443dd10a0828deb747a5dbea8bda8df601699cd8 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:10:35 +0200 Subject: [PATCH 33/62] initutils: fix includes Signed-off-by: Christian Brauner --- src/lxc/initutils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lxc/initutils.h b/src/lxc/initutils.h index e99de13af..35ff377c1 100644 --- a/src/lxc/initutils.h +++ b/src/lxc/initutils.h @@ -3,6 +3,8 @@ #ifndef __LXC_INITUTILS_H #define __LXC_INITUTILS_H +#include "config.h" + #include #include #include @@ -15,7 +17,6 @@ #include #include -#include "config.h" #include "cgroups/cgroup.h" #include "compiler.h" #include "string_utils.h" From 30cf580be54ac2251e104a4cecccff6fecf5d7a2 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:10:44 +0200 Subject: [PATCH 34/62] log: fix includes Signed-off-by: Christian Brauner --- src/lxc/log.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lxc/log.h b/src/lxc/log.h index 8ee5f9862..b3aecf9cb 100644 --- a/src/lxc/log.h +++ b/src/lxc/log.h @@ -3,9 +3,8 @@ #ifndef __LXC_LOG_H #define __LXC_LOG_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -18,7 +17,6 @@ #include "compiler.h" #include "conf.h" -#include "config.h" #ifndef O_CLOEXEC #define O_CLOEXEC 02000000 From ab908541fa176be875fa9aa4cd1122ecdf98af31 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:11:39 +0200 Subject: [PATCH 35/62] initutils: fix includes Signed-off-by: Christian Brauner --- src/lxc/initutils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lxc/initutils.h b/src/lxc/initutils.h index 35ff377c1..814365122 100644 --- a/src/lxc/initutils.h +++ b/src/lxc/initutils.h @@ -17,7 +17,6 @@ #include #include -#include "cgroups/cgroup.h" #include "compiler.h" #include "string_utils.h" From 5de879e6a51f056d1120d49f7013c4c46941f64b Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:12:09 +0200 Subject: [PATCH 36/62] arguments: fix includes Signed-off-by: Christian Brauner --- src/lxc/tools/arguments.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lxc/tools/arguments.c b/src/lxc/tools/arguments.c index eb0336367..9b16a9409 100644 --- a/src/lxc/tools/arguments.c +++ b/src/lxc/tools/arguments.c @@ -16,7 +16,6 @@ #include "version.h" #include "arguments.h" -#include "config.h" #include "initutils.h" #include "namespace.h" From f614b9f43d520b0ab2ba54a2fb6a69ff3d80ba36 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:13:12 +0200 Subject: [PATCH 37/62] tools/lxc_start: fix includes Signed-off-by: Christian Brauner --- src/lxc/tools/lxc_start.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c index 459b86793..f3c990783 100644 --- a/src/lxc/tools/lxc_start.c +++ b/src/lxc/tools/lxc_start.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -20,11 +19,11 @@ #include #include -#include +#include "lxccontainer.h" +#include "attach_options.h" #include "arguments.h" #include "caps.h" -#include "config.h" #include "confile.h" #include "log.h" From 924c626a94ce32ba77a35e14a4658761b92b3805 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:14:16 +0200 Subject: [PATCH 38/62] caps: fix includes Signed-off-by: Christian Brauner --- src/lxc/caps.c | 6 ++---- src/lxc/caps.h | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lxc/caps.c b/src/lxc/caps.c index b3ab37a1f..e464042d8 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -11,7 +10,6 @@ #include #include "caps.h" -#include "config.h" #include "file_utils.h" #include "log.h" #include "macro.h" diff --git a/src/lxc/caps.h b/src/lxc/caps.h index c3e2c6d21..2f8d802fd 100644 --- a/src/lxc/caps.h +++ b/src/lxc/caps.h @@ -3,9 +3,10 @@ #ifndef __LXC_CAPS_H #define __LXC_CAPS_H +#include "config.h" + #include -#include "config.h" #include "compiler.h" #if HAVE_LIBCAP From 12ae2a33c683a42f3e780f18007d8b1c374539d5 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 17:05:12 +0200 Subject: [PATCH 39/62] tree-wide: fix lxc header inclusion Signed-off-by: Christian Brauner --- src/lxc/attach.h | 4 ++-- src/lxc/cmd/lxc_init.c | 4 ++-- src/lxc/cmd/lxc_monitord.c | 2 +- src/lxc/commands.h | 5 ++++- src/lxc/confile.h | 3 +-- src/lxc/confile_utils.c | 3 ++- src/lxc/criu.h | 2 +- src/lxc/log.c | 3 ++- src/lxc/lxc.h | 4 ++++ src/lxc/lxccontainer.c | 3 ++- src/lxc/lxclock.c | 2 +- src/lxc/seccomp.c | 3 ++- src/lxc/start.c | 3 ++- src/lxc/storage/overlay.c | 3 ++- src/lxc/storage/storage.h | 2 +- src/lxc/terminal.c | 3 ++- src/lxc/tools/arguments.c | 3 +-- src/lxc/tools/arguments.h | 2 +- src/lxc/tools/lxc_attach.c | 2 +- src/lxc/tools/lxc_autostart.c | 2 +- src/lxc/tools/lxc_cgroup.c | 2 +- src/lxc/tools/lxc_checkpoint.c | 2 +- src/lxc/tools/lxc_config.c | 2 +- src/lxc/tools/lxc_console.c | 2 +- src/lxc/tools/lxc_copy.c | 2 +- src/lxc/tools/lxc_create.c | 2 +- src/lxc/tools/lxc_destroy.c | 2 +- src/lxc/tools/lxc_device.c | 2 +- src/lxc/tools/lxc_execute.c | 2 +- src/lxc/tools/lxc_freeze.c | 2 +- src/lxc/tools/lxc_info.c | 2 +- src/lxc/tools/lxc_ls.c | 2 +- src/lxc/tools/lxc_monitor.c | 2 +- src/lxc/tools/lxc_snapshot.c | 2 +- src/lxc/tools/lxc_start.c | 3 +-- src/lxc/tools/lxc_stop.c | 2 +- src/lxc/tools/lxc_top.c | 2 +- src/lxc/tools/lxc_unfreeze.c | 2 +- src/lxc/tools/lxc_wait.c | 2 +- 39 files changed, 54 insertions(+), 43 deletions(-) diff --git a/src/lxc/attach.h b/src/lxc/attach.h index 6556bab40..d9b356bbf 100644 --- a/src/lxc/attach.h +++ b/src/lxc/attach.h @@ -6,8 +6,8 @@ #include #include -#include "lxccontainer.h" -#include "attach_options.h" +#include "lxc.h" + #include "compiler.h" #include "namespace.h" diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c index f8a0bc23d..6491e2406 100644 --- a/src/lxc/cmd/lxc_init.c +++ b/src/lxc/cmd/lxc_init.c @@ -16,8 +16,8 @@ #include #include -#include -#include +#include "lxc.h" +#include "version.h" #include "compiler.h" #include "config.h" diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c index a18712b64..8f3ef023f 100644 --- a/src/lxc/cmd/lxc_monitord.c +++ b/src/lxc/cmd/lxc_monitord.c @@ -21,7 +21,7 @@ #include #include -#include +#include "lxc.h" #include "af_unix.h" #include "config.h" diff --git a/src/lxc/commands.h b/src/lxc/commands.h index 8d93bbd3a..b4aac93a0 100644 --- a/src/lxc/commands.h +++ b/src/lxc/commands.h @@ -3,14 +3,17 @@ #ifndef __LXC_COMMANDS_H #define __LXC_COMMANDS_H +#include "config.h" + #include #include #include #include +#include "lxc.h" + #include "compiler.h" #include "cgroups/cgroup.h" -#include "lxccontainer.h" #include "macro.h" #include "state.h" diff --git a/src/lxc/confile.h b/src/lxc/confile.h index 73935a858..f085d1e22 100644 --- a/src/lxc/confile.h +++ b/src/lxc/confile.h @@ -6,8 +6,7 @@ #include #include -#include "lxccontainer.h" -#include "attach_options.h" +#include "lxc.h" #include "compiler.h" diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index 07aabd2de..ae05ddac3 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -9,6 +9,8 @@ #include #include +#include "lxc.h" + #include "conf.h" #include "config.h" #include "confile.h" @@ -17,7 +19,6 @@ #include "list.h" #include "lxc.h" #include "log.h" -#include "lxccontainer.h" #include "macro.h" #include "memory_utils.h" #include "network.h" diff --git a/src/lxc/criu.h b/src/lxc/criu.h index 2e0ca7feb..234f79b79 100644 --- a/src/lxc/criu.h +++ b/src/lxc/criu.h @@ -5,7 +5,7 @@ #include -#include +#include "lxc.h" __hidden extern bool __criu_pre_dump(struct lxc_container *c, struct migrate_opts *opts); __hidden extern bool __criu_dump(struct lxc_container *c, struct migrate_opts *opts); diff --git a/src/lxc/log.c b/src/lxc/log.c index 9c5053ec9..781cc2fa5 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -18,11 +18,12 @@ #include #include +#include "lxc.h" + #include "caps.h" #include "config.h" #include "file_utils.h" #include "log.h" -#include "lxccontainer.h" #include "memory_utils.h" #include "utils.h" diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index f688b25c2..9cf8da67a 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -12,6 +12,10 @@ extern "C" { #include #include +#include "attach_options.h" +#include "lxccontainer.h" +#include "version.h" + #include "compiler.h" #include "memory_utils.h" #include "state.h" diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 401288986..e51a1c463 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -25,6 +25,8 @@ #include #include +#include "lxc.h" + #include "netns_ifaddrs.h" #include "af_unix.h" #include "api_extensions.h" @@ -42,7 +44,6 @@ #include "initutils.h" #include "log.h" #include "lxc.h" -#include "lxccontainer.h" #include "lxclock.h" #include "memory_utils.h" #include "monitor.h" diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c index a6a43cef2..12be6ef00 100644 --- a/src/lxc/lxclock.c +++ b/src/lxc/lxclock.c @@ -12,7 +12,7 @@ #include #include -#include +#include "lxc.h" #include "config.h" #include "log.h" diff --git a/src/lxc/seccomp.c b/src/lxc/seccomp.c index c2c0928bd..2b9ecaf69 100644 --- a/src/lxc/seccomp.c +++ b/src/lxc/seccomp.c @@ -11,11 +11,12 @@ #include #include +#include "lxc.h" + #include "af_unix.h" #include "commands.h" #include "config.h" #include "log.h" -#include "lxccontainer.h" #include "lxcseccomp.h" #include "mainloop.h" #include "memory_utils.h" diff --git a/src/lxc/start.c b/src/lxc/start.c index 58c4136ea..252fc8a8a 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -25,6 +25,8 @@ #include #include +#include "lxc.h" + #include "af_unix.h" #include "attach_options.h" #include "caps.h" @@ -41,7 +43,6 @@ #include "list.h" #include "log.h" #include "lsm/lsm.h" -#include "lxccontainer.h" #include "lxclock.h" #include "lxcseccomp.h" #include "macro.h" diff --git a/src/lxc/storage/overlay.c b/src/lxc/storage/overlay.c index c00ebc344..86c21a96d 100644 --- a/src/lxc/storage/overlay.c +++ b/src/lxc/storage/overlay.c @@ -8,11 +8,12 @@ #include #include +#include "lxc.h" + #include "conf.h" #include "config.h" #include "confile.h" #include "log.h" -#include "lxccontainer.h" #include "macro.h" #include "memory_utils.h" #include "overlay.h" diff --git a/src/lxc/storage/storage.h b/src/lxc/storage/storage.h index 0f14fd260..62ac75e26 100644 --- a/src/lxc/storage/storage.h +++ b/src/lxc/storage/storage.h @@ -6,7 +6,7 @@ #include #include -#include +#include "lxc.h" #if IS_BIONIC #include "lxcmntent.h" diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index a1f974be0..b86d8c59a 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -5,7 +5,6 @@ #endif #include #include -#include #include #include #include @@ -15,6 +14,8 @@ #include #include +#include "lxc.h" + #include "af_unix.h" #include "caps.h" #include "commands.h" diff --git a/src/lxc/tools/arguments.c b/src/lxc/tools/arguments.c index 9b16a9409..4176db0e7 100644 --- a/src/lxc/tools/arguments.c +++ b/src/lxc/tools/arguments.c @@ -12,8 +12,7 @@ #include #include -#include "lxccontainer.h" -#include "version.h" +#include "lxc.h" #include "arguments.h" #include "initutils.h" diff --git a/src/lxc/tools/arguments.h b/src/lxc/tools/arguments.h index e49913740..0f0875079 100644 --- a/src/lxc/tools/arguments.h +++ b/src/lxc/tools/arguments.h @@ -11,7 +11,7 @@ #include #include -#include "lxccontainer.h" +#include "lxc.h" #include "compiler.h" struct lxc_arguments; diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c index e6b388b20..6a9ac817b 100644 --- a/src/lxc/tools/lxc_attach.c +++ b/src/lxc/tools/lxc_attach.c @@ -15,7 +15,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "attach.h" diff --git a/src/lxc/tools/lxc_autostart.c b/src/lxc/tools/lxc_autostart.c index ecede5c34..4a5031810 100644 --- a/src/lxc/tools/lxc_autostart.c +++ b/src/lxc/tools/lxc_autostart.c @@ -8,7 +8,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_cgroup.c b/src/lxc/tools/lxc_cgroup.c index 17975152d..edfc03c28 100644 --- a/src/lxc/tools/lxc_cgroup.c +++ b/src/lxc/tools/lxc_cgroup.c @@ -10,7 +10,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_checkpoint.c b/src/lxc/tools/lxc_checkpoint.c index 4fd25f75b..22abf1866 100644 --- a/src/lxc/tools/lxc_checkpoint.c +++ b/src/lxc/tools/lxc_checkpoint.c @@ -10,7 +10,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_config.c b/src/lxc/tools/lxc_config.c index dda2db6dc..333dde54f 100644 --- a/src/lxc/tools/lxc_config.c +++ b/src/lxc/tools/lxc_config.c @@ -6,7 +6,7 @@ #include #include -#include +#include "lxc.h" #include "config.h" diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c index 3e35fe4aa..d11827121 100644 --- a/src/lxc/tools/lxc_console.c +++ b/src/lxc/tools/lxc_console.c @@ -17,7 +17,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_copy.c b/src/lxc/tools/lxc_copy.c index 94b339f63..384a7e3c8 100644 --- a/src/lxc/tools/lxc_copy.c +++ b/src/lxc/tools/lxc_copy.c @@ -18,7 +18,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_create.c b/src/lxc/tools/lxc_create.c index 368d0d0a5..6af554031 100644 --- a/src/lxc/tools/lxc_create.c +++ b/src/lxc/tools/lxc_create.c @@ -11,7 +11,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_destroy.c b/src/lxc/tools/lxc_destroy.c index e2e5f9843..581460ae4 100644 --- a/src/lxc/tools/lxc_destroy.c +++ b/src/lxc/tools/lxc_destroy.c @@ -10,7 +10,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "log.h" diff --git a/src/lxc/tools/lxc_device.c b/src/lxc/tools/lxc_device.c index 62d5ac86e..ed69cdfd7 100644 --- a/src/lxc/tools/lxc_device.c +++ b/src/lxc/tools/lxc_device.c @@ -10,7 +10,7 @@ #include #include -#include +#include "lxc.h" #include "netns_ifaddrs.h" #include "arguments.h" diff --git a/src/lxc/tools/lxc_execute.c b/src/lxc/tools/lxc_execute.c index 6352114ec..a706d94db 100644 --- a/src/lxc/tools/lxc_execute.c +++ b/src/lxc/tools/lxc_execute.c @@ -14,7 +14,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "caps.h" diff --git a/src/lxc/tools/lxc_freeze.c b/src/lxc/tools/lxc_freeze.c index 483d3aca3..cf5ff6162 100644 --- a/src/lxc/tools/lxc_freeze.c +++ b/src/lxc/tools/lxc_freeze.c @@ -9,7 +9,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_info.c b/src/lxc/tools/lxc_info.c index fda811fd8..12b2562d3 100644 --- a/src/lxc/tools/lxc_info.c +++ b/src/lxc/tools/lxc_info.c @@ -12,7 +12,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_ls.c b/src/lxc/tools/lxc_ls.c index 562622c4d..cc64f8732 100644 --- a/src/lxc/tools/lxc_ls.c +++ b/src/lxc/tools/lxc_ls.c @@ -19,7 +19,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_monitor.c b/src/lxc/tools/lxc_monitor.c index 326b8e7e0..2ecc55c43 100644 --- a/src/lxc/tools/lxc_monitor.c +++ b/src/lxc/tools/lxc_monitor.c @@ -23,7 +23,7 @@ #include #include -#include +#include "lxc.h" #include "af_unix.h" #include "arguments.h" diff --git a/src/lxc/tools/lxc_snapshot.c b/src/lxc/tools/lxc_snapshot.c index a3c058abd..a920a595c 100644 --- a/src/lxc/tools/lxc_snapshot.c +++ b/src/lxc/tools/lxc_snapshot.c @@ -12,7 +12,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c index f3c990783..6d2c0ae25 100644 --- a/src/lxc/tools/lxc_start.c +++ b/src/lxc/tools/lxc_start.c @@ -19,8 +19,7 @@ #include #include -#include "lxccontainer.h" -#include "attach_options.h" +#include "lxc.h" #include "arguments.h" #include "caps.h" diff --git a/src/lxc/tools/lxc_stop.c b/src/lxc/tools/lxc_stop.c index 73ae61766..e3cecb6b2 100644 --- a/src/lxc/tools/lxc_stop.c +++ b/src/lxc/tools/lxc_stop.c @@ -9,7 +9,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c index 9cf2cbbbd..35fe76b5a 100644 --- a/src/lxc/tools/lxc_top.c +++ b/src/lxc/tools/lxc_top.c @@ -18,7 +18,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_unfreeze.c b/src/lxc/tools/lxc_unfreeze.c index e8e2f3180..e5b287289 100644 --- a/src/lxc/tools/lxc_unfreeze.c +++ b/src/lxc/tools/lxc_unfreeze.c @@ -9,7 +9,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" diff --git a/src/lxc/tools/lxc_wait.c b/src/lxc/tools/lxc_wait.c index b5ce3e13f..27f8020d7 100644 --- a/src/lxc/tools/lxc_wait.c +++ b/src/lxc/tools/lxc_wait.c @@ -11,7 +11,7 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "config.h" From 09618fb8abd37b6bec5d691904799ef937a503b6 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 17:29:04 +0200 Subject: [PATCH 40/62] tools: fix build warnings Signed-off-by: Christian Brauner --- src/lxc/tools/lxc_monitor.c | 5 +++-- src/lxc/tools/lxc_unshare.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lxc/tools/lxc_monitor.c b/src/lxc/tools/lxc_monitor.c index 2ecc55c43..aeb5ed8d0 100644 --- a/src/lxc/tools/lxc_monitor.c +++ b/src/lxc/tools/lxc_monitor.c @@ -185,8 +185,9 @@ static int lxc_tool_monitord_spawn(const char *lxcpath) * synced with the child process. the if-empty-statement * construct is to quiet the warn-unused-result warning. */ - if (lxc_read_nointr(pipefd[0], &c, 1)) + if (lxc_read_nointr(pipefd[0], &c, 1)) { ; + } close(pipefd[0]); @@ -207,7 +208,7 @@ static int lxc_tool_monitord_spawn(const char *lxcpath) close(pipefd[0]); ret = snprintf(pipefd_str, sizeof(pipefd_str), "%d", pipefd[1]); - if (ret < 0 || ret >= sizeof(pipefd_str)) { + if (ret < 0 || (size_t)ret >= sizeof(pipefd_str)) { ERROR("Failed to create pid argument to pass to monitord"); _exit(EXIT_FAILURE); } diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index a0ef5f618..c77ac70e7 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -149,14 +149,14 @@ static bool lookup_user(const char *oparg, uid_t *uid) struct passwd pwent; struct passwd *pwentp = NULL; char *buf; - size_t bufsize; + ssize_t bufsize; int ret; if (!oparg || (oparg[0] == '\0')) return false; bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); - if (bufsize == -1) + if (bufsize < 0) bufsize = 1024; buf = malloc(bufsize); From 1160ce891d285f666fbae3fe97bfd73078dd84d6 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 17:47:49 +0200 Subject: [PATCH 41/62] tree-wide: fix config.h inclusion Signed-off-by: Christian Brauner --- src/lxc/af_unix.c | 6 ++---- src/lxc/af_unix.h | 2 ++ src/lxc/api_extensions.h | 4 ++-- src/lxc/attach.c | 6 ++---- src/lxc/attach.h | 2 ++ src/lxc/cgroups/cgfsng.c | 4 ---- src/lxc/cgroups/cgroup.c | 6 ++---- src/lxc/cgroups/cgroup.h | 2 ++ src/lxc/cgroups/cgroup2_devices.c | 6 ++---- src/lxc/cgroups/cgroup2_devices.h | 3 ++- src/lxc/cgroups/cgroup_utils.c | 6 ++---- src/lxc/cgroups/cgroup_utils.h | 2 ++ src/lxc/commands.c | 6 ++---- src/lxc/commands_utils.c | 7 ++----- src/lxc/commands_utils.h | 2 ++ src/lxc/compiler.h | 6 +----- src/lxc/confile.c | 8 ++------ src/lxc/confile.h | 2 ++ src/lxc/confile_utils.c | 6 ++---- src/lxc/confile_utils.h | 2 ++ src/lxc/criu.c | 6 ++---- src/lxc/criu.h | 2 ++ src/lxc/error.c | 2 ++ src/lxc/error_utils.h | 2 ++ src/lxc/execute.c | 6 ++---- src/lxc/file_utils.c | 6 ++---- src/lxc/file_utils.h | 2 ++ src/lxc/freezer.c | 6 ++---- src/lxc/initutils.c | 6 ++---- src/lxc/list.h | 2 ++ src/lxc/log.c | 7 ++----- src/lxc/lsm/apparmor.c | 6 ++---- src/lxc/lsm/lsm.c | 6 ++---- src/lxc/lsm/lsm.h | 2 ++ src/lxc/lsm/nop.c | 6 ++---- src/lxc/lsm/selinux.c | 6 ++---- src/lxc/lxc.h | 2 ++ src/lxc/lxccontainer.c | 6 ++---- src/lxc/lxccontainer.h | 2 ++ src/lxc/lxclock.c | 6 ++---- src/lxc/lxclock.h | 2 ++ src/lxc/lxcseccomp.h | 6 ++---- src/lxc/macro.h | 7 ++----- src/lxc/mainloop.c | 6 ++---- src/lxc/mainloop.h | 2 ++ src/lxc/memory_utils.h | 2 ++ src/lxc/monitor.c | 6 ++---- src/lxc/monitor.h | 2 ++ src/lxc/mount_utils.c | 5 ++--- src/lxc/mount_utils.h | 2 ++ src/lxc/namespace.c | 6 ++---- src/lxc/namespace.h | 2 ++ src/lxc/network.c | 6 ++---- src/lxc/network.h | 2 ++ src/lxc/nl.c | 6 ++---- src/lxc/nl.h | 2 ++ src/lxc/pam/pam_cgfs.c | 6 ++---- src/lxc/parse.c | 6 ++---- src/lxc/parse.h | 2 ++ src/lxc/process_utils.c | 6 ++---- src/lxc/process_utils.h | 6 ++---- src/lxc/rexec.c | 6 ++---- src/lxc/rexec.h | 2 ++ src/lxc/ringbuf.c | 7 ++----- src/lxc/ringbuf.h | 2 ++ src/lxc/rtnl.c | 6 ++---- src/lxc/rtnl.h | 2 ++ src/lxc/seccomp.c | 6 ++---- src/lxc/start.c | 6 ++---- src/lxc/start.h | 2 ++ src/lxc/state.c | 6 ++---- src/lxc/state.h | 2 ++ src/lxc/storage/btrfs.c | 6 ++---- src/lxc/storage/btrfs.h | 2 ++ src/lxc/storage/dir.c | 6 ++---- src/lxc/storage/dir.h | 2 ++ src/lxc/storage/loop.c | 7 ++----- src/lxc/storage/loop.h | 2 ++ src/lxc/storage/lvm.c | 7 ++----- src/lxc/storage/lvm.h | 2 ++ src/lxc/storage/nbd.c | 6 ++---- src/lxc/storage/nbd.h | 2 ++ src/lxc/storage/overlay.c | 6 ++---- src/lxc/storage/overlay.h | 2 ++ src/lxc/storage/rbd.c | 7 ++----- src/lxc/storage/rbd.h | 2 ++ src/lxc/storage/rsync.c | 6 ++---- src/lxc/storage/rsync.h | 2 ++ src/lxc/storage/storage.c | 6 ++---- src/lxc/storage/storage.h | 2 ++ src/lxc/storage/storage_utils.c | 6 ++---- src/lxc/storage/storage_utils.h | 2 ++ src/lxc/storage/zfs.c | 6 ++---- src/lxc/storage/zfs.h | 2 ++ src/lxc/string_utils.h | 4 ++-- src/lxc/sync.c | 6 ++---- src/lxc/sync.h | 2 ++ src/lxc/syscall_numbers.h | 5 ++--- src/lxc/syscall_wrappers.h | 6 ++---- src/lxc/terminal.c | 6 ++---- src/lxc/terminal.h | 2 ++ src/lxc/tools/lxc_attach.c | 6 ++---- src/lxc/tools/lxc_autostart.c | 6 ++---- src/lxc/tools/lxc_cgroup.c | 6 ++---- src/lxc/tools/lxc_checkpoint.c | 6 ++---- src/lxc/tools/lxc_config.c | 7 ++----- src/lxc/tools/lxc_console.c | 6 ++---- src/lxc/tools/lxc_copy.c | 6 ++---- src/lxc/tools/lxc_create.c | 6 ++---- src/lxc/tools/lxc_device.c | 6 ++---- src/lxc/tools/lxc_execute.c | 6 ++---- src/lxc/tools/lxc_freeze.c | 6 ++---- src/lxc/tools/lxc_info.c | 6 ++---- src/lxc/tools/lxc_ls.c | 7 ++----- src/lxc/tools/lxc_monitor.c | 7 ++----- src/lxc/tools/lxc_snapshot.c | 6 ++---- src/lxc/tools/lxc_stop.c | 6 ++---- src/lxc/tools/lxc_top.c | 7 ++----- src/lxc/tools/lxc_unfreeze.c | 6 ++---- src/lxc/tools/lxc_unshare.c | 6 ++---- src/lxc/tools/lxc_wait.c | 6 ++---- 121 files changed, 239 insertions(+), 321 deletions(-) diff --git a/src/lxc/af_unix.c b/src/lxc/af_unix.c index 4f8e2fad6..7dae44c59 100644 --- a/src/lxc/af_unix.c +++ b/src/lxc/af_unix.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -15,7 +14,6 @@ #include #include "af_unix.h" -#include "config.h" #include "log.h" #include "macro.h" #include "memory_utils.h" diff --git a/src/lxc/af_unix.h b/src/lxc/af_unix.h index 77c115a3b..ba119cffc 100644 --- a/src/lxc/af_unix.h +++ b/src/lxc/af_unix.h @@ -3,6 +3,8 @@ #ifndef __LXC_AF_UNIX_H #define __LXC_AF_UNIX_H +#include "config.h" + #include #include #include diff --git a/src/lxc/api_extensions.h b/src/lxc/api_extensions.h index 04e37fd54..bdffa649f 100644 --- a/src/lxc/api_extensions.h +++ b/src/lxc/api_extensions.h @@ -3,11 +3,11 @@ #ifndef __LXC_API_EXTENSIONS_H #define __LXC_API_EXTENSIONS_H +#include "config.h" + #include #include -#include "config.h" - /* * api_extensions is the list of all API extensions in the order they were * added. diff --git a/src/lxc/attach.c b/src/lxc/attach.c index a1b16607a..93a1162eb 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -31,7 +30,6 @@ #include "cgroups/cgroup_utils.h" #include "commands.h" #include "conf.h" -#include "config.h" #include "confile.h" #include "log.h" #include "lsm/lsm.h" diff --git a/src/lxc/attach.h b/src/lxc/attach.h index d9b356bbf..c85b84fbe 100644 --- a/src/lxc/attach.h +++ b/src/lxc/attach.h @@ -3,6 +3,8 @@ #ifndef __LXC_ATTACH_H #define __LXC_ATTACH_H +#include "config.h" + #include #include diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 3103263b3..b111f521c 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -14,10 +14,6 @@ #include "config.h" -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif - #include #include #include diff --git a/src/lxc/cgroups/cgroup.c b/src/lxc/cgroups/cgroup.c index aef7ad84d..8f6e49e04 100644 --- a/src/lxc/cgroups/cgroup.c +++ b/src/lxc/cgroups/cgroup.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include "cgroup2_devices.h" #include "compiler.h" #include "conf.h" -#include "config.h" #include "initutils.h" #include "memory_utils.h" #include "log.h" diff --git a/src/lxc/cgroups/cgroup.h b/src/lxc/cgroups/cgroup.h index 42285ff40..d26559d11 100644 --- a/src/lxc/cgroups/cgroup.h +++ b/src/lxc/cgroups/cgroup.h @@ -3,6 +3,8 @@ #ifndef __LXC_CGROUP_H #define __LXC_CGROUP_H +#include "config.h" + #include #include #include diff --git a/src/lxc/cgroups/cgroup2_devices.c b/src/lxc/cgroups/cgroup2_devices.c index 5ccd35fd8..480859ccc 100644 --- a/src/lxc/cgroups/cgroup2_devices.c +++ b/src/lxc/cgroups/cgroup2_devices.c @@ -2,9 +2,8 @@ /* Parts of this taken from systemd's implementation. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -16,7 +15,6 @@ #include #include "cgroup2_devices.h" -#include "config.h" #include "file_utils.h" #include "log.h" #include "macro.h" diff --git a/src/lxc/cgroups/cgroup2_devices.h b/src/lxc/cgroups/cgroup2_devices.h index 31896d292..4b0fb7362 100644 --- a/src/lxc/cgroups/cgroup2_devices.h +++ b/src/lxc/cgroups/cgroup2_devices.h @@ -5,6 +5,8 @@ #ifndef __LXC_CGROUP2_DEVICES_H #define __LXC_CGROUP2_DEVICES_H +#include "config.h" + #include #include #include @@ -18,7 +20,6 @@ #include "cgroup.h" #include "compiler.h" #include "conf.h" -#include "config.h" #include "list.h" #include "macro.h" #include "memory_utils.h" diff --git a/src/lxc/cgroups/cgroup_utils.c b/src/lxc/cgroups/cgroup_utils.c index 78bd9ecb0..c5fb91c2f 100644 --- a/src/lxc/cgroups/cgroup_utils.c +++ b/src/lxc/cgroups/cgroup_utils.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -11,7 +10,6 @@ #include "cgroup.h" #include "cgroup_utils.h" -#include "config.h" #include "file_utils.h" #include "log.h" #include "macro.h" diff --git a/src/lxc/cgroups/cgroup_utils.h b/src/lxc/cgroups/cgroup_utils.h index b18621d30..5b23e912f 100644 --- a/src/lxc/cgroups/cgroup_utils.h +++ b/src/lxc/cgroups/cgroup_utils.h @@ -3,6 +3,8 @@ #ifndef __LXC_CGROUP_UTILS_H #define __LXC_CGROUP_UTILS_H +#include "config.h" + #include #include diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 4c2f77ada..4b52ff736 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -22,7 +21,6 @@ #include "commands.h" #include "commands_utils.h" #include "conf.h" -#include "config.h" #include "confile.h" #include "log.h" #include "lxc.h" diff --git a/src/lxc/commands_utils.c b/src/lxc/commands_utils.c index 8f77880e6..3558ff7e2 100644 --- a/src/lxc/commands_utils.c +++ b/src/lxc/commands_utils.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */ +#include "config.h" + #include #include #include @@ -17,7 +15,6 @@ #include "af_unix.h" #include "commands.h" #include "commands_utils.h" -#include "config.h" #include "file_utils.h" #include "initutils.h" #include "log.h" diff --git a/src/lxc/commands_utils.h b/src/lxc/commands_utils.h index 0bdf7a2e8..28ce4907a 100644 --- a/src/lxc/commands_utils.h +++ b/src/lxc/commands_utils.h @@ -3,6 +3,8 @@ #ifndef __LXC_COMMANDS_UTILS_H #define __LXC_COMMANDS_UTILS_H +#include "config.h" + #include #include "state.h" diff --git a/src/lxc/compiler.h b/src/lxc/compiler.h index 4b2fc1b3a..ec071dc83 100644 --- a/src/lxc/compiler.h +++ b/src/lxc/compiler.h @@ -3,15 +3,11 @@ #ifndef __LXC_COMPILER_H #define __LXC_COMPILER_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" #include #include -#include "config.h" - #ifndef thread_local #if __STDC_VERSION__ >= 201112L && \ !(defined(__STDC_NO_THREADS__) || \ diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 6b1cfd4be..f4cb4b5e2 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS +#include "config.h" + #include #include #include @@ -26,7 +24,6 @@ #include "af_unix.h" #include "conf.h" -#include "config.h" #include "confile.h" #include "confile_utils.h" #include "netns_ifaddrs.h" @@ -36,7 +33,6 @@ #include "memory_utils.h" #include "network.h" #include "parse.h" -#include "storage/storage.h" #include "utils.h" #ifndef HAVE_STRLCPY diff --git a/src/lxc/confile.h b/src/lxc/confile.h index f085d1e22..d9b20c64e 100644 --- a/src/lxc/confile.h +++ b/src/lxc/confile.h @@ -3,6 +3,8 @@ #ifndef __LXC_CONFILE_H #define __LXC_CONFILE_H +#include "config.h" + #include #include diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index ae05ddac3..5534daa41 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include "lxc.h" #include "conf.h" -#include "config.h" #include "confile.h" #include "confile_utils.h" #include "error.h" diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h index 7dae2aec7..ed7418dd6 100644 --- a/src/lxc/confile_utils.h +++ b/src/lxc/confile_utils.h @@ -3,6 +3,8 @@ #ifndef __LXC_CONFILE_UTILS_H #define __LXC_CONFILE_UTILS_H +#include "config.h" + #include #include "compiler.h" diff --git a/src/lxc/criu.c b/src/lxc/criu.c index 3d61bea6d..3ee736922 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -19,7 +18,6 @@ #include "cgroup.h" #include "commands.h" #include "conf.h" -#include "config.h" #include "criu.h" #include "log.h" #include "lxc.h" diff --git a/src/lxc/criu.h b/src/lxc/criu.h index 234f79b79..873f88786 100644 --- a/src/lxc/criu.h +++ b/src/lxc/criu.h @@ -3,6 +3,8 @@ #ifndef __LXC_CRIU_H #define __LXC_CRIU_H +#include "config.h" + #include #include "lxc.h" diff --git a/src/lxc/error.c b/src/lxc/error.c index 51fe5092a..a3467d517 100644 --- a/src/lxc/error.c +++ b/src/lxc/error.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ +#include "config.h" + #include #include #include diff --git a/src/lxc/error_utils.h b/src/lxc/error_utils.h index ac0860d4f..614dd344a 100644 --- a/src/lxc/error_utils.h +++ b/src/lxc/error_utils.h @@ -3,6 +3,8 @@ #ifndef __LXC_ERROR_UTILS_H #define __LXC_ERROR_UTILS_H +#include "config.h" + #include #include "macro.h" diff --git a/src/lxc/execute.c b/src/lxc/execute.c index 346e127ab..6a7ae39f4 100644 --- a/src/lxc/execute.c +++ b/src/lxc/execute.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -11,7 +10,6 @@ #include #include "conf.h" -#include "config.h" #include "log.h" #include "start.h" #include "process_utils.h" diff --git a/src/lxc/file_utils.c b/src/lxc/file_utils.c index f7e4fb378..ca31690e4 100644 --- a/src/lxc/file_utils.c +++ b/src/lxc/file_utils.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -13,7 +12,6 @@ #include #include -#include "config.h" #include "file_utils.h" #include "macro.h" #include "memory_utils.h" diff --git a/src/lxc/file_utils.h b/src/lxc/file_utils.h index c9765da50..7d2af0128 100644 --- a/src/lxc/file_utils.h +++ b/src/lxc/file_utils.h @@ -3,6 +3,8 @@ #ifndef __LXC_FILE_UTILS_H #define __LXC_FILE_UTILS_H +#include "config.h" + #include #include #include diff --git a/src/lxc/freezer.c b/src/lxc/freezer.c index ef6afa046..718fbff39 100644 --- a/src/lxc/freezer.c +++ b/src/lxc/freezer.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -17,7 +16,6 @@ #include "cgroups/cgroup_utils.h" #include "commands.h" #include "commands_utils.h" -#include "config.h" #include "error.h" #include "log.h" #include "lxc.h" diff --git a/src/lxc/initutils.c b/src/lxc/initutils.c index 397e94692..218125c1a 100644 --- a/src/lxc/initutils.c +++ b/src/lxc/initutils.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -11,7 +10,6 @@ #include #include "compiler.h" -#include "config.h" #include "error.h" #include "file_utils.h" #include "initutils.h" diff --git a/src/lxc/list.h b/src/lxc/list.h index c984af451..3b363a9b6 100644 --- a/src/lxc/list.h +++ b/src/lxc/list.h @@ -3,6 +3,8 @@ #ifndef __LXC_LIST_H #define __LXC_LIST_H +#include "config.h" + #include #include "memory_utils.h" diff --git a/src/lxc/log.c b/src/lxc/log.c index 781cc2fa5..ac3713ecc 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */ +#include "config.h" + #include #include #include @@ -21,7 +19,6 @@ #include "lxc.h" #include "caps.h" -#include "config.h" #include "file_utils.h" #include "log.h" #include "memory_utils.h" diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c index 2d81acdc8..fa4e4d6e0 100644 --- a/src/lxc/lsm/apparmor.c +++ b/src/lxc/lsm/apparmor.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -15,7 +14,6 @@ #include "caps.h" #include "cgroups/cgroup_utils.h" #include "conf.h" -#include "config.h" #include "initutils.h" #include "file_utils.h" #include "log.h" diff --git a/src/lxc/lsm/lsm.c b/src/lxc/lsm/lsm.c index f6692e4ee..d9380c4b3 100644 --- a/src/lxc/lsm/lsm.c +++ b/src/lxc/lsm/lsm.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -11,7 +10,6 @@ #include "compiler.h" #include "conf.h" -#include "config.h" #include "log.h" #include "lsm.h" diff --git a/src/lxc/lsm/lsm.h b/src/lxc/lsm/lsm.h index bb6a7e93c..a26abb812 100644 --- a/src/lxc/lsm/lsm.h +++ b/src/lxc/lsm/lsm.h @@ -3,6 +3,8 @@ #ifndef __LXC_LSM_H #define __LXC_LSM_H +#include "config.h" + struct lxc_conf; #include diff --git a/src/lxc/lsm/nop.c b/src/lxc/lsm/nop.c index ff9c4b86e..56b97aaf0 100644 --- a/src/lxc/lsm/nop.c +++ b/src/lxc/lsm/nop.c @@ -1,11 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include -#include "config.h" #include "lsm/lsm.h" static char *nop_process_label_get(struct lsm_ops *ops, pid_t pid) diff --git a/src/lxc/lsm/selinux.c b/src/lxc/lsm/selinux.c index e0833f1b7..7a34b9cc4 100644 --- a/src/lxc/lsm/selinux.c +++ b/src/lxc/lsm/selinux.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include #include "conf.h" -#include "config.h" #include "file_utils.h" #include "log.h" #include "lsm.h" diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index 9cf8da67a..8ba9f62a6 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -3,6 +3,8 @@ #ifndef __LXC_LXC_H #define __LXC_LXC_H +#include "config.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index e51a1c463..ac4b312c0 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -36,7 +35,6 @@ #include "commands.h" #include "commands_utils.h" #include "conf.h" -#include "config.h" #include "confile.h" #include "confile_utils.h" #include "criu.h" diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h index 3386bfff6..2663d5e24 100644 --- a/src/lxc/lxccontainer.h +++ b/src/lxc/lxccontainer.h @@ -3,6 +3,8 @@ #ifndef __LXC_CONTAINER_H #define __LXC_CONTAINER_H +#include "config.h" + #include #include #include diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c index 12be6ef00..acddc1380 100644 --- a/src/lxc/lxclock.c +++ b/src/lxc/lxclock.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -14,7 +13,6 @@ #include "lxc.h" -#include "config.h" #include "log.h" #include "lxclock.h" #include "memory_utils.h" diff --git a/src/lxc/lxclock.h b/src/lxc/lxclock.h index 38f49b5b4..a20d35680 100644 --- a/src/lxc/lxclock.h +++ b/src/lxc/lxclock.h @@ -3,6 +3,8 @@ #ifndef __LXC_LXCLOCK_H #define __LXC_LXCLOCK_H +#include "config.h" + #include #include #include diff --git a/src/lxc/lxcseccomp.h b/src/lxc/lxcseccomp.h index 41293bcea..070dcaf5a 100644 --- a/src/lxc/lxcseccomp.h +++ b/src/lxc/lxcseccomp.h @@ -3,9 +3,8 @@ #ifndef __LXC_LXCSECCOMP_H #define __LXC_LXCSECCOMP_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #ifdef HAVE_SECCOMP #include @@ -18,7 +17,6 @@ #include "compiler.h" #include "conf.h" -#include "config.h" #include "memory_utils.h" struct lxc_conf; diff --git a/src/lxc/macro.h b/src/lxc/macro.h index 2780c7454..9054c326c 100644 --- a/src/lxc/macro.h +++ b/src/lxc/macro.h @@ -3,10 +3,8 @@ #ifndef __LXC_MACRO_H #define __LXC_MACRO_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS +#include "config.h" + #include #include #include @@ -22,7 +20,6 @@ #include #include "compiler.h" -#include "config.h" #ifndef PATH_MAX #define PATH_MAX 4096 diff --git a/src/lxc/mainloop.c b/src/lxc/mainloop.c index 69152a897..ba20224ae 100644 --- a/src/lxc/mainloop.c +++ b/src/lxc/mainloop.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include #include -#include "config.h" #include "log.h" #include "macro.h" #include "mainloop.h" diff --git a/src/lxc/mainloop.h b/src/lxc/mainloop.h index 0197ee2dd..6d6d38cf8 100644 --- a/src/lxc/mainloop.h +++ b/src/lxc/mainloop.h @@ -3,6 +3,8 @@ #ifndef __LXC_MAINLOOP_H #define __LXC_MAINLOOP_H +#include "config.h" + #include #include "compiler.h" diff --git a/src/lxc/memory_utils.h b/src/lxc/memory_utils.h index f2352a175..757fa49d9 100644 --- a/src/lxc/memory_utils.h +++ b/src/lxc/memory_utils.h @@ -3,6 +3,8 @@ #ifndef __LXC_MEMORY_UTILS_H #define __LXC_MEMORY_UTILS_H +#include "config.h" + #include #include #include diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index b01355168..c9d4bcc9e 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -22,7 +21,6 @@ #include #include "af_unix.h" -#include "config.h" #include "error.h" #include "log.h" #include "lxclock.h" diff --git a/src/lxc/monitor.h b/src/lxc/monitor.h index 0f89e4ff6..ae1dcdf16 100644 --- a/src/lxc/monitor.h +++ b/src/lxc/monitor.h @@ -3,6 +3,8 @@ #ifndef __LXC_MONITOR_H #define __LXC_MONITOR_H +#include "config.h" + #include #include #include diff --git a/src/lxc/mount_utils.c b/src/lxc/mount_utils.c index 945de8c1a..bba75f933 100644 --- a/src/lxc/mount_utils.c +++ b/src/lxc/mount_utils.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include diff --git a/src/lxc/mount_utils.h b/src/lxc/mount_utils.h index 7d6857866..ea392672d 100644 --- a/src/lxc/mount_utils.h +++ b/src/lxc/mount_utils.h @@ -3,6 +3,8 @@ #ifndef __LXC_MOUNT_UTILS_H #define __LXC_MOUNT_UTILS_H +#include "config.h" + #include #include #include diff --git a/src/lxc/namespace.c b/src/lxc/namespace.c index 020840d01..d97d9b37b 100644 --- a/src/lxc/namespace.c +++ b/src/lxc/namespace.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -13,7 +12,6 @@ #include #include -#include "config.h" #include "log.h" #include "memory_utils.h" #include "namespace.h" diff --git a/src/lxc/namespace.h b/src/lxc/namespace.h index a744edb78..587e00b3a 100644 --- a/src/lxc/namespace.h +++ b/src/lxc/namespace.h @@ -3,6 +3,8 @@ #ifndef __LXC_NAMESPACE_H #define __LXC_NAMESPACE_H +#include "config.h" + #include #include #include diff --git a/src/lxc/network.c b/src/lxc/network.c index 6c6715d57..654561d44 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -29,7 +28,6 @@ #include "netns_ifaddrs.h" #include "af_unix.h" #include "conf.h" -#include "config.h" #include "file_utils.h" #include "log.h" #include "macro.h" diff --git a/src/lxc/network.h b/src/lxc/network.h index 2b5c0901c..d5d3d54b6 100644 --- a/src/lxc/network.h +++ b/src/lxc/network.h @@ -3,6 +3,8 @@ #ifndef __LXC_NETWORK_H #define __LXC_NETWORK_H +#include "config.h" + #include #include #include diff --git a/src/lxc/nl.c b/src/lxc/nl.c index 27f62c50b..63cbf5ac5 100644 --- a/src/lxc/nl.c +++ b/src/lxc/nl.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -13,7 +12,6 @@ #include #include -#include "config.h" #include "log.h" #include "nl.h" diff --git a/src/lxc/nl.h b/src/lxc/nl.h index 1135d1f66..28058bc0e 100644 --- a/src/lxc/nl.h +++ b/src/lxc/nl.h @@ -3,6 +3,8 @@ #ifndef __LXC_NL_H #define __LXC_NL_H +#include "config.h" + #include #include "compiler.h" diff --git a/src/lxc/pam/pam_cgfs.c b/src/lxc/pam/pam_cgfs.c index 91efe5c80..01167fa47 100644 --- a/src/lxc/pam/pam_cgfs.c +++ b/src/lxc/pam/pam_cgfs.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -23,7 +22,6 @@ #include #include -#include "config.h" #include "file_utils.h" #include "macro.h" #include "memory_utils.h" diff --git a/src/lxc/parse.c b/src/lxc/parse.c index 5a5b85345..c174de96c 100644 --- a/src/lxc/parse.c +++ b/src/lxc/parse.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include #include -#include "config.h" #include "file_utils.h" #include "log.h" #include "macro.h" diff --git a/src/lxc/parse.h b/src/lxc/parse.h index e4808ed0f..fe3bb4b78 100644 --- a/src/lxc/parse.h +++ b/src/lxc/parse.h @@ -3,6 +3,8 @@ #ifndef __LXC_PARSE_H #define __LXC_PARSE_H +#include "config.h" + #include #include diff --git a/src/lxc/process_utils.c b/src/lxc/process_utils.c index 3dadeb7d7..76e27da0f 100644 --- a/src/lxc/process_utils.c +++ b/src/lxc/process_utils.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include #include "compiler.h" -#include "config.h" #include "log.h" #include "macro.h" #include "process_utils.h" diff --git a/src/lxc/process_utils.h b/src/lxc/process_utils.h index e0157c631..2a5032c03 100644 --- a/src/lxc/process_utils.h +++ b/src/lxc/process_utils.h @@ -3,9 +3,8 @@ #ifndef __LXC_PROCESS_UTILS_H #define __LXC_PROCESS_UTILS_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -16,7 +15,6 @@ #include #include "compiler.h" -#include "config.h" #include "syscall_numbers.h" #ifndef CSIGNAL diff --git a/src/lxc/rexec.c b/src/lxc/rexec.c index 2d6345651..ee0b453db 100644 --- a/src/lxc/rexec.c +++ b/src/lxc/rexec.c @@ -1,15 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include #include #include -#include "config.h" #include "file_utils.h" #include "macro.h" #include "memory_utils.h" diff --git a/src/lxc/rexec.h b/src/lxc/rexec.h index 198d6cb08..c4967b08c 100644 --- a/src/lxc/rexec.h +++ b/src/lxc/rexec.h @@ -3,6 +3,8 @@ #ifndef __LXC_REXEC_H #define __LXC_REXEC_H +#include "config.h" + #include "compiler.h" __hidden extern int lxc_rexec(const char *memfd_name); diff --git a/src/lxc/ringbuf.c b/src/lxc/ringbuf.c index 43f363656..37ffc8f39 100644 --- a/src/lxc/ringbuf.c +++ b/src/lxc/ringbuf.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS +#include "config.h" + #include #include #include @@ -13,7 +11,6 @@ #include #include -#include "config.h" #include "ringbuf.h" #include "syscall_wrappers.h" #include "utils.h" diff --git a/src/lxc/ringbuf.h b/src/lxc/ringbuf.h index 889b6e65c..bd9a4de1e 100644 --- a/src/lxc/ringbuf.h +++ b/src/lxc/ringbuf.h @@ -3,6 +3,8 @@ #ifndef __LXC_RINGBUF_H #define __LXC_RINGBUF_H +#include "config.h" + #include #include #include diff --git a/src/lxc/rtnl.c b/src/lxc/rtnl.c index cea7336c1..d1fe585e8 100644 --- a/src/lxc/rtnl.c +++ b/src/lxc/rtnl.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include #include -#include "config.h" #include "nl.h" #include "rtnl.h" diff --git a/src/lxc/rtnl.h b/src/lxc/rtnl.h index bfe66db05..5578c6f62 100644 --- a/src/lxc/rtnl.h +++ b/src/lxc/rtnl.h @@ -3,6 +3,8 @@ #ifndef __LXC_RTNL_H #define __LXC_RTNL_H +#include "config.h" + #include /* diff --git a/src/lxc/seccomp.c b/src/lxc/seccomp.c index 2b9ecaf69..6c56b8d0f 100644 --- a/src/lxc/seccomp.c +++ b/src/lxc/seccomp.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -15,7 +14,6 @@ #include "af_unix.h" #include "commands.h" -#include "config.h" #include "log.h" #include "lxcseccomp.h" #include "mainloop.h" diff --git a/src/lxc/start.c b/src/lxc/start.c index 252fc8a8a..4eed60a21 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -36,7 +35,6 @@ #include "commands_utils.h" #include "compiler.h" #include "conf.h" -#include "config.h" #include "confile_utils.h" #include "error.h" #include "file_utils.h" diff --git a/src/lxc/start.h b/src/lxc/start.h index e3aa0e95e..86b4c29a4 100644 --- a/src/lxc/start.h +++ b/src/lxc/start.h @@ -3,6 +3,8 @@ #ifndef __LXC_START_H #define __LXC_START_H +#include "config.h" + #include #include #include diff --git a/src/lxc/state.c b/src/lxc/state.c index 0682b35da..5e26855d9 100644 --- a/src/lxc/state.c +++ b/src/lxc/state.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -19,7 +18,6 @@ #include "cgroup.h" #include "commands.h" #include "commands_utils.h" -#include "config.h" #include "log.h" #include "lxc.h" #include "monitor.h" diff --git a/src/lxc/state.h b/src/lxc/state.h index afb2fbb78..39a6f962d 100644 --- a/src/lxc/state.h +++ b/src/lxc/state.h @@ -3,6 +3,8 @@ #ifndef __LXC_STATE_H #define __LXC_STATE_H +#include "config.h" + #include "compiler.h" #define MAX_STATE_LENGTH (8 + 1) diff --git a/src/lxc/storage/btrfs.c b/src/lxc/storage/btrfs.c index e0b7586c3..270eb057e 100644 --- a/src/lxc/storage/btrfs.c +++ b/src/lxc/storage/btrfs.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -18,7 +17,6 @@ #include #include "btrfs.h" -#include "config.h" #include "log.h" #include "memory_utils.h" #include "rsync.h" diff --git a/src/lxc/storage/btrfs.h b/src/lxc/storage/btrfs.h index 210a4e21d..72849f943 100644 --- a/src/lxc/storage/btrfs.h +++ b/src/lxc/storage/btrfs.h @@ -3,6 +3,8 @@ #ifndef __LXC_BTRFS_H #define __LXC_BTRFS_H +#include "config.h" + #include #include /* __le64, __l32 ... */ #include diff --git a/src/lxc/storage/dir.c b/src/lxc/storage/dir.c index 03ad036d5..dca510140 100644 --- a/src/lxc/storage/dir.c +++ b/src/lxc/storage/dir.c @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include -#include "config.h" #include "log.h" #include "macro.h" #include "memory_utils.h" diff --git a/src/lxc/storage/dir.h b/src/lxc/storage/dir.h index 24d8c53ff..c74e369cf 100644 --- a/src/lxc/storage/dir.h +++ b/src/lxc/storage/dir.h @@ -3,6 +3,8 @@ #ifndef __LXC_DIR_H #define __LXC_DIR_H +#include "config.h" + #include #include diff --git a/src/lxc/storage/loop.c b/src/lxc/storage/loop.c index eebc1b67c..870b84c52 100644 --- a/src/lxc/storage/loop.c +++ b/src/lxc/storage/loop.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS +#include "config.h" + #include #include #include @@ -15,7 +13,6 @@ #include #include -#include "config.h" #include "log.h" #include "loop.h" #include "memory_utils.h" diff --git a/src/lxc/storage/loop.h b/src/lxc/storage/loop.h index 9b04f09b2..c9be261ab 100644 --- a/src/lxc/storage/loop.h +++ b/src/lxc/storage/loop.h @@ -3,6 +3,8 @@ #ifndef __LXC_LOOP_H #define __LXC_LOOP_H +#include "config.h" + #include #include diff --git a/src/lxc/storage/lvm.c b/src/lxc/storage/lvm.c index ed53bd086..208dcc9d0 100644 --- a/src/lxc/storage/lvm.c +++ b/src/lxc/storage/lvm.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS +#include "config.h" + #include #include #include @@ -13,7 +11,6 @@ #include #include -#include "config.h" #include "log.h" #include "lvm.h" #include "memory_utils.h" diff --git a/src/lxc/storage/lvm.h b/src/lxc/storage/lvm.h index 8d3dd6a9f..7351e1a3a 100644 --- a/src/lxc/storage/lvm.h +++ b/src/lxc/storage/lvm.h @@ -3,6 +3,8 @@ #ifndef __LXC_LVM_H #define __LXC_LVM_H +#include "config.h" + #include #include diff --git a/src/lxc/storage/nbd.c b/src/lxc/storage/nbd.c index 06515b833..e27a98102 100644 --- a/src/lxc/storage/nbd.c +++ b/src/lxc/storage/nbd.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include #include -#include "config.h" #include "log.h" #include "memory_utils.h" #include "nbd.h" diff --git a/src/lxc/storage/nbd.h b/src/lxc/storage/nbd.h index f6e4fb87c..f9c538663 100644 --- a/src/lxc/storage/nbd.h +++ b/src/lxc/storage/nbd.h @@ -3,6 +3,8 @@ #ifndef __LXC_NBD_H #define __LXC_NBD_H +#include "config.h" + #include #include diff --git a/src/lxc/storage/overlay.c b/src/lxc/storage/overlay.c index 86c21a96d..f8094fada 100644 --- a/src/lxc/storage/overlay.c +++ b/src/lxc/storage/overlay.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -11,7 +10,6 @@ #include "lxc.h" #include "conf.h" -#include "config.h" #include "confile.h" #include "log.h" #include "macro.h" diff --git a/src/lxc/storage/overlay.h b/src/lxc/storage/overlay.h index bed876e80..a33961792 100644 --- a/src/lxc/storage/overlay.h +++ b/src/lxc/storage/overlay.h @@ -3,6 +3,8 @@ #ifndef __LXC_OVERLAY_H #define __LXC_OVERLAY_H +#include "config.h" + #include #include #include diff --git a/src/lxc/storage/rbd.c b/src/lxc/storage/rbd.c index f387ac21a..e1505e264 100644 --- a/src/lxc/storage/rbd.c +++ b/src/lxc/storage/rbd.c @@ -1,16 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */ +#include "config.h" + #include /* Required for PRIu64 to work. */ #include #include #include #include -#include "config.h" #include "log.h" #include "memory_utils.h" #include "storage.h" diff --git a/src/lxc/storage/rbd.h b/src/lxc/storage/rbd.h index 56bfcb214..45f299ad7 100644 --- a/src/lxc/storage/rbd.h +++ b/src/lxc/storage/rbd.h @@ -3,6 +3,8 @@ #ifndef __LXC_RDB_H #define __LXC_RDB_H +#include "config.h" + #include #include diff --git a/src/lxc/storage/rsync.c b/src/lxc/storage/rsync.c index c02a3f95d..572fe4a1b 100644 --- a/src/lxc/storage/rsync.c +++ b/src/lxc/storage/rsync.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -13,7 +12,6 @@ #include #include -#include "config.h" #include "log.h" #include "rsync.h" #include "storage.h" diff --git a/src/lxc/storage/rsync.h b/src/lxc/storage/rsync.h index c9e3210a1..ab30311c5 100644 --- a/src/lxc/storage/rsync.h +++ b/src/lxc/storage/rsync.h @@ -3,6 +3,8 @@ #ifndef __LXC_RSYNC_H #define __LXC_RSYNC_H +#include "config.h" + #include #include "compiler.h" diff --git a/src/lxc/storage/storage.c b/src/lxc/storage/storage.c index e40ecee1f..8fb8fe6b4 100644 --- a/src/lxc/storage/storage.c +++ b/src/lxc/storage/storage.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -22,7 +21,6 @@ #include "btrfs.h" #include "conf.h" -#include "config.h" #include "dir.h" #include "error.h" #include "log.h" diff --git a/src/lxc/storage/storage.h b/src/lxc/storage/storage.h index 62ac75e26..001a39c36 100644 --- a/src/lxc/storage/storage.h +++ b/src/lxc/storage/storage.h @@ -3,6 +3,8 @@ #ifndef __LXC_STORAGE_H #define __LXC_STORAGE_H +#include "config.h" + #include #include diff --git a/src/lxc/storage/storage_utils.c b/src/lxc/storage/storage_utils.c index d3548d21b..f50682159 100644 --- a/src/lxc/storage/storage_utils.c +++ b/src/lxc/storage/storage_utils.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -21,7 +20,6 @@ #include #include -#include "config.h" #include "log.h" #include "nbd.h" #include "parse.h" diff --git a/src/lxc/storage/storage_utils.h b/src/lxc/storage/storage_utils.h index 470e754c9..1ec9e0c3c 100644 --- a/src/lxc/storage/storage_utils.h +++ b/src/lxc/storage/storage_utils.h @@ -3,6 +3,8 @@ #ifndef __LXC_STORAGE_UTILS_H #define __LXC_STORAGE_UTILS_H +#include "config.h" + #include #include #include diff --git a/src/lxc/storage/zfs.c b/src/lxc/storage/zfs.c index 6e3c739af..8a9bc16f2 100644 --- a/src/lxc/storage/zfs.c +++ b/src/lxc/storage/zfs.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -11,7 +10,6 @@ #include #include -#include "config.h" #include "log.h" #include "parse.h" #include "rsync.h" diff --git a/src/lxc/storage/zfs.h b/src/lxc/storage/zfs.h index da8f66bec..9890d377e 100644 --- a/src/lxc/storage/zfs.h +++ b/src/lxc/storage/zfs.h @@ -3,6 +3,8 @@ #ifndef __LXC_ZFS_H #define __LXC_ZFS_H +#include "config.h" + #include #include #include diff --git a/src/lxc/string_utils.h b/src/lxc/string_utils.h index 7bf4f585a..7abbc537f 100644 --- a/src/lxc/string_utils.h +++ b/src/lxc/string_utils.h @@ -3,10 +3,10 @@ #ifndef __LXC_STRING_UTILS_H #define __LXC_STRING_UTILS_H -#include - #include "config.h" +#include + #include "initutils.h" #include "macro.h" diff --git a/src/lxc/sync.c b/src/lxc/sync.c index d8917ba7e..1075d987a 100644 --- a/src/lxc/sync.c +++ b/src/lxc/sync.c @@ -1,15 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include #include #include -#include "config.h" #include "log.h" #include "start.h" #include "sync.h" diff --git a/src/lxc/sync.h b/src/lxc/sync.h index c621f41f8..6703eda02 100644 --- a/src/lxc/sync.h +++ b/src/lxc/sync.h @@ -3,6 +3,8 @@ #ifndef __LXC_SYNC_H #define __LXC_SYNC_H +#include "config.h" + #include #include "compiler.h" diff --git a/src/lxc/syscall_numbers.h b/src/lxc/syscall_numbers.h index 97273b449..ae5fdd064 100644 --- a/src/lxc/syscall_numbers.h +++ b/src/lxc/syscall_numbers.h @@ -2,9 +2,8 @@ #ifndef __LXC_SYSCALL_NUMBERS_H #define __LXC_SYSCALL_NUMBERS_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h index b545b0365..10f2fff34 100644 --- a/src/lxc/syscall_wrappers.h +++ b/src/lxc/syscall_wrappers.h @@ -3,9 +3,8 @@ #ifndef __LXC_SYSCALL_WRAPPER_H #define __LXC_SYSCALL_WRAPPER_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -15,7 +14,6 @@ #include #include -#include "config.h" #include "macro.h" #include "syscall_numbers.h" diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index b86d8c59a..8c84f2875 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -20,7 +19,6 @@ #include "caps.h" #include "commands.h" #include "conf.h" -#include "config.h" #include "log.h" #include "lxclock.h" #include "mainloop.h" diff --git a/src/lxc/terminal.h b/src/lxc/terminal.h index 194f88711..45d6a18cc 100644 --- a/src/lxc/terminal.h +++ b/src/lxc/terminal.h @@ -3,6 +3,8 @@ #ifndef __LXC_TERMINAL_H #define __LXC_TERMINAL_H +#include "config.h" + #include #include diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c index 6a9ac817b..d7888ddf4 100644 --- a/src/lxc/tools/lxc_attach.c +++ b/src/lxc/tools/lxc_attach.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -20,7 +19,6 @@ #include "arguments.h" #include "attach.h" #include "caps.h" -#include "config.h" #include "confile.h" #include "log.h" #ifdef ENFORCE_MEMFD_REXEC diff --git a/src/lxc/tools/lxc_autostart.c b/src/lxc/tools/lxc_autostart.c index 4a5031810..91596d4f6 100644 --- a/src/lxc/tools/lxc_autostart.c +++ b/src/lxc/tools/lxc_autostart.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -11,7 +10,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "list.h" #include "log.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_cgroup.c b/src/lxc/tools/lxc_cgroup.c index edfc03c28..eb96c63ee 100644 --- a/src/lxc/tools/lxc_cgroup.c +++ b/src/lxc/tools/lxc_cgroup.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -13,7 +12,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" lxc_log_define(lxc_cgroup, lxc); diff --git a/src/lxc/tools/lxc_checkpoint.c b/src/lxc/tools/lxc_checkpoint.c index 22abf1866..a8edb4526 100644 --- a/src/lxc/tools/lxc_checkpoint.c +++ b/src/lxc/tools/lxc_checkpoint.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -13,7 +12,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_config.c b/src/lxc/tools/lxc_config.c index 333dde54f..e4424c4cf 100644 --- a/src/lxc/tools/lxc_config.c +++ b/src/lxc/tools/lxc_config.c @@ -1,15 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include "lxc.h" -#include "config.h" - struct lxc_config_items { char *name; }; diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c index d11827121..7f43f506b 100644 --- a/src/lxc/tools/lxc_console.c +++ b/src/lxc/tools/lxc_console.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -20,7 +19,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_copy.c b/src/lxc/tools/lxc_copy.c index 384a7e3c8..d497610d0 100644 --- a/src/lxc/tools/lxc_copy.c +++ b/src/lxc/tools/lxc_copy.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -21,7 +20,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "storage_utils.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_create.c b/src/lxc/tools/lxc_create.c index 6af554031..f0482867a 100644 --- a/src/lxc/tools/lxc_create.c +++ b/src/lxc/tools/lxc_create.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -14,7 +13,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "storage_utils.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_device.c b/src/lxc/tools/lxc_device.c index ed69cdfd7..82e543462 100644 --- a/src/lxc/tools/lxc_device.c +++ b/src/lxc/tools/lxc_device.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -14,7 +13,6 @@ #include "netns_ifaddrs.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_execute.c b/src/lxc/tools/lxc_execute.c index a706d94db..5b6a863b4 100644 --- a/src/lxc/tools/lxc_execute.c +++ b/src/lxc/tools/lxc_execute.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -18,7 +17,6 @@ #include "arguments.h" #include "caps.h" -#include "config.h" #include "confile.h" #include "log.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_freeze.c b/src/lxc/tools/lxc_freeze.c index cf5ff6162..c18779ba3 100644 --- a/src/lxc/tools/lxc_freeze.c +++ b/src/lxc/tools/lxc_freeze.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" lxc_log_define(lxc_freeze, lxc); diff --git a/src/lxc/tools/lxc_info.c b/src/lxc/tools/lxc_info.c index 12b2562d3..9755a503d 100644 --- a/src/lxc/tools/lxc_info.c +++ b/src/lxc/tools/lxc_info.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -15,7 +14,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_ls.c b/src/lxc/tools/lxc_ls.c index cc64f8732..23bee59de 100644 --- a/src/lxc/tools/lxc_ls.c +++ b/src/lxc/tools/lxc_ls.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#include +#include "config.h" + #include #include #include @@ -22,7 +20,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "memory_utils.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_monitor.c b/src/lxc/tools/lxc_monitor.c index aeb5ed8d0..6065f2683 100644 --- a/src/lxc/tools/lxc_monitor.c +++ b/src/lxc/tools/lxc_monitor.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS +#include "config.h" + #include #include #include @@ -27,7 +25,6 @@ #include "af_unix.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "macro.h" #include "monitor.h" diff --git a/src/lxc/tools/lxc_snapshot.c b/src/lxc/tools/lxc_snapshot.c index a920a595c..fc2e91c6b 100644 --- a/src/lxc/tools/lxc_snapshot.c +++ b/src/lxc/tools/lxc_snapshot.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -15,7 +14,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" lxc_log_define(lxc_snapshot, lxc); diff --git a/src/lxc/tools/lxc_stop.c b/src/lxc/tools/lxc_stop.c index e3cecb6b2..8787bacd5 100644 --- a/src/lxc/tools/lxc_stop.c +++ b/src/lxc/tools/lxc_stop.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c index 35fe76b5a..d3db4142c 100644 --- a/src/lxc/tools/lxc_top.c +++ b/src/lxc/tools/lxc_top.c @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */ +#include "config.h" + #include #include #include @@ -21,7 +19,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "mainloop.h" #include "utils.h" diff --git a/src/lxc/tools/lxc_unfreeze.c b/src/lxc/tools/lxc_unfreeze.c index e5b287289..818447cad 100644 --- a/src/lxc/tools/lxc_unfreeze.c +++ b/src/lxc/tools/lxc_unfreeze.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -12,7 +11,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" lxc_log_define(lxc_unfreeze, lxc); diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index c77ac70e7..d53f4299b 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -22,7 +21,6 @@ #include "arguments.h" #include "caps.h" -#include "config.h" #include "list.h" #include "log.h" #include "namespace.h" diff --git a/src/lxc/tools/lxc_wait.c b/src/lxc/tools/lxc_wait.c index 27f8020d7..7bafbd52c 100644 --- a/src/lxc/tools/lxc_wait.c +++ b/src/lxc/tools/lxc_wait.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include @@ -14,7 +13,6 @@ #include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" lxc_log_define(lxc_wait, lxc); From f7edcf94394263da83cf8ced524d4418d3e250f7 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 18:04:42 +0200 Subject: [PATCH 42/62] tests: include "version.h" Signed-off-by: Christian Brauner --- src/tests/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index a64d61302..3c87ccaf7 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -23,6 +23,7 @@ endif lxc_test_arch_parse_SOURCES = arch_parse.c \ lxctest.h \ ../lxc/lxc.h \ + ../lxc/version.h \ ../lxc/memory_utils.h lxc_test_api_reboot_SOURCES = api_reboot.c \ From 914f275f2ef2fb7d63dfa8e7825ac305d408f5d4 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 19:05:35 +0200 Subject: [PATCH 43/62] lxc: remove "version.h" inclusion Signed-off-by: Christian Brauner --- src/lxc/lxc.h | 1 - src/tests/Makefile.am | 1 - 2 files changed, 2 deletions(-) diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index 8ba9f62a6..e58fb2185 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -16,7 +16,6 @@ extern "C" { #include "attach_options.h" #include "lxccontainer.h" -#include "version.h" #include "compiler.h" #include "memory_utils.h" diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 3c87ccaf7..a64d61302 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -23,7 +23,6 @@ endif lxc_test_arch_parse_SOURCES = arch_parse.c \ lxctest.h \ ../lxc/lxc.h \ - ../lxc/version.h \ ../lxc/memory_utils.h lxc_test_api_reboot_SOURCES = api_reboot.c \ From 784839ae18423c02070ca340cd7b2d3b7ff47443 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 17:57:39 +0200 Subject: [PATCH 44/62] build: make sure _GNU_SOURCE is set Signed-off-by: Christian Brauner --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 95da6bef7..396f6c34d 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,7 @@ AC_CANONICAL_HOST AM_PROG_CC_C_O AC_USE_SYSTEM_EXTENSIONS AC_SYS_LARGEFILE +AC_GNU_SOURCE # Test if we have a new enough compiler. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ From 9b9d56e6e8c5052b2d327b5f74027b4c0b7b700a Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 09:26:52 +0200 Subject: [PATCH 45/62] build: add meson skeleton Signed-off-by: Christian Brauner --- meson.build | 325 ++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 29 ++++ src/include/meson.build | 95 ++++++++++++ src/lxc/meson.build | 133 ++++++++++++++++ 4 files changed, 582 insertions(+) create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 src/include/meson.build create mode 100644 src/lxc/meson.build diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..8d898e736 --- /dev/null +++ b/meson.build @@ -0,0 +1,325 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +project('lxc', 'c', + version : '4.0.0', + license : 'LGPLv2+', + default_options: [ + 'c_std=gnu11', + 'warning_level=2', + ], + meson_version : '>= 0.45', + ) + +liblxc_version = '4.0.0' + +conf = configuration_data() +conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxc/introduction/') +conf.set('PROJECT_VERSION', meson.project_version(), + description : 'Numerical project version (used where a simple number is expected)') + +version_data = configuration_data() +version_data.set('LXC_VERSION_MAJOR', '4') +version_data.set('LXC_VERSION_MINOR', '0') +version_data.set('LXC_VERSION_MICRO', '7') +version_data.set('LXC_ABI', '4.0.7') +version_data.set('LXC_DEVEL', '1') +version_data.set('LXC_VERSION', '4.0.7-devel') + +project_source_root = meson.current_source_dir() +project_build_root = meson.current_build_dir() + +# join_paths ignores the preceding arguments if an absolute component is +# encountered, so this should canonicalize various paths when they are +# absolute or relative. +prefixdir = get_option('prefix') +if not prefixdir.startswith('/') + error('Prefix is not absolute: "@0@"'.format(prefixdir)) +endif +datadir = join_paths(prefixdir, get_option('datadir')) +bindir = join_paths(prefixdir, get_option('bindir')) +sbindir = join_paths(prefixdir, get_option('sbindir')) +includedir = join_paths(prefixdir, get_option('includedir')) +libdir = join_paths(prefixdir, get_option('libdir')) +libexecdir = join_paths(prefixdir, get_option('libexecdir')) +sysconfdir = join_paths(prefixdir, get_option('sysconfdir')) +runtimepath = join_paths(prefixdir, get_option('runtime-path')) +localstatedir = join_paths('/', get_option('localstatedir')) +apparmorcachedir = get_option('apparmor-cache-dir') +rootfsmount = get_option('rootfs-mount-dir') +cgrouppattern = get_option('cgroup-pattern') +logpath = get_option('log-path') +lxcpath = get_option('config-path') +globalconfig = get_option('global-config') + +conf.set_quoted('BINDIR', bindir) +conf.set_quoted('SBINDIR', sbindir) +conf.set_quoted('INCLUDEDIR', includedir) +conf.set_quoted('LIBDIR', libdir) +conf.set_quoted('LIBEXECDIR', libexecdir) +conf.set_quoted('SYSCONFDIR', sysconfdir) +conf.set_quoted('LXC_DEFAULT_CONFIG', join_paths(sysconfdir, 'lxc/default.conf')) +conf.set_quoted('APPARMOR_CACHE_DIR', join_paths(localstatedir, apparmorcachedir)) +conf.set_quoted('LXCROOTFSMOUNT', join_paths(prefixdir, rootfsmount)) +conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern) +conf.set_quoted('RUNTIME_PATH', runtimepath) +conf.set_quoted('LOGPATH', join_paths(localstatedir, logpath)) +conf.set_quoted('LXCPATH', join_paths(localstatedir, lxcpath)) +conf.set_quoted('LXC_GLOBAL_CONF', join_paths(sysconfdir, globalconfig)) +conf.set_quoted('DATADIR', datadir) +conf.set_quoted('LXCTEMPLATECONFIG', join_paths(datadir, 'lxc/config')) +conf.set_quoted('LXCTEMPLATEDIR', join_paths(datadir, 'lxc/templates')) +conf.set_quoted('LXCINITDIR', libexecdir) + +# AS_AC_EXPAND(DATADIR, "$datadir") +# AS_AC_EXPAND(LOCALSTATEDIR, "$localstatedir") +# AS_AC_EXPAND(DOCDIR, "$docdir") +# AS_AC_EXPAND(LXC_GENERATE_DATE, "$(date --utc --date=@${SOURCE_DATE_EPOCH:-$(date +%s)} '+%Y-%m-%d')") +# AS_AC_EXPAND(LXCPATH, "$with_config_path") +# AS_AC_EXPAND(LXC_GLOBAL_CONF, "$with_global_conf") +# AS_AC_EXPAND(LXC_USERNIC_CONF, "$with_usernic_conf") +# AS_AC_EXPAND(LXC_USERNIC_DB, "$with_usernic_db") +# AS_AC_EXPAND(LXC_DISTRO_SYSCONF, "$distrosysconf") +# AS_AC_EXPAND(LXCHOOKDIR, "$datadir/lxc/hooks") +# AS_AC_EXPAND(LXCBINHOOKDIR, "$libexecdir/lxc/hooks") +# AS_AC_EXPAND(LXCINITDIR, "$libexecdir") +# +# # We need the install path so criu knows where to reference the hook scripts. +# AC_DEFINE_UNQUOTED([DATADIR], "$DATADIR", ["Prefix for shared files."]) + +cc = meson.get_compiler('c') +pkgconfig = import('pkgconfig') + +possible_cc_flags = [ + '-fPIE', + '-Wvla', + '-fdiagnostics-color', + '-Wimplicit-fallthrough=5', + '-Wcast-align', + '-Wstrict-prototypes', + '-fno-strict-aliasing', + '-fstack-clash-protection', + '-fstack-protector-strong', + '--param=ssp-buffer-size=4', + '--mcet -fcf-protection', + '-Werror=implicit-function-declaration', + '-Wlogical-op', + '-Wmissing-include-dirs', + '-Wold-style-definition', + '-Winit-self', + '-Wunused-but-set-variable', + '-Wno-unused-parameter', + '-Wfloat-equal', + '-Wsuggest-attribute=noreturn', + '-Werror=return-type', + '-Werror=incompatible-pointer-types', + '-Wformat=2', + '-Wshadow', + '-Wendif-labels', + '-Werror=overflow', + '-fdiagnostics-show-option', + '-Werror=shift-count-overflow', + '-Werror=shift-overflow=2', + '-Wdate-time', + '-Wnested-externs', + '-fasynchronous-unwind-tables', + '-fexceptions', + '-Warray-bounds', + '-Wrestrict', + '-Wreturn-local-addr', + '-fsanitize=cfi', + '-Wstringop-overflow', +] + +possible_link_flags = [ + '-Wl,--as-needed', + '-Wl,--gc-sections', + '-Wl,-z,relro', + '-Wl,-z,now', + '-pie', + '-Wl,-fuse-ld=gold', +] + +if meson.version().version_compare('>=0.46') + add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c') +else + add_project_link_arguments(possible_link_flags, language : 'c') +endif + +add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c') + +foreach header : ['sys/resource.h', + 'sys/memfd.h', + 'sys/personality.h', + 'sys/signalfd.h', + 'sys/timerfd.h', + 'pty.h', + 'utmpx.h', + ] + + conf.set10('HAVE_' + header.underscorify().to_upper(), + cc.has_header(header)) +endforeach + +decl_headers = ''' +#include +#include +#include +#include +#include +#include +#include +''' + +foreach decl : [ + '__aligned_u64', + 'struct mount_attr', + 'struct open_how', + 'struct clone_args', + ] + + # We get -1 if the size cannot be determined + have = cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0 + + if have == true + conf.set10('HAVE_' + decl.underscorify().to_upper(), have) + endif +endforeach + +foreach ident : [ + ['memfd_create', '''#include '''], + ['gettid', '''#include + #include '''], + ['pivot_root', '''#include + #include '''], # no known header declares pivot_root + ['setns', '''#include '''], + ['renameat2', '''#include + #include '''], + ['kcmp', '''#include '''], + ['keyctl', '''#include + #include '''], + ['bpf', '''#include + #include '''], + ['statx', '''#include + #include + #include '''], + ['pidfd_send_signal', '''#include + #include + #include + #include '''], + ['pidfd_open', '''#include + #include + #include + #include '''], + ['execveat', '''#include '''], + ['close_range', '''#include '''], + ['mount_setattr', '''#include '''], + ['move_mount', '''#include '''], + ['open_tree', '''#include '''], + ['strlcpy', '''#include '''], + ['strlcat', '''#include '''], + ['sethostname', '''#include '''], + ['faccessat', '''#include + #include '''], + ['unshare', '''#include '''], + ['prlimit', '''#include + #include '''], + ['prlimit64', '''#include + #include '''], +] + + have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') + if have == true + conf.set10('HAVE_' + ident[0].to_upper(), have) + endif +endforeach + +threads = dependency('threads') +libseccomp = cc.find_library('seccomp', required : false) +if libseccomp.found() + conf.set10('HAVE_SECCOMP', libseccomp.found()) + + seccomp_headers = ''' + #include + ''' + + if cc.has_function('seccomp_notify_fd', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp) + conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true) + endif + + if cc.has_function('seccomp_syscall_resolve_name_arch', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp) + conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true) + endif + + foreach decl : [ + 'scmp_filter_ctx', + 'struct seccomp_notif_sizes', + 'struct clone_args', + ] + + # We get -1 if the size cannot be determined + have = cc.sizeof(decl, prefix : seccomp_headers, args : '-D_GNU_SOURCE') > 0 + + if have == true + conf.set10('HAVE_' + decl.underscorify().to_upper(), have) + endif + endforeach +endif + +libselinux = cc.find_library('selinux', required : false) +if libselinux.found() + conf.set10('HAVE_SELINUX', libselinux.found()) +endif + +libapparmor = cc.find_library('apparmor', required : false) +if libapparmor.found() + conf.set10('HAVE_APPARMOR', libapparmor.found()) +endif + +libopenssl = dependency('openssl', required : false) +if libopenssl.found() + conf.set10('HAVE_OPENSSL', libopenssl.found()) +endif + +libcap = dependency('libcap', required : false) +if not libcap.found() + # Compat with Ubuntu 14.04 which ships libcap w/o .pc file + libcap = cc.find_library('cap') +endif + +if libcap.found() + conf.set10('HAVE_LIBCAP', libcap.found()) +endif + +basic_includes = include_directories( + 'src', + 'src/include', + '.') + +liblxc_includes = [basic_includes, include_directories( + 'src/lxc/cgroups', + 'src/lxc/lsm', + 'src/lxc/storage')] + +add_project_arguments('-include', 'config.h', language : 'c') + +subdir('src/include') +subdir('src/lxc') + +config_h = configure_file( + output : 'config.h', + configuration : conf) + +liblxc = shared_library( + 'lxc', + version : liblxc_version, + include_directories : liblxc_includes, + link_args : ['-shared', '-fPIC', '-DPIC'], + link_whole : [liblxc_static], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : libdir) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 000000000..874516e72 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,29 @@ +# -*- mode: meson -*- + +option('tests', type : 'boolean', value: 'false', + description : 'enable tests') + +option('runtime-path', type : 'string', value : '/run', + description : 'the runtime directory') + +option('init-script', type : 'combo', + choices : ['systemd', 'sysvinit', 'openrc', 'upstart'], value : 'systemd', + description : 'init script') + +option('apparmor-cache-dir', type : 'string', value : 'cache/lxc/apparmor', + description : 'the AppArmor cache directory') + +option('rootfs-mount-dir', type : 'string', value : 'lib/x86_64-linux-gnu/lxc', + description : 'the rootfs mount directory') + +option('cgroup-pattern', type : 'string', value : '', + description : 'the rootfs mount directory') + +option('log-path', type : 'string', value : 'log/lxc', + description : 'the rootfs mount directory') + +option('config-path', type : 'string', value : 'lib/lxc', + description : 'the rootfs mount directory') + +option('global-config', type : 'string', value : 'lxc/lxc.conf', + description : 'the rootfs mount directory') diff --git a/src/include/meson.build b/src/include/meson.build new file mode 100644 index 000000000..85292e232 --- /dev/null +++ b/src/include/meson.build @@ -0,0 +1,95 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +include_sources = files( + 'bpf.h', + 'bpf_common.h', + 'netns_ifaddrs.c', + 'netns_ifaddrs.h') + +if cc.has_function('getline', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_GETLINE', have) +else + include_sources += files( + 'getline.c', + 'getline.h') +endif + +if cc.has_function('fexecve', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_FEXECVE', have) +else + include_sources += files( + 'fexecve.c', + 'fexecve.h') +endif + + +getgr_headers = ''' +#include +#include +''' + +if cc.has_function('getgrgid_r', prefix : getgr_headers, args : '-D_GNU_SOURCE') + conf.set10('HAVE_GETGRGID_R', have) +else + include_sources += files( + 'getgrgid_r.c', + 'getgrgid_r.h') +endif + +mntent_headers = ''' +#include +#include +''' + +have_hasmntopt = cc.has_function('hasmntopt', prefix : mntent_headers, args : '-D_GNU_SOURCE') +if have_hasmntopt + conf.set10('HAVE_HASMNTOPT', have) +endif + +have_setmntent = cc.has_function('setmntent', prefix : mntent_headers, args : '-D_GNU_SOURCE') +if have_setmntent + conf.set10('HAVE_SETMNTENT', have) +endif + +have_endmntent = cc.has_function('endmntent', prefix : mntent_headers, args : '-D_GNU_SOURCE') +if have_endmntent + conf.set10('HAVE_ENDMNTENT', have) +endif + +if have_hasmntopt == false or have_setmntent == false or have_endmntent == false + include_sources += files( + 'lxcmntent.c', + 'lxcmntent.h') +endif + +if cc.has_function('strlcpy', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_STRLCPY', have) +else + include_sources += files( + 'strlcpy.c', + 'strlcpy.h') +endif + +if cc.has_function('strlcat', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_STRLCAT', have) +else + include_sources += files( + 'strlcat.c', + 'strlcat.h') +endif + +if cc.has_function('strchrnul', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_STRCHRNUL', have) +else + include_sources += files( + 'strchrnul.c', + 'strchrnul.h') +endif + +if cc.has_function('openpty', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_OPENPTY', have) +else + include_sources += files( + 'openpty.c', + 'openpty.h') +endif diff --git a/src/lxc/meson.build b/src/lxc/meson.build new file mode 100644 index 000000000..faf3a939e --- /dev/null +++ b/src/lxc/meson.build @@ -0,0 +1,133 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +liblxcfs_version_file = configure_file( + configuration : version_data, + input : 'version.h.in', + output : 'version.h') + +liblxc_sources = files( + 'cgroups/cgfsng.c', + 'cgroups/cgroup.c', + 'cgroups/cgroup.h', + 'cgroups/cgroup2_devices.c', + 'cgroups/cgroup2_devices.h', + 'cgroups/cgroup_utils.c', + 'cgroups/cgroup_utils.h', + 'lsm/apparmor.c', + 'lsm/lsm.c', + 'lsm/lsm.h', + 'lsm/nop.c', + 'lsm/selinux.c', + 'storage/btrfs.c', + 'storage/btrfs.h', + 'storage/dir.c', + 'storage/dir.h', + 'storage/loop.c', + 'storage/loop.h', + 'storage/lvm.c', + 'storage/lvm.h', + 'storage/nbd.c', + 'storage/nbd.h', + 'storage/overlay.c', + 'storage/overlay.h', + 'storage/rbd.c', + 'storage/rbd.h', + 'storage/rsync.c', + 'storage/rsync.h', + 'storage/storage.c', + 'storage/storage.h', + 'storage/storage_utils.c', + 'storage/storage_utils.h', + 'storage/zfs.c', + 'storage/zfs.h', + 'af_unix.c', + 'af_unix.h', + 'api_extensions.h', + 'attach.c', + 'attach.h', + 'attach_options.h', + 'caps.c', + 'caps.h', + 'commands.c', + 'commands.h', + 'commands_utils.c', + 'commands_utils.h', + 'compiler.h', + 'conf.c', + 'conf.h', + 'confile.c', + 'confile.h', + 'confile_utils.c', + 'confile_utils.h', + 'criu.c', + 'criu.h', + 'error.c', + 'error.h', + 'error_utils.h', + 'execute.c', + 'file_utils.c', + 'file_utils.h', + 'freezer.c', + 'hlist.h', + 'initutils.c', + 'initutils.h', + 'list.h', + 'log.c', + 'log.h', + 'lxc.h', + 'lxccontainer.c', + 'lxccontainer.h', + 'lxclock.c', + 'lxclock.h', + 'lxcseccomp.h', + 'macro.h', + 'mainloop.c', + 'mainloop.h', + 'memory_utils.h', + 'monitor.c', + 'monitor.h', + 'mount_utils.c', + 'mount_utils.h', + 'namespace.c', + 'namespace.h', + 'network.c', + 'network.h', + 'nl.c', + 'nl.h', + 'parse.c', + 'parse.h', + 'process_utils.c', + 'process_utils.h', + 'rexec.c', + 'rexec.h', + 'ringbuf.c', + 'ringbuf.h', + 'rtnl.c', + 'rtnl.h', + 'seccomp.c', + 'start.c', + 'start.h', + 'state.c', + 'state.h', + 'string_utils.c', + 'string_utils.h', + 'sync.c', + 'sync.h', + 'syscall_numbers.h', + 'syscall_wrappers.h', + 'terminal.c', + 'terminal.h', + 'utils.c', + 'utils.h', + 'uuid.c', + 'uuid.h') + +liblxc_c_args = ['-fvisibility=default'] + +liblxc_static = static_library( + 'lxc_static', + liblxc_sources + include_sources, + install : false, + include_directories : liblxc_includes, + dependencies : [threads], + c_args : liblxc_c_args) From 297e5f969380377f07e62cdd5c320b88bd164f06 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 3 Sep 2021 16:35:55 +0200 Subject: [PATCH 46/62] build: add tools to meson Signed-off-by: Christian Brauner --- meson.build | 301 +++++++++++++++++++++++++++++++++++++- src/lxc/tools/meson.build | 191 ++++++++++++++++++++++++ 2 files changed, 491 insertions(+), 1 deletion(-) create mode 100644 src/lxc/tools/meson.build diff --git a/meson.build b/meson.build index 8d898e736..16f94bc31 100644 --- a/meson.build +++ b/meson.build @@ -16,6 +16,8 @@ conf = configuration_data() conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxc/introduction/') conf.set('PROJECT_VERSION', meson.project_version(), description : 'Numerical project version (used where a simple number is expected)') +conf.set('_GNU_SOURCE', true) +conf.set('__STDC_FORMAT_MACROS', true) version_data = configuration_data() version_data.set('LXC_VERSION_MAJOR', '4') @@ -304,6 +306,7 @@ add_project_arguments('-include', 'config.h', language : 'c') subdir('src/include') subdir('src/lxc') +subdir('src/lxc/tools') config_h = configure_file( output : 'config.h', @@ -312,7 +315,7 @@ config_h = configure_file( liblxc = shared_library( 'lxc', version : liblxc_version, - include_directories : liblxc_includes, + include_directories : tools_liblxc_includes, link_args : ['-shared', '-fPIC', '-DPIC'], link_whole : [liblxc_static], dependencies : [threads, @@ -323,3 +326,299 @@ liblxc = shared_library( libapparmor], install : true, install_dir : libdir) + +public_programs = [] + +public_programs += executable( + 'lxc-autostart', + tools_lxc_autostart_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-cgroup', + tools_lxc_cgroup_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-checkpoint', + tools_lxc_checkpoint_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-config', + tools_lxc_config_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-console', + tools_lxc_console_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-copy', + tools_lxc_copy_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-create', + tools_lxc_create_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-destroy', + tools_lxc_destroy_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-device', + tools_lxc_device_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-execute', + tools_lxc_execute_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-freeze', + tools_lxc_freeze_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-info', + tools_lxc_info_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-ls', + tools_lxc_ls_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-monitor', + tools_lxc_monitor_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-snapshot', + tools_lxc_snapshot_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-start', + tools_lxc_start_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-stop', + tools_lxc_stop_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-top', + tools_lxc_top_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-unfreeze', + tools_lxc_unfreeze_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-unshare', + tools_lxc_unshare_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) + +public_programs += executable( + 'lxc-wait', + tools_lxc_wait_sources, + include_directories : tools_liblxc_includes, + link_with : [liblxc], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor], + install : true, + install_dir : bindir) diff --git a/src/lxc/tools/meson.build b/src/lxc/tools/meson.build new file mode 100644 index 000000000..1e91cdfae --- /dev/null +++ b/src/lxc/tools/meson.build @@ -0,0 +1,191 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +tools_liblxc_includes = include_directories( + '.', + '../', + '../cgroups', + '../lsm', + '../storage', + '../../include') + +tools_basic_source = files( + 'arguments.c', + 'arguments.h', + '../compiler.h', + '../initutils.c', + '../initutils.h', + '../macro.h', + '../string_utils.c', + '../string_utils.h', + '../lxc.h') + include_sources + +tools_common_sources = files( + 'arguments.c', + 'arguments.h', + '../af_unix.c', + '../af_unix.h', + '../attach_options.h', + '../caps.c', + '../caps.h', + '../commands.c', + '../commands.h', + '../commands_utils.c', + '../commands_utils.h', + '../compiler.h', + '../conf.c', + '../conf.h', + '../confile.c', + '../confile.h', + '../confile_utils.c', + '../confile_utils.h', + '../cgroups/cgfsng.c', + '../cgroups/cgroup.c', + '../cgroups/cgroup.h', + '../cgroups/cgroup2_devices.c', + '../cgroups/cgroup2_devices.h', + '../cgroups/cgroup_utils.c', + '../cgroups/cgroup_utils.h', + '../error.c', + '../error.h', + '../initutils.c', + '../initutils.h', + '../file_utils.c', + '../file_utils.h', + '../lsm/apparmor.c', + '../lsm/lsm.c', + '../lsm/lsm.h', + '../lsm/nop.c', + '../lsm/selinux.c', + '../lxcseccomp.h', + '../lxclock.c', + '../lxclock.h', + '../macro.h', + '../mainloop.c', + '../mainloop.h', + '../memory_utils.h', + '../monitor.c', + '../monitor.h', + '../mount_utils.c', + '../mount_utils.h', + '../namespace.c', + '../namespace.h', + '../network.c', + '../network.h', + '../nl.c', + '../nl.h', + '../parse.c', + '../parse.h', + '../process_utils.c', + '../process_utils.h', + '../ringbuf.c', + '../ringbuf.h', + '../seccomp.c', + '../start.c', + '../start.h', + '../state.c', + '../state.h', + '../storage/btrfs.c', + '../storage/btrfs.h', + '../storage/dir.c', + '../storage/dir.h', + '../storage/loop.c', + '../storage/loop.h', + '../storage/lvm.c', + '../storage/lvm.h', + '../storage/nbd.c', + '../storage/nbd.h', + '../storage/overlay.c', + '../storage/overlay.h', + '../storage/rbd.c', + '../storage/rbd.h', + '../storage/rsync.c', + '../storage/rsync.h', + '../storage/storage.c', + '../storage/storage.h', + '../storage/storage_utils.c', + '../storage/storage_utils.h', + '../storage/zfs.c', + '../storage/zfs.h', + '../string_utils.c', + '../string_utils.h', + '../sync.c', + '../sync.h', + '../terminal.c', + '../terminal.h', + '../utils.c', + '../utils.h', + '../uuid.c', + '../uuid.h', + '../log.h', + '../log.c') + include_sources + +tools_lxc_autostart_sources = files( + 'lxc_autostart.c') + tools_basic_source + +tools_lxc_cgroup_sources = files( + 'lxc_cgroup.c') + tools_basic_source + +tools_lxc_checkpoint_sources = files( + 'lxc_checkpoint.c') + tools_common_sources + +tools_lxc_config_sources = files( + 'lxc_config.c') + tools_basic_source + +tools_lxc_console_sources = files( + 'lxc_console.c') + tools_common_sources + +if cc.has_function('getsubopt', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_GETSUBOPT', have) +else + include_sources += files( + 'tools/include/getsubopt.c', + 'tools/include/getsubopt.h') +endif + +tools_lxc_copy_sources = files( + 'lxc_copy.c') + tools_common_sources + +tools_lxc_create_sources = files( + 'lxc_create.c') + tools_common_sources + +tools_lxc_destroy_sources = files( + 'lxc_destroy.c') + tools_common_sources + +tools_lxc_device_sources = files( + 'lxc_device.c') + tools_common_sources + +tools_lxc_execute_sources = files( + 'lxc_execute.c') + tools_common_sources + +tools_lxc_freeze_sources = files( + 'lxc_freeze.c') + tools_common_sources + +tools_lxc_info_sources = files( + 'lxc_info.c') + tools_common_sources + +tools_lxc_ls_sources = files( + 'lxc_ls.c') + tools_common_sources + +tools_lxc_monitor_sources = files( + 'lxc_monitor.c') + tools_common_sources + +tools_lxc_snapshot_sources = files( + 'lxc_snapshot.c') + tools_basic_source + +tools_lxc_start_sources = files( + 'lxc_start.c') + tools_common_sources + +tools_lxc_stop_sources = files( + 'lxc_stop.c') + tools_basic_source + +tools_lxc_top_sources = files( + 'lxc_top.c') + tools_common_sources + +tools_lxc_unfreeze_sources = files( + 'lxc_unfreeze.c') + tools_common_sources + +tools_lxc_unshare_sources = files( + 'lxc_unshare.c') + tools_common_sources + +tools_lxc_wait_sources = files( + 'lxc_wait.c') + tools_basic_source From 98f3b52712efbf5f9fa980fe7f7f2e6b8f11e144 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 09:43:29 +0200 Subject: [PATCH 47/62] build: set pie in default_options Signed-off-by: Christian Brauner --- meson.build | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 16f94bc31..b4fb9c70e 100644 --- a/meson.build +++ b/meson.build @@ -4,6 +4,7 @@ project('lxc', 'c', version : '4.0.0', license : 'LGPLv2+', default_options: [ + 'b_pie=true', 'c_std=gnu11', 'warning_level=2', ], @@ -92,7 +93,6 @@ cc = meson.get_compiler('c') pkgconfig = import('pkgconfig') possible_cc_flags = [ - '-fPIE', '-Wvla', '-fdiagnostics-color', '-Wimplicit-fallthrough=5', @@ -137,7 +137,6 @@ possible_link_flags = [ '-Wl,--gc-sections', '-Wl,-z,relro', '-Wl,-z,now', - '-pie', '-Wl,-fuse-ld=gold', ] From 5e0a302b1e43e20cb3f209923643a1d29ef6d524 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 09:44:32 +0200 Subject: [PATCH 48/62] build: set as-needed in default_options Signed-off-by: Christian Brauner --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index b4fb9c70e..c44f6d71e 100644 --- a/meson.build +++ b/meson.build @@ -4,6 +4,7 @@ project('lxc', 'c', version : '4.0.0', license : 'LGPLv2+', default_options: [ + 'b_asneeded=true', 'b_pie=true', 'c_std=gnu11', 'warning_level=2', @@ -133,7 +134,6 @@ possible_cc_flags = [ ] possible_link_flags = [ - '-Wl,--as-needed', '-Wl,--gc-sections', '-Wl,-z,relro', '-Wl,-z,now', From e4384f1cbb8ec2fc742459d279afdc7014283dae Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 09:54:17 +0200 Subject: [PATCH 49/62] build: use dependency() where possible Signed-off-by: Christian Brauner --- meson.build | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index c44f6d71e..6e476c3e3 100644 --- a/meson.build +++ b/meson.build @@ -235,22 +235,23 @@ foreach ident : [ endforeach threads = dependency('threads') -libseccomp = cc.find_library('seccomp', required : false) +libseccomp = dependency('libseccomp') if libseccomp.found() conf.set10('HAVE_SECCOMP', libseccomp.found()) + if libseccomp.version().version_compare('>=2.5.0') + # https://github.com/seccomp/libseccomp/commit/dead12bc788b259b148cc4d93b970ef0bd602b1a + conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true) + endif + + if libseccomp.version().version_compare('>=2.0.0') + # https://github.com/seccomp/libseccomp/commit/6220c8c0fc479d97b6d3e3166a4e46fbfe25a3c0 + conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true) + endif + seccomp_headers = ''' #include ''' - - if cc.has_function('seccomp_notify_fd', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp) - conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true) - endif - - if cc.has_function('seccomp_syscall_resolve_name_arch', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp) - conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true) - endif - foreach decl : [ 'scmp_filter_ctx', 'struct seccomp_notif_sizes', @@ -266,12 +267,12 @@ if libseccomp.found() endforeach endif -libselinux = cc.find_library('selinux', required : false) +libselinux = dependency('libselinux', required : false) if libselinux.found() conf.set10('HAVE_SELINUX', libselinux.found()) endif -libapparmor = cc.find_library('apparmor', required : false) +libapparmor = dependency('libapparmor', required : false) if libapparmor.found() conf.set10('HAVE_APPARMOR', libapparmor.found()) endif From 305490ba8e290eb892667afb85c425a4a7693d8f Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 09:57:53 +0200 Subject: [PATCH 50/62] build: -fPIC and -shared are handled automatically Signed-off-by: Christian Brauner --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 6e476c3e3..c9f084b3c 100644 --- a/meson.build +++ b/meson.build @@ -316,7 +316,8 @@ liblxc = shared_library( 'lxc', version : liblxc_version, include_directories : tools_liblxc_includes, - link_args : ['-shared', '-fPIC', '-DPIC'], + link_args : ['-DPIC'], + c_args : ['-DPIC'], link_whole : [liblxc_static], dependencies : [threads, libseccomp, From 4ce4aac4941f07880c18c69b2e440f34801949db Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 09:58:44 +0200 Subject: [PATCH 51/62] build: set find_library('libcap', require : false) Signed-off-by: Christian Brauner --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index c9f084b3c..ce1c0e5c1 100644 --- a/meson.build +++ b/meson.build @@ -285,7 +285,7 @@ endif libcap = dependency('libcap', required : false) if not libcap.found() # Compat with Ubuntu 14.04 which ships libcap w/o .pc file - libcap = cc.find_library('cap') + libcap = cc.find_library('cap', required : false) endif if libcap.found() From e8ef4deae083b4edfd83c24dfdbc4b1090839b5c Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 10:01:46 +0200 Subject: [PATCH 52/62] build: libdir and bindir are the default for shared libraries and executables Signed-off-by: Christian Brauner --- meson.build | 66 ++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/meson.build b/meson.build index ce1c0e5c1..c0af902e7 100644 --- a/meson.build +++ b/meson.build @@ -325,8 +325,7 @@ liblxc = shared_library( libopenssl, libselinux, libapparmor], - install : true, - install_dir : libdir) + install : true) public_programs = [] @@ -341,8 +340,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-cgroup', @@ -355,8 +353,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-checkpoint', @@ -369,8 +366,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-config', @@ -383,8 +379,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-console', @@ -397,8 +392,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-copy', @@ -411,8 +405,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-create', @@ -425,8 +418,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-destroy', @@ -439,8 +431,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-device', @@ -453,8 +444,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-execute', @@ -467,8 +457,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-freeze', @@ -481,8 +470,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-info', @@ -495,8 +483,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-ls', @@ -509,8 +496,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-monitor', @@ -523,8 +509,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-snapshot', @@ -537,8 +522,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-start', @@ -551,8 +535,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-stop', @@ -565,8 +548,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-top', @@ -579,8 +561,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-unfreeze', @@ -593,8 +574,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-unshare', @@ -607,8 +587,7 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) public_programs += executable( 'lxc-wait', @@ -621,5 +600,4 @@ public_programs += executable( libopenssl, libselinux, libapparmor], - install : true, - install_dir : bindir) + install : true) From c6ea1dec85196691f624e69c4e45fa29ff65abec Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 10:05:48 +0200 Subject: [PATCH 53/62] build: use common dependencies variable Signed-off-by: Christian Brauner --- meson.build | 177 +++++++++------------------------------------------- 1 file changed, 30 insertions(+), 147 deletions(-) diff --git a/meson.build b/meson.build index c0af902e7..30be7e0bd 100644 --- a/meson.build +++ b/meson.build @@ -327,277 +327,160 @@ liblxc = shared_library( libapparmor], install : true) +liblxc_dep = declare_dependency( + link_with: liblxc, + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + libapparmor]) + public_programs = [] public_programs += executable( 'lxc-autostart', tools_lxc_autostart_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-cgroup', tools_lxc_cgroup_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-checkpoint', tools_lxc_checkpoint_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-config', tools_lxc_config_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-console', tools_lxc_console_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-copy', tools_lxc_copy_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-create', tools_lxc_create_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-destroy', tools_lxc_destroy_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-device', tools_lxc_device_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-execute', tools_lxc_execute_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-freeze', tools_lxc_freeze_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-info', tools_lxc_info_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-ls', tools_lxc_ls_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-monitor', tools_lxc_monitor_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-snapshot', tools_lxc_snapshot_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-start', tools_lxc_start_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-stop', tools_lxc_stop_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-top', tools_lxc_top_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-unfreeze', tools_lxc_unfreeze_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-unshare', tools_lxc_unshare_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) public_programs += executable( 'lxc-wait', tools_lxc_wait_sources, include_directories : tools_liblxc_includes, - link_with : [liblxc], - dependencies : [threads, - libseccomp, - libcap, - libopenssl, - libselinux, - libapparmor], + dependencies : liblxc_dep, install : true) From 4ad3a929d969c92f7c6a98d8d58b84d372dda98c Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 10:09:45 +0200 Subject: [PATCH 54/62] build: remove unneeded variables Signed-off-by: Christian Brauner --- meson.build | 17 ++++++----------- src/include/meson.build | 20 ++++++++++---------- src/lxc/tools/meson.build | 2 +- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/meson.build b/meson.build index 30be7e0bd..a62a8a900 100644 --- a/meson.build +++ b/meson.build @@ -179,10 +179,8 @@ foreach decl : [ ] # We get -1 if the size cannot be determined - have = cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0 - - if have == true - conf.set10('HAVE_' + decl.underscorify().to_upper(), have) + if cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0 + conf.set10('HAVE_' + decl.underscorify().to_upper(), true) endif endforeach @@ -228,9 +226,8 @@ foreach ident : [ #include '''], ] - have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') - if have == true - conf.set10('HAVE_' + ident[0].to_upper(), have) + if cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') + conf.set10('HAVE_' + ident[0].to_upper(), true) endif endforeach @@ -259,10 +256,8 @@ if libseccomp.found() ] # We get -1 if the size cannot be determined - have = cc.sizeof(decl, prefix : seccomp_headers, args : '-D_GNU_SOURCE') > 0 - - if have == true - conf.set10('HAVE_' + decl.underscorify().to_upper(), have) + if cc.sizeof(decl, prefix : seccomp_headers, args : '-D_GNU_SOURCE') > 0 + conf.set10('HAVE_' + decl.underscorify().to_upper(), true) endif endforeach endif diff --git a/src/include/meson.build b/src/include/meson.build index 85292e232..03817c157 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -7,7 +7,7 @@ include_sources = files( 'netns_ifaddrs.h') if cc.has_function('getline', prefix : '#include ', args : '-D_GNU_SOURCE') - conf.set10('HAVE_GETLINE', have) + conf.set10('HAVE_GETLINE', true) else include_sources += files( 'getline.c', @@ -15,7 +15,7 @@ else endif if cc.has_function('fexecve', prefix : '#include ', args : '-D_GNU_SOURCE') - conf.set10('HAVE_FEXECVE', have) + conf.set10('HAVE_FEXECVE', true) else include_sources += files( 'fexecve.c', @@ -29,7 +29,7 @@ getgr_headers = ''' ''' if cc.has_function('getgrgid_r', prefix : getgr_headers, args : '-D_GNU_SOURCE') - conf.set10('HAVE_GETGRGID_R', have) + conf.set10('HAVE_GETGRGID_R', true) else include_sources += files( 'getgrgid_r.c', @@ -43,17 +43,17 @@ mntent_headers = ''' have_hasmntopt = cc.has_function('hasmntopt', prefix : mntent_headers, args : '-D_GNU_SOURCE') if have_hasmntopt - conf.set10('HAVE_HASMNTOPT', have) + conf.set10('HAVE_HASMNTOPT', true) endif have_setmntent = cc.has_function('setmntent', prefix : mntent_headers, args : '-D_GNU_SOURCE') if have_setmntent - conf.set10('HAVE_SETMNTENT', have) + conf.set10('HAVE_SETMNTENT', true) endif have_endmntent = cc.has_function('endmntent', prefix : mntent_headers, args : '-D_GNU_SOURCE') if have_endmntent - conf.set10('HAVE_ENDMNTENT', have) + conf.set10('HAVE_ENDMNTENT', true) endif if have_hasmntopt == false or have_setmntent == false or have_endmntent == false @@ -63,7 +63,7 @@ if have_hasmntopt == false or have_setmntent == false or have_endmntent == false endif if cc.has_function('strlcpy', prefix : '#include ', args : '-D_GNU_SOURCE') - conf.set10('HAVE_STRLCPY', have) + conf.set10('HAVE_STRLCPY', true) else include_sources += files( 'strlcpy.c', @@ -71,7 +71,7 @@ else endif if cc.has_function('strlcat', prefix : '#include ', args : '-D_GNU_SOURCE') - conf.set10('HAVE_STRLCAT', have) + conf.set10('HAVE_STRLCAT', true) else include_sources += files( 'strlcat.c', @@ -79,7 +79,7 @@ else endif if cc.has_function('strchrnul', prefix : '#include ', args : '-D_GNU_SOURCE') - conf.set10('HAVE_STRCHRNUL', have) + conf.set10('HAVE_STRCHRNUL', true) else include_sources += files( 'strchrnul.c', @@ -87,7 +87,7 @@ else endif if cc.has_function('openpty', prefix : '#include ', args : '-D_GNU_SOURCE') - conf.set10('HAVE_OPENPTY', have) + conf.set10('HAVE_OPENPTY', true) else include_sources += files( 'openpty.c', diff --git a/src/lxc/tools/meson.build b/src/lxc/tools/meson.build index 1e91cdfae..40a131959 100644 --- a/src/lxc/tools/meson.build +++ b/src/lxc/tools/meson.build @@ -135,7 +135,7 @@ tools_lxc_console_sources = files( 'lxc_console.c') + tools_common_sources if cc.has_function('getsubopt', prefix : '#include ', args : '-D_GNU_SOURCE') - conf.set10('HAVE_GETSUBOPT', have) + conf.set10('HAVE_GETSUBOPT', true) else include_sources += files( 'tools/include/getsubopt.c', From 1531f8d53df57dc8d1a6604fef593b4d65ec90ec Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 10:14:45 +0200 Subject: [PATCH 55/62] build: add single option directly to static library Signed-off-by: Christian Brauner --- src/lxc/meson.build | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lxc/meson.build b/src/lxc/meson.build index faf3a939e..756dd22c5 100644 --- a/src/lxc/meson.build +++ b/src/lxc/meson.build @@ -122,12 +122,10 @@ liblxc_sources = files( 'uuid.c', 'uuid.h') -liblxc_c_args = ['-fvisibility=default'] - liblxc_static = static_library( 'lxc_static', liblxc_sources + include_sources, install : false, include_directories : liblxc_includes, dependencies : [threads], - c_args : liblxc_c_args) + c_args : '-fvisibility=default') From 455dae78dcf3ec64dcbd9b995ce5dfd0da81389b Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 10:15:01 +0200 Subject: [PATCH 56/62] build: set diagnostic colours directly in default_options Signed-off-by: Christian Brauner --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index a62a8a900..190b248a0 100644 --- a/meson.build +++ b/meson.build @@ -4,6 +4,7 @@ project('lxc', 'c', version : '4.0.0', license : 'LGPLv2+', default_options: [ + 'b_colorout=always', 'b_asneeded=true', 'b_pie=true', 'c_std=gnu11', @@ -95,7 +96,6 @@ pkgconfig = import('pkgconfig') possible_cc_flags = [ '-Wvla', - '-fdiagnostics-color', '-Wimplicit-fallthrough=5', '-Wcast-align', '-Wstrict-prototypes', From dcfe4e135d3776763940f2a2256e3c7905dff685 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 11:03:34 +0200 Subject: [PATCH 57/62] build: add more global config variables Signed-off-by: Christian Brauner --- meson.build | 16 +++++----------- meson_options.txt | 3 +++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 190b248a0..64fc5c3cd 100644 --- a/meson.build +++ b/meson.build @@ -40,6 +40,7 @@ prefixdir = get_option('prefix') if not prefixdir.startswith('/') error('Prefix is not absolute: "@0@"'.format(prefixdir)) endif +docdir = join_paths(prefixdir, get_option('docdir')) datadir = join_paths(prefixdir, get_option('datadir')) bindir = join_paths(prefixdir, get_option('bindir')) sbindir = join_paths(prefixdir, get_option('sbindir')) @@ -57,8 +58,10 @@ lxcpath = get_option('config-path') globalconfig = get_option('global-config') conf.set_quoted('BINDIR', bindir) +conf.set_quoted('DOCDIR', docdir) conf.set_quoted('SBINDIR', sbindir) conf.set_quoted('INCLUDEDIR', includedir) +conf.set_quoted('LOCALSTATEDIR', localstatedir) conf.set_quoted('LIBDIR', libdir) conf.set_quoted('LIBEXECDIR', libexecdir) conf.set_quoted('SYSCONFDIR', sysconfdir) @@ -74,22 +77,13 @@ conf.set_quoted('DATADIR', datadir) conf.set_quoted('LXCTEMPLATECONFIG', join_paths(datadir, 'lxc/config')) conf.set_quoted('LXCTEMPLATEDIR', join_paths(datadir, 'lxc/templates')) conf.set_quoted('LXCINITDIR', libexecdir) +conf.set_quoted('LXCHOOKDIR', join_paths(datadir, 'lxc/hooks')) +conf.set_quoted('LXCBINHOOKDIR', join_paths(libexecdir, 'lxc/hooks')) -# AS_AC_EXPAND(DATADIR, "$datadir") -# AS_AC_EXPAND(LOCALSTATEDIR, "$localstatedir") -# AS_AC_EXPAND(DOCDIR, "$docdir") # AS_AC_EXPAND(LXC_GENERATE_DATE, "$(date --utc --date=@${SOURCE_DATE_EPOCH:-$(date +%s)} '+%Y-%m-%d')") -# AS_AC_EXPAND(LXCPATH, "$with_config_path") -# AS_AC_EXPAND(LXC_GLOBAL_CONF, "$with_global_conf") # AS_AC_EXPAND(LXC_USERNIC_CONF, "$with_usernic_conf") # AS_AC_EXPAND(LXC_USERNIC_DB, "$with_usernic_db") # AS_AC_EXPAND(LXC_DISTRO_SYSCONF, "$distrosysconf") -# AS_AC_EXPAND(LXCHOOKDIR, "$datadir/lxc/hooks") -# AS_AC_EXPAND(LXCBINHOOKDIR, "$libexecdir/lxc/hooks") -# AS_AC_EXPAND(LXCINITDIR, "$libexecdir") -# -# # We need the install path so criu knows where to reference the hook scripts. -# AC_DEFINE_UNQUOTED([DATADIR], "$DATADIR", ["Prefix for shared files."]) cc = meson.get_compiler('c') pkgconfig = import('pkgconfig') diff --git a/meson_options.txt b/meson_options.txt index 874516e72..bab30ec6b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -27,3 +27,6 @@ option('config-path', type : 'string', value : 'lib/lxc', option('global-config', type : 'string', value : 'lxc/lxc.conf', description : 'the rootfs mount directory') + +option('docdir', type : 'string', + description : 'documentation directory') From bf1f3470fd11e2af0245ef3483784cf5ae637087 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 13 Sep 2021 11:21:23 +0200 Subject: [PATCH 58/62] build: set more variables and print summary Signed-off-by: Christian Brauner --- meson.build | 95 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 21 deletions(-) diff --git a/meson.build b/meson.build index 64fc5c3cd..733172de3 100644 --- a/meson.build +++ b/meson.build @@ -40,45 +40,68 @@ prefixdir = get_option('prefix') if not prefixdir.startswith('/') error('Prefix is not absolute: "@0@"'.format(prefixdir)) endif -docdir = join_paths(prefixdir, get_option('docdir')) -datadir = join_paths(prefixdir, get_option('datadir')) bindir = join_paths(prefixdir, get_option('bindir')) -sbindir = join_paths(prefixdir, get_option('sbindir')) +datadir = join_paths(prefixdir, get_option('datadir')) +docdir = join_paths(prefixdir, get_option('docdir')) includedir = join_paths(prefixdir, get_option('includedir')) libdir = join_paths(prefixdir, get_option('libdir')) libexecdir = join_paths(prefixdir, get_option('libexecdir')) -sysconfdir = join_paths(prefixdir, get_option('sysconfdir')) -runtimepath = join_paths(prefixdir, get_option('runtime-path')) localstatedir = join_paths('/', get_option('localstatedir')) +sbindir = join_paths(prefixdir, get_option('sbindir')) +sysconfdir = join_paths(prefixdir, get_option('sysconfdir')) + apparmorcachedir = get_option('apparmor-cache-dir') -rootfsmount = get_option('rootfs-mount-dir') cgrouppattern = get_option('cgroup-pattern') -logpath = get_option('log-path') -lxcpath = get_option('config-path') globalconfig = get_option('global-config') +logpath = get_option('log-path') +lxcpathprefix = get_option('config-path') +rootfsmount = get_option('rootfs-mount-dir') +runtimepath = join_paths(prefixdir, get_option('runtime-path')) + conf.set_quoted('BINDIR', bindir) +conf.set_quoted('DATADIR', datadir) conf.set_quoted('DOCDIR', docdir) -conf.set_quoted('SBINDIR', sbindir) conf.set_quoted('INCLUDEDIR', includedir) conf.set_quoted('LOCALSTATEDIR', localstatedir) conf.set_quoted('LIBDIR', libdir) conf.set_quoted('LIBEXECDIR', libexecdir) +conf.set_quoted('SBINDIR', sbindir) conf.set_quoted('SYSCONFDIR', sysconfdir) -conf.set_quoted('LXC_DEFAULT_CONFIG', join_paths(sysconfdir, 'lxc/default.conf')) -conf.set_quoted('APPARMOR_CACHE_DIR', join_paths(localstatedir, apparmorcachedir)) -conf.set_quoted('LXCROOTFSMOUNT', join_paths(prefixdir, rootfsmount)) + +conf.set_quoted('LXCINITDIR', libexecdir) conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern) conf.set_quoted('RUNTIME_PATH', runtimepath) -conf.set_quoted('LOGPATH', join_paths(localstatedir, logpath)) -conf.set_quoted('LXCPATH', join_paths(localstatedir, lxcpath)) -conf.set_quoted('LXC_GLOBAL_CONF', join_paths(sysconfdir, globalconfig)) -conf.set_quoted('DATADIR', datadir) -conf.set_quoted('LXCTEMPLATECONFIG', join_paths(datadir, 'lxc/config')) -conf.set_quoted('LXCTEMPLATEDIR', join_paths(datadir, 'lxc/templates')) -conf.set_quoted('LXCINITDIR', libexecdir) -conf.set_quoted('LXCHOOKDIR', join_paths(datadir, 'lxc/hooks')) -conf.set_quoted('LXCBINHOOKDIR', join_paths(libexecdir, 'lxc/hooks')) + +lxcdefaultconfig = join_paths(sysconfdir, 'lxc/default.conf') +conf.set_quoted('LXC_DEFAULT_CONFIG', lxcdefaultconfig) + +lxcapparmorcachedir = join_paths(localstatedir, apparmorcachedir) +conf.set_quoted('APPARMOR_CACHE_DIR', lxcapparmorcachedir) + +lxcrootfsmount = join_paths(prefixdir, rootfsmount) +conf.set_quoted('LXCROOTFSMOUNT', lxcrootfsmount) + +lxcglobalconfig = join_paths(sysconfdir, globalconfig) +conf.set_quoted('LXC_GLOBAL_CONF', lxcglobalconfig) + +lxclogpath = join_paths(localstatedir, logpath) +conf.set_quoted('LOGPATH', lxclogpath) + +lxcpath = join_paths(localstatedir, lxcpathprefix) +conf.set_quoted('LXCPATH', lxcpath) + +lxctemplateconfig = join_paths(datadir, 'lxc/config') +conf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfig) + +lxctemplatedir = join_paths(datadir, 'lxc/templates') +conf.set_quoted('LXCTEMPLATEDIR', lxctemplatedir) + +lxchookdir = join_paths(datadir, 'lxc/hooks') +conf.set_quoted('LXCHOOKDIR', lxchookdir) + +lxchookbindir = join_paths(libexecdir, 'lxc/hooks') +conf.set_quoted('LXCBINHOOKDIR', lxchookbindir) # AS_AC_EXPAND(LXC_GENERATE_DATE, "$(date --utc --date=@${SOURCE_DATE_EPOCH:-$(date +%s)} '+%Y-%m-%d')") # AS_AC_EXPAND(LXC_USERNIC_CONF, "$with_usernic_conf") @@ -473,3 +496,33 @@ public_programs += executable( include_directories : tools_liblxc_includes, dependencies : liblxc_dep, install : true) + +status = [ + '@0@ @1@'.format(meson.project_name(), meson.project_version()), + + 'prefix directory: @0@'.format(prefixdir), + 'bin directory: @0@'.format(bindir), + 'data directory: @0@'.format(datadir), + 'doc directory: @0@'.format(docdir), + 'include directory: @0@'.format(includedir), + 'lib directory: @0@'.format(libdir), + 'libexec directory: @0@'.format(libexecdir), + 'local state directory: @0@'.format(localstatedir), + 'sbin directory: @0@'.format(sbindir), + 'sysconf directory: @0@'.format(sysconfdir), + + 'lxc cgroup pattern: @0@'.format(cgrouppattern), + 'lxc init directory: @0@'.format(libexecdir), + 'runtime path: @0@'.format(runtimepath), + + 'lxc default config: @0@'.format(lxcdefaultconfig), + 'lxc global config: @0@'.format(lxcglobalconfig), + 'lxc hook directory: @0@'.format(lxchookdir), + 'lxc hook bin directory: @0@'.format(lxchookbindir), + 'lxc rootfs mount directory: @0@'.format(lxcrootfsmount), + 'log path: @0@'.format(lxclogpath), + 'lxc path: @0@'.format(lxcpath), + 'lxc template config: @0@'.format(lxctemplateconfig), + 'lxc template directory: @0@'.format(lxctemplatedir)] + +message('\n '.join(status)) From ec5d2163f3494a16668cd4b2939f287ff093a3f3 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Tue, 14 Sep 2021 10:03:12 +0200 Subject: [PATCH 59/62] build: remove pointless prefixdir validation Meson will handle this internall and treat a non-absolute path as an error. Signed-off-by: Christian Brauner --- meson.build | 3 --- 1 file changed, 3 deletions(-) diff --git a/meson.build b/meson.build index 733172de3..aac9330e3 100644 --- a/meson.build +++ b/meson.build @@ -37,9 +37,6 @@ project_build_root = meson.current_build_dir() # encountered, so this should canonicalize various paths when they are # absolute or relative. prefixdir = get_option('prefix') -if not prefixdir.startswith('/') - error('Prefix is not absolute: "@0@"'.format(prefixdir)) -endif bindir = join_paths(prefixdir, get_option('bindir')) datadir = join_paths(prefixdir, get_option('datadir')) docdir = join_paths(prefixdir, get_option('docdir')) From 589e116754f26f663ff4c43a5d9955ac26bd6985 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Tue, 14 Sep 2021 10:23:37 +0200 Subject: [PATCH 60/62] build: use correct minimal meson version requirement Signed-off-by: Christian Brauner --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index aac9330e3..9b104160a 100644 --- a/meson.build +++ b/meson.build @@ -10,7 +10,7 @@ project('lxc', 'c', 'c_std=gnu11', 'warning_level=2', ], - meson_version : '>= 0.45', + meson_version : '>= 0.46', ) liblxc_version = '4.0.0' From e282c460af4232679a41e4b6b534c7ce0d28391e Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Tue, 14 Sep 2021 10:34:05 +0200 Subject: [PATCH 61/62] build: record meson version Signed-off-by: Christian Brauner --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index 9b104160a..c0b21e048 100644 --- a/meson.build +++ b/meson.build @@ -497,6 +497,8 @@ public_programs += executable( status = [ '@0@ @1@'.format(meson.project_name(), meson.project_version()), + 'Meson version: @0@'.format(meson.version()), + 'prefix directory: @0@'.format(prefixdir), 'bin directory: @0@'.format(bindir), 'data directory: @0@'.format(datadir), From ea6da2577b515677dfb84781f56dc800b5b95cdd Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Tue, 14 Sep 2021 11:01:59 +0200 Subject: [PATCH 62/62] build: show more detailed information Signed-off-by: Christian Brauner --- meson.build | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/meson.build b/meson.build index c0b21e048..b28ffd588 100644 --- a/meson.build +++ b/meson.build @@ -245,6 +245,17 @@ foreach ident : [ endif endforeach +sh = find_program('sh') +git = find_program('git', required : false) +time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"').stdout().strip() +if time_epoch == '' and git.found() and run_command('test', '-e', '.git').returncode() == 0 + # If we're in a git repository, use the creation time of the latest git tag. + latest_tag = run_command(git, 'describe', '--abbrev=0', '--tags').stdout().strip() + time_epoch = run_command(git, 'log', '--no-show-signature', '-1', '--format=%at', latest_tag).stdout() +endif +time_epoch = time_epoch.to_int() +conf.set('TIME_EPOCH', time_epoch) + threads = dependency('threads') libseccomp = dependency('libseccomp') if libseccomp.found() @@ -494,6 +505,128 @@ public_programs += executable( dependencies : liblxc_dep, install : true) +found_syscalls = [] +missing_syscalls = [] + +foreach tuple : [ + ['fexecve'], + ['memfd_create'], + ['gettid'], + ['pivot_root'], + ['setns'], + ['renameat2'], + ['kcmp'], + ['keyctl'], + ['bpf'], + ['statx'], + ['pidfd_send_signal'], + ['pidfd_open'], + ['execveat'], + ['close_range'], + ['mount_setattr'], + ['move_mount'], + ['open_tree'], + ['strlcpy'], + ['strlcat'], + ['sethostname'], + ['faccessat'], + ['unshare'], + ['prlimit'], + ['prlimit64'], +] + + if tuple.length() >= 2 + cond = tuple[1] + else + ident1 = 'HAVE_' + tuple[0].underscorify().to_upper() + ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper() + cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1 + endif + if cond + found_syscalls += tuple[0] + else + missing_syscalls += tuple[0] + endif +endforeach + +found_types = [] +missing_types = [] + +foreach tuple : [ + ['scmp_filter_ctx'], + ['struct seccomp_notif_sizes'], + ['struct clone_args'], + ['__aligned_u64'], + ['struct mount_attr'], + ['struct open_how'], +] + + if tuple.length() >= 2 + cond = tuple[1] + else + ident1 = 'HAVE_' + tuple[0].underscorify().to_upper() + ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper() + cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1 + endif + if cond + found_types += tuple[0] + else + missing_types += tuple[0] + endif +endforeach + +found_headers = [] +missing_headers = [] + +foreach tuple : [ + ['sys/resource.h'], + ['sys/memfd.h'], + ['sys/personality.h'], + ['sys/signalfd.h'], + ['sys/timerfd.h'], + ['pty.h'], + ['utmpx.h' ], +] + + if tuple.length() >= 2 + cond = tuple[1] + else + ident1 = 'HAVE_' + tuple[0].underscorify().to_upper() + ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper() + cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1 + endif + if cond + found_headers += tuple[0] + else + missing_headers += tuple[0] + endif +endforeach + +found_deps = [] +missing_deps = [] + +foreach tuple : [ + ['AppArmor'], + ['SECCOMP'], + ['SELinux'], + ['libcap'], + ['openssl'], +] + + if tuple.length() >= 2 + cond = tuple[1] + else + ident1 = 'HAVE_' + tuple[0].underscorify().to_upper() + ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper() + cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1 + endif + if cond + found_deps += tuple[0] + else + missing_deps += tuple[0] + endif +endforeach + status = [ '@0@ @1@'.format(meson.project_name(), meson.project_version()), @@ -524,4 +657,37 @@ status = [ 'lxc template config: @0@'.format(lxctemplateconfig), 'lxc template directory: @0@'.format(lxctemplatedir)] +alt_time_epoch = run_command('date', '-Is', '-u', '-d', + '@@0@'.format(time_epoch)).stdout().strip() +status += [ + 'time epoch: @0@ (@1@)'.format(time_epoch, alt_time_epoch)] + +status += [ + '', + 'supported dependencies: @0@'.format(', '.join(found_deps)), + '', + 'unsupported dependencies: @0@'.format(', '.join(missing_deps)), + ''] + +status += [ + '', + 'supported headers: @0@'.format(', '.join(found_headers)), + '', + 'unsupported headers: @0@'.format(', '.join(missing_headers)), + ''] + +status += [ + '', + 'supported calls: @0@'.format(', '.join(found_syscalls)), + '', + 'unsupported calls: @0@'.format(', '.join(missing_syscalls)), + ''] + +status += [ + '', + 'supported types: @0@'.format(', '.join(found_types)), + '', + 'unsupported types: @0@'.format(', '.join(missing_types)), + ''] + message('\n '.join(status))