From: Mike Frysinger Date: Fri, 7 Sep 2007 14:55:36 +0000 (+0200) Subject: build-sys: unify method for checking system calls and fallback handling X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72065909ccd29cd3c7c3105c95ba2434db304552;p=util-linux build-sys: unify method for checking system calls and fallback handling Co-Author: Stepan Kasal Signed-off-by: Mike Frysinger Signed-off-by: Stepan Kasal --- diff --git a/configure.ac b/configure.ac index e7cfca3c..b23395fd 100644 --- a/configure.ac +++ b/configure.ac @@ -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 #include -]], [[ -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 -#include -]], [[ -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([[ diff --git a/schedutils/Makefile.am b/schedutils/Makefile.am index e93d31b3..81a734e9 100644 --- a/schedutils/Makefile.am +++ b/schedutils/Makefile.am @@ -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 diff --git a/schedutils/ionice.c b/schedutils/ionice.c index 9eb13877..679014af 100644 --- a/schedutils/ionice.c +++ b/schedutils/ionice.c @@ -15,38 +15,6 @@ #include #include -#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);