Specifying a PID of 0 for the -p option of chrt would previously result
in a "number 0... not in range" error. Now, it means instead that the
calling process (i.e. chrt itself) should be operated on; this is to be
consistent with the behavior of util-linux's version of chrt:

$ chrt -p 0
pid 27644437's current scheduling policy: SCHED_OTHER
pid 27644437's current scheduling priority: 0

Note that the PID shown in the output is the actual value of getpid().

function                                             old     new   delta
chrt_main                                            516     530     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 14/0)               Total: 14 bytes

Signed-off-by: Zuo An <[email protected]>
---
 util-linux/chrt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/util-linux/chrt.c b/util-linux/chrt.c
index 51d08584e15c..a59f49fe61ea 100644
--- a/util-linux/chrt.c
+++ b/util-linux/chrt.c
@@ -133,7 +133,14 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
                        pid_str = *argv;
                }
                /* else "-p PID", and *argv == NULL */
-               pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 
1);
+               pid = xatoul_range(pid_str, 0, ((unsigned)(pid_t)ULONG_MAX) >> 
1);
+
+               /* sched_{get,set}scheduler accept PID 0 to mean the calling 
process,
+                * but this is needed to display the actual PID like 
util-linux's chrt
+                */
+               if (pid == 0) {
+                       pid = getpid();
+               }
        } else {
                priority = *argv++;
                if (!*argv)
-- 
2.51.0

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to