Avoid some possibly wrong configure test results.
[gnulib.git] / m4 / mknod.m4
blobe86ad593f52a5bd6d25d636543d2a488dd378744
1 # mknod.m4
2 # serial 8
3 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # See if we need to provide mknod replacement.
10 # Written by Eric Blake.
12 AC_DEFUN([gl_FUNC_MKNOD],
14   AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
15   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
16   AC_REQUIRE([gl_FUNC_MKFIFO])
17   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
18   AC_CHECK_FUNCS_ONCE([mknod])
19   if test $ac_cv_func_mknod = no; then
20     HAVE_MKNOD=0
21   else
22     dnl Detect BSD bug, where mknod requires root privileges to create fifo.
23     AC_CACHE_CHECK([whether mknod can create fifo without root privileges],
24       [gl_cv_func_mknod_works],
25       [AC_RUN_IFELSE(
26          [AC_LANG_PROGRAM(
27            [[#include <sys/stat.h>
28              #include <unistd.h>
30              /* Copied from root-uid.h.  FIXME: Just use root-uid.h.  */
31              #ifdef __TANDEM
32              # define ROOT_UID 65535
33              #else
34              # define ROOT_UID 0
35              #endif
36 ]], [[/* Indeterminate for super-user, assume no.  Why are you running
37          configure as root, anyway?  */
38       if (geteuid () == ROOT_UID) return 99;
39       if (mknod ("conftest.fifo", S_IFIFO | 0600, 0)) return 2;]])],
40          [gl_cv_func_mknod_works=yes],
41          [if test $? = 99 && test x"$FORCE_UNSAFE_CONFIGURE" = x; then
42             AC_MSG_FAILURE([you should not run configure as root ]dnl
43 [(set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)])
44           fi
45           gl_cv_func_mknod_works=no],
46          [case "$host_os" in
47                              # Guess yes on Linux systems.
48             linux-* | linux) gl_cv_func_mknod_works="guessing yes" ;;
49                              # Guess yes on glibc systems.
50             *-gnu* | gnu*)   gl_cv_func_mknod_works="guessing yes" ;;
51                              # If we don't know, obey --enable-cross-guesses.
52             *)               gl_cv_func_mknod_works="$gl_cross_guess_normal" ;;
53           esac
54          ])
55        rm -f conftest.fifo])
56     case "$gl_cv_func_mknod_works" in
57       *yes) ;;
58       *)
59         REPLACE_MKNOD=1
60         AC_DEFINE([MKNOD_FIFO_BUG], [1], [Define to 1 if mknod cannot create
61           a fifo without super-user privileges])
62         ;;
63     esac
64     dnl Systems that mishandle trailing slash on mkfifo also goof on mknod.
65     if test $REPLACE_MKFIFO = 1; then
66       REPLACE_MKNOD=1
67     fi
68   fi