From: Diego Nieto Cid <[email protected]>
Check for task_max_priority RPC
* config.h.in: add #undef for HAVE_MACH_TASK_MAX_PRIORITY.
* sysdeps/mach/configure.ac: use mach_RPC_CHECK to check for
task_max_priority RPC in mach_host.defs.
* sysdeps/mach/configure: regenerate file.
Use task_max_priority when setpriority is called by root
* sysdeps/mach/hurd/setpriority.c: clamp the prio argument
to the range [-NZERO, NZERO-1] and use task_max_priority
when called by root.
Message-ID:
<8e806c83d8d7b59b2894b4944e4ad82477ecc3cd.1779316637.git.dnie...@gmail.com>
---
config.h.in | 3 +++
sysdeps/mach/configure | 30 ++++++++++++++++++++++++++++++
sysdeps/mach/configure.ac | 2 ++
sysdeps/mach/hurd/setpriority.c | 16 +++++++++++++++-
4 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/config.h.in b/config.h.in
index b53731c393..87befaa9c6 100644
--- a/config.h.in
+++ b/config.h.in
@@ -170,6 +170,9 @@
/* Mach specific: define if the `vm_set_size_limit' RPC is available. */
#undef HAVE_MACH_VM_SET_SIZE_LIMIT
+/* Mach specific: define if the `task_max_priority' RPC is available. */
+#undef HAVE_MACH_TASK_MAX_PRIORITY
+
/* Mach/i386 specific: define if the `i386_io_perm_*' RPCs are available. */
#undef HAVE_I386_IO_PERM_MODIFY
diff --git a/sysdeps/mach/configure b/sysdeps/mach/configure
index 0161937ab4..a725cd1c7d 100755
--- a/sysdeps/mach/configure
+++ b/sysdeps/mach/configure
@@ -641,6 +641,36 @@ if test $libc_cv_mach_rpc_vm_get_size_limit = yes; then
fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for task_max_priority
in mach_host.defs" >&5
+printf %s "checking for task_max_priority in mach_host.defs... " >&6; }
+if test ${libc_cv_mach_rpc_task_max_priority+y}
+then :
+ printf %s "(cached) " >&6
+else case e in #(
+ e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <mach/mach_host.defs>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ $EGREP_TRADITIONAL "task_max_priority" >/dev/null 2>&1
+then :
+ libc_cv_mach_rpc_task_max_priority=yes
+else case e in #(
+ e) libc_cv_mach_rpc_task_max_priority=no ;;
+esac
+fi
+rm -rf conftest*
+ ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result:
$libc_cv_mach_rpc_task_max_priority" >&5
+printf "%s\n" "$libc_cv_mach_rpc_task_max_priority" >&6; }
+if test $libc_cv_mach_rpc_task_max_priority = yes; then
+ printf "%s\n" "#define HAVE_MACH_TASK_MAX_PRIORITY 1" >>confdefs.h
+
+fi
+
ac_fn_c_check_header_preproc "$LINENO" "mach/machine/ndr_def.h"
"ac_cv_header_mach_machine_ndr_def_h"
if test "x$ac_cv_header_mach_machine_ndr_def_h" = xyes
diff --git a/sysdeps/mach/configure.ac b/sysdeps/mach/configure.ac
index 237b8be937..b591e6fd9b 100644
--- a/sysdeps/mach/configure.ac
+++ b/sysdeps/mach/configure.ac
@@ -104,6 +104,8 @@ mach_RPC_CHECK(gnumach.defs, vm_set_size_limit,
HAVE_MACH_VM_SET_SIZE_LIMIT)
mach_RPC_CHECK(gnumach.defs, vm_get_size_limit,
HAVE_MACH_VM_GET_SIZE_LIMIT)
+mach_RPC_CHECK(mach_host.defs, task_max_priority,
+ HAVE_MACH_TASK_MAX_PRIORITY)
AC_CHECK_HEADER(mach/machine/ndr_def.h, [dnl
DEFINES="$DEFINES -DNDR_DEF_HEADER='<mach/machine/ndr_def.h>'"], [dnl
diff --git a/sysdeps/mach/hurd/setpriority.c b/sysdeps/mach/hurd/setpriority.c
index 8107098991..6ee34aa1a9 100644
--- a/sysdeps/mach/hurd/setpriority.c
+++ b/sysdeps/mach/hurd/setpriority.c
@@ -57,11 +57,25 @@ __setpriority (enum __priority_which which, id_t who, int
prio)
0, 1);
}
#else
- prierr = __task_priority (task, NICE_TO_MACH_PRIORITY (prio), 1);
+ do {
+#ifdef HAVE_MACH_TASK_MAX_PRIORITY
+ mach_port_t host = MACH_PORT_NULL;
+ error_t priverr = __get_privileged_ports (&host, NULL);
+ if (!priverr)
+ {
+ prierr = __task_max_priority (host, task, NICE_TO_MACH_PRIORITY
(prio), 1, 1);
+ __mach_port_deallocate (__mach_task_self (), host);
+ if (prierr != MIG_BAD_ID)
+ break;
+ }
+#endif
+ prierr = __task_priority (task, NICE_TO_MACH_PRIORITY (prio), 1);
+ } while (0);
#endif
__mach_port_deallocate (__mach_task_self (), task);
switch (prierr)
{
+ case KERN_NO_ACCESS:
case KERN_FAILURE:
++nacces;
break;
--
2.53.0