diff options
author | Ron Yorston <rmy@pobox.com> | 2017-02-08 20:09:29 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-02-08 20:09:29 +0000 |
commit | 373275a708bafb88fa4f0519de2166154f44fed9 (patch) | |
tree | 4587b4fd3f695e0f3705b2a217e199f3144df931 /miscutils | |
parent | b74b2619779b1deb903b7766261807df1e9b1f7f (diff) | |
parent | c2b18583a3df06aeecf535c3cea6856aa1f2e205 (diff) | |
download | busybox-w32-373275a708bafb88fa4f0519de2166154f44fed9.tar.gz busybox-w32-373275a708bafb88fa4f0519de2166154f44fed9.tar.bz2 busybox-w32-373275a708bafb88fa4f0519de2166154f44fed9.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/chat.c | 1 | ||||
-rw-r--r-- | miscutils/conspy.c | 17 | ||||
-rw-r--r-- | miscutils/crond.c | 2 | ||||
-rw-r--r-- | miscutils/devfsd.c | 2 | ||||
-rw-r--r-- | miscutils/flash_lock_unlock.c | 3 | ||||
-rw-r--r-- | miscutils/hdparm.c | 12 | ||||
-rw-r--r-- | miscutils/last.c | 2 | ||||
-rw-r--r-- | miscutils/less.c | 5 | ||||
-rw-r--r-- | miscutils/microcom.c | 1 | ||||
-rw-r--r-- | miscutils/nandwrite.c | 4 | ||||
-rw-r--r-- | miscutils/rx.c | 3 | ||||
-rw-r--r-- | miscutils/taskset.c | 217 | ||||
-rw-r--r-- | miscutils/ubi_tools.c | 11 |
13 files changed, 139 insertions, 141 deletions
diff --git a/miscutils/chat.c b/miscutils/chat.c index dc85f82fb..8df194534 100644 --- a/miscutils/chat.c +++ b/miscutils/chat.c | |||
@@ -213,6 +213,7 @@ int chat_main(int argc UNUSED_PARAM, char **argv) | |||
213 | , signal_handler); | 213 | , signal_handler); |
214 | 214 | ||
215 | #if ENABLE_FEATURE_CHAT_TTY_HIFI | 215 | #if ENABLE_FEATURE_CHAT_TTY_HIFI |
216 | //TODO: use set_termios_to_raw() | ||
216 | tcgetattr(STDIN_FILENO, &tio); | 217 | tcgetattr(STDIN_FILENO, &tio); |
217 | tio0 = tio; | 218 | tio0 = tio; |
218 | cfmakeraw(&tio); | 219 | cfmakeraw(&tio); |
diff --git a/miscutils/conspy.c b/miscutils/conspy.c index d9d09d482..1f0278b47 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c | |||
@@ -363,7 +363,6 @@ int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
363 | int conspy_main(int argc UNUSED_PARAM, char **argv) | 363 | int conspy_main(int argc UNUSED_PARAM, char **argv) |
364 | { | 364 | { |
365 | char tty_name[sizeof(DEV_TTY "NN")]; | 365 | char tty_name[sizeof(DEV_TTY "NN")]; |
366 | struct termios termbuf; | ||
367 | unsigned opts; | 366 | unsigned opts; |
368 | unsigned ttynum; | 367 | unsigned ttynum; |
369 | int poll_timeout_ms; | 368 | int poll_timeout_ms; |
@@ -414,16 +413,14 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
414 | 413 | ||
415 | bb_signals(BB_FATAL_SIGS, cleanup); | 414 | bb_signals(BB_FATAL_SIGS, cleanup); |
416 | 415 | ||
417 | // All characters must be passed through to us unaltered | ||
418 | G.kbd_fd = xopen(CURRENT_TTY, O_RDONLY); | 416 | G.kbd_fd = xopen(CURRENT_TTY, O_RDONLY); |
419 | tcgetattr(G.kbd_fd, &G.term_orig); | 417 | |
420 | termbuf = G.term_orig; | 418 | // All characters must be passed through to us unaltered |
421 | termbuf.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL); | 419 | set_termios_to_raw(G.kbd_fd, &G.term_orig, 0 |
422 | //termbuf.c_oflag &= ~(OPOST); - no, we still want \n -> \r\n | 420 | | TERMIOS_CLEAR_ISIG // no signals on ^C ^Z etc |
423 | termbuf.c_lflag &= ~(ISIG|ICANON|ECHO); | 421 | | TERMIOS_RAW_INPUT // turn off all input conversions |
424 | termbuf.c_cc[VMIN] = 1; | 422 | ); |
425 | termbuf.c_cc[VTIME] = 0; | 423 | //Note: termios.c_oflag &= ~(OPOST); - no, we still want \n -> \r\n |
426 | tcsetattr(G.kbd_fd, TCSANOW, &termbuf); | ||
427 | 424 | ||
428 | poll_timeout_ms = 250; | 425 | poll_timeout_ms = 250; |
429 | while (1) { | 426 | while (1) { |
diff --git a/miscutils/crond.c b/miscutils/crond.c index f96c96ee7..88e7b47b3 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -52,7 +52,7 @@ | |||
52 | //usage: " -f Foreground" | 52 | //usage: " -f Foreground" |
53 | //usage: "\n -b Background (default)" | 53 | //usage: "\n -b Background (default)" |
54 | //usage: "\n -S Log to syslog (default)" | 54 | //usage: "\n -S Log to syslog (default)" |
55 | //usage: "\n -l N Set log level. Most verbose:0, default:8" | 55 | //usage: "\n -l N Set log level. Most verbose 0, default 8" |
56 | //usage: IF_FEATURE_CROND_D( | 56 | //usage: IF_FEATURE_CROND_D( |
57 | //usage: "\n -d N Set log level, log to stderr" | 57 | //usage: "\n -d N Set log level, log to stderr" |
58 | //usage: ) | 58 | //usage: ) |
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 99bdc72b8..334f1071b 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c | |||
@@ -82,7 +82,7 @@ | |||
82 | //config: the external modutils. | 82 | //config: the external modutils. |
83 | //config: | 83 | //config: |
84 | //config:config DEVFSD_FG_NP | 84 | //config:config DEVFSD_FG_NP |
85 | //config: bool "Enables the -fg and -np options" | 85 | //config: bool "Enable the -fg and -np options" |
86 | //config: default y | 86 | //config: default y |
87 | //config: depends on DEVFSD | 87 | //config: depends on DEVFSD |
88 | //config: help | 88 | //config: help |
diff --git a/miscutils/flash_lock_unlock.c b/miscutils/flash_lock_unlock.c index 2f698641f..003496d5b 100644 --- a/miscutils/flash_lock_unlock.c +++ b/miscutils/flash_lock_unlock.c | |||
@@ -17,7 +17,8 @@ | |||
17 | //config: The flash_unlock binary from mtd-utils as of git head 5ec0c10d0. This | 17 | //config: The flash_unlock binary from mtd-utils as of git head 5ec0c10d0. This |
18 | //config: utility unlocks part or all of the flash device. | 18 | //config: utility unlocks part or all of the flash device. |
19 | 19 | ||
20 | //applet:IF_FLASH_LOCK(APPLET_ODDNAME(flash_lock, flash_lock_unlock, BB_DIR_USR_SBIN, BB_SUID_DROP, flash_lock)) | 20 | // APPLET_ODDNAME:name main location suid_type help |
21 | //applet:IF_FLASH_LOCK( APPLET_ODDNAME(flash_lock, flash_lock_unlock, BB_DIR_USR_SBIN, BB_SUID_DROP, flash_lock)) | ||
21 | //applet:IF_FLASH_UNLOCK(APPLET_ODDNAME(flash_unlock, flash_lock_unlock, BB_DIR_USR_SBIN, BB_SUID_DROP, flash_unlock)) | 22 | //applet:IF_FLASH_UNLOCK(APPLET_ODDNAME(flash_unlock, flash_lock_unlock, BB_DIR_USR_SBIN, BB_SUID_DROP, flash_unlock)) |
22 | 23 | ||
23 | //kbuild:lib-$(CONFIG_FLASH_LOCK) += flash_lock_unlock.o | 24 | //kbuild:lib-$(CONFIG_FLASH_LOCK) += flash_lock_unlock.o |
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index e43a0dec2..84675285a 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
@@ -25,7 +25,7 @@ | |||
25 | //config: default y | 25 | //config: default y |
26 | //config: depends on HDPARM | 26 | //config: depends on HDPARM |
27 | //config: help | 27 | //config: help |
28 | //config: Enables the -I and -i options to obtain detailed information | 28 | //config: Enable the -I and -i options to obtain detailed information |
29 | //config: directly from drives about their capabilities and supported ATA | 29 | //config: directly from drives about their capabilities and supported ATA |
30 | //config: feature set. If no device name is specified, hdparm will read | 30 | //config: feature set. If no device name is specified, hdparm will read |
31 | //config: identify data from stdin. Enabling this option will add about 16k... | 31 | //config: identify data from stdin. Enabling this option will add about 16k... |
@@ -35,7 +35,7 @@ | |||
35 | //config: default y | 35 | //config: default y |
36 | //config: depends on HDPARM | 36 | //config: depends on HDPARM |
37 | //config: help | 37 | //config: help |
38 | //config: Enables the 'hdparm -R' option to register an IDE interface. | 38 | //config: Enable the 'hdparm -R' option to register an IDE interface. |
39 | //config: This is dangerous stuff, so you should probably say N. | 39 | //config: This is dangerous stuff, so you should probably say N. |
40 | //config: | 40 | //config: |
41 | //config:config FEATURE_HDPARM_HDIO_UNREGISTER_HWIF | 41 | //config:config FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
@@ -43,7 +43,7 @@ | |||
43 | //config: default y | 43 | //config: default y |
44 | //config: depends on HDPARM | 44 | //config: depends on HDPARM |
45 | //config: help | 45 | //config: help |
46 | //config: Enables the 'hdparm -U' option to un-register an IDE interface. | 46 | //config: Enable the 'hdparm -U' option to un-register an IDE interface. |
47 | //config: This is dangerous stuff, so you should probably say N. | 47 | //config: This is dangerous stuff, so you should probably say N. |
48 | //config: | 48 | //config: |
49 | //config:config FEATURE_HDPARM_HDIO_DRIVE_RESET | 49 | //config:config FEATURE_HDPARM_HDIO_DRIVE_RESET |
@@ -51,7 +51,7 @@ | |||
51 | //config: default y | 51 | //config: default y |
52 | //config: depends on HDPARM | 52 | //config: depends on HDPARM |
53 | //config: help | 53 | //config: help |
54 | //config: Enables the 'hdparm -w' option to perform a device reset. | 54 | //config: Enable the 'hdparm -w' option to perform a device reset. |
55 | //config: This is dangerous stuff, so you should probably say N. | 55 | //config: This is dangerous stuff, so you should probably say N. |
56 | //config: | 56 | //config: |
57 | //config:config FEATURE_HDPARM_HDIO_TRISTATE_HWIF | 57 | //config:config FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
@@ -59,7 +59,7 @@ | |||
59 | //config: default y | 59 | //config: default y |
60 | //config: depends on HDPARM | 60 | //config: depends on HDPARM |
61 | //config: help | 61 | //config: help |
62 | //config: Enables the 'hdparm -x' option to tristate device for hotswap, | 62 | //config: Enable the 'hdparm -x' option to tristate device for hotswap, |
63 | //config: and the '-b' option to get/set bus state. This is dangerous | 63 | //config: and the '-b' option to get/set bus state. This is dangerous |
64 | //config: stuff, so you should probably say N. | 64 | //config: stuff, so you should probably say N. |
65 | //config: | 65 | //config: |
@@ -68,7 +68,7 @@ | |||
68 | //config: default y | 68 | //config: default y |
69 | //config: depends on HDPARM | 69 | //config: depends on HDPARM |
70 | //config: help | 70 | //config: help |
71 | //config: Enables the 'hdparm -d' option to get/set using_dma flag. | 71 | //config: Enable the 'hdparm -d' option to get/set using_dma flag. |
72 | 72 | ||
73 | //applet:IF_HDPARM(APPLET(hdparm, BB_DIR_SBIN, BB_SUID_DROP)) | 73 | //applet:IF_HDPARM(APPLET(hdparm, BB_DIR_SBIN, BB_SUID_DROP)) |
74 | 74 | ||
diff --git a/miscutils/last.c b/miscutils/last.c index 67c1343f1..b3f125c3f 100644 --- a/miscutils/last.c +++ b/miscutils/last.c | |||
@@ -14,7 +14,7 @@ | |||
14 | //config: 'last' displays a list of the last users that logged into the system. | 14 | //config: 'last' displays a list of the last users that logged into the system. |
15 | //config: | 15 | //config: |
16 | //config:config FEATURE_LAST_FANCY | 16 | //config:config FEATURE_LAST_FANCY |
17 | //config: bool "Turn on output of extra information" | 17 | //config: bool "Output extra information" |
18 | //config: default y | 18 | //config: default y |
19 | //config: depends on LAST | 19 | //config: depends on LAST |
20 | //config: help | 20 | //config: help |
diff --git a/miscutils/less.c b/miscutils/less.c index 8f9b329ba..220e2c693 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -87,7 +87,6 @@ | |||
87 | //config: this option makes less perform a last-ditch effort to find it: | 87 | //config: this option makes less perform a last-ditch effort to find it: |
88 | //config: position cursor to 999,999 and ask terminal to report real | 88 | //config: position cursor to 999,999 and ask terminal to report real |
89 | //config: cursor position using "ESC [ 6 n" escape sequence, then read stdin. | 89 | //config: cursor position using "ESC [ 6 n" escape sequence, then read stdin. |
90 | //config: | ||
91 | //config: This is not clean but helps a lot on serial lines and such. | 90 | //config: This is not clean but helps a lot on serial lines and such. |
92 | //config: | 91 | //config: |
93 | //config:config FEATURE_LESS_DASHCMD | 92 | //config:config FEATURE_LESS_DASHCMD |
@@ -99,11 +98,9 @@ | |||
99 | //config: less itself ('-' keyboard command). | 98 | //config: less itself ('-' keyboard command). |
100 | //config: | 99 | //config: |
101 | //config:config FEATURE_LESS_LINENUMS | 100 | //config:config FEATURE_LESS_LINENUMS |
102 | //config: bool "Enable dynamic switching of line numbers" | 101 | //config: bool "Enable -N (dynamic switching of line numbers)" |
103 | //config: default y | 102 | //config: default y |
104 | //config: depends on FEATURE_LESS_DASHCMD | 103 | //config: depends on FEATURE_LESS_DASHCMD |
105 | //config: help | ||
106 | //config: Enables "-N" command. | ||
107 | 104 | ||
108 | //applet:IF_LESS(APPLET(less, BB_DIR_USR_BIN, BB_SUID_DROP)) | 105 | //applet:IF_LESS(APPLET(less, BB_DIR_USR_BIN, BB_SUID_DROP)) |
109 | 106 | ||
diff --git a/miscutils/microcom.c b/miscutils/microcom.c index 04605d883..5a4bbefa9 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c | |||
@@ -33,6 +33,7 @@ | |||
33 | // set raw tty mode | 33 | // set raw tty mode |
34 | static void xget1(int fd, struct termios *t, struct termios *oldt) | 34 | static void xget1(int fd, struct termios *t, struct termios *oldt) |
35 | { | 35 | { |
36 | //TODO: use set_termios_to_raw() | ||
36 | tcgetattr(fd, oldt); | 37 | tcgetattr(fd, oldt); |
37 | *t = *oldt; | 38 | *t = *oldt; |
38 | cfmakeraw(t); | 39 | cfmakeraw(t); |
diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index c95cbb21e..dbe9043f4 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c | |||
@@ -37,7 +37,7 @@ | |||
37 | //usage: "\n -s ADDR Start address" | 37 | //usage: "\n -s ADDR Start address" |
38 | 38 | ||
39 | //usage:#define nanddump_trivial_usage | 39 | //usage:#define nanddump_trivial_usage |
40 | //usage: "[-no]" IF_LONG_OPTS(" [--bb=padbad|skipbad]") " [-s ADDR] [-l LEN] [-f FILE] MTD_DEVICE" | 40 | //usage: "[-no]" IF_LONG_OPTS(" [--bb padbad|skipbad]") " [-s ADDR] [-l LEN] [-f FILE] MTD_DEVICE" |
41 | //usage:#define nanddump_full_usage "\n\n" | 41 | //usage:#define nanddump_full_usage "\n\n" |
42 | //usage: "Dump MTD_DEVICE\n" | 42 | //usage: "Dump MTD_DEVICE\n" |
43 | //usage: "\n -n Read without ecc" | 43 | //usage: "\n -n Read without ecc" |
@@ -46,7 +46,7 @@ | |||
46 | //usage: "\n -l LEN Length" | 46 | //usage: "\n -l LEN Length" |
47 | //usage: "\n -f FILE Dump to file ('-' for stdout)" | 47 | //usage: "\n -f FILE Dump to file ('-' for stdout)" |
48 | //usage: IF_LONG_OPTS( | 48 | //usage: IF_LONG_OPTS( |
49 | //usage: "\n --bb=METHOD:" | 49 | //usage: "\n --bb METHOD" |
50 | //usage: "\n skipbad: skip bad blocks" | 50 | //usage: "\n skipbad: skip bad blocks" |
51 | //usage: "\n padbad: substitute bad blocks by 0xff (default)" | 51 | //usage: "\n padbad: substitute bad blocks by 0xff (default)" |
52 | //usage: ) | 52 | //usage: ) |
diff --git a/miscutils/rx.c b/miscutils/rx.c index 660f66a89..1f6f2825c 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c | |||
@@ -94,7 +94,7 @@ static int receive(/*int read_fd, */int file_fd) | |||
94 | int blockBegin; | 94 | int blockBegin; |
95 | int blockNo, blockNoOnesCompl; | 95 | int blockNo, blockNoOnesCompl; |
96 | int cksum_or_crc; | 96 | int cksum_or_crc; |
97 | int expected; | 97 | unsigned expected; |
98 | int i, j; | 98 | int i, j; |
99 | 99 | ||
100 | blockBegin = read_byte(timeout); | 100 | blockBegin = read_byte(timeout); |
@@ -263,6 +263,7 @@ int rx_main(int argc UNUSED_PARAM, char **argv) | |||
263 | 263 | ||
264 | termios_err = tcgetattr(read_fd, &tty); | 264 | termios_err = tcgetattr(read_fd, &tty); |
265 | if (termios_err == 0) { | 265 | if (termios_err == 0) { |
266 | //TODO: use set_termios_to_raw() | ||
266 | orig_tty = tty; | 267 | orig_tty = tty; |
267 | cfmakeraw(&tty); | 268 | cfmakeraw(&tty); |
268 | tcsetattr(read_fd, TCSAFLUSH, &tty); | 269 | tcsetattr(read_fd, TCSAFLUSH, &tty); |
diff --git a/miscutils/taskset.c b/miscutils/taskset.c index fb352ab8d..94a07383a 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c | |||
@@ -8,7 +8,7 @@ | |||
8 | 8 | ||
9 | //config:config TASKSET | 9 | //config:config TASKSET |
10 | //config: bool "taskset" | 10 | //config: bool "taskset" |
11 | //config: default n # doesn't build on some non-x86 targets (m68k) | 11 | //config: default y |
12 | //config: help | 12 | //config: help |
13 | //config: Retrieve or set a processes's CPU affinity. | 13 | //config: Retrieve or set a processes's CPU affinity. |
14 | //config: This requires sched_{g,s}etaffinity support in your libc. | 14 | //config: This requires sched_{g,s}etaffinity support in your libc. |
@@ -18,15 +18,15 @@ | |||
18 | //config: default y | 18 | //config: default y |
19 | //config: depends on TASKSET | 19 | //config: depends on TASKSET |
20 | //config: help | 20 | //config: help |
21 | //config: Add code for fancy output. This merely silences a compiler-warning | 21 | //config: Needed for machines with more than 32-64 CPUs: |
22 | //config: and adds about 135 Bytes. May be needed for machines with alot | 22 | //config: affinity parameter 0xHHHHHHHHHHHHHHHHHHHH can be arbitrarily long |
23 | //config: of CPUs. | 23 | //config: in this case. Otherwise, it is limited to sizeof(long). |
24 | 24 | ||
25 | //applet:IF_TASKSET(APPLET(taskset, BB_DIR_USR_BIN, BB_SUID_DROP)) | 25 | //applet:IF_TASKSET(APPLET(taskset, BB_DIR_USR_BIN, BB_SUID_DROP)) |
26 | //kbuild:lib-$(CONFIG_TASKSET) += taskset.o | 26 | //kbuild:lib-$(CONFIG_TASKSET) += taskset.o |
27 | 27 | ||
28 | //usage:#define taskset_trivial_usage | 28 | //usage:#define taskset_trivial_usage |
29 | //usage: "[-p] [MASK] [PID | PROG ARGS]" | 29 | //usage: "[-p] [HEXMASK] PID | PROG ARGS" |
30 | //usage:#define taskset_full_usage "\n\n" | 30 | //usage:#define taskset_full_usage "\n\n" |
31 | //usage: "Set or get CPU affinity\n" | 31 | //usage: "Set or get CPU affinity\n" |
32 | //usage: "\n -p Operate on an existing PID" | 32 | //usage: "\n -p Operate on an existing PID" |
@@ -42,72 +42,81 @@ | |||
42 | //usage: "$ taskset -p 1\n" | 42 | //usage: "$ taskset -p 1\n" |
43 | //usage: "pid 1's current affinity mask: 3\n" | 43 | //usage: "pid 1's current affinity mask: 3\n" |
44 | /* | 44 | /* |
45 | Not yet implemented: | 45 | * Not yet implemented: |
46 | * -a/--all-tasks (affect all threads) | 46 | * -a/--all-tasks (affect all threads) |
47 | * needs to get TIDs from /proc/PID/task/ and use _them_ as "pid" in sched_setaffinity(pid) | ||
47 | * -c/--cpu-list (specify CPUs via "1,3,5-7") | 48 | * -c/--cpu-list (specify CPUs via "1,3,5-7") |
48 | */ | 49 | */ |
49 | 50 | ||
50 | #include <sched.h> | 51 | #include <sched.h> |
51 | #include "libbb.h" | 52 | #include "libbb.h" |
52 | 53 | ||
54 | typedef unsigned long ul; | ||
55 | #define SZOF_UL (unsigned)(sizeof(ul)) | ||
56 | #define BITS_UL (unsigned)(sizeof(ul)*8) | ||
57 | #define MASK_UL (unsigned)(sizeof(ul)*8 - 1) | ||
58 | |||
53 | #if ENABLE_FEATURE_TASKSET_FANCY | 59 | #if ENABLE_FEATURE_TASKSET_FANCY |
54 | #define TASKSET_PRINTF_MASK "%s" | 60 | #define TASKSET_PRINTF_MASK "%s" |
55 | /* craft a string from the mask */ | 61 | /* craft a string from the mask */ |
56 | static char *from_cpuset(cpu_set_t *mask) | 62 | static char *from_mask(const ul *mask, unsigned sz_in_bytes) |
57 | { | 63 | { |
58 | int i; | 64 | char *str = xzalloc((sz_in_bytes+1) * 2); /* we will leak it */ |
59 | char *ret = NULL; | 65 | char *p = str; |
60 | char *str = xzalloc((CPU_SETSIZE / 4) + 1); /* we will leak it */ | 66 | for (;;) { |
61 | 67 | ul v = *mask++; | |
62 | for (i = CPU_SETSIZE - 4; i >= 0; i -= 4) { | 68 | if (SZOF_UL == 4) |
63 | int val = 0; | 69 | p += sprintf(p, "%08lx", v); |
64 | int off; | 70 | if (SZOF_UL == 8) |
65 | for (off = 0; off <= 3; ++off) | 71 | p += sprintf(p, "%016lx", v); |
66 | if (CPU_ISSET(i + off, mask)) | 72 | if (SZOF_UL == 16) |
67 | val |= 1 << off; | 73 | p += sprintf(p, "%032lx", v); /* :) */ |
68 | if (!ret && val) | 74 | sz_in_bytes -= SZOF_UL; |
69 | ret = str; | 75 | if ((int)sz_in_bytes <= 0) |
70 | *str++ = bb_hexdigits_upcase[val] | 0x20; | 76 | break; |
71 | } | 77 | } |
72 | return ret; | 78 | while (str[0] == '0' && str[1]) |
79 | str++; | ||
80 | return str; | ||
73 | } | 81 | } |
74 | #else | 82 | #else |
75 | #define TASKSET_PRINTF_MASK "%llx" | 83 | #define TASKSET_PRINTF_MASK "%lx" |
76 | static unsigned long long from_cpuset(cpu_set_t *mask) | 84 | static unsigned long long from_mask(ul *mask, unsigned sz_in_bytes UNUSED_PARAM) |
77 | { | 85 | { |
78 | BUILD_BUG_ON(CPU_SETSIZE < 8*sizeof(int)); | 86 | return *mask; |
79 | |||
80 | /* Take the least significant bits. Assume cpu_set_t is | ||
81 | * implemented as an array of unsigned long or unsigned | ||
82 | * int. | ||
83 | */ | ||
84 | if (CPU_SETSIZE < 8*sizeof(long)) | ||
85 | return *(unsigned*)mask; | ||
86 | if (CPU_SETSIZE < 8*sizeof(long long)) | ||
87 | return *(unsigned long*)mask; | ||
88 | # if BB_BIG_ENDIAN | ||
89 | if (sizeof(long long) > sizeof(long)) { | ||
90 | /* We can put two long in the long long, but they have to | ||
91 | * be swapped: the least significant word comes first in the | ||
92 | * array */ | ||
93 | unsigned long *p = (void*)mask; | ||
94 | return p[0] + ((unsigned long long)p[1] << (8*sizeof(long))); | ||
95 | } | ||
96 | # endif | ||
97 | return *(unsigned long long*)mask; | ||
98 | } | 87 | } |
99 | #endif | 88 | #endif |
100 | 89 | ||
90 | static unsigned long *get_aff(int pid, unsigned *sz) | ||
91 | { | ||
92 | int r; | ||
93 | unsigned long *mask = NULL; | ||
94 | unsigned sz_in_bytes = *sz; | ||
95 | |||
96 | for (;;) { | ||
97 | mask = xrealloc(mask, sz_in_bytes); | ||
98 | r = sched_getaffinity(pid, sz_in_bytes, (void*)mask); | ||
99 | if (r == 0) | ||
100 | break; | ||
101 | sz_in_bytes *= 2; | ||
102 | if (errno == EINVAL && (int)sz_in_bytes > 0) | ||
103 | continue; | ||
104 | bb_perror_msg_and_die("can't %cet pid %d's affinity", 'g', pid); | ||
105 | } | ||
106 | //bb_error_msg("get mask[0]:%lx sz_in_bytes:%d", mask[0], sz_in_bytes); | ||
107 | *sz = sz_in_bytes; | ||
108 | return mask; | ||
109 | } | ||
101 | 110 | ||
102 | int taskset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 111 | int taskset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
103 | int taskset_main(int argc UNUSED_PARAM, char **argv) | 112 | int taskset_main(int argc UNUSED_PARAM, char **argv) |
104 | { | 113 | { |
105 | cpu_set_t mask; | 114 | ul *mask; |
115 | unsigned mask_size_in_bytes; | ||
106 | pid_t pid = 0; | 116 | pid_t pid = 0; |
107 | unsigned opt_p; | 117 | unsigned opt_p; |
108 | const char *current_new; | 118 | const char *current_new; |
109 | char *pid_str; | 119 | char *aff; |
110 | char *aff = aff; /* for compiler */ | ||
111 | 120 | ||
112 | /* NB: we mimic util-linux's taskset: -p does not take | 121 | /* NB: we mimic util-linux's taskset: -p does not take |
113 | * an argument, i.e., "-pN" is NOT valid, only "-p N"! | 122 | * an argument, i.e., "-pN" is NOT valid, only "-p N"! |
@@ -118,102 +127,92 @@ int taskset_main(int argc UNUSED_PARAM, char **argv) | |||
118 | opt_p = getopt32(argv, "+p"); | 127 | opt_p = getopt32(argv, "+p"); |
119 | argv += optind; | 128 | argv += optind; |
120 | 129 | ||
130 | aff = *argv++; | ||
121 | if (opt_p) { | 131 | if (opt_p) { |
122 | pid_str = *argv++; | 132 | char *pid_str = aff; |
123 | if (*argv) { /* "-p <aff> <pid> ...rest.is.ignored..." */ | 133 | if (*argv) { /* "-p <aff> <pid> ...rest.is.ignored..." */ |
124 | aff = pid_str; | ||
125 | pid_str = *argv; /* NB: *argv != NULL in this case */ | 134 | pid_str = *argv; /* NB: *argv != NULL in this case */ |
126 | } | 135 | } |
127 | /* else it was just "-p <pid>", and *argv == NULL */ | 136 | /* else it was just "-p <pid>", and *argv == NULL */ |
128 | pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1); | 137 | pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1); |
129 | } else { | 138 | } else { |
130 | aff = *argv++; /* <aff> <cmd...> */ | 139 | /* <aff> <cmd...> */ |
131 | if (!*argv) | 140 | if (!*argv) |
132 | bb_show_usage(); | 141 | bb_show_usage(); |
133 | } | 142 | } |
134 | 143 | ||
135 | current_new = "current\0new"; | 144 | mask_size_in_bytes = SZOF_UL; |
136 | if (opt_p) { | 145 | current_new = "current"; |
137 | print_aff: | 146 | print_aff: |
138 | if (sched_getaffinity(pid, sizeof(mask), &mask) < 0) | 147 | mask = get_aff(pid, &mask_size_in_bytes); |
139 | bb_perror_msg_and_die("can't %cet pid %d's affinity", 'g', pid); | 148 | if (opt_p) { |
140 | printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n", | 149 | printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n", |
141 | pid, current_new, from_cpuset(&mask)); | 150 | pid, current_new, from_mask(mask, mask_size_in_bytes)); |
142 | if (!*argv) { | 151 | if (*argv == NULL) { |
143 | /* Either it was just "-p <pid>", | 152 | /* Either it was just "-p <pid>", |
144 | * or it was "-p <aff> <pid>" and we came here | 153 | * or it was "-p <aff> <pid>" and we came here |
145 | * for the second time (see goto below) */ | 154 | * for the second time (see goto below) */ |
146 | return EXIT_SUCCESS; | 155 | return EXIT_SUCCESS; |
147 | } | 156 | } |
148 | *argv = NULL; | 157 | *argv = NULL; |
149 | current_new += 8; /* "new" */ | 158 | current_new = "new"; |
150 | } | 159 | } |
160 | memset(mask, 0, mask_size_in_bytes); | ||
161 | |||
162 | /* Affinity was specified, translate it into mask */ | ||
163 | /* it is always in hex, skip "0x" if it exists */ | ||
164 | if (aff[0] == '0' && (aff[1]|0x20) == 'x') | ||
165 | aff += 2; | ||
151 | 166 | ||
152 | /* Affinity was specified, translate it into cpu_set_t */ | ||
153 | CPU_ZERO(&mask); | ||
154 | if (!ENABLE_FEATURE_TASKSET_FANCY) { | 167 | if (!ENABLE_FEATURE_TASKSET_FANCY) { |
155 | unsigned i; | 168 | mask[0] = xstrtoul(aff, 16); |
156 | unsigned long long m; | ||
157 | |||
158 | /* Do not allow zero mask: */ | ||
159 | m = xstrtoull_range(aff, 0, 1, ULLONG_MAX); | ||
160 | i = 0; | ||
161 | do { | ||
162 | if (m & 1) | ||
163 | CPU_SET(i, &mask); | ||
164 | i++; | ||
165 | m >>= 1; | ||
166 | } while (m != 0); | ||
167 | } else { | 169 | } else { |
168 | unsigned i; | 170 | unsigned i; |
169 | char *last_byte; | 171 | char *last_char; |
170 | char *bin; | 172 | |
171 | uint8_t bit_in_byte; | 173 | i = 0; /* bit pos in mask[] */ |
172 | 174 | ||
173 | /* Cheap way to get "long enough" buffer */ | 175 | /* aff is ASCII hex string, accept very long masks in this form. |
174 | bin = xstrdup(aff); | 176 | * Process hex string AABBCCDD... to ulong mask[] |
175 | 177 | * from the rightmost nibble, which is least-significant. | |
176 | if (aff[0] != '0' || (aff[1]|0x20) != 'x') { | 178 | * Bits not fitting into mask[] are ignored: (example: 1234 |
177 | /* TODO: decimal/octal masks are still limited to 2^64 */ | 179 | * in 12340000000000000000000000000000000000000ff) |
178 | unsigned long long m = xstrtoull_range(aff, 0, 1, ULLONG_MAX); | 180 | */ |
179 | bin += strlen(bin); | 181 | last_char = strchrnul(aff, '\0'); |
180 | last_byte = bin - 1; | 182 | while (last_char > aff) { |
181 | while (m) { | 183 | char c; |
182 | *--bin = m & 0xff; | 184 | ul val; |
183 | m >>= 8; | 185 | |
184 | } | 186 | last_char--; |
185 | } else { | 187 | c = *last_char; |
186 | /* aff is "0x.....", we accept very long masks in this form */ | 188 | if (isdigit(c)) |
187 | last_byte = hex2bin(bin, aff + 2, INT_MAX); | 189 | val = c - '0'; |
188 | if (!last_byte) { | 190 | else if ((c|0x20) >= 'a' && (c|0x20) <= 'f') |
189 | bad_aff: | 191 | val = (c|0x20) - ('a' - 10); |
192 | else | ||
190 | bb_error_msg_and_die("bad affinity '%s'", aff); | 193 | bb_error_msg_and_die("bad affinity '%s'", aff); |
191 | } | ||
192 | last_byte--; /* now points to the last byte */ | ||
193 | } | ||
194 | 194 | ||
195 | i = 0; | 195 | if (i < mask_size_in_bytes * 8) { |
196 | bit_in_byte = 1; | 196 | mask[i / BITS_UL] |= val << (i & MASK_UL); |
197 | while (last_byte >= bin) { | ||
198 | if (bit_in_byte & *last_byte) { | ||
199 | if (i >= CPU_SETSIZE) | ||
200 | goto bad_aff; | ||
201 | CPU_SET(i, &mask); | ||
202 | //bb_error_msg("bit %d set", i); | 197 | //bb_error_msg("bit %d set", i); |
203 | } | 198 | } |
204 | i++; | 199 | /* else: |
205 | /* bit_in_byte is uint8_t! & 0xff is implied */ | 200 | * We can error out here, but we don't. |
206 | bit_in_byte = (bit_in_byte << 1); | 201 | * For one, kernel itself ignores bits in mask[] |
207 | if (!bit_in_byte) { | 202 | * which do not map to any CPUs: |
208 | bit_in_byte = 1; | 203 | * if mask[] has one 32-bit long element, |
209 | last_byte--; | 204 | * but you have only 8 CPUs, all bits beyond first 8 |
210 | } | 205 | * are ignored, silently. |
206 | * No point in making bits past 31th to be errors. | ||
207 | */ | ||
208 | i += 4; | ||
211 | } | 209 | } |
212 | } | 210 | } |
213 | 211 | ||
214 | /* Set pid's or our own (pid==0) affinity */ | 212 | /* Set pid's or our own (pid==0) affinity */ |
215 | if (sched_setaffinity(pid, sizeof(mask), &mask)) | 213 | if (sched_setaffinity(pid, mask_size_in_bytes, (void*)mask)) |
216 | bb_perror_msg_and_die("can't %cet pid %d's affinity", 's', pid); | 214 | bb_perror_msg_and_die("can't %cet pid %d's affinity", 's', pid); |
215 | //bb_error_msg("set mask[0]:%lx", mask[0]); | ||
217 | 216 | ||
218 | if (!argv[0]) /* "-p <aff> <pid> [...ignored...]" */ | 217 | if (!argv[0]) /* "-p <aff> <pid> [...ignored...]" */ |
219 | goto print_aff; /* print new affinity and exit */ | 218 | goto print_aff; /* print new affinity and exit */ |
diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index 8e55e9577..982e3e52a 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c | |||
@@ -45,11 +45,12 @@ | |||
45 | //config: help | 45 | //config: help |
46 | //config: Update a UBI volume. | 46 | //config: Update a UBI volume. |
47 | 47 | ||
48 | //applet:IF_UBIATTACH(APPLET_ODDNAME(ubiattach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiattach)) | 48 | // APPLET_ODDNAME:name main location suid_type help |
49 | //applet:IF_UBIDETACH(APPLET_ODDNAME(ubidetach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubidetach)) | 49 | //applet:IF_UBIATTACH( APPLET_ODDNAME(ubiattach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiattach)) |
50 | //applet:IF_UBIMKVOL(APPLET_ODDNAME(ubimkvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubimkvol)) | 50 | //applet:IF_UBIDETACH( APPLET_ODDNAME(ubidetach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubidetach)) |
51 | //applet:IF_UBIRMVOL(APPLET_ODDNAME(ubirmvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirmvol)) | 51 | //applet:IF_UBIMKVOL( APPLET_ODDNAME(ubimkvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubimkvol)) |
52 | //applet:IF_UBIRSVOL(APPLET_ODDNAME(ubirsvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirsvol)) | 52 | //applet:IF_UBIRMVOL( APPLET_ODDNAME(ubirmvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirmvol)) |
53 | //applet:IF_UBIRSVOL( APPLET_ODDNAME(ubirsvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirsvol)) | ||
53 | //applet:IF_UBIUPDATEVOL(APPLET_ODDNAME(ubiupdatevol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiupdatevol)) | 54 | //applet:IF_UBIUPDATEVOL(APPLET_ODDNAME(ubiupdatevol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiupdatevol)) |
54 | 55 | ||
55 | //kbuild:lib-$(CONFIG_UBIATTACH) += ubi_tools.o | 56 | //kbuild:lib-$(CONFIG_UBIATTACH) += ubi_tools.o |