1 From b0a2386089fd6efade6b89094325ed8a9f8c6fff Mon Sep 17 00:00:00 2001
2 From: Christian Hesse <mail@eworm.de>
3 Date: Sat, 22 Oct 2016 22:06:54 +0200
4 Subject: [PATCH] sload.f2fs: allow to build without libselinux
6 Some systems do not have libselinux. Allow to build sload.f2fs without
9 Signed-off-by: Christian Hesse <mail@eworm.de>
10 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
13 fsck/sload.c | 12 +++++++++++-
14 2 files changed, 14 insertions(+), 2 deletions(-)
16 diff --git a/configure.ac b/configure.ac
17 index f519790..7a62328 100644
20 @@ -54,7 +54,9 @@ AC_PATH_PROG([LDCONFIG], [ldconfig],
22 # Checks for libraries.
23 PKG_CHECK_MODULES([libuuid], [uuid])
24 -PKG_CHECK_MODULES([libselinux], [libselinux])
25 +PKG_CHECK_MODULES([libselinux], [libselinux],
26 + [AC_DEFINE([HAVE_LIBSELINUX], [1], [Use libselinux])],
27 + [AC_MSG_NOTICE([libselinux not found])])
29 # Checks for header files.
30 AC_CHECK_HEADERS([linux/fs.h fcntl.h mntent.h stdlib.h string.h \
31 diff --git a/fsck/sload.c b/fsck/sload.c
32 index ea072d1..68799c1 100644
40 +#ifdef HAVE_LIBSELINUX
41 #include <selinux/selinux.h>
42 #include <selinux/label.h>
46 #include <selinux/label.h>
47 @@ -110,10 +113,12 @@ static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
48 handle_selabel(dentries + i, S_ISDIR(stat.st_mode),
51 +#ifdef HAVE_LIBSELINUX
52 if (sehnd && selabel_lookup(sehnd, &dentries[i].secon,
53 dentries[i].path, stat.st_mode) < 0)
54 ERR_MSG("Cannot lookup security context for %s\n",
58 dentries[i].pino = dir_ino;
60 @@ -174,6 +179,7 @@ static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
61 MSG(1, "Error unknown file type\n");
64 +#ifdef HAVE_LIBSELINUX
65 if (dentries[i].secon) {
66 inode_set_selinux(sbi, dentries[i].ino, dentries[i].secon);
67 MSG(1, "File = %s \n----->SELinux context = %s\n",
68 @@ -184,10 +190,12 @@ static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
69 dentries[i].gid, dentries[i].capabilities);
72 + free(dentries[i].secon);
75 free(dentries[i].path);
76 free(dentries[i].full_path);
77 free((void *)dentries[i].name);
78 - free(dentries[i].secon);
82 @@ -218,6 +226,7 @@ int f2fs_sload(struct f2fs_sb_info *sbi, const char *from_dir,
86 +#ifdef HAVE_LIBSELINUX
88 char *secontext = NULL;
90 @@ -233,6 +242,7 @@ int f2fs_sload(struct f2fs_sb_info *sbi, const char *from_dir,
96 /* update curseg info; can update sit->types */
97 move_curseg_info(sbi, SM_I(sbi)->main_blkaddr);