~vcs-imports/busybox/trunk

« back to all changes in this revision

Viewing changes to util-linux/chrt.c

  • Committer: Denys Vlasenko
  • Author(s): Christian Franke
  • Date: 2023-11-13 10:32:35 UTC
  • Revision ID: git-v1:a63b60bdd6fa26b867c80d44074118babbae7ffd
Cygwin: regenerate defconfig

Signed-off-by: Christian Franke <christian.franke@t-online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
7
7
 */
8
8
//config:config CHRT
9
 
//config:       bool "chrt (4.7 kb)"
 
9
//config:       bool "chrt (5.1 kb)"
10
10
//config:       default y
11
11
//config:       help
12
12
//config:       Manipulate real-time attributes of a process.
17
17
//kbuild:lib-$(CONFIG_CHRT) += chrt.o
18
18
 
19
19
//usage:#define chrt_trivial_usage
20
 
//usage:       "-m | -p [PRIO] PID | [-rfobi] PRIO PROG [ARGS]"
 
20
//usage:       "-m | -p [PRIO] PID | [-rfobi] PRIO PROG ARGS"
21
21
//usage:#define chrt_full_usage "\n\n"
22
22
//usage:       "Change scheduling priority and class for a process\n"
23
23
//usage:     "\n        -m      Show min/max priorities"
39
39
# define SCHED_IDLE 5
40
40
#endif
41
41
 
 
42
//musl has no __MUSL__ or similar define to check for,
 
43
//but its <sys/types.h> has these lines:
 
44
// #define __NEED_fsblkcnt_t
 
45
// #define __NEED_fsfilcnt_t
 
46
#if defined(__linux__) && defined(__NEED_fsblkcnt_t) && defined(__NEED_fsfilcnt_t)
 
47
# define LIBC_IS_MUSL 1
 
48
# include <sys/syscall.h>
 
49
#else
 
50
# define LIBC_IS_MUSL 0
 
51
#endif
 
52
 
42
53
static const char *policy_name(int pol)
43
54
{
44
55
        if (pol > 6)
82
93
        unsigned opt;
83
94
        struct sched_param sp;
84
95
        char *pid_str;
85
 
        char *priority = priority; /* for compiler */
 
96
        char *priority = NULL;
86
97
        const char *current_new;
87
98
        int policy = SCHED_RR;
 
99
        int ret;
88
100
 
89
101
        opt = getopt32(argv, "^"
90
102
                        "+" "mprfobi"
98
110
                show_min_max(SCHED_RR);
99
111
                show_min_max(SCHED_BATCH);
100
112
                show_min_max(SCHED_IDLE);
101
 
                fflush_stdout_and_exit(EXIT_SUCCESS);
 
113
                fflush_stdout_and_exit_SUCCESS();
102
114
        }
103
115
        //if (opt & OPT_r)
104
116
        //      policy = SCHED_RR; - default, already set
132
144
        if (opt & OPT_p) {
133
145
                int pol;
134
146
 print_rt_info:
 
147
#if LIBC_IS_MUSL
 
148
                /* musl libc returns ENOSYS for its sched_getscheduler library
 
149
                 * function, because the sched_getscheduler Linux kernel system call
 
150
                 * does not conform to Posix; so we use the system call directly
 
151
                 */
 
152
                pol = syscall(SYS_sched_getscheduler, pid);
 
153
#else
135
154
                pol = sched_getscheduler(pid);
 
155
#endif
136
156
                if (pol < 0)
137
157
                        bb_perror_msg_and_die("can't %cet pid %u's policy", 'g', (int)pid);
138
158
#ifdef SCHED_RESET_ON_FORK
149
169
                printf("pid %u's %s scheduling policy: SCHED_%s\n",
150
170
                        pid, current_new, policy_name(pol)
151
171
                );
152
 
                if (sched_getparam(pid, &sp))
 
172
#if LIBC_IS_MUSL
 
173
                ret = syscall(SYS_sched_getparam, pid, &sp);
 
174
#else
 
175
                ret = sched_getparam(pid, &sp);
 
176
#endif
 
177
                if (ret)
153
178
                        bb_perror_msg_and_die("can't get pid %u's attributes", (int)pid);
154
179
                printf("pid %u's %s scheduling priority: %d\n",
155
180
                        (int)pid, current_new, sp.sched_priority
168
193
                sched_get_priority_min(policy), sched_get_priority_max(policy)
169
194
        );
170
195
 
171
 
        if (sched_setscheduler(pid, policy, &sp) < 0)
 
196
#if LIBC_IS_MUSL
 
197
        ret = syscall(SYS_sched_setscheduler, pid, policy, &sp);
 
198
#else
 
199
        ret = sched_setscheduler(pid, policy, &sp);
 
200
#endif
 
201
        if (ret)
172
202
                bb_perror_msg_and_die("can't %cet pid %u's policy", 's', (int)pid);
173
203
 
174
204
        if (!argv[0]) /* "-p PRIO PID [...]" */