]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: let the root user raise its priority
authorDiego Nieto Cid <dnietoc@gmail.com>
Wed, 20 May 2026 22:49:27 +0000 (23:49 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 25 May 2026 21:38:23 +0000 (23:38 +0200)
    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.dnietoc@gmail.com>

config.h.in
sysdeps/mach/configure
sysdeps/mach/configure.ac
sysdeps/mach/hurd/setpriority.c

index b53731c39341b2493f1354fe51c3452a9cebe054..87befaa9c6d3eb0c0f88f2ff729bb78095b3eb0b 100644 (file)
 /* 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
 
index 0161937ab43e8e1c1c05e7ce411b9bfbe8ef600e..a725cd1c7db57378f1a7839eeb3474aa8b1931ff 100755 (executable)
@@ -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
index 237b8be937bf4c6211f1e059c521916ca93cf9fa..b591e6fd9be95a462b0da55ea9f12d9e29010590 100644 (file)
@@ -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
index 810709899113a9824b46e08984e1ec72bd574640..6ee34aa1a9fce75bbeb0c773b94c886e59b06885 100644 (file)
@@ -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;