[lxc-devel] [lxc/master] tree-wide: fix includes to fix bionic builds

brauner on Github lxc-bot at linuxcontainers.org
Wed Sep 26 22:53:16 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180926/baa05f19/attachment.bin>
-------------- next part --------------
From 7b206e95bba4b0d7e7467b4aa98d23126a3274e3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 27 Sep 2018 00:51:59 +0200
Subject: [PATCH] tree-wide: fix includes to fix bionic builds

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/af_unix.c               |  5 ++++-
 src/lxc/api_extensions.h        |  1 -
 src/lxc/attach.c                |  4 +++-
 src/lxc/caps.c                  |  7 ++++---
 src/lxc/caps.h                  |  3 ++-
 src/lxc/cgroups/cgfsng.c        | 12 +++++++-----
 src/lxc/cgroups/cgroup.c        |  6 +++++-
 src/lxc/cgroups/cgroup_utils.c  |  7 +++++--
 src/lxc/cmd/lxc_init.c          |  5 ++++-
 src/lxc/cmd/lxc_monitord.c      |  5 ++++-
 src/lxc/cmd/lxc_user_nic.c      | 20 +++++++++++---------
 src/lxc/cmd/lxc_usernsexec.c    |  6 ++++--
 src/lxc/commands.c              |  8 +++++---
 src/lxc/commands_utils.c        |  9 ++++++---
 src/lxc/compiler.h              |  3 +++
 src/lxc/conf.c                  | 10 ++++++----
 src/lxc/conf.h                  | 20 +++++++++++---------
 src/lxc/confile.c               | 18 ++++++++++--------
 src/lxc/confile_utils.c         |  8 +++++---
 src/lxc/confile_utils.h         |  2 --
 src/lxc/criu.c                  | 10 ++++++----
 src/lxc/criu.h                  |  8 ++++----
 src/lxc/execute.c               | 13 ++++++++-----
 src/lxc/file_utils.c            |  6 ++++--
 src/lxc/file_utils.h            |  2 --
 src/lxc/freezer.c               | 13 ++++++++-----
 src/lxc/initutils.c             |  7 +++++--
 src/lxc/initutils.h             |  2 --
 src/lxc/log.c                   | 26 +++++++++++++-------------
 src/lxc/log.h                   |  2 --
 src/lxc/lsm/apparmor.c          | 21 ++++++++++++---------
 src/lxc/lsm/lsm.c               |  7 +++++--
 src/lxc/lsm/nop.c               |  5 +++++
 src/lxc/lsm/selinux.c           | 11 +++++++----
 src/lxc/lxc.h                   |  1 +
 src/lxc/lxccontainer.c          |  6 ++++--
 src/lxc/lxccontainer.h          |  3 ++-
 src/lxc/lxclock.c               |  7 +++++--
 src/lxc/lxclock.h               |  2 +-
 src/lxc/macro.h                 |  2 --
 src/lxc/mainloop.c              |  6 +++++-
 src/lxc/mainloop.h              |  1 +
 src/lxc/monitor.c               | 12 +++++++-----
 src/lxc/monitor.h               |  2 +-
 src/lxc/namespace.c             |  7 +++++--
 src/lxc/namespace.h             |  2 --
 src/lxc/network.c               | 18 ++++++++++--------
 src/lxc/network.h               |  6 +++---
 src/lxc/nl.c                    | 18 ++++++++++--------
 src/lxc/pam/pam_cgfs.c          | 10 +++++++---
 src/lxc/parse.c                 | 10 ++++++----
 src/lxc/ringbuf.c               |  7 +++++--
 src/lxc/rtnl.c                  | 15 ++++++++++-----
 src/lxc/seccomp.c               |  4 +++-
 src/lxc/start.c                 | 11 ++++++-----
 src/lxc/start.h                 |  1 -
 src/lxc/state.c                 |  8 +++++---
 src/lxc/storage/btrfs.c         | 11 +++++++----
 src/lxc/storage/btrfs.h         |  3 +--
 src/lxc/storage/dir.c           |  5 ++++-
 src/lxc/storage/dir.h           |  1 -
 src/lxc/storage/loop.c          |  7 +++++--
 src/lxc/storage/loop.h          |  1 -
 src/lxc/storage/lvm.c           |  6 ++++--
 src/lxc/storage/lvm.h           |  1 -
 src/lxc/storage/nbd.c           |  5 ++++-
 src/lxc/storage/nbd.h           |  1 -
 src/lxc/storage/overlay.c       |  5 ++++-
 src/lxc/storage/rbd.c           |  5 ++++-
 src/lxc/storage/rbd.h           |  1 -
 src/lxc/storage/rsync.c         | 11 +++++++----
 src/lxc/storage/rsync.h         |  1 -
 src/lxc/storage/storage.c       | 10 ++++++----
 src/lxc/storage/storage.h       |  1 -
 src/lxc/storage/storage_utils.c |  9 ++++++---
 src/lxc/storage/storage_utils.h |  3 +--
 src/lxc/storage/zfs.c           |  4 +++-
 src/lxc/storage/zfs.h           |  1 -
 src/lxc/string_utils.c          |  8 +++++---
 src/lxc/sync.c                  | 13 ++++++++-----
 src/lxc/terminal.c              |  4 +++-
 src/lxc/terminal.h              |  2 --
 src/lxc/tools/arguments.c       |  9 ++++++---
 src/lxc/tools/arguments.h       |  3 ++-
 src/lxc/tools/lxc_attach.c      |  9 ++++++---
 src/lxc/tools/lxc_autostart.c   |  5 ++++-
 src/lxc/tools/lxc_cgroup.c      |  7 +++++--
 src/lxc/tools/lxc_checkpoint.c  |  7 +++++--
 src/lxc/tools/lxc_config.c      |  5 +++++
 src/lxc/tools/lxc_console.c     |  9 ++++++---
 src/lxc/tools/lxc_copy.c        |  9 ++++++---
 src/lxc/tools/lxc_create.c      |  7 +++++--
 src/lxc/tools/lxc_destroy.c     |  7 +++++--
 src/lxc/tools/lxc_device.c      |  9 ++++++---
 src/lxc/tools/lxc_execute.c     |  7 +++++--
 src/lxc/tools/lxc_freeze.c      |  8 +++++---
 src/lxc/tools/lxc_info.c        |  7 +++++--
 src/lxc/tools/lxc_ls.c          |  9 ++++++---
 src/lxc/tools/lxc_monitor.c     |  7 +++++--
 src/lxc/tools/lxc_snapshot.c    |  7 +++++--
 src/lxc/tools/lxc_start.c       | 11 +++++++----
 src/lxc/tools/lxc_stop.c        |  5 ++++-
 src/lxc/tools/lxc_top.c         |  9 ++++++---
 src/lxc/tools/lxc_unfreeze.c    |  7 +++++--
 src/lxc/tools/lxc_unshare.c     |  9 ++++++---
 src/lxc/tools/lxc_wait.c        | 13 ++++++++-----
 src/lxc/utils.c                 |  8 +++++---
 src/lxc/utils.h                 | 10 ++++------
 108 files changed, 482 insertions(+), 291 deletions(-)

diff --git a/src/lxc/af_unix.c b/src/lxc/af_unix.c
index e0231f3a2..648c7d2a8 100644
--- a/src/lxc/af_unix.c
+++ b/src/lxc/af_unix.c
@@ -20,8 +20,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "config.h"
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <stddef.h>
@@ -33,6 +35,7 @@
 #include <sys/syscall.h>
 #include <sys/un.h>
 
+#include "config.h"
 #include "log.h"
 #include "utils.h"
 
diff --git a/src/lxc/api_extensions.h b/src/lxc/api_extensions.h
index 3cac925a4..226567f66 100644
--- a/src/lxc/api_extensions.h
+++ b/src/lxc/api_extensions.h
@@ -20,7 +20,6 @@
 #ifndef __LXC_API_EXTENSIONS_H
 #define __LXC_API_EXTENSIONS_H
 
-#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 4c01dea18..733f3da36 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
diff --git a/src/lxc/caps.c b/src/lxc/caps.c
index f0e662be9..2578d3ba4 100644
--- a/src/lxc/caps.c
+++ b/src/lxc/caps.c
@@ -21,9 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <limits.h>
 #include <fcntl.h>
@@ -32,6 +32,7 @@
 #include <sys/prctl.h>
 
 #include "caps.h"
+#include "config.h"
 #include "log.h"
 #include "macro.h"
 
diff --git a/src/lxc/caps.h b/src/lxc/caps.h
index 14c498ae7..3f9aed50f 100644
--- a/src/lxc/caps.h
+++ b/src/lxc/caps.h
@@ -24,9 +24,10 @@
 #ifndef __LXC_CAPS_H
 #define __LXC_CAPS_H
 
-#include "config.h"
 #include <stdbool.h>
 
+#include "config.h"
+
 #if HAVE_LIBCAP
 #include <linux/types.h> /* workaround for libcap < 2.17 bug */
 #include <sys/capability.h>
diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 5475f7eff..5a3ee1b80 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -34,26 +34,28 @@
  * a comman-separated list of controllers.
  */
 
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <grp.h>
+#include <linux/kdev_t.h>
+#include <linux/types.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#include <linux/kdev_t.h>
-#include <linux/types.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include "caps.h"
 #include "cgroup.h"
 #include "cgroup_utils.h"
 #include "commands.h"
 #include "conf.h"
+#include "config.h"
 #include "log.h"
 #include "macro.h"
 #include "storage/storage.h"
diff --git a/src/lxc/cgroups/cgroup.c b/src/lxc/cgroups/cgroup.c
index cf81f3edb..916a041bf 100644
--- a/src/lxc/cgroups/cgroup.c
+++ b/src/lxc/cgroups/cgroup.c
@@ -21,13 +21,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include "cgroup.h"
 #include "conf.h"
+#include "config.h"
 #include "initutils.h"
 #include "log.h"
 #include "start.h"
diff --git a/src/lxc/cgroups/cgroup_utils.c b/src/lxc/cgroups/cgroup_utils.c
index 8e2a40eda..5a44f36db 100644
--- a/src/lxc/cgroups/cgroup_utils.c
+++ b/src/lxc/cgroups/cgroup_utils.c
@@ -22,14 +22,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
 #include "cgroup_utils.h"
+#include "config.h"
+#include "macro.h"
 #include "utils.h"
 
 int get_cgroup_version(char *line)
diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index c052fee80..b6c7ca3d5 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <ctype.h>
 #include <errno.h>
 #include <getopt.h>
@@ -40,6 +42,7 @@
 #include <lxc/version.h>
 
 #include "compiler.h"
+#include "config.h"
 #include "error.h"
 #include "initutils.h"
 #include "log.h"
diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c
index fe0ba7f35..466bc6f20 100644
--- a/src/lxc/cmd/lxc_monitord.c
+++ b/src/lxc/cmd/lxc_monitord.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <net/if.h>
@@ -43,6 +45,7 @@
 #include <lxc/lxccontainer.h>
 
 #include "af_unix.h"
+#include "config.h"
 #include "log.h"
 #include "mainloop.h"
 #include "monitor.h"
diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c
index e25ac10bb..9a4dd8af2 100644
--- a/src/lxc/cmd/lxc_user_nic.c
+++ b/src/lxc/cmd/lxc_user_nic.c
@@ -17,26 +17,27 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <alloca.h>
+#include <arpa/inet.h>
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
-#include <pwd.h>
-#include <sched.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <arpa/inet.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
 #include <linux/sockios.h>
 #include <net/if.h>
 #include <net/if_arp.h>
 #include <netinet/in.h>
+#include <pwd.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/file.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
@@ -44,6 +45,7 @@
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include "config.h"
 #include "log.h"
diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c
index e5b5d1f01..db4e1dac0 100644
--- a/src/lxc/cmd/lxc_usernsexec.c
+++ b/src/lxc/cmd/lxc_usernsexec.c
@@ -22,8 +22,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
@@ -42,6 +43,7 @@
 #include <unistd.h>
 
 #include "conf.h"
+#include "config.h"
 #include "list.h"
 #include "log.h"
 #include "macro.h"
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 4d542eb94..4a8c24a37 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -21,8 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <caps.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -31,16 +32,17 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <unistd.h>
 
 #include "af_unix.h"
 #include "cgroup.h"
 #include "commands.h"
 #include "commands_utils.h"
 #include "conf.h"
+#include "config.h"
 #include "confile.h"
 #include "log.h"
 #include "lxc.h"
diff --git a/src/lxc/commands_utils.c b/src/lxc/commands_utils.c
index d079d7116..5d5f55f79 100644
--- a/src/lxc/commands_utils.c
+++ b/src/lxc/commands_utils.c
@@ -17,22 +17,25 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
 #include <errno.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <unistd.h>
 
 #include "af_unix.h"
 #include "commands.h"
 #include "commands_utils.h"
-#include "initutils.h"
+#include "config.h"
 #include "file_utils.h"
+#include "initutils.h"
 #include "log.h"
 #include "lxclock.h"
 #include "monitor.h"
diff --git a/src/lxc/compiler.h b/src/lxc/compiler.h
index 12214b9b1..5d1c0561b 100644
--- a/src/lxc/compiler.h
+++ b/src/lxc/compiler.h
@@ -20,6 +20,9 @@
 #ifndef __LXC_COMPILER_H
 #define __LXC_COMPILER_H
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <sys/cdefs.h>
 
 #include "config.h"
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 7070516d6..8ffcfc4ca 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -21,10 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
-#include "config.h"
-#include "confile.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <arpa/inet.h>
 #include <dirent.h>
 #include <errno.h>
@@ -55,6 +54,9 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "config.h"
+#include "confile.h"
+
 #ifdef MAJOR_IN_MKDEV
 #include <sys/mkdev.h>
 #endif
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 7d206a3af..befadc8cd 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -23,27 +23,29 @@
 #ifndef __LXC_CONF_H
 #define __LXC_CONF_H
 
-#include "config.h"
-
-#include <stdio.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <linux/magic.h>
 #include <net/if.h>
 #include <netinet/in.h>
+#include <stdbool.h>
+#include <stdio.h>
 #include <sys/param.h>
 #include <sys/types.h>
-#include <stdbool.h>
 #include <sys/vfs.h>
 
-#if HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
-
 #include "compiler.h"
+#include "config.h"
 #include "list.h"
 #include "ringbuf.h"
-#include "start.h" /* for lxc_handler */
+#include "start.h"
 #include "terminal.h"
 
+#if HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
 #if HAVE_SCMP_FILTER_CTX
 typedef void * scmp_filter_ctx;
 #endif
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 6312fdf90..97917d3ac 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -22,33 +22,35 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS
+#include <arpa/inet.h>
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
+#include <net/if.h>
+#include <netinet/in.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
-#include <time.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <netinet/in.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/utsname.h>
+#include <syslog.h>
+#include <time.h>
+#include <unistd.h>
 
 #include "conf.h"
 #include "config.h"
 #include "confile.h"
 #include "confile_utils.h"
-#include <../include/netns_ifaddrs.h>
+#include "include/netns_ifaddrs.h"
 #include "log.h"
 #include "lxcseccomp.h"
 #include "network.h"
diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c
index 4a22fdb6c..36341fb73 100644
--- a/src/lxc/confile_utils.c
+++ b/src/lxc/confile_utils.c
@@ -17,15 +17,17 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+#include <arpa/inet.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <arpa/inet.h>
 
 #include "conf.h"
+#include "config.h"
 #include "confile.h"
 #include "confile_utils.h"
 #include "error.h"
diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h
index 10077bf67..e381cbe64 100644
--- a/src/lxc/confile_utils.h
+++ b/src/lxc/confile_utils.h
@@ -20,8 +20,6 @@
 #ifndef __LXC_CONFILE_UTILS_H
 #define __LXC_CONFILE_UTILS_H
 
-#include "config.h"
-
 #include <stdbool.h>
 
 #include "conf.h"
diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index ffcb1bb0f..66470a016 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -20,7 +20,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#define _GNU_SOURCE
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <inttypes.h>
 #include <linux/limits.h>
 #include <sched.h>
@@ -32,11 +35,10 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
-#include "config.h"
-
 #include "cgroup.h"
-#include "conf.h"
 #include "commands.h"
+#include "conf.h"
+#include "config.h"
 #include "criu.h"
 #include "log.h"
 #include "lxc.h"
diff --git a/src/lxc/criu.h b/src/lxc/criu.h
index 9f842a90e..fd125976a 100644
--- a/src/lxc/criu.h
+++ b/src/lxc/criu.h
@@ -27,9 +27,9 @@
 
 #include <lxc/lxccontainer.h>
 
-bool __criu_pre_dump(struct lxc_container *c, struct migrate_opts *opts);
-bool __criu_dump(struct lxc_container *c, struct migrate_opts *opts);
-bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts);
-bool __criu_check_feature(uint64_t *features_to_check);
+extern bool __criu_pre_dump(struct lxc_container *c, struct migrate_opts *opts);
+extern bool __criu_dump(struct lxc_container *c, struct migrate_opts *opts);
+extern bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts);
+extern bool __criu_check_feature(uint64_t *features_to_check);
 
 #endif
diff --git a/src/lxc/execute.c b/src/lxc/execute.c
index 163f3f473..cdf5bc848 100644
--- a/src/lxc/execute.c
+++ b/src/lxc/execute.c
@@ -21,15 +21,18 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/stat.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include "conf.h"
+#include "config.h"
 #include "log.h"
 #include "start.h"
 #include "utils.h"
diff --git a/src/lxc/file_utils.c b/src/lxc/file_utils.c
index 9a7bd160e..891aa0ffd 100644
--- a/src/lxc/file_utils.c
+++ b/src/lxc/file_utils.c
@@ -17,8 +17,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/magic.h>
@@ -26,6 +27,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include "config.h"
 #include "file_utils.h"
 #include "log.h"
 #include "macro.h"
diff --git a/src/lxc/file_utils.h b/src/lxc/file_utils.h
index 7ae286975..92e29f4e9 100644
--- a/src/lxc/file_utils.h
+++ b/src/lxc/file_utils.h
@@ -20,8 +20,6 @@
 #ifndef __LXC_FILE_UTILS_H
 #define __LXC_FILE_UTILS_H
 
-#include "config.h"
-
 #include <fcntl.h>
 #include <stdbool.h>
 #include <stdio.h>
diff --git a/src/lxc/freezer.c b/src/lxc/freezer.c
index b6caec178..88f69222f 100644
--- a/src/lxc/freezer.c
+++ b/src/lxc/freezer.c
@@ -20,19 +20,22 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "config.h"
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+#include <errno.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
 #include <string.h>
-#include <fcntl.h>
-#include <sys/types.h>
 #include <sys/param.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include "cgroup.h"
 #include "commands.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 4257ffeaa..79333e272 100644
--- a/src/lxc/initutils.c
+++ b/src/lxc/initutils.c
@@ -21,14 +21,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <sys/prctl.h>
 
+#include "compiler.h"
+#include "config.h"
 #include "file_utils.h"
 #include "initutils.h"
 #include "log.h"
 #include "macro.h"
-#include "compiler.h"
 
 #ifndef HAVE_STRLCPY
 #include "include/strlcpy.h"
diff --git a/src/lxc/initutils.h b/src/lxc/initutils.h
index 4af8c3e6c..6bf23a706 100644
--- a/src/lxc/initutils.h
+++ b/src/lxc/initutils.h
@@ -24,8 +24,6 @@
 #ifndef __LXC_INITUTILS_H
 #define __LXC_INITUTILS_H
 
-#include "config.h"
-
 #include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
diff --git a/src/lxc/log.c b/src/lxc/log.c
index 4fd3fb75e..203accc31 100644
--- a/src/lxc/log.c
+++ b/src/lxc/log.c
@@ -21,29 +21,29 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
-#include <stdint.h>
-#include <stdio.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <inttypes.h>
 #include <limits.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
 #include <pthread.h>
-
-#include <syslog.h>
+#include <stdint.h>
 #include <stdio.h>
-
-#include <fcntl.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <syslog.h>
+#include <unistd.h>
 
-#include "log.h"
 #include "caps.h"
-#include "utils.h"
+#include "config.h"
+#include "log.h"
 #include "lxccontainer.h"
+#include "utils.h"
 
 #ifndef HAVE_STRLCPY
 #include "include/strlcpy.h"
diff --git a/src/lxc/log.h b/src/lxc/log.h
index 9cab04a13..7760f63b7 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -24,8 +24,6 @@
 #ifndef __LXC_LOG_H
 #define __LXC_LOG_H
 
-#include "config.h"
-
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c
index ff5378f62..8c833ce75 100644
--- a/src/lxc/lsm/apparmor.c
+++ b/src/lxc/lsm/apparmor.c
@@ -18,23 +18,26 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <sys/vfs.h>
+#include <unistd.h>
 
-#include "log.h"
-#include "lsm.h"
+#include "caps.h"
 #include "conf.h"
-#include "utils.h"
+#include "config.h"
 #include "initutils.h"
-#include "caps.h"
+#include "log.h"
+#include "lsm.h"
 #include "parse.h"
+#include "utils.h"
 
 lxc_log_define(apparmor, lsm);
 
diff --git a/src/lxc/lsm/lsm.c b/src/lxc/lsm/lsm.c
index 46e212069..5538c9e84 100644
--- a/src/lxc/lsm/lsm.c
+++ b/src/lxc/lsm/lsm.c
@@ -21,14 +21,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <sys/mount.h>
 #include <sys/param.h>
+#include <unistd.h>
 
 #include "conf.h"
+#include "config.h"
 #include "log.h"
 #include "lsm.h"
 
diff --git a/src/lxc/lsm/nop.c b/src/lxc/lsm/nop.c
index 9397f2bfb..07bc6351f 100644
--- a/src/lxc/lsm/nop.c
+++ b/src/lxc/lsm/nop.c
@@ -21,7 +21,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <stdlib.h>
+
+#include "config.h"
 #include "lsm/lsm.h"
 
 static char *nop_process_label_get(pid_t pid)
diff --git a/src/lxc/lsm/selinux.c b/src/lxc/lsm/selinux.c
index 9f7b7bc31..625bcae90 100644
--- a/src/lxc/lsm/selinux.c
+++ b/src/lxc/lsm/selinux.c
@@ -21,16 +21,19 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
-#include <stdlib.h>
+#include <selinux/selinux.h>
 #include <stdbool.h>
+#include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#include <selinux/selinux.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include "conf.h"
+#include "config.h"
 #include "log.h"
 #include "lsm.h"
 
diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h
index 237d74750..97bf7a5e5 100644
--- a/src/lxc/lxc.h
+++ b/src/lxc/lxc.h
@@ -31,6 +31,7 @@ extern "C" {
 #include <stddef.h>
 #include <sys/select.h>
 #include <sys/types.h>
+
 #include "state.h"
 
 struct lxc_msg;
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 412fe0456..0d9276492 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -18,7 +18,9 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <arpa/inet.h>
 #include <dirent.h>
 #include <errno.h>
@@ -41,6 +43,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
+#include "../include/netns_ifaddrs.h"
 #include "af_unix.h"
 #include "api_extensions.h"
 #include "attach.h"
@@ -53,7 +56,6 @@
 #include "confile_utils.h"
 #include "criu.h"
 #include "error.h"
-#include <../include/netns_ifaddrs.h>
 #include "initutils.h"
 #include "log.h"
 #include "lxc.h"
diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
index 459531076..cb0cf8d2d 100644
--- a/src/lxc/lxccontainer.h
+++ b/src/lxc/lxccontainer.h
@@ -22,11 +22,12 @@
 
 #ifndef __LXC_CONTAINER_H
 #define __LXC_CONTAINER_H
+
 #include <malloc.h>
 #include <semaphore.h>
 #include <stdbool.h>
-#include <stdlib.h>
 #include <stdint.h>
+#include <stdlib.h>
 
 #include <lxc/attach_options.h>
 
diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c
index 190352fb9..e3d4654b3 100644
--- a/src/lxc/lxclock.c
+++ b/src/lxc/lxclock.c
@@ -18,7 +18,9 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <malloc.h>
@@ -30,9 +32,10 @@
 
 #include <lxc/lxccontainer.h>
 
+#include "config.h"
+#include "log.h"
 #include "lxclock.h"
 #include "utils.h"
-#include "log.h"
 
 #ifdef MUTEX_DEBUGGING
 #include <execinfo.h>
diff --git a/src/lxc/lxclock.h b/src/lxc/lxclock.h
index 02b471fda..364a71b8e 100644
--- a/src/lxc/lxclock.h
+++ b/src/lxc/lxclock.h
@@ -26,8 +26,8 @@
 #include <fcntl.h>
 #include <semaphore.h>
 #include <string.h>
-#include <sys/stat.h>
 #include <sys/file.h>
+#include <sys/stat.h>
 #include <time.h>
 #include <unistd.h>
 
diff --git a/src/lxc/macro.h b/src/lxc/macro.h
index c9b46bd21..471e34f4e 100644
--- a/src/lxc/macro.h
+++ b/src/lxc/macro.h
@@ -20,8 +20,6 @@
 #ifndef __LXC_MACRO_H
 #define __LXC_MACRO_H
 
-#include "config.h"
-
 #include <asm/types.h>
 #include <linux/if_link.h>
 #include <linux/loop.h>
diff --git a/src/lxc/mainloop.c b/src/lxc/mainloop.c
index 84dfb39e9..b169aa6fe 100644
--- a/src/lxc/mainloop.c
+++ b/src/lxc/mainloop.c
@@ -21,14 +21,18 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/epoll.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "mainloop.h"
 
 struct mainloop_handler {
diff --git a/src/lxc/mainloop.h b/src/lxc/mainloop.h
index 44f76a443..903246a19 100644
--- a/src/lxc/mainloop.h
+++ b/src/lxc/mainloop.h
@@ -25,6 +25,7 @@
 #define __LXC_MAINLOOP_H
 
 #include <stdint.h>
+
 #include "list.h"
 
 #define LXC_MAINLOOP_ERROR -1
diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c
index 4cca9002c..4a5b9a985 100644
--- a/src/lxc/monitor.c
+++ b/src/lxc/monitor.c
@@ -22,27 +22,29 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
+#include <net/if.h>
+#include <netinet/in.h>
 #include <poll.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#include <net/if.h>
-#include <netinet/in.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
-#include "config.h"
 #include "af_unix.h"
+#include "config.h"
 #include "error.h"
 #include "log.h"
 #include "lxclock.h"
diff --git a/src/lxc/monitor.h b/src/lxc/monitor.h
index 97e995a8f..d13a61252 100644
--- a/src/lxc/monitor.h
+++ b/src/lxc/monitor.h
@@ -24,9 +24,9 @@
 #define __LXC_MONITOR_H
 
 #include <limits.h>
+#include <poll.h>
 #include <sys/param.h>
 #include <sys/un.h>
-#include <poll.h>
 
 typedef enum {
 	lxc_msg_state,
diff --git a/src/lxc/namespace.c b/src/lxc/namespace.c
index 5b26d64ba..8df173ff9 100644
--- a/src/lxc/namespace.c
+++ b/src/lxc/namespace.c
@@ -21,18 +21,21 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <alloca.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <sched.h>
 #include <signal.h>
-#include <unistd.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "log.h"
 #include "namespace.h"
 #include "utils.h"
diff --git a/src/lxc/namespace.h b/src/lxc/namespace.h
index 1341af0e6..8de2d5186 100644
--- a/src/lxc/namespace.h
+++ b/src/lxc/namespace.h
@@ -27,8 +27,6 @@
 #include <unistd.h>
 #include <sys/syscall.h>
 
-#include "config.h"
-
 #ifndef CLONE_PARENT_SETTID
 #define CLONE_PARENT_SETTID 0x00100000
 #endif
diff --git a/src/lxc/network.c b/src/lxc/network.c
index 62fdd9097..20ab21ae6 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -21,16 +21,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+#include <arpa/inet.h>
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <arpa/inet.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
 #include <linux/sockios.h>
@@ -38,17 +35,22 @@
 #include <net/if.h>
 #include <net/if_arp.h>
 #include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/inotify.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
 
+#include "../include/netns_ifaddrs.h"
 #include "af_unix.h"
 #include "conf.h"
 #include "config.h"
-#include <../include/netns_ifaddrs.h>
 #include "file_utils.h"
 #include "log.h"
 #include "macro.h"
diff --git a/src/lxc/network.h b/src/lxc/network.h
index 38f7c8d5f..ef1b41b89 100644
--- a/src/lxc/network.h
+++ b/src/lxc/network.h
@@ -23,12 +23,12 @@
 #ifndef __LXC_NETWORK_H
 #define __LXC_NETWORK_H
 
-#include <stdbool.h>
-#include <stdio.h>
-#include <unistd.h>
 #include <arpa/inet.h>
 #include <linux/types.h>
+#include <stdbool.h>
+#include <stdio.h>
 #include <sys/socket.h>
+#include <unistd.h>
 
 #include "list.h"
 
diff --git a/src/lxc/nl.c b/src/lxc/nl.c
index 06a72fb88..eb4535a73 100644
--- a/src/lxc/nl.c
+++ b/src/lxc/nl.c
@@ -21,18 +21,20 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
-
-#include <sys/socket.h>
-#include <string.h>
-#include <stdio.h>
-#include <time.h>
-#include <unistd.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
-#include <stdlib.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <time.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "log.h"
 #include "nl.h"
 
diff --git a/src/lxc/pam/pam_cgfs.c b/src/lxc/pam/pam_cgfs.c
index 9a8e87760..9fe268413 100644
--- a/src/lxc/pam/pam_cgfs.c
+++ b/src/lxc/pam/pam_cgfs.c
@@ -33,10 +33,14 @@
  * See COPYING file for details.
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <linux/unistd.h>
 #include <pwd.h>
 #include <stdarg.h>
 #include <stdbool.h>
@@ -44,19 +48,19 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
-#include <unistd.h>
-#include <linux/unistd.h>
 #include <sys/mount.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/vfs.h>
+#include <syslog.h>
+#include <unistd.h>
 
 #define PAM_SM_SESSION
 #include <security/_pam_macros.h>
 #include <security/pam_modules.h>
 
+#include "config.h"
 #include "macro.h"
 #include "utils.h"
 
diff --git a/src/lxc/parse.c b/src/lxc/parse.c
index 3ae96f307..fcc174a77 100644
--- a/src/lxc/parse.c
+++ b/src/lxc/parse.c
@@ -21,18 +21,20 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
-
-#include <stdio.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <dirent.h>
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
 
+#include "config.h"
+#include "log.h"
 #include "parse.h"
 #include "utils.h"
-#include "log.h"
 
 lxc_log_define(parse, lxc);
 
diff --git a/src/lxc/ringbuf.c b/src/lxc/ringbuf.c
index 7aa2e6310..1d5cfe916 100644
--- a/src/lxc/ringbuf.c
+++ b/src/lxc/ringbuf.c
@@ -17,7 +17,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS
 #include <errno.h>
 #include <inttypes.h>
@@ -25,9 +27,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/mman.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "ringbuf.h"
 #include "utils.h"
 
diff --git a/src/lxc/rtnl.c b/src/lxc/rtnl.c
index bb1f7d521..2f237a73e 100644
--- a/src/lxc/rtnl.c
+++ b/src/lxc/rtnl.c
@@ -20,15 +20,20 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include <string.h>
-#include <stdio.h>
-#include <sys/socket.h>
-#include <stdlib.h>
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
-#include <unistd.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "nl.h"
 #include "rtnl.h"
 
diff --git a/src/lxc/seccomp.c b/src/lxc/seccomp.c
index 7d5addb9e..1e14be17e 100644
--- a/src/lxc/seccomp.c
+++ b/src/lxc/seccomp.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <seccomp.h>
 #include <stdio.h>
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 0629e90c4..4a5a50ff8 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -23,9 +23,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <alloca.h>
 #include <dirent.h>
 #include <errno.h>
@@ -37,7 +37,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/file.h>
 #include <sys/mount.h>
 #include <sys/param.h>
@@ -48,6 +47,7 @@
 #include <sys/types.h>
 #include <sys/un.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
 #if HAVE_LIBCAP
 #include <sys/capability.h>
@@ -59,12 +59,13 @@
 #include "commands.h"
 #include "commands_utils.h"
 #include "conf.h"
+#include "config.h"
 #include "confile_utils.h"
 #include "error.h"
 #include "file_utils.h"
 #include "list.h"
-#include "lsm/lsm.h"
 #include "log.h"
+#include "lsm/lsm.h"
 #include "lxccontainer.h"
 #include "lxclock.h"
 #include "lxcseccomp.h"
diff --git a/src/lxc/start.h b/src/lxc/start.h
index bcb852e8b..df987dcb9 100644
--- a/src/lxc/start.h
+++ b/src/lxc/start.h
@@ -32,7 +32,6 @@
 #include <sys/un.h>
 
 #include "conf.h"
-#include "config.h"
 #include "namespace.h"
 #include "state.h"
 
diff --git a/src/lxc/state.c b/src/lxc/state.c
index d8a8dab25..b3e6f83f8 100644
--- a/src/lxc/state.c
+++ b/src/lxc/state.c
@@ -21,19 +21,21 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <time.h>
-#include <unistd.h>
 #include <sys/file.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
 
 #include "cgroup.h"
 #include "commands.h"
diff --git a/src/lxc/storage/btrfs.c b/src/lxc/storage/btrfs.c
index 3204ffcd5..af7f6eb1e 100644
--- a/src/lxc/storage/btrfs.c
+++ b/src/lxc/storage/btrfs.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
@@ -29,15 +31,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
-#include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/vfs.h>
+#include <sys/wait.h>
+#include <unistd.h>
 
-#include "log.h"
 #include "btrfs.h"
+#include "config.h"
+#include "log.h"
 #include "rsync.h"
 #include "storage.h"
 #include "utils.h"
diff --git a/src/lxc/storage/btrfs.h b/src/lxc/storage/btrfs.h
index 4d02a7842..930799ade 100644
--- a/src/lxc/storage/btrfs.h
+++ b/src/lxc/storage/btrfs.h
@@ -24,11 +24,10 @@
 #ifndef __LXC_BTRFS_H
 #define __LXC_BTRFS_H
 
-#define _GNU_SOURCE
+#include <byteswap.h>
 #include <linux/types.h> /* __le64, __l32 ... */
 #include <stdbool.h>
 #include <stdint.h>
-#include <byteswap.h>
 
 #ifndef BTRFS_SUPER_MAGIC
 #  define BTRFS_SUPER_MAGIC       0x9123683E
diff --git a/src/lxc/storage/dir.c b/src/lxc/storage/dir.c
index 2414f533e..79b646961 100644
--- a/src/lxc/storage/dir.c
+++ b/src/lxc/storage/dir.c
@@ -21,10 +21,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <stdint.h>
 #include <string.h>
 
+#include "config.h"
 #include "log.h"
 #include "storage.h"
 #include "utils.h"
diff --git a/src/lxc/storage/dir.h b/src/lxc/storage/dir.h
index 6858e0040..7a3f73472 100644
--- a/src/lxc/storage/dir.h
+++ b/src/lxc/storage/dir.h
@@ -24,7 +24,6 @@
 #ifndef __LXC_DIR_H
 #define __LXC_DIR_H
 
-#define _GNU_SOURCE
 #include <stdbool.h>
 #include <stdint.h>
 
diff --git a/src/lxc/storage/loop.c b/src/lxc/storage/loop.c
index fa5386548..8ea40e088 100644
--- a/src/lxc/storage/loop.c
+++ b/src/lxc/storage/loop.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS
 #include <dirent.h>
 #include <errno.h>
@@ -30,10 +32,11 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "log.h"
 #include "loop.h"
 #include "storage.h"
diff --git a/src/lxc/storage/loop.h b/src/lxc/storage/loop.h
index a8b1a4185..92945e178 100644
--- a/src/lxc/storage/loop.h
+++ b/src/lxc/storage/loop.h
@@ -24,7 +24,6 @@
 #ifndef __LXC_LOOP_H
 #define __LXC_LOOP_H
 
-#define _GNU_SOURCE
 #include <stdbool.h>
 #include <stdint.h>
 
diff --git a/src/lxc/storage/lvm.c b/src/lxc/storage/lvm.c
index 2d4f12d7a..8bb16175d 100644
--- a/src/lxc/storage/lvm.c
+++ b/src/lxc/storage/lvm.c
@@ -21,16 +21,18 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS
 #include <inttypes.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/sysmacros.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
 #include "config.h"
 #include "log.h"
diff --git a/src/lxc/storage/lvm.h b/src/lxc/storage/lvm.h
index a86387b07..a54859f74 100644
--- a/src/lxc/storage/lvm.h
+++ b/src/lxc/storage/lvm.h
@@ -24,7 +24,6 @@
 #ifndef __LXC_LVM_H
 #define __LXC_LVM_H
 
-#define _GNU_SOURCE
 #include <stdbool.h>
 #include <stdint.h>
 
diff --git a/src/lxc/storage/nbd.c b/src/lxc/storage/nbd.c
index 4c3ff51ef..cc2289426 100644
--- a/src/lxc/storage/nbd.c
+++ b/src/lxc/storage/nbd.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -31,6 +33,7 @@
 #include <sys/prctl.h>
 #include <sys/wait.h>
 
+#include "config.h"
 #include "log.h"
 #include "nbd.h"
 #include "storage.h"
diff --git a/src/lxc/storage/nbd.h b/src/lxc/storage/nbd.h
index bd2335947..49c08ff54 100644
--- a/src/lxc/storage/nbd.h
+++ b/src/lxc/storage/nbd.h
@@ -24,7 +24,6 @@
 #ifndef __LXC_NBD_H
 #define __LXC_NBD_H
 
-#define _GNU_SOURCE
 #include <stdbool.h>
 #include <stdint.h>
 
diff --git a/src/lxc/storage/overlay.c b/src/lxc/storage/overlay.c
index f47ccc39b..a95c6b7e6 100644
--- a/src/lxc/storage/overlay.c
+++ b/src/lxc/storage/overlay.c
@@ -21,13 +21,16 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "conf.h"
+#include "config.h"
 #include "confile.h"
 #include "log.h"
 #include "lxccontainer.h"
diff --git a/src/lxc/storage/rbd.c b/src/lxc/storage/rbd.c
index 10ad892a0..daeb76e70 100644
--- a/src/lxc/storage/rbd.c
+++ b/src/lxc/storage/rbd.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
 #include <inttypes.h>	/* Required for PRIu64 to work. */
 #include <stdint.h>
@@ -29,6 +31,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "config.h"
 #include "log.h"
 #include "storage.h"
 #include "storage_utils.h"
diff --git a/src/lxc/storage/rbd.h b/src/lxc/storage/rbd.h
index 9e6e57c3a..a449e72e9 100644
--- a/src/lxc/storage/rbd.h
+++ b/src/lxc/storage/rbd.h
@@ -24,7 +24,6 @@
 #ifndef __LXC_RDB_H
 #define __LXC_RDB_H
 
-#define _GNU_SOURCE
 #include <stdbool.h>
 #include <stdint.h>
 
diff --git a/src/lxc/storage/rsync.c b/src/lxc/storage/rsync.c
index 39d09e98d..e3ade30a0 100644
--- a/src/lxc/storage/rsync.c
+++ b/src/lxc/storage/rsync.c
@@ -21,17 +21,20 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <grp.h>
 #include <sched.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
 #include <sys/mount.h>
+#include <sys/types.h>
+#include <unistd.h>
 
+#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 fca81a724..f0a13d6fb 100644
--- a/src/lxc/storage/rsync.h
+++ b/src/lxc/storage/rsync.h
@@ -24,7 +24,6 @@
 #ifndef __LXC_RSYNC_H
 #define __LXC_RSYNC_H
 
-#define _GNU_SOURCE
 #include <stdio.h>
 
 struct rsync_data {
diff --git a/src/lxc/storage/storage.c b/src/lxc/storage/storage.c
index 3e64a4a62..3a1053ea2 100644
--- a/src/lxc/storage/storage.c
+++ b/src/lxc/storage/storage.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -32,12 +34,12 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/mount.h>
 #include <sys/prctl.h>
-#include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
 #include "btrfs.h"
 #include "conf.h"
@@ -49,8 +51,8 @@
 #include "lvm.h"
 #include "lxc.h"
 #include "lxclock.h"
-#include "nbd.h"
 #include "namespace.h"
+#include "nbd.h"
 #include "overlay.h"
 #include "parse.h"
 #include "rbd.h"
diff --git a/src/lxc/storage/storage.h b/src/lxc/storage/storage.h
index fb3b54293..5486c2855 100644
--- a/src/lxc/storage/storage.h
+++ b/src/lxc/storage/storage.h
@@ -24,7 +24,6 @@
 #ifndef __LXC_STORAGE_H
 #define __LXC_STORAGE_H
 
-#include "config.h"
 #include <stdint.h>
 #include <sys/mount.h>
 
diff --git a/src/lxc/storage/storage_utils.c b/src/lxc/storage/storage_utils.c
index da1ed7fcc..36a62a11e 100644
--- a/src/lxc/storage/storage_utils.c
+++ b/src/lxc/storage/storage_utils.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
@@ -33,13 +35,14 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/mount.h>
 #include <sys/prctl.h>
-#include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "log.h"
 #include "nbd.h"
 #include "parse.h"
diff --git a/src/lxc/storage/storage_utils.h b/src/lxc/storage/storage_utils.h
index 905233a24..7fc1dcdee 100644
--- a/src/lxc/storage/storage_utils.h
+++ b/src/lxc/storage/storage_utils.h
@@ -24,10 +24,9 @@
 #ifndef __LXC_STORAGE_UTILS_H
 #define __LXC_STORAGE_UTILS_H
 
-#include "config.h"
-#include <stdio.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <stdio.h>
 
 #include "conf.h"
 
diff --git a/src/lxc/storage/zfs.c b/src/lxc/storage/zfs.c
index 5ee81575e..a948755db 100644
--- a/src/lxc/storage/zfs.c
+++ b/src/lxc/storage/zfs.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <stdint.h>
 #include <stdio.h>
diff --git a/src/lxc/storage/zfs.h b/src/lxc/storage/zfs.h
index abfc0129e..78f729ef2 100644
--- a/src/lxc/storage/zfs.h
+++ b/src/lxc/storage/zfs.h
@@ -24,7 +24,6 @@
 #ifndef __LXC_ZFS_H
 #define __LXC_ZFS_H
 
-#define _GNU_SOURCE
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdint.h>
diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c
index fb5cb54e7..fb46109b9 100644
--- a/src/lxc/string_utils.c
+++ b/src/lxc/string_utils.c
@@ -17,8 +17,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
 #include <ctype.h>
 #include <dirent.h>
@@ -32,7 +33,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/mman.h>
 #include <sys/mount.h>
 #include <sys/param.h>
@@ -40,7 +40,9 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "log.h"
 #include "lxclock.h"
 #include "macro.h"
diff --git a/src/lxc/sync.c b/src/lxc/sync.c
index 273654565..2d2bb6f13 100644
--- a/src/lxc/sync.c
+++ b/src/lxc/sync.c
@@ -21,16 +21,19 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
 
-#include "sync.h"
+#include "config.h"
 #include "log.h"
 #include "start.h"
+#include "sync.h"
 #include "utils.h"
 
 lxc_log_define(sync, lxc);
diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c
index b7220a030..03bd8983b 100644
--- a/src/lxc/terminal.c
+++ b/src/lxc/terminal.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <lxc/lxccontainer.h>
diff --git a/src/lxc/terminal.h b/src/lxc/terminal.h
index 7077b02dd..d1d404a6f 100644
--- a/src/lxc/terminal.h
+++ b/src/lxc/terminal.h
@@ -24,8 +24,6 @@
 #ifndef __LXC_TERMINAL_H
 #define __LXC_TERMINAL_H
 
-#include "config.h"
-
 #include <signal.h>
 #include <stdio.h>
 
diff --git a/src/lxc/tools/arguments.c b/src/lxc/tools/arguments.c
index b47df0ecb..99b346207 100644
--- a/src/lxc/tools/arguments.c
+++ b/src/lxc/tools/arguments.c
@@ -22,24 +22,27 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.h>
 #include <lxc/version.h>
 
 #include "arguments.h"
 #include "compiler.h"
-#include "namespace.h"
+#include "config.h"
 #include "initutils.h"
+#include "namespace.h"
 
 static int build_shortopts(const struct option *a_options, char *a_shortopts,
 			   size_t a_size)
diff --git a/src/lxc/tools/arguments.h b/src/lxc/tools/arguments.h
index 43b3a86e2..810050ad2 100644
--- a/src/lxc/tools/arguments.h
+++ b/src/lxc/tools/arguments.h
@@ -28,8 +28,9 @@
 #include <getopt.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <sys/types.h>
 #include <sys/param.h>
+#include <sys/types.h>
+
 #include <lxc/lxccontainer.h>
 
 struct lxc_arguments;
diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index 551f9f396..3de0d7747 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -21,24 +21,27 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <termios.h>
-#include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <termios.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.h>
 
 #include "arguments.h"
 #include "attach.h"
 #include "caps.h"
+#include "config.h"
 #include "confile.h"
 #include "log.h"
 #include "utils.h"
diff --git a/src/lxc/tools/lxc_autostart.c b/src/lxc/tools/lxc_autostart.c
index e2702f6e9..1209897ec 100644
--- a/src/lxc/tools/lxc_autostart.c
+++ b/src/lxc/tools/lxc_autostart.c
@@ -18,7 +18,9 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -27,6 +29,7 @@
 #include <lxc/lxccontainer.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 069da365f..eb9bf7d66 100644
--- a/src/lxc/tools/lxc_cgroup.c
+++ b/src/lxc/tools/lxc_cgroup.c
@@ -21,17 +21,20 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 de6cc9453..107a737b0 100644
--- a/src/lxc/tools/lxc_checkpoint.c
+++ b/src/lxc/tools/lxc_checkpoint.c
@@ -16,17 +16,20 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 c71a3109b..f94de40cc 100644
--- a/src/lxc/tools/lxc_config.c
+++ b/src/lxc/tools/lxc_config.c
@@ -18,11 +18,16 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <stdio.h>
 #include <string.h>
 
 #include <lxc/lxccontainer.h>
 
+#include "config.h"
+
 struct lxc_config_items {
 	char *name;
 };
diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c
index c1f99069d..fff5d5b84 100644
--- a/src/lxc/tools/lxc_console.c
+++ b/src/lxc/tools/lxc_console.c
@@ -21,24 +21,27 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <libgen.h>
 #include <poll.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <signal.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 2d6080134..b9e647e5c 100644
--- a/src/lxc/tools/lxc_copy.c
+++ b/src/lxc/tools/lxc_copy.c
@@ -16,7 +16,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
@@ -26,15 +28,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <time.h>
-#include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.h>
 
 #include "arguments.h"
+#include "config.h"
 #include "log.h"
 #include "storage_utils.h"
 #include "utils.h"
diff --git a/src/lxc/tools/lxc_create.c b/src/lxc/tools/lxc_create.c
index ae72f929e..819f7d4a0 100644
--- a/src/lxc/tools/lxc_create.c
+++ b/src/lxc/tools/lxc_create.c
@@ -17,18 +17,21 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <fcntl.h>
 #include <libgen.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 7e7809893..6669300d5 100644
--- a/src/lxc/tools/lxc_destroy.c
+++ b/src/lxc/tools/lxc_destroy.c
@@ -17,18 +17,21 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <fcntl.h>
 #include <libgen.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.h>
 
 #include "arguments.h"
+#include "config.h"
 #include "log.h"
 #include "utils.h"
 
diff --git a/src/lxc/tools/lxc_device.c b/src/lxc/tools/lxc_device.c
index 1d0c40415..05e64effe 100644
--- a/src/lxc/tools/lxc_device.c
+++ b/src/lxc/tools/lxc_device.c
@@ -19,18 +19,21 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <libgen.h>
 #include <limits.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.h>
 
-#include "arguments.h"
 #include "../../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 8e69f7244..09d20e7bb 100644
--- a/src/lxc/tools/lxc_execute.c
+++ b/src/lxc/tools/lxc_execute.c
@@ -21,22 +21,25 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 16b4064d8..d99acc175 100644
--- a/src/lxc/tools/lxc_freeze.c
+++ b/src/lxc/tools/lxc_freeze.c
@@ -21,17 +21,19 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <libgen.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
-#include <unistd.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 16369b720..07303366c 100644
--- a/src/lxc/tools/lxc_info.c
+++ b/src/lxc/tools/lxc_info.c
@@ -21,19 +21,22 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <libgen.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 32278d498..7f1510f93 100644
--- a/src/lxc/tools/lxc_ls.c
+++ b/src/lxc/tools/lxc_ls.c
@@ -16,7 +16,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <dirent.h>
 #include <getopt.h>
 #include <limits.h>
@@ -26,16 +28,17 @@
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
-#include <termios.h>
-#include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <termios.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.h>
 
 #include "arguments.h"
+#include "config.h"
 #include "log.h"
 #include "utils.h"
 
diff --git a/src/lxc/tools/lxc_monitor.c b/src/lxc/tools/lxc_monitor.c
index 86a77c3af..ed4d3efd1 100644
--- a/src/lxc/tools/lxc_monitor.c
+++ b/src/lxc/tools/lxc_monitor.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS
 #include <dirent.h>
 #include <errno.h>
@@ -34,18 +36,19 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/un.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.h>
 
 #include "af_unix.h"
 #include "arguments.h"
+#include "config.h"
 #include "log.h"
 #include "macro.h"
 #include "monitor.h"
diff --git a/src/lxc/tools/lxc_snapshot.c b/src/lxc/tools/lxc_snapshot.c
index f943bdd1c..26830162f 100644
--- a/src/lxc/tools/lxc_snapshot.c
+++ b/src/lxc/tools/lxc_snapshot.c
@@ -17,19 +17,22 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <ctype.h>
 #include <fcntl.h>
 #include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 1815991e4..74d2e06ea 100644
--- a/src/lxc/tools/lxc_start.c
+++ b/src/lxc/tools/lxc_start.c
@@ -21,28 +21,31 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+#include <arpa/inet.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <libgen.h>
 #include <net/if.h>
+#include <netinet/in.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/utsname.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 76c759d0c..1267fd11e 100644
--- a/src/lxc/tools/lxc_stop.c
+++ b/src/lxc/tools/lxc_stop.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <libgen.h>
 #include <stdio.h>
 #include <string.h>
@@ -31,6 +33,7 @@
 #include <lxc/lxccontainer.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 0ffc65e6f..9fad3a433 100644
--- a/src/lxc/tools/lxc_top.c
+++ b/src/lxc/tools/lxc_top.c
@@ -21,7 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
 #include <errno.h>
 #include <inttypes.h>
@@ -31,15 +33,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <termios.h>
-#include <unistd.h>
 #include <sys/epoll.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
+#include <termios.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 7a9972c4c..3df8dc04d 100644
--- a/src/lxc/tools/lxc_unfreeze.c
+++ b/src/lxc/tools/lxc_unfreeze.c
@@ -21,16 +21,19 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <libgen.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.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 a7458fa41..3aa703e5f 100644
--- a/src/lxc/tools/lxc_unshare.c
+++ b/src/lxc/tools/lxc_unshare.c
@@ -21,26 +21,29 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
 #include <libgen.h>
+#include <netinet/in.h>
 #include <pwd.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <netinet/in.h>
-#include <unistd.h>
 #include <sys/eventfd.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
 #include "arguments.h"
 #include "caps.h"
+#include "config.h"
 #include "list.h"
 #include "log.h"
 #include "namespace.h"
diff --git a/src/lxc/tools/lxc_wait.c b/src/lxc/tools/lxc_wait.c
index 6c3c07085..fa249593e 100644
--- a/src/lxc/tools/lxc_wait.c
+++ b/src/lxc/tools/lxc_wait.c
@@ -21,18 +21,21 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #include <libgen.h>
-#include <unistd.h>
-#include <stdlib.h>
 #include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <lxc/lxccontainer.h>
 
 #include "arguments.h"
+#include "config.h"
 #include "log.h"
 
 lxc_log_define(lxc_wait, lxc);
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 9b6f0a617..52b75b3f9 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -21,8 +21,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
-
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
 #define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
 #include <ctype.h>
 #include <dirent.h>
@@ -36,7 +37,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/mman.h>
 #include <sys/mount.h>
 #include <sys/param.h>
@@ -44,7 +44,9 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
+#include "config.h"
 #include "log.h"
 #include "lxclock.h"
 #include "namespace.h"
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 0f121e673..b56a074d5 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -26,18 +26,16 @@
 /* Properly support loop devices on 32bit systems. */
 #define _FILE_OFFSET_BITS 64
 
-#include "config.h"
-
 #include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <unistd.h>
 #include <linux/loop.h>
 #include <linux/types.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
 #include <sys/vfs.h>
+#include <unistd.h>
 
 #ifdef HAVE_LINUX_MEMFD_H
 #include <linux/memfd.h>


More information about the lxc-devel mailing list