diff --git a/configure.ac b/configure.ac index b073d52a1..f9860923c 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([[ 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/meson.build b/meson.build new file mode 100644 index 000000000..b28ffd588 --- /dev/null +++ b/meson.build @@ -0,0 +1,693 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +project('lxc', 'c', + version : '4.0.0', + license : 'LGPLv2+', + default_options: [ + 'b_colorout=always', + 'b_asneeded=true', + 'b_pie=true', + 'c_std=gnu11', + 'warning_level=2', + ], + meson_version : '>= 0.46', + ) + +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)') +conf.set('_GNU_SOURCE', true) +conf.set('__STDC_FORMAT_MACROS', true) + +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') +bindir = join_paths(prefixdir, get_option('bindir')) +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')) +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') +cgrouppattern = get_option('cgroup-pattern') +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('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('LXCINITDIR', libexecdir) +conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern) +conf.set_quoted('RUNTIME_PATH', runtimepath) + +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") +# AS_AC_EXPAND(LXC_USERNIC_DB, "$with_usernic_db") +# AS_AC_EXPAND(LXC_DISTRO_SYSCONF, "$distrosysconf") + +cc = meson.get_compiler('c') +pkgconfig = import('pkgconfig') + +possible_cc_flags = [ + '-Wvla', + '-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,--gc-sections', + '-Wl,-z,relro', + '-Wl,-z,now', + '-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 + if cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0 + conf.set10('HAVE_' + decl.underscorify().to_upper(), true) + 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 '''], +] + + if cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') + conf.set10('HAVE_' + ident[0].to_upper(), true) + 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() + 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 + ''' + foreach decl : [ + 'scmp_filter_ctx', + 'struct seccomp_notif_sizes', + 'struct clone_args', + ] + + # We get -1 if the size cannot be determined + if cc.sizeof(decl, prefix : seccomp_headers, args : '-D_GNU_SOURCE') > 0 + conf.set10('HAVE_' + decl.underscorify().to_upper(), true) + endif + endforeach +endif + +libselinux = dependency('libselinux', required : false) +if libselinux.found() + conf.set10('HAVE_SELINUX', libselinux.found()) +endif + +libapparmor = dependency('libapparmor', 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', required : false) +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') +subdir('src/lxc/tools') + +config_h = configure_file( + output : 'config.h', + configuration : conf) + +liblxc = shared_library( + 'lxc', + version : liblxc_version, + include_directories : tools_liblxc_includes, + link_args : ['-DPIC'], + c_args : ['-DPIC'], + link_whole : [liblxc_static], + dependencies : [threads, + libseccomp, + libcap, + libopenssl, + libselinux, + 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, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-cgroup', + tools_lxc_cgroup_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-checkpoint', + tools_lxc_checkpoint_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-config', + tools_lxc_config_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-console', + tools_lxc_console_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-copy', + tools_lxc_copy_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-create', + tools_lxc_create_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-destroy', + tools_lxc_destroy_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-device', + tools_lxc_device_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-execute', + tools_lxc_execute_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-freeze', + tools_lxc_freeze_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-info', + tools_lxc_info_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-ls', + tools_lxc_ls_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-monitor', + tools_lxc_monitor_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-snapshot', + tools_lxc_snapshot_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-start', + tools_lxc_start_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-stop', + tools_lxc_stop_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-top', + tools_lxc_top_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-unfreeze', + tools_lxc_unfreeze_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-unshare', + tools_lxc_unshare_sources, + include_directories : tools_liblxc_includes, + dependencies : liblxc_dep, + install : true) + +public_programs += executable( + 'lxc-wait', + tools_lxc_wait_sources, + include_directories : tools_liblxc_includes, + 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()), + + 'Meson version: @0@'.format(meson.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)] + +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)) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 000000000..bab30ec6b --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,32 @@ +# -*- 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') + +option('docdir', type : 'string', + description : 'documentation directory') 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; } diff --git a/src/include/meson.build b/src/include/meson.build new file mode 100644 index 000000000..03817c157 --- /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', true) +else + include_sources += files( + 'getline.c', + 'getline.h') +endif + +if cc.has_function('fexecve', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_FEXECVE', true) +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', true) +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', true) +endif + +have_setmntent = cc.has_function('setmntent', prefix : mntent_headers, args : '-D_GNU_SOURCE') +if have_setmntent + 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', true) +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', true) +else + include_sources += files( + 'strlcpy.c', + 'strlcpy.h') +endif + +if cc.has_function('strlcat', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_STRLCAT', true) +else + include_sources += files( + 'strlcat.c', + 'strlcat.h') +endif + +if cc.has_function('strchrnul', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_STRCHRNUL', true) +else + include_sources += files( + 'strchrnul.c', + 'strchrnul.h') +endif + +if cc.has_function('openpty', prefix : '#include ', args : '-D_GNU_SOURCE') + conf.set10('HAVE_OPENPTY', true) +else + include_sources += files( + 'openpty.c', + 'openpty.h') +endif 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)) 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..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" @@ -23,7 +21,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/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 5668fd035..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 @@ -22,7 +21,7 @@ #include #include -#include +#include "attach.h" #include "af_unix.h" #include "attach.h" @@ -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" @@ -163,7 +161,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 +1795,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 +1804,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); diff --git a/src/lxc/attach.h b/src/lxc/attach.h index 66b9796a3..c85b84fbe 100644 --- a/src/lxc/attach.h +++ b/src/lxc/attach.h @@ -3,10 +3,13 @@ #ifndef __LXC_ATTACH_H #define __LXC_ATTACH_H +#include "config.h" + #include -#include #include +#include "lxc.h" + #include "compiler.h" #include "namespace.h" 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 diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 1f8080241..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 @@ -54,11 +50,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); @@ -163,7 +159,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 +2128,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 +2204,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 +2433,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)) 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 c8a1606a1..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,14 +20,13 @@ #include "cgroup.h" #include "compiler.h" #include "conf.h" -#include "config.h" #include "list.h" #include "macro.h" #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/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/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/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/commands.c b/src/lxc/commands.c index 535242f10..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" @@ -253,14 +251,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 +1487,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 */ 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/commands_utils.c b/src/lxc/commands_utils.c index b2957b007..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 @@ -13,10 +11,10 @@ #include #include +#include "attach_options.h" #include "af_unix.h" #include "commands.h" #include "commands_utils.h" -#include "config.h" #include "file_utils.h" #include "initutils.h" #include "log.h" @@ -129,7 +127,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); 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/conf.c b/src/lxc/conf.c index 86ad68b52..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 @@ -34,12 +33,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" #include "error.h" @@ -75,7 +73,7 @@ #if HAVE_OPENPTY #include #else -#include <../include/openpty.h> +#include "openpty.h" #endif #if HAVE_LIBCAP @@ -83,25 +81,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); @@ -185,7 +183,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[] = { @@ -885,7 +883,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 +972,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 +980,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 +1026,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 +1105,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 +1116,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 +1124,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 +1295,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 +1305,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 +2244,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) { @@ -2803,7 +2800,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); @@ -2979,7 +2976,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, @@ -3438,7 +3435,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 +3506,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 +3717,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 +4115,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 +5520,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 +5548,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); 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" diff --git a/src/lxc/confile.c b/src/lxc/confile.c index a5f7249b7..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 @@ -21,30 +19,32 @@ #include #include #include -#include +#include #include #include "af_unix.h" #include "conf.h" -#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" #include "memory_utils.h" #include "network.h" #include "parse.h" -#include "storage/storage.h" #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 + +#if HAVE_SYS_RESOURCE_H +#include #endif lxc_log_define(confile, lxc); @@ -2540,7 +2540,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 +2585,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 +3216,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 +4508,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]); diff --git a/src/lxc/confile.h b/src/lxc/confile.h index 999dc1648..d9b20c64e 100644 --- a/src/lxc/confile.h +++ b/src/lxc/confile.h @@ -3,11 +3,12 @@ #ifndef __LXC_CONFILE_H #define __LXC_CONFILE_H +#include "config.h" + #include #include -#include -#include +#include "lxc.h" #include "compiler.h" diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index fff20375c..5534daa41 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -1,23 +1,22 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include #include #include +#include "lxc.h" + #include "conf.h" -#include "config.h" #include "confile.h" #include "confile_utils.h" #include "error.h" #include "list.h" #include "lxc.h" #include "log.h" -#include "lxccontainer.h" #include "macro.h" #include "memory_utils.h" #include "network.h" @@ -25,7 +24,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(confile_utils, lxc); @@ -799,7 +798,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; 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 4452d0b0c..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 @@ -14,10 +13,11 @@ #include #include +#include "attach_options.h" + #include "cgroup.h" #include "commands.h" #include "conf.h" -#include "config.h" #include "criu.h" #include "log.h" #include "lxc.h" @@ -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" @@ -335,7 +335,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"); @@ -443,7 +443,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"); diff --git a/src/lxc/criu.h b/src/lxc/criu.h index 2e0ca7feb..873f88786 100644 --- a/src/lxc/criu.h +++ b/src/lxc/criu.h @@ -3,9 +3,11 @@ #ifndef __LXC_CRIU_H #define __LXC_CRIU_H +#include "config.h" + #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/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 eaa9a5a40..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" @@ -259,14 +257,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 +596,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 +613,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; 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 5d2d48978..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 @@ -12,11 +11,11 @@ #include #include +#include "attach_options.h" #include "cgroups/cgroup.h" #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 5f2a42454..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" @@ -20,7 +18,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/initutils.h b/src/lxc/initutils.h index e99de13af..814365122 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,8 +17,6 @@ #include #include -#include "config.h" -#include "cgroups/cgroup.h" #include "compiler.h" #include "string_utils.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 be3a16fcc..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 @@ -18,16 +16,16 @@ #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" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #if HAVE_DLOG diff --git a/src/lxc/log.h b/src/lxc/log.h index 17fccc14e..80fb49c36 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 diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c index 0667526d4..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" @@ -406,7 +404,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 +415,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 +719,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/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 34987a6c7..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" @@ -136,7 +134,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); diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index f688b25c2..e58fb2185 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 @@ -12,6 +14,9 @@ extern "C" { #include #include +#include "attach_options.h" +#include "lxccontainer.h" + #include "compiler.h" #include "memory_utils.h" #include "state.h" diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 3b18d00ff..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 @@ -25,7 +24,9 @@ #include #include -#include "../include/netns_ifaddrs.h" +#include "lxc.h" + +#include "netns_ifaddrs.h" #include "af_unix.h" #include "api_extensions.h" #include "attach.h" @@ -34,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" @@ -42,7 +42,6 @@ #include "initutils.h" #include "log.h" #include "lxc.h" -#include "lxccontainer.h" #include "lxclock.h" #include "memory_utils.h" #include "monitor.h" @@ -1625,13 +1624,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 +1707,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 +4267,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 +5473,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); } 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 a6a43cef2..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 @@ -12,9 +11,8 @@ #include #include -#include +#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/meson.build b/src/lxc/meson.build new file mode 100644 index 000000000..756dd22c5 --- /dev/null +++ b/src/lxc/meson.build @@ -0,0 +1,131 @@ +# 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_static = static_library( + 'lxc_static', + liblxc_sources + include_sources, + install : false, + include_directories : liblxc_includes, + dependencies : [threads], + c_args : '-fvisibility=default') diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index 26f1ec04b..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" @@ -33,7 +31,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(monitor, lxc); @@ -224,7 +222,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 +233,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 +324,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]); 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 15ed81bd5..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 @@ -26,10 +25,9 @@ #include #include -#include "../include/netns_ifaddrs.h" +#include "netns_ifaddrs.h" #include "af_unix.h" #include "conf.h" -#include "config.h" #include "file_utils.h" #include "log.h" #include "macro.h" @@ -42,7 +40,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(network, lxc); @@ -2518,7 +2516,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 +2619,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); 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 81e9cbab4..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" @@ -42,7 +40,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 +120,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 +186,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; 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 74d10a760..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" @@ -34,11 +32,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/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 060df680e..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" @@ -19,7 +17,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/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 ff1d6e04e..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 @@ -11,11 +10,11 @@ #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" @@ -93,9 +92,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 +128,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 +263,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 +496,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 +543,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 +618,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]; diff --git a/src/lxc/start.c b/src/lxc/start.c index 7f0903f1b..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 @@ -25,7 +24,10 @@ #include #include +#include "lxc.h" + #include "af_unix.h" +#include "attach_options.h" #include "caps.h" #include "cgroups/cgroup.h" #include "cgroups/cgroup_utils.h" @@ -33,14 +35,12 @@ #include "commands_utils.h" #include "compiler.h" #include "conf.h" -#include "config.h" #include "confile_utils.h" #include "error.h" #include "file_utils.h" #include "list.h" #include "log.h" #include "lsm/lsm.h" -#include "lxccontainer.h" #include "lxclock.h" #include "lxcseccomp.h" #include "macro.h" @@ -63,7 +63,7 @@ #endif #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif lxc_log_define(start, lxc); @@ -316,7 +316,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; } @@ -354,7 +354,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; @@ -445,7 +445,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 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 b115e10bb..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" @@ -26,11 +24,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); @@ -687,11 +685,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 +704,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 +737,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 +800,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/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 9c79565e2..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" @@ -275,10 +272,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/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 ba4207380..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" @@ -22,7 +20,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/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 410b4ff5a..f8094fada 100644 --- a/src/lxc/storage/overlay.c +++ b/src/lxc/storage/overlay.c @@ -1,18 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #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" @@ -116,7 +115,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 +466,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/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 7a8a8b8be..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" @@ -18,7 +15,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/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 a8c4be5f3..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" @@ -43,7 +41,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..001a39c36 100644 --- a/src/lxc/storage/storage.h +++ b/src/lxc/storage/storage.h @@ -3,13 +3,15 @@ #ifndef __LXC_STORAGE_H #define __LXC_STORAGE_H +#include "config.h" + #include #include -#include +#include "lxc.h" #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..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" @@ -31,7 +29,7 @@ #include "utils.h" #ifndef HAVE_STRLCPY -#include "include/strlcpy.h" +#include "strlcpy.h" #endif #ifndef BLKGETSIZE64 @@ -184,6 +182,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 +203,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/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 b209d79e0..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" @@ -380,7 +378,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 +512,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 +537,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 +715,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; } 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.c b/src/lxc/string_utils.c index b1d6dc9bc..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,20 +24,16 @@ #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 "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) @@ -1000,10 +994,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 ac916c6b6..7abbc537f 100644 --- a/src/lxc/string_utils.h +++ b/src/lxc/string_utils.h @@ -3,23 +3,23 @@ #ifndef __LXC_STRING_UTILS_H #define __LXC_STRING_UTILS_H -#include - #include "config.h" +#include + #include "initutils.h" #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) */ @@ -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) 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 7d62b7c5b..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" @@ -67,7 +65,7 @@ extern int memfd_create(const char *name, unsigned int flags); #endif #ifndef HAVE_PIVOT_ROOT -static int pivot_root(const char *new_root, const char *put_old) +static inline int pivot_root(const char *new_root, const char *put_old) { return syscall(__NR_pivot_root, new_root, put_old); } diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index 7327893b3..8c84f2875 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -1,11 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include -#include #include #include #include @@ -15,11 +13,12 @@ #include #include +#include "lxc.h" + #include "af_unix.h" #include "caps.h" #include "commands.h" #include "conf.h" -#include "config.h" #include "log.h" #include "lxclock.h" #include "mainloop.h" @@ -32,7 +31,7 @@ #if HAVE_OPENPTY #include #else -#include <../include/openpty.h> +#include "openpty.h" #endif #define LXC_TERMINAL_BUFFER_SIZE 1024 @@ -270,7 +269,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 +300,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 +614,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 +631,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 +651,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 +663,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; 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/arguments.c b/src/lxc/tools/arguments.c index 447031fc0..4176db0e7 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,12 +12,9 @@ #include #include -#include -#include +#include "lxc.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..0f0875079 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 "lxc.h" #include "compiler.h" struct lxc_arguments; 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_attach.c b/src/lxc/tools/lxc_attach.c index e6b388b20..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 @@ -15,12 +14,11 @@ #include #include -#include +#include "lxc.h" #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 ecede5c34..91596d4f6 100644 --- a/src/lxc/tools/lxc_autostart.c +++ b/src/lxc/tools/lxc_autostart.c @@ -1,17 +1,15 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include #include -#include +#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 17975152d..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 @@ -10,10 +9,9 @@ #include #include -#include +#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 4fd25f75b..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 @@ -10,10 +9,9 @@ #include #include -#include +#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 dda2db6dc..e4424c4cf 100644 --- a/src/lxc/tools/lxc_config.c +++ b/src/lxc/tools/lxc_config.c @@ -1,14 +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 "lxc.h" struct lxc_config_items { char *name; diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c index 3e35fe4aa..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 @@ -17,10 +16,9 @@ #include #include -#include +#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 a786a300c..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 @@ -18,16 +17,15 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "storage_utils.h" #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_create.c b/src/lxc/tools/lxc_create.c index 368d0d0a5..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 @@ -11,10 +10,9 @@ #include #include -#include +#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_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 c6641f45a..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 @@ -10,11 +9,10 @@ #include #include -#include +#include "lxc.h" -#include "../../include/netns_ifaddrs.h" +#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 6352114ec..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 @@ -14,11 +13,10 @@ #include #include -#include +#include "lxc.h" #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 483d3aca3..c18779ba3 100644 --- a/src/lxc/tools/lxc_freeze.c +++ b/src/lxc/tools/lxc_freeze.c @@ -1,18 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include #include #include -#include +#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 fda811fd8..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 @@ -12,10 +11,9 @@ #include #include -#include +#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 562622c4d..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 @@ -19,10 +17,9 @@ #include #include -#include +#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 326b8e7e0..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 @@ -23,11 +21,10 @@ #include #include -#include +#include "lxc.h" #include "af_unix.h" #include "arguments.h" -#include "config.h" #include "log.h" #include "macro.h" #include "monitor.h" @@ -185,8 +182,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 +205,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_snapshot.c b/src/lxc/tools/lxc_snapshot.c index a3c058abd..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 @@ -12,10 +11,9 @@ #include #include -#include +#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_start.c b/src/lxc/tools/lxc_start.c index 459b86793..6d2c0ae25 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,10 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" #include "caps.h" -#include "config.h" #include "confile.h" #include "log.h" diff --git a/src/lxc/tools/lxc_stop.c b/src/lxc/tools/lxc_stop.c index 73ae61766..8787bacd5 100644 --- a/src/lxc/tools/lxc_stop.c +++ b/src/lxc/tools/lxc_stop.c @@ -1,18 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include #include #include -#include +#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 9cf2cbbbd..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 @@ -18,10 +16,9 @@ #include #include -#include +#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 e8e2f3180..818447cad 100644 --- a/src/lxc/tools/lxc_unfreeze.c +++ b/src/lxc/tools/lxc_unfreeze.c @@ -1,18 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include #include #include -#include +#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 a0ef5f618..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" @@ -149,14 +147,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); diff --git a/src/lxc/tools/lxc_wait.c b/src/lxc/tools/lxc_wait.c index b5ce3e13f..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 @@ -11,10 +10,9 @@ #include #include -#include +#include "lxc.h" #include "arguments.h" -#include "config.h" #include "log.h" lxc_log_define(lxc_wait, lxc); diff --git a/src/lxc/tools/meson.build b/src/lxc/tools/meson.build new file mode 100644 index 000000000..40a131959 --- /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', true) +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 diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 55995405c..aab0dda23 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 @@ -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; } 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/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; 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/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/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" 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