>       selinux-h: Fix compilation errors in Termux on Android.

This patch fixed the situation in Termux on Android. But outside Termux,
for example when GNU Emacs is being built with GUI support, libandroid-selinux
is not available, only the system's libselinux. In this case link errors
would occur as well, because the configure test tests for a symbol
in libselinux. We need that configure test to fail.


2026-01-24  Bruno Haible  <[email protected]>

        selinux-h: Fix compilation errors on Android outside Termux.
        * m4/selinux-selinux-h.m4 (gl_LIBSELINUX): Test for getfilecon_raw
        instead of setfilecon.
        (gl_CHECK_HEADER_SELINUX_SELINUX_H): Update.

diff --git a/m4/selinux-selinux-h.m4 b/m4/selinux-selinux-h.m4
index 0db23ebe87..c964ced072 100644
--- a/m4/selinux-selinux-h.m4
+++ b/m4/selinux-selinux-h.m4
@@ -1,5 +1,5 @@
 # selinux-selinux-h.m4
-# serial 11   -*- Autoconf -*-
+# serial 12   -*- Autoconf -*-
 dnl Copyright (C) 2006-2007, 2009-2026 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -49,7 +49,7 @@ AC_DEFUN([gl_CHECK_HEADER_SELINUX_SELINUX_H]
       USE_SELINUX_SELINUX_H=0
     fi
 
-    case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in
+    case "$ac_cv_search_getfilecon_raw:$ac_cv_header_selinux_selinux_h" in
       no:*) # already warned
         ;;
       *:no)
@@ -81,15 +81,15 @@ AC_DEFUN([gl_LIBSELINUX]
     gl_saved_LIBS=$LIBS
     dnl On Android, in Termux, prefer libandroid-selinux.so, because it
     dnl defines many more API functions than /system/lib/libselinux.so.
-    AC_SEARCH_LIBS([setfilecon], [android-selinux selinux],
-                   [test "$ac_cv_search_setfilecon" = "none required" ||
-                    LIB_SELINUX=$ac_cv_search_setfilecon])
+    AC_SEARCH_LIBS([getfilecon_raw], [android-selinux selinux],
+                   [test "$ac_cv_search_getfilecon_raw" = "none required" ||
+                    LIB_SELINUX=$ac_cv_search_getfilecon_raw])
     LIBS=$gl_saved_LIBS
   fi
   AC_SUBST([LIB_SELINUX])
 
   # Warn if SELinux is found but libselinux is absent;
-  if test "$ac_cv_search_setfilecon" = no; then
+  if test "$ac_cv_search_getfilecon_raw" = no; then
     if test "$host" = "$build" \
        && { test -d /sys/fs/selinux || test -d /selinux; }; then
       AC_MSG_WARN([This system supports SELinux but libselinux is missing.])




Reply via email to