]> err.no Git - util-linux/commitdiff
build-sys: unify method for checking system calls and fallback handling
authorMike Frysinger <vapier@gentoo.org>
Fri, 7 Sep 2007 14:55:36 +0000 (16:55 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 19 Sep 2007 22:22:22 +0000 (00:22 +0200)
Co-Author: Stepan Kasal <skasal@redhat.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Stepan Kasal <skasal@redhat.com>
configure.ac
schedutils/Makefile.am
schedutils/ionice.c

index e7cfca3cd5890afb7d63e53753ad84b91cb8ce89..b23395fd577a30acb819a7145bd61687eaa0dee5 100644 (file)
@@ -187,24 +187,79 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 ])
 
 
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+dnl UTIL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...)
+dnl Only specify FALLBACK if the SYSCALL
+dnl you're checking for is a "newish" one
+dnl -------------------------------------
+AC_DEFUN([UTIL_CHECK_SYSCALL], [
+  dnl This macro uses host_cpu.
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_CACHE_CHECK([for syscall $1],
+    [util_cv_syscall_$1],
+    [_UTIL_SYSCALL_CHECK_DECL([SYS_$1],
+      [syscall=SYS_$1],
+      [dnl Our libc failed use, so see if we can get the kernel
+      dnl headers to play ball ...
+      _UTIL_SYSCALL_CHECK_DECL([_NR_$1],
+       [syscall=_NR_$1],
+       [
+         syscall=no
+         case $host_cpu in
+           _UTIL_CHECK_SYSCALL_FALLBACK(m4_shift($@))
+         esac
+        ])
+      ])
+    util_cv_syscall_$1=$syscall
+    ])
+  AM_CONDITIONAL([HAVE_]m4_toupper($1), [test $util_cv_syscall_$1 != no])
+  case $util_cv_syscall_$1 in #(
+  no) AC_MSG_WARN([Unable to detect syscall $1.]) ;;
+  SYS_*) ;;
+  *) AC_DEFINE_UNQUOTED([SYS_$1], [$util_cv_syscall_$1],
+       [Fallback syscall number for $1]) ;;
+  esac
+])
+
+dnl _UTIL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
+dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
+dnl -------------------------------------
+m4_define([_UTIL_SYSCALL_CHECK_DECL],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/syscall.h>
 #include <unistd.h>
-]], [[
-int test = SYS_pivot_root;
-]])],
-[AM_CONDITIONAL(HAVE_PIVOT_ROOT, true)],
-[AM_CONDITIONAL(HAVE_PIVOT_ROOT, false)])
+]], [[int test = $1;]])],
+[$2], [$3])
+])
 
+dnl _UTIL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
+dnl Helper macro to create the body for the above `case'.
+dnl -------------------------------------
+m4_define([_UTIL_CHECK_SYSCALL_FALLBACK],
+[m4_ifval([$1],
+  [#(
+  $1) syscall="$2" ;;dnl
+  _UTIL_CHECK_SYSCALL_FALLBACK(m4_shiftn(2, $@))])dnl
+])
 
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-#include <sys/syscall.h>
-#include <unistd.h>
-]], [[
-int test = SYS_sched_getaffinity;
-]])],
-[AM_CONDITIONAL(HAVE_SCHED_GETAFFINITY, true)],
-[AM_CONDITIONAL(HAVE_SCHED_GETAFFINITY, false)])
+
+UTIL_CHECK_SYSCALL([pivot_root])
+UTIL_CHECK_SYSCALL([sched_getaffinity])
+UTIL_CHECK_SYSCALL([ioprio_set],
+  [alpha],    [442],
+  [i*86],     [289],
+  [ia64*],    [1274],
+  [powerpc*], [273],
+  [s390*],    [282],
+  [sparc*],   [196],
+  [x86_64*],  [251])
+UTIL_CHECK_SYSCALL([ioprio_get],
+  [alpha],    [443],
+  [i*86],     [290],
+  [ia64*],    [1275],
+  [powerpc*], [274],
+  [s390*],    [283],
+  [sparc*],   [218],
+  [x86_64*],  [252])
 
 
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
index e93d31b39857dec5bc3c3573f746ec7e765b3f28..81a734e96905ed963efd6917d1569ad97b138db0 100644 (file)
@@ -2,8 +2,15 @@ include $(top_srcdir)/config/include-Makefile.am
 
 if BUILD_SCHEDUTILS
 
-usrbinexec_PROGRAMS = chrt ionice
-man_MANS = chrt.1 ionice.1
+usrbinexec_PROGRAMS = chrt
+man_MANS = chrt.1
+
+if HAVE_IOPRIO_GET
+if HAVE_IOPRIO_SET
+usrbinexec_PROGRAMS += ionice
+man_MANS += ionice.1
+endif
+endif
 
 if HAVE_SCHED_GETAFFINITY
 usrbinexec_PROGRAMS += taskset
index 9eb13877b08def5f7c4226e0761674a033cd151f..679014af42907a9ea84c2cc9031fceede7a134ec 100644 (file)
 #include <sys/syscall.h>
 #include <asm/unistd.h>
 
-#if !defined(SYS_ioprio_get) || !defined(SYS_ioprio_set)
-
-# if defined(__i386__)
-#  define __NR_ioprio_set              289
-#  define __NR_ioprio_get              290
-# elif defined(__powerpc__) || defined(__powerpc64__)
-#  define __NR_ioprio_set              273
-#  define __NR_ioprio_get              274
-# elif defined(__x86_64__)
-#  define __NR_ioprio_set              251
-#  define __NR_ioprio_get              252
-# elif defined(__ia64__)
-#  define __NR_ioprio_set              1274
-#  define __NR_ioprio_get              1275
-# elif defined(__alpha__)
-#  define __NR_ioprio_set              442
-#  define __NR_ioprio_get              443
-# elif defined(__s390x__) || defined(__s390__)
-#  define __NR_ioprio_set              282
-#  define __NR_ioprio_get              283
-# elif defined(__sparc__) || defined(__sparc64__)
-#  define __NR_ioprio_set              196
-#  define __NR_ioprio_get              218
-# else
-#  error "Unsupported arch"
-# endif
-
-# define SYS_ioprio_get                __NR_ioprio_get
-# define SYS_ioprio_set                __NR_ioprio_set
-
-#endif /* !SYS_ioprio_get */
-
 static inline int ioprio_set(int which, int who, int ioprio)
 {
        return syscall(SYS_ioprio_set, which, who, ioprio);