diff options
| author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2007-03-09 16:56:38 +0000 |
|---|---|---|
| committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2007-03-09 16:56:38 +0000 |
| commit | 71bc71a7dc2601b1d9beb73ee1f178da1733788e (patch) | |
| tree | 0dba091508cc1a72f77a0c6eae2afed1d0d550aa | |
| parent | 339f5eb2e0676da591150015e157c38c4ab52a3e (diff) | |
| download | busybox-w32-71bc71a7dc2601b1d9beb73ee1f178da1733788e.tar.gz busybox-w32-71bc71a7dc2601b1d9beb73ee1f178da1733788e.tar.bz2 busybox-w32-71bc71a7dc2601b1d9beb73ee1f178da1733788e.zip | |
- add chrt applet.
text data bss dec hex filename
769 0 0 769 301 miscutils/chrt.o
and could use some further shrinkage
| -rw-r--r-- | include/applets.h | 1 | ||||
| -rw-r--r-- | include/usage.h | 16 | ||||
| -rw-r--r-- | miscutils/Config.in | 7 | ||||
| -rw-r--r-- | miscutils/Kbuild | 1 | ||||
| -rw-r--r-- | miscutils/chrt.c | 124 | ||||
| -rw-r--r-- | scripts/defconfig | 1 |
6 files changed, 150 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h index d1bf0f36b..214e63aa2 100644 --- a/include/applets.h +++ b/include/applets.h | |||
| @@ -74,6 +74,7 @@ USE_CHMOD(APPLET(chmod, _BB_DIR_BIN, _BB_SUID_NEVER)) | |||
| 74 | USE_CHOWN(APPLET(chown, _BB_DIR_BIN, _BB_SUID_NEVER)) | 74 | USE_CHOWN(APPLET(chown, _BB_DIR_BIN, _BB_SUID_NEVER)) |
| 75 | USE_CHPST(APPLET(chpst, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 75 | USE_CHPST(APPLET(chpst, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
| 76 | USE_CHROOT(APPLET(chroot, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | 76 | USE_CHROOT(APPLET(chroot, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) |
| 77 | USE_CHRT(APPLET(chrt, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | ||
| 77 | USE_CHVT(APPLET(chvt, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 78 | USE_CHVT(APPLET(chvt, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
| 78 | USE_CKSUM(APPLET(cksum, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 79 | USE_CKSUM(APPLET(cksum, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
| 79 | USE_CLEAR(APPLET(clear, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 80 | USE_CLEAR(APPLET(clear, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
diff --git a/include/usage.h b/include/usage.h index d8faa4f12..4d1ecb8f5 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -382,6 +382,22 @@ | |||
| 382 | #define bbsh_full_usage \ | 382 | #define bbsh_full_usage \ |
| 383 | "The bbsh shell (command interpreter)" | 383 | "The bbsh shell (command interpreter)" |
| 384 | 384 | ||
| 385 | #define chrt_trivial_usage \ | ||
| 386 | "[OPTION]... [prio] [pid | command [arg]...]" | ||
| 387 | #define chrt_full_usage \ | ||
| 388 | "manipulate real-time attributes of a process" \ | ||
| 389 | "\n\nOptions:\n" \ | ||
| 390 | " -p operate on pid\n" \ | ||
| 391 | " -r set scheduling policy to SCHED_RR\n" \ | ||
| 392 | " -f set scheduling policy to SCHED_FIFO\n" \ | ||
| 393 | " -o set scheduling policy to SCHED_OTHER\n" \ | ||
| 394 | " -m show min and max priorities" | ||
| 395 | |||
| 396 | #define chrt_example_usage \ | ||
| 397 | "$ chrt -r 4 sleep 900 ; x=$!\n" \ | ||
| 398 | "$ chrt -f -p 3 $x\n" \ | ||
| 399 | "You need CAP_SYS_NICE privileges to set scheduling attributes of a process" | ||
| 400 | |||
| 385 | #define cp_trivial_usage \ | 401 | #define cp_trivial_usage \ |
| 386 | "[OPTION]... SOURCE DEST" | 402 | "[OPTION]... SOURCE DEST" |
| 387 | #define cp_full_usage \ | 403 | #define cp_full_usage \ |
diff --git a/miscutils/Config.in b/miscutils/Config.in index 5afeb2a7e..a1ed24368 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
| @@ -19,6 +19,13 @@ config BBCONFIG | |||
| 19 | The bbconfig applet will print the config file with which | 19 | The bbconfig applet will print the config file with which |
| 20 | busybox was built. | 20 | busybox was built. |
| 21 | 21 | ||
| 22 | config CHRT | ||
| 23 | bool "chrt" | ||
| 24 | default n | ||
| 25 | help | ||
| 26 | manipulate real-time attributes of a process. | ||
| 27 | This requires sched_{g,s}etparam support in your libc. | ||
| 28 | |||
| 22 | config CROND | 29 | config CROND |
| 23 | bool "crond" | 30 | bool "crond" |
| 24 | default n | 31 | default n |
diff --git a/miscutils/Kbuild b/miscutils/Kbuild index fe147d884..455113764 100644 --- a/miscutils/Kbuild +++ b/miscutils/Kbuild | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | lib-y:= | 7 | lib-y:= |
| 8 | lib-$(CONFIG_ADJTIMEX) += adjtimex.o | 8 | lib-$(CONFIG_ADJTIMEX) += adjtimex.o |
| 9 | lib-$(CONFIG_BBCONFIG) += bbconfig.o | 9 | lib-$(CONFIG_BBCONFIG) += bbconfig.o |
| 10 | lib-$(CONFIG_CHRT) += chrt.o | ||
| 10 | lib-$(CONFIG_CROND) += crond.o | 11 | lib-$(CONFIG_CROND) += crond.o |
| 11 | lib-$(CONFIG_CRONTAB) += crontab.o | 12 | lib-$(CONFIG_CRONTAB) += crontab.o |
| 12 | lib-$(CONFIG_DC) += dc.o | 13 | lib-$(CONFIG_DC) += dc.o |
diff --git a/miscutils/chrt.c b/miscutils/chrt.c new file mode 100644 index 000000000..75d77d536 --- /dev/null +++ b/miscutils/chrt.c | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * chrt - manipulate real-time attributes of a process | ||
| 4 | * Copyright (c) 2006-2007 Bernhard Fischer | ||
| 5 | * | ||
| 6 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "busybox.h" | ||
| 10 | #include <unistd.h> | ||
| 11 | #include <sched.h> | ||
| 12 | #include <getopt.h> /* optind */ | ||
| 13 | #ifndef _POSIX_PRIORITY_SCHEDULING | ||
| 14 | #warning your system may be foobared | ||
| 15 | #endif | ||
| 16 | static const struct { | ||
| 17 | const int policy; | ||
| 18 | const char const name[12]; | ||
| 19 | } policies[] = { | ||
| 20 | {SCHED_OTHER, "SCHED_OTHER"}, | ||
| 21 | {SCHED_FIFO, "SCHED_FIFO"}, | ||
| 22 | {SCHED_RR, "SCHED_RR"} | ||
| 23 | }; | ||
| 24 | |||
| 25 | static void show_min_max(int pol) { | ||
| 26 | const char *fmt = "%s min/max priority\t: %d/%d\n\0%s not supported?\n"; | ||
| 27 | int max, min; | ||
| 28 | max = sched_get_priority_max(pol); | ||
| 29 | min = sched_get_priority_min(pol); | ||
| 30 | if (max >= 0 && min >= 0) | ||
| 31 | printf(fmt, policies[pol].name, min, max); | ||
| 32 | else { | ||
| 33 | fmt += 29; | ||
| 34 | printf(fmt, policies[pol].name); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | #define OPT_m (1<<0) | ||
| 39 | #define OPT_p (1<<1) | ||
| 40 | #define OPT_r (1<<2) | ||
| 41 | #define OPT_f (1<<3) | ||
| 42 | #define OPT_o (1<<4) | ||
| 43 | |||
| 44 | int chrt_main(int argc, char** argv); | ||
| 45 | int chrt_main(int argc, char** argv) | ||
| 46 | { | ||
| 47 | pid_t pid = 0; | ||
| 48 | unsigned opt; | ||
| 49 | struct sched_param sp; | ||
| 50 | char *p_opt = NULL, *priority = NULL; | ||
| 51 | const char *state = "current\0new"; | ||
| 52 | int prio = 0, policy = SCHED_RR; | ||
| 53 | |||
| 54 | opt_complementary = "r--fo:f--ro:r--fo"; /* only one policy accepted */ | ||
| 55 | opt = getopt32(argc, argv, "+mp:rfo", &p_opt); | ||
| 56 | if (opt & OPT_r) | ||
| 57 | policy = SCHED_RR; | ||
| 58 | if (opt & OPT_f) | ||
| 59 | policy = SCHED_FIFO; | ||
| 60 | if (opt & OPT_o) | ||
| 61 | policy = SCHED_OTHER; | ||
| 62 | |||
| 63 | if (opt & OPT_m) { /* print min/max */ | ||
| 64 | show_min_max(SCHED_FIFO); | ||
| 65 | show_min_max(SCHED_RR); | ||
| 66 | show_min_max(SCHED_OTHER); | ||
| 67 | fflush_stdout_and_exit(EXIT_SUCCESS); | ||
| 68 | } | ||
| 69 | if (opt & OPT_p) { | ||
| 70 | if (argc == optind+1) { /* -p <priority> <pid> */ | ||
| 71 | priority = p_opt; | ||
| 72 | p_opt = argv[optind]; | ||
| 73 | } | ||
| 74 | argv += optind; /* me -p <arg> */ | ||
| 75 | pid = xatoul_range(p_opt, 1, ULONG_MAX); /* -p <pid> */ | ||
| 76 | } else { | ||
| 77 | argv += optind; /* me -p <arg> */ | ||
| 78 | priority = *argv; | ||
| 79 | } | ||
| 80 | if (priority) { | ||
| 81 | /* from the manpage of sched_getscheduler: | ||
| 82 | [...] sched_priority can have a value | ||
| 83 | in the range 0 to 99. | ||
| 84 | [...] SCHED_OTHER or SCHED_BATCH must be assigned | ||
| 85 | the static priority 0. [...] SCHED_FIFO or | ||
| 86 | SCHED_RR can have a static priority in the range 1 to 99. | ||
| 87 | */ | ||
| 88 | prio = xstrtol_range(priority, 0, policy == SCHED_OTHER | ||
| 89 | ? 0 : 1, 99); | ||
| 90 | } | ||
| 91 | |||
| 92 | if (opt & OPT_p) { | ||
| 93 | int pol = 0; | ||
| 94 | print_rt_info: | ||
| 95 | pol = sched_getscheduler(pid); | ||
| 96 | if (pol < 0) | ||
| 97 | bb_perror_msg_and_die("failed to %cet pid %d's policy", 'g', pid); | ||
| 98 | printf("pid %d's %s scheduling policy: %s\n", | ||
| 99 | pid, state, policies[pol].name); | ||
| 100 | if (sched_getparam(pid, &sp)) | ||
| 101 | bb_perror_msg_and_die("failed to get pid %d's attributes", pid); | ||
| 102 | printf("pid %d's %s scheduling priority: %d\n", | ||
| 103 | pid, state, sp.sched_priority); | ||
| 104 | if (!*argv) /* no new prio given or we did print already, done. */ | ||
| 105 | return EXIT_SUCCESS; | ||
| 106 | } | ||
| 107 | |||
| 108 | sp.sched_priority = prio; | ||
| 109 | if (sched_setscheduler(pid, policy, &sp) < 0) | ||
| 110 | bb_perror_msg_and_die("failed to %cet pid %d's policy", 's', pid); | ||
| 111 | if (opt & OPT_p) { | ||
| 112 | state += 8; | ||
| 113 | ++argv; | ||
| 114 | goto print_rt_info; | ||
| 115 | } | ||
| 116 | ++argv; | ||
| 117 | BB_EXECVP(*argv, argv); | ||
| 118 | bb_perror_msg_and_die("%s", *argv); | ||
| 119 | } | ||
| 120 | #undef OPT_p | ||
| 121 | #undef OPT_r | ||
| 122 | #undef OPT_f | ||
| 123 | #undef OPT_o | ||
| 124 | #undef OPT_m | ||
diff --git a/scripts/defconfig b/scripts/defconfig index a3e59c8aa..178db1d74 100644 --- a/scripts/defconfig +++ b/scripts/defconfig | |||
| @@ -454,6 +454,7 @@ CONFIG_FEATURE_MOUNT_LOOP=y | |||
| 454 | # | 454 | # |
| 455 | CONFIG_ADJTIMEX=y | 455 | CONFIG_ADJTIMEX=y |
| 456 | # CONFIG_BBCONFIG is not set | 456 | # CONFIG_BBCONFIG is not set |
| 457 | CONFIG_CHRT=y | ||
| 457 | CONFIG_CROND=y | 458 | CONFIG_CROND=y |
| 458 | # CONFIG_DEBUG_CROND_OPTION is not set | 459 | # CONFIG_DEBUG_CROND_OPTION is not set |
| 459 | CONFIG_FEATURE_CROND_CALL_SENDMAIL=y | 460 | CONFIG_FEATURE_CROND_CALL_SENDMAIL=y |
