diff --git a/meson.build b/meson.build index c873b9b6..b9a108a6 100644 --- a/meson.build +++ b/meson.build @@ -125,7 +125,9 @@ foreach ident : [ conf.set10('HAVE_' + ident[0].to_upper(), have) endforeach +conf.set('_GNU_SOURCE', true) conf.set('_FILE_OFFSET_BITS', 64) +conf.set('__STDC_FORMAT_MACROS', true) libfuse = dependency('fuse3', required : false) if libfuse.found() diff --git a/src/api_extensions.h b/src/api_extensions.h index 9ee55daf..77f69e71 100644 --- a/src/api_extensions.h +++ b/src/api_extensions.h @@ -3,11 +3,11 @@ #ifndef __LXCFS_API_EXTENSIONS_H #define __LXCFS_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/bindings.c b/src/bindings.c index dc4da142..eb62ddbd 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -1,9 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include diff --git a/src/bindings.h b/src/bindings.h index 4e033628..a278aa7a 100644 --- a/src/bindings.h +++ b/src/bindings.h @@ -14,11 +14,7 @@ #include #include -#if HAVE_FUSE3 -#include -#else -#include -#endif +#include "lxcfs_fuse.h" #include "cgroup_fuse.h" #include "macro.h" diff --git a/src/cgroup_fuse.c b/src/cgroup_fuse.c index cfdf7701..5c22fd15 100644 --- a/src/cgroup_fuse.c +++ b/src/cgroup_fuse.c @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" -#define __STDC_FORMAT_MACROS #include #include #include diff --git a/src/cgroup_fuse.h b/src/cgroup_fuse.h index 494dac70..c2315230 100644 --- a/src/cgroup_fuse.h +++ b/src/cgroup_fuse.h @@ -11,11 +11,7 @@ #include #include -#if HAVE_FUSE3 -#include -#else -#include -#endif +#include "lxcfs_fuse.h" #include "macro.h" diff --git a/src/cgroups/cgfsng.c b/src/cgroups/cgfsng.c index eb951b40..b0d26569 100644 --- a/src/cgroups/cgfsng.c +++ b/src/cgroups/cgfsng.c @@ -12,10 +12,6 @@ * a comma-separated list of controllers. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include diff --git a/src/cgroups/cgroup.c b/src/cgroups/cgroup.c index 7aec7aed..5bf7f62d 100644 --- a/src/cgroups/cgroup.c +++ b/src/cgroups/cgroup.c @@ -1,9 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include diff --git a/src/cgroups/cgroup.h b/src/cgroups/cgroup.h index c9ea3700..122e8ebf 100644 --- a/src/cgroups/cgroup.h +++ b/src/cgroups/cgroup.h @@ -3,22 +3,13 @@ #ifndef __LXC_CGROUP_H #define __LXC_CGROUP_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#ifndef FUSE_USE_VERSION -#define FUSE_USE_VERSION 26 -#endif - -#define _FILE_OFFSET_BITS 64 +#include "config.h" #include #include #include #include -#include "../config.h" #include "../macro.h" #include "../memory_utils.h" diff --git a/src/cgroups/cgroup2_devices.c b/src/cgroups/cgroup2_devices.c index 06d258fa..e2eab796 100644 --- a/src/cgroups/cgroup2_devices.c +++ b/src/cgroups/cgroup2_devices.c @@ -2,10 +2,6 @@ /* Parts of this taken from systemd's implementation. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include diff --git a/src/cgroups/cgroup2_devices.h b/src/cgroups/cgroup2_devices.h index 67a2da8c..6de10216 100644 --- a/src/cgroups/cgroup2_devices.h +++ b/src/cgroups/cgroup2_devices.h @@ -5,15 +5,7 @@ #ifndef __LXC_CGROUP2_DEVICES_H #define __LXC_CGROUP2_DEVICES_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#ifndef FUSE_USE_VERSION -#define FUSE_USE_VERSION 26 -#endif - -#define _FILE_OFFSET_BITS 64 +#include "config.h" #include #include diff --git a/src/cgroups/cgroup_utils.c b/src/cgroups/cgroup_utils.c index f4ae4ccf..83e4cbf7 100644 --- a/src/cgroups/cgroup_utils.c +++ b/src/cgroups/cgroup_utils.c @@ -1,9 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include diff --git a/src/cgroups/cgroup_utils.h b/src/cgroups/cgroup_utils.h index 8576e5e4..f4316866 100644 --- a/src/cgroups/cgroup_utils.h +++ b/src/cgroups/cgroup_utils.h @@ -3,15 +3,7 @@ #ifndef __LXC_CGROUP_UTILS_H #define __LXC_CGROUP_UTILS_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#ifndef FUSE_USE_VERSION -#define FUSE_USE_VERSION 26 -#endif - -#define _FILE_OFFSET_BITS 64 +#include "config.h" #include #include @@ -25,7 +17,6 @@ #include #include -#include "../config.h" #include "../macro.h" #include "../memory_utils.h" diff --git a/src/cpuset_parse.c b/src/cpuset_parse.c index c2edbc04..e511bb02 100644 --- a/src/cpuset_parse.c +++ b/src/cpuset_parse.c @@ -1,15 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" -#define _FILE_OFFSET_BITS 64 - -#define __STDC_FORMAT_MACROS - #include #include #include diff --git a/src/cpuset_parse.h b/src/cpuset_parse.h index 5ff8e668..33243457 100644 --- a/src/cpuset_parse.h +++ b/src/cpuset_parse.h @@ -3,11 +3,7 @@ #ifndef __LXCFS_CPUSET_PARSE_H #define __LXCFS_CPUSET_PARSE_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#define _FILE_OFFSET_BITS 64 +#include "config.h" #include #include diff --git a/src/lxcfs.c b/src/lxcfs.c index b6e404d0..56355967 100644 --- a/src/lxcfs.c +++ b/src/lxcfs.c @@ -1,9 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include @@ -28,11 +24,7 @@ #include #include -#if HAVE_FUSE3 -#include -#else -#include -#endif +#include "lxcfs_fuse.h" #include "bindings.h" #include "lxcfs_fuse_compat.h" @@ -607,7 +599,7 @@ static int do_sys_releasedir(const char *path, struct fuse_file_info *fi) return __sys_releasedir(path, fi); } -#ifdef HAVE_FUSE3 +#if HAVE_FUSE3 static int lxcfs_getattr(const char *path, struct stat *sb, struct fuse_file_info *fi) #else static int lxcfs_getattr(const char *path, struct stat *sb) @@ -678,7 +670,7 @@ static int lxcfs_opendir(const char *path, struct fuse_file_info *fi) return -ENOENT; } -#ifdef HAVE_FUSE3 +#if HAVE_FUSE3 static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags) #else @@ -926,7 +918,7 @@ int lxcfs_mkdir(const char *path, mode_t mode) return -EPERM; } -#ifdef HAVE_FUSE3 +#if HAVE_FUSE3 int lxcfs_chown(const char *path, uid_t uid, gid_t gid, struct fuse_file_info *fi) #else int lxcfs_chown(const char *path, uid_t uid, gid_t gid) @@ -955,7 +947,7 @@ int lxcfs_chown(const char *path, uid_t uid, gid_t gid) * really make sense for cgroups. So just return 0 always but do * nothing. */ -#ifdef HAVE_FUSE3 +#if HAVE_FUSE3 int lxcfs_truncate(const char *path, off_t newsize, struct fuse_file_info *fi) #else int lxcfs_truncate(const char *path, off_t newsize) @@ -984,7 +976,7 @@ int lxcfs_rmdir(const char *path) return -EPERM; } -#ifdef HAVE_FUSE3 +#if HAVE_FUSE3 int lxcfs_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) #else int lxcfs_chmod(const char *path, mode_t mode) @@ -1008,7 +1000,7 @@ int lxcfs_chmod(const char *path, mode_t mode) return -ENOENT; } -#ifdef HAVE_FUSE3 +#if HAVE_FUSE3 static void *lxcfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg) #else static void *lxcfs_init(struct fuse_conn_info *conn) @@ -1048,11 +1040,11 @@ const struct fuse_operations lxcfs_ops = { .create = NULL, .destroy = NULL, -#ifndef HAVE_FUSE3 +#if !HAVE_FUSE3 .fgetattr = NULL, #endif .fsyncdir = NULL, -#ifndef HAVE_FUSE3 +#if !HAVE_FUSE3 .ftruncate = NULL, .getdir = NULL, #endif @@ -1066,7 +1058,7 @@ const struct fuse_operations lxcfs_ops = { .statfs = NULL, .symlink = NULL, .unlink = NULL, -#ifndef HAVE_FUSE3 +#if !HAVE_FUSE3 .utime = NULL, #endif }; @@ -1181,7 +1173,7 @@ int main(int argc, char *argv[]) char *pidfile = NULL, *token = NULL; char pidfile_buf[STRLITERALLEN(RUNTIME_PATH) + STRLITERALLEN("/lxcfs.pid") + 1] = {}; bool debug = false, foreground = false; -#ifndef HAVE_FUSE3 +#if !HAVE_FUSE3 bool nonempty = false; #endif bool load_use = false; @@ -1307,7 +1299,7 @@ int main(int argc, char *argv[]) /* default with fuse3 */ if (strcmp(token, "nonempty") == 0) { - #ifndef HAVE_FUSE3 + #if !HAVE_FUSE3 nonempty = true; #endif continue; @@ -1327,7 +1319,7 @@ int main(int argc, char *argv[]) goto out; } -#ifndef HAVE_FUSE3 +#if !HAVE_FUSE3 if (nonempty) { if (append_comma_separate(&new_fuse_opts, "nonempty")) { lxcfs_error("Failed to copy fuse argument \"nonempty\""); diff --git a/src/lxcfs_fuse.h b/src/lxcfs_fuse.h new file mode 100644 index 00000000..e4b2c1e0 --- /dev/null +++ b/src/lxcfs_fuse.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#ifndef __LXCFS_FUSE_H +#define __LXCFS_FUSE_H + +#include "config.h" + +#include "lxcfs_fuse_compat.h" + +#if HAVE_FUSE3 +#include +#else +#include +#endif + +#endif /* __LXCFS_FUSE_H */ diff --git a/src/lxcfs_fuse_compat.h b/src/lxcfs_fuse_compat.h index 9c61af04..fcf2da2f 100644 --- a/src/lxcfs_fuse_compat.h +++ b/src/lxcfs_fuse_compat.h @@ -3,13 +3,12 @@ #ifndef __LXCFS_FUSE_COMPAT_H #define __LXCFS_FUSE_COMPAT_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif +#include "config.h" -#ifdef HAVE_FUSE3 +#if HAVE_FUSE3 #define DIR_FILLER(F,B,N,S,O) F(B,N,S,O,FUSE_FILL_DIR_PLUS) #else #define DIR_FILLER(F,B,N,S,O) F(B,N,S,O) #endif + #endif /* __LXCFS_FUSE_COMPAT_H */ diff --git a/src/macro.h b/src/macro.h index b9abf11a..caa0126f 100644 --- a/src/macro.h +++ b/src/macro.h @@ -3,20 +3,10 @@ #ifndef __LXCFS_MACRO_H #define __LXCFS_MACRO_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#ifndef FUSE_USE_VERSION -#define FUSE_USE_VERSION 26 -#endif - -#define _FILE_OFFSET_BITS 64 +#include "config.h" #include -#include "config.h" - #define BATCH_SIZE 50 /* filesystem magic values */ diff --git a/src/memory_utils.h b/src/memory_utils.h index 2916f566..c689c8ec 100644 --- a/src/memory_utils.h +++ b/src/memory_utils.h @@ -3,6 +3,8 @@ #ifndef __LXCFS_MEMORY_UTILS_H #define __LXCFS_MEMORY_UTILS_H +#include "config.h" + #include #include #include diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c index b3bed6d0..472d69df 100644 --- a/src/proc_cpuview.c +++ b/src/proc_cpuview.c @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" -#define __STDC_FORMAT_MACROS #include #include #include diff --git a/src/proc_cpuview.h b/src/proc_cpuview.h index 15511e96..32eee540 100644 --- a/src/proc_cpuview.h +++ b/src/proc_cpuview.h @@ -10,11 +10,7 @@ #include #include -#if HAVE_FUSE3 -#include -#else -#include -#endif +#include "lxcfs_fuse.h" #include "macro.h" diff --git a/src/proc_fuse.c b/src/proc_fuse.c index 80dc9a32..4ac5d44b 100644 --- a/src/proc_fuse.c +++ b/src/proc_fuse.c @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" -#define __STDC_FORMAT_MACROS #include #include #include diff --git a/src/proc_fuse.h b/src/proc_fuse.h index 2c1f5727..c97d60c7 100644 --- a/src/proc_fuse.h +++ b/src/proc_fuse.h @@ -5,11 +5,7 @@ #include "config.h" -#if HAVE_FUSE3 -#include -#else -#include -#endif +#include "lxcfs_fuse.h" #include #include diff --git a/src/proc_loadavg.c b/src/proc_loadavg.c index b70437a9..5f9bec79 100644 --- a/src/proc_loadavg.c +++ b/src/proc_loadavg.c @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" -#define __STDC_FORMAT_MACROS #include #include #include diff --git a/src/proc_loadavg.h b/src/proc_loadavg.h index bb6a78b1..e6ae2ded 100644 --- a/src/proc_loadavg.h +++ b/src/proc_loadavg.h @@ -11,11 +11,7 @@ #include #include -#if HAVE_FUSE3 -#include -#else -#include -#endif +#include "lxcfs_fuse.h" #include "macro.h" diff --git a/src/syscall_numbers.h b/src/syscall_numbers.h index 41eb5dcc..c9006af3 100644 --- a/src/syscall_numbers.h +++ b/src/syscall_numbers.h @@ -2,9 +2,8 @@ #ifndef __LXCFS_SYSCALL_NUMBERS_H #define __LXCFS_SYSCALL_NUMBERS_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif +#include "config.h" + #include #include #include diff --git a/src/sysfs_fuse.c b/src/sysfs_fuse.c index 4525b69e..b07464c7 100644 --- a/src/sysfs_fuse.c +++ b/src/sysfs_fuse.c @@ -1,17 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" -/* Taken over modified from the kernel sources. */ -#define NBITS 32 /* bits in uint32_t */ -#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d)) -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, NBITS) - -#define __STDC_FORMAT_MACROS #include #include #include @@ -47,6 +37,11 @@ #include "lxcfs_fuse_compat.h" #include "utils.h" +/* Taken over modified from the kernel sources. */ +#define NBITS 32 /* bits in uint32_t */ +#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d)) +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, NBITS) + static ssize_t get_max_cpus(char *cpulist) { char *c1, *c2; diff --git a/src/sysfs_fuse.h b/src/sysfs_fuse.h index f151af7f..a80d3d82 100644 --- a/src/sysfs_fuse.h +++ b/src/sysfs_fuse.h @@ -11,11 +11,7 @@ #include #include -#if HAVE_FUSE3 -#include -#else -#include -#endif +#include "lxcfs_fuse.h" #include "macro.h" diff --git a/src/utils.c b/src/utils.c index 99271854..b826b2ef 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" -#define _FILE_OFFSET_BITS 64 #include #include #include diff --git a/src/utils.h b/src/utils.h index e19eba49..18d85a73 100644 --- a/src/utils.h +++ b/src/utils.h @@ -13,11 +13,7 @@ #include #include -#if HAVE_FUSE3 -#include -#else -#include -#endif +#include "lxcfs_fuse.h" #include "macro.h" #include "syscall_numbers.h" diff --git a/tests/cpusetrange.c b/tests/cpusetrange.c index 38eea26b..50af4ff5 100644 --- a/tests/cpusetrange.c +++ b/tests/cpusetrange.c @@ -1,9 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include diff --git a/tests/test-read.c b/tests/test-read.c index 9166dde8..2929c35a 100644 --- a/tests/test-read.c +++ b/tests/test-read.c @@ -1,9 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include diff --git a/tests/test_syscalls.c b/tests/test_syscalls.c index f0dbf455..56137f21 100644 --- a/tests/test_syscalls.c +++ b/tests/test_syscalls.c @@ -1,9 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "config.h" #include