Since RHBZ#726528, filesystem.rpm doesn't include /selinux.  setfiles
then gives us the warning: "Can't stat exclude path "/sysroot/selinux",
No such file or directory - ignoring."

Though the warning is harmless, let's get rid of it by checking the
existence of /selinux directory.

Signed-off-by: Andrey Drobyshev <andrey.drobys...@virtuozzo.com>
---
 daemon/selinux-relabel.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/daemon/selinux-relabel.c b/daemon/selinux-relabel.c
index 976cffe37..454486c17 100644
--- a/daemon/selinux-relabel.c
+++ b/daemon/selinux-relabel.c
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include "guestfs_protocol.h"
 #include "daemon.h"
@@ -37,6 +38,17 @@ optgroup_selinuxrelabel_available (void)
   return prog_exists ("setfiles");
 }
 
+static int
+dir_exists (const char *dir)
+{
+  struct stat statbuf;
+
+  if (stat (dir, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
+    return 1;
+  else
+    return 0;
+}
+
 static int
 setfiles_has_option (int *flag, char opt_char)
 {
@@ -99,8 +111,10 @@ do_selinux_relabel (const char *specfile, const char *path,
    */
   ADD_ARG (argv, i, "-e"); ADD_ARG (argv, i, s_dev);
   ADD_ARG (argv, i, "-e"); ADD_ARG (argv, i, s_proc);
-  ADD_ARG (argv, i, "-e"); ADD_ARG (argv, i, s_selinux);
   ADD_ARG (argv, i, "-e"); ADD_ARG (argv, i, s_sys);
+  if (dir_exists (s_selinux)) {
+    ADD_ARG (argv, i, "-e"); ADD_ARG (argv, i, s_selinux);
+  }
 
   /* You have to use the -m option (where available) otherwise
    * setfiles puts all the mountpoints on the excludes list for no
-- 
2.31.1

_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs

Reply via email to