]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroupv1: fix build on non-linux OSes
authorPavel Hrdina <phrdina@redhat.com>
Thu, 27 Sep 2018 10:22:20 +0000 (12:22 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 27 Sep 2018 11:08:40 +0000 (13:08 +0200)
Cgroups are linux specific and we need to make sure that the code is
compiled only on linux.  On different OSes it fails the compilation:

../../src/util/vircgroupv1.c:65:19: error: variable has incomplete type 'struct mntent'
    struct mntent entry;
                  ^
../../src/util/vircgroupv1.c:65:12: note: forward declaration of 'struct mntent'
    struct mntent entry;
           ^
../../src/util/vircgroupv1.c:74:12: error: implicit declaration of function 'getmntent_r' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) {
           ^
../../src/util/vircgroupv1.c:814:39: error: use of undeclared identifier 'MS_NOSUID'
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
                                      ^
../../src/util/vircgroupv1.c:814:49: error: use of undeclared identifier 'MS_NODEV'
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
                                                ^
../../src/util/vircgroupv1.c:814:58: error: use of undeclared identifier 'MS_NOEXEC'
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
                                                         ^
../../src/util/vircgroupv1.c:841:65: error: use of undeclared identifier 'MS_BIND'
            if (mount(src, group->legacy[i].mountPoint, "none", MS_BIND,
                                                                ^

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroupv1.c

index 62a6e5c448ee0c670825891d41e342efcf222ecb..28a74474ee8259129c524cd1aa1802e3c095eb7b 100644 (file)
  */
 #include <config.h>
 
-#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
+#ifdef __linux__
 # include <mntent.h>
-#endif
-#include <sys/stat.h>
-#if defined HAVE_SYS_MOUNT_H
+# include <sys/stat.h>
 # include <sys/mount.h>
-#endif
+#endif /* __linux__ */
 
 #include "internal.h"
 
@@ -55,6 +53,8 @@ VIR_ENUM_IMPL(virCgroupV1Controller, VIR_CGROUP_CONTROLLER_LAST,
               "name=systemd");
 
 
+#ifdef __linux__
+
 /* We're looking for at least one 'cgroup' fs mount,
  * which is *not* a named mount. */
 static bool
@@ -2099,3 +2099,13 @@ virCgroupV1Register(void)
 {
     virCgroupBackendRegister(&virCgroupV1Backend);
 }
+
+#else /* !__linux__ */
+
+void
+virCgroupV1Register(void)
+{
+    VIR_INFO("Control groups not supported on this platform");
+}
+
+#endif /* !__linux__ */