c313de
From 2b27d54de68a4581a9b46fe5c399b45c0014fcbd Mon Sep 17 00:00:00 2001
c313de
Message-Id: <2b27d54de68a4581a9b46fe5c399b45c0014fcbd@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:07:10 +0200
c313de
Subject: [PATCH] vircgroupv1: fix build on non-linux OSes
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
Cgroups are linux specific and we need to make sure that the code is
c313de
compiled only on linux.  On different OSes it fails the compilation:
c313de
c313de
../../src/util/vircgroupv1.c:65:19: error: variable has incomplete type 'struct mntent'
c313de
    struct mntent entry;
c313de
                  ^
c313de
../../src/util/vircgroupv1.c:65:12: note: forward declaration of 'struct mntent'
c313de
    struct mntent entry;
c313de
           ^
c313de
../../src/util/vircgroupv1.c:74:12: error: implicit declaration of function 'getmntent_r' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
c313de
    while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) {
c313de
           ^
c313de
../../src/util/vircgroupv1.c:814:39: error: use of undeclared identifier 'MS_NOSUID'
c313de
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
c313de
                                      ^
c313de
../../src/util/vircgroupv1.c:814:49: error: use of undeclared identifier 'MS_NODEV'
c313de
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
c313de
                                                ^
c313de
../../src/util/vircgroupv1.c:814:58: error: use of undeclared identifier 'MS_NOEXEC'
c313de
    if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
c313de
                                                         ^
c313de
../../src/util/vircgroupv1.c:841:65: error: use of undeclared identifier 'MS_BIND'
c313de
            if (mount(src, group->legacy[i].mountPoint, "none", MS_BIND,
c313de
                                                                ^
c313de
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit 0615c8436ac868889454bee2781b6c9993518597)
c313de
c313de
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
Message-Id: <a1b4d0cfa90a65f5c431a388e6f51be2ab9a7cdd.1561993100.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/util/vircgroupv1.c | 20 +++++++++++++++-----
c313de
 1 file changed, 15 insertions(+), 5 deletions(-)
c313de
c313de
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c313de
index 482615f3c8..97d108d3ac 100644
c313de
--- a/src/util/vircgroupv1.c
c313de
+++ b/src/util/vircgroupv1.c
c313de
@@ -20,13 +20,11 @@
c313de
  */
c313de
 #include <config.h>
c313de
 
c313de
-#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
c313de
+#ifdef __linux__
c313de
 # include <mntent.h>
c313de
-#endif
c313de
-#include <sys/stat.h>
c313de
-#if defined HAVE_SYS_MOUNT_H
c313de
+# include <sys/stat.h>
c313de
 # include <sys/mount.h>
c313de
-#endif
c313de
+#endif /* __linux__ */
c313de
 
c313de
 #include "internal.h"
c313de
 
c313de
@@ -56,6 +54,8 @@ VIR_ENUM_IMPL(virCgroupV1Controller, VIR_CGROUP_CONTROLLER_LAST,
c313de
               "name=systemd");
c313de
 
c313de
 
c313de
+#ifdef __linux__
c313de
+
c313de
 /* We're looking for at least one 'cgroup' fs mount,
c313de
  * which is *not* a named mount. */
c313de
 static bool
c313de
@@ -2100,3 +2100,13 @@ virCgroupV1Register(void)
c313de
 {
c313de
     virCgroupBackendRegister(&virCgroupV1Backend);
c313de
 }
c313de
+
c313de
+#else /* !__linux__ */
c313de
+
c313de
+void
c313de
+virCgroupV1Register(void)
c313de
+{
c313de
+    VIR_INFO("Control groups not supported on this platform");
c313de
+}
c313de
+
c313de
+#endif /* !__linux__ */
c313de
-- 
c313de
2.22.0
c313de