changeset 17170:661d79eb6d77

selinux-h: better 'inline' * lib/se-context.c, lib/se-selinux.c: New files. * lib/getfilecon.c (map_to_failure): Omit 'inline' for static function. * lib/se-context.in.h (SE_CONTEXT_INLINE): New macro. Replace all uses of 'static inline' with it. Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. * lib/se-selinux.in.h (SE_SELINUX_INLINE): New macro. Replace all uses of 'static inline' with it. Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. * modules/selinux-h (Files, lib_SOURCES): Add lib/se-context.c, lib/se-selinux.c. (Depends-on): Add extern-inline. (configure.ac): Do not require AC_C_INLINE.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 20 Nov 2012 22:25:06 -0800
parents 8b10fbdb551e
children 7531a1bd77d7
files ChangeLog lib/getfilecon.c lib/se-context.c lib/se-context.in.h lib/se-selinux.c lib/se-selinux.in.h modules/selinux-h
diffstat 7 files changed, 94 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2012-11-29  Paul Eggert  <eggert@cs.ucla.edu>
 
+	selinux-h: better 'inline'
+	* lib/se-context.c, lib/se-selinux.c: New files.
+	* lib/getfilecon.c (map_to_failure): Omit 'inline' for static function.
+	* lib/se-context.in.h (SE_CONTEXT_INLINE):
+	New macro.  Replace all uses of 'static inline' with it.
+	Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
+	* lib/se-selinux.in.h (SE_SELINUX_INLINE):
+	New macro.  Replace all uses of 'static inline' with it.
+	Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
+	* modules/selinux-h (Files, lib_SOURCES):
+	Add lib/se-context.c, lib/se-selinux.c.
+	(Depends-on): Add extern-inline.
+	(configure.ac): Do not require AC_C_INLINE.
+
 	pthread: better 'inline'
 	* lib/pthread.c: New file.
 	* lib/pthread.in.h (_GL_PTHREAD_INLINE):
--- a/lib/getfilecon.c
+++ b/lib/getfilecon.c
@@ -45,7 +45,7 @@
    "unlabeled" context.  Map both failures to a return value of -1, and
    set errno to ENOTSUP in the first case, and ENODATA in the latter.  */
 
-static inline int
+static int
 map_to_failure (int ret, security_context_t *con)
 {
   if (ret == 0)
new file mode 100644
--- /dev/null
+++ b/lib/se-context.c
@@ -0,0 +1,3 @@
+#include <config.h>
+#define SE_CONTEXT_INLINE _GL_EXTERN_INLINE
+#include <selinux/context.h>
--- a/lib/se-context.in.h
+++ b/lib/se-context.in.h
@@ -3,26 +3,33 @@
 
 # include <errno.h>
 
+_GL_INLINE_HEADER_BEGIN
+#ifndef SE_CONTEXT_INLINE
+# define SE_CONTEXT_INLINE _GL_INLINE
+#endif
+
 /* The definition of _GL_UNUSED_PARAMETER is copied here.  */
 
 typedef int context_t;
-static inline context_t context_new (char const *s _GL_UNUSED_PARAMETER)
+SE_CONTEXT_INLINE context_t context_new (char const *s _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return 0; }
-static inline char *context_str (context_t con _GL_UNUSED_PARAMETER)
+SE_CONTEXT_INLINE char *context_str (context_t con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return (void *) 0; }
-static inline void context_free (context_t c _GL_UNUSED_PARAMETER) {}
+SE_CONTEXT_INLINE void context_free (context_t c _GL_UNUSED_PARAMETER) {}
 
-static inline int context_user_set (context_t sc _GL_UNUSED_PARAMETER,
-                                    char const *s _GL_UNUSED_PARAMETER)
+SE_CONTEXT_INLINE int context_user_set (context_t sc _GL_UNUSED_PARAMETER,
+                                        char const *s _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int context_role_set (context_t sc _GL_UNUSED_PARAMETER,
-                                    char const *s _GL_UNUSED_PARAMETER)
+SE_CONTEXT_INLINE int context_role_set (context_t sc _GL_UNUSED_PARAMETER,
+                                        char const *s _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int context_range_set (context_t sc _GL_UNUSED_PARAMETER,
-                                     char const *s _GL_UNUSED_PARAMETER)
+SE_CONTEXT_INLINE int context_range_set (context_t sc _GL_UNUSED_PARAMETER,
+                                         char const *s _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int context_type_set (context_t sc _GL_UNUSED_PARAMETER,
-                                    char const *s _GL_UNUSED_PARAMETER)
+SE_CONTEXT_INLINE int context_type_set (context_t sc _GL_UNUSED_PARAMETER,
+                                        char const *s _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
 
+_GL_INLINE_HEADER_END
+
 #endif
new file mode 100644
--- /dev/null
+++ b/lib/se-selinux.c
@@ -0,0 +1,3 @@
+#include <config.h>
+#define SE_SELINUX_INLINE _GL_EXTERN_INLINE
+#include <selinux/selinux.h>
--- a/lib/se-selinux.in.h
+++ b/lib/se-selinux.in.h
@@ -31,6 +31,11 @@
 #  include <sys/types.h>
 #  include <errno.h>
 
+_GL_INLINE_HEADER_BEGIN
+#  ifndef SE_SELINUX_INLINE
+#   define SE_SELINUX_INLINE _GL_INLINE
+#  endif
+
 /* The definition of _GL_UNUSED_PARAMETER is copied here.  */
 
 #  if !GNULIB_defined_security_types
@@ -39,59 +44,71 @@
 #   define security_context_t char*
 #   define is_selinux_enabled() 0
 
-static inline int getcon (security_context_t *con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+getcon (security_context_t *con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline void freecon (security_context_t con _GL_UNUSED_PARAMETER) {}
-
+SE_SELINUX_INLINE void
+freecon (security_context_t con _GL_UNUSED_PARAMETER) {}
 
-static inline int getfscreatecon (security_context_t *con _GL_UNUSED_PARAMETER)
-  { errno = ENOTSUP; return -1; }
-static inline int setfscreatecon (security_context_t con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+getfscreatecon (security_context_t *con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int matchpathcon (char const *file _GL_UNUSED_PARAMETER,
-                                mode_t m _GL_UNUSED_PARAMETER,
-                                security_context_t *con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+setfscreatecon (security_context_t con _GL_UNUSED_PARAMETER)
+  { errno = ENOTSUP; return -1; }
+SE_SELINUX_INLINE int
+matchpathcon (char const *file _GL_UNUSED_PARAMETER,
+              mode_t m _GL_UNUSED_PARAMETER,
+  security_context_t *con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int getfilecon (char const *file _GL_UNUSED_PARAMETER,
-                              security_context_t *con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+getfilecon (char const *file _GL_UNUSED_PARAMETER,
+            security_context_t *con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int lgetfilecon (char const *file _GL_UNUSED_PARAMETER,
-                               security_context_t *con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+lgetfilecon (char const *file _GL_UNUSED_PARAMETER,
+             security_context_t *con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int fgetfilecon (int fd,
-                               security_context_t *con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+fgetfilecon (int fd, security_context_t *con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int setfilecon (char const *file _GL_UNUSED_PARAMETER,
-                              security_context_t con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+setfilecon (char const *file _GL_UNUSED_PARAMETER,
+            security_context_t con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int lsetfilecon (char const *file _GL_UNUSED_PARAMETER,
-                               security_context_t con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+lsetfilecon (char const *file _GL_UNUSED_PARAMETER,
+             security_context_t con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int fsetfilecon (int fd _GL_UNUSED_PARAMETER,
-                               security_context_t con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+fsetfilecon (int fd _GL_UNUSED_PARAMETER,
+             security_context_t con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
 
-static inline int security_check_context
-    (security_context_t con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+security_check_context (security_context_t con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int security_check_context_raw
-    (security_context_t con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+security_check_context_raw (security_context_t con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int setexeccon (security_context_t con _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+setexeccon (security_context_t con _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int security_compute_create
-    (security_context_t scon _GL_UNUSED_PARAMETER,
-     security_context_t tcon _GL_UNUSED_PARAMETER,
-     security_class_t tclass _GL_UNUSED_PARAMETER,
-     security_context_t *newcon _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+security_compute_create (security_context_t scon _GL_UNUSED_PARAMETER,
+                         security_context_t tcon _GL_UNUSED_PARAMETER,
+                         security_class_t tclass _GL_UNUSED_PARAMETER,
+                         security_context_t *newcon _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
-static inline int matchpathcon_init_prefix
-    (char const *path _GL_UNUSED_PARAMETER,
-     char const *prefix _GL_UNUSED_PARAMETER)
+SE_SELINUX_INLINE int
+matchpathcon_init_prefix (char const *path _GL_UNUSED_PARAMETER,
+                          char const *prefix _GL_UNUSED_PARAMETER)
   { errno = ENOTSUP; return -1; }
 
 #   define GNULIB_defined_security_types 1
 #  endif
 
+_GL_INLINE_HEADER_BEGIN
+
 # endif
 #endif /* _@GUARD_PREFIX@_SELINUX_SELINUX_H */
--- a/modules/selinux-h
+++ b/modules/selinux-h
@@ -5,23 +5,25 @@
 lib/getfilecon.c
 lib/se-context.in.h
 lib/se-selinux.in.h
+lib/se-context.c
+lib/se-selinux.c
 m4/selinux-context-h.m4
 m4/selinux-selinux-h.m4
 
 Depends-on:
 errno
+extern-inline
 snippet/unused-parameter
 
 configure.ac:
 gl_HEADERS_SELINUX_SELINUX_H
 gl_HEADERS_SELINUX_CONTEXT_H
-AC_REQUIRE([AC_C_INLINE])
 if test "$with_selinux" != no && test "$ac_cv_header_selinux_selinux_h" = yes; then
   AC_LIBOBJ([getfilecon])
 fi
 
 Makefile.am:
-lib_SOURCES += se-context.in.h se-selinux.in.h
+lib_SOURCES += se-context.in.h se-selinux.in.h se-context.c se-selinux.c
 
 BUILT_SOURCES += selinux/selinux.h
 selinux/selinux.h: se-selinux.in.h $(top_builddir)/config.status $(UNUSED_PARAMETER_H)