selinux: unconditionally include the header and provide stub methods

If selinux is disabled, then stub methods will be provided instead of
calling the real methods. This removes some warnings about unused
parameters which used to be covered up with #ifdef HAVE_SELINUX.

Signed-off-by: Jason Zaman <jason@perfinion.com>
This commit is contained in:
William Hubbs 2015-03-25 00:57:05 -05:00
parent d38cc8f221
commit a4cf61e8bf
3 changed files with 16 additions and 12 deletions

View File

@ -45,10 +45,7 @@
#include "builtins.h" #include "builtins.h"
#include "einfo.h" #include "einfo.h"
#include "rc-misc.h" #include "rc-misc.h"
#ifdef HAVE_SELINUX
#include "rc-selinux.h" #include "rc-selinux.h"
#endif
typedef enum { typedef enum {
inode_unknown = 0, inode_unknown = 0,
@ -164,8 +161,10 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode,
} }
} }
#ifdef HAVE_SELINUX
if (selinux_on) if (selinux_on)
selinux_util_label(path); selinux_util_label(path);
#endif
return 0; return 0;
} }
@ -294,10 +293,8 @@ int checkpath(int argc, char **argv)
if (gr) if (gr)
gid = gr->gr_gid; gid = gr->gr_gid;
#ifdef HAVE_SELINUX
if (selinux_util_open() == 1) if (selinux_util_open() == 1)
selinux_on = true; selinux_on = true;
#endif
while (optind < argc) { while (optind < argc) {
if (writable) if (writable)
@ -307,10 +304,8 @@ int checkpath(int argc, char **argv)
optind++; optind++;
} }
#ifdef HAVE_SELINUX
if (selinux_on) if (selinux_on)
selinux_util_close(); selinux_util_close();
#endif
return retval; return retval;
} }

View File

@ -26,10 +26,24 @@
#ifndef RC_SELINUX_UTIL_H #ifndef RC_SELINUX_UTIL_H
#define RC_SELINUX_UTIL_H #define RC_SELINUX_UTIL_H
#ifdef HAVE_SELINUX
int selinux_util_open(void); int selinux_util_open(void);
int selinux_util_label(const char *path); int selinux_util_label(const char *path);
int selinux_util_close(void); int selinux_util_close(void);
void selinux_setup(char **argv); void selinux_setup(char **argv);
#else
/* always return false for selinux_util_open() */
#define selinux_util_open() (0)
#define selinux_util_label(x) do { } while(0)
#define selinux_util_close() do { } while(0)
#define selinux_setup(x) do { } while(0)
#endif
#endif #endif

View File

@ -66,10 +66,7 @@
#include "rc.h" #include "rc.h"
#include "rc-misc.h" #include "rc-misc.h"
#include "rc-plugin.h" #include "rc-plugin.h"
#ifdef HAVE_SELINUX
#include "rc-selinux.h" #include "rc-selinux.h"
#endif
#define PREFIX_LOCK RC_SVCDIR "/prefix.lock" #define PREFIX_LOCK RC_SVCDIR "/prefix.lock"
@ -1191,10 +1188,8 @@ openrc_run(int argc, char **argv)
eprefix(prefix); eprefix(prefix);
} }
#ifdef HAVE_SELINUX
/* Ok, we are ready to go, so setup selinux if applicable */ /* Ok, we are ready to go, so setup selinux if applicable */
selinux_setup(argv); selinux_setup(argv);
#endif
deps = true; deps = true;