Commit Graph

1445 Commits

Author SHA1 Message Date
Denys Vlasenko
56a361bec1 fix more instances of ": $((a++))" in shell scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko
f807b8e96e inetd,mount: do not die if uclibc without RPC is detected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Patrick Steinhardt
ee67c9a60a setpriv: do not process remaining args
By default, the 'getopt32' call will continue parsing the command line
even after hitting a non-option string. But in setpriv, this should be
avoided, as all parameters following the initial non-option argument are
in fact arguments to the binary that is to be executed by setpriv.
Otherwise, calling e.g. 'busybox setpriv ls -l' would result in an error
due to the unknown parameter "-l".

Fix the issue by passing "+" as the first character in the options
string. This will cause 'getopt32' to stop processing after hitting the
first non-option.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko
442d522f0b fixes for bugs found by make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko
45100b8d07 unshare: fix help text; select LONG_OPTS instead depending on them
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-14 16:20:02 +02:00
Assaf Gordon
62d1e98fbd setpriv: new applet
Add a minimal 'setpriv' implementation supporting the NO_NEW_PRIVS bit.
Typical usage:

    $ busybox setpriv sudo uname
    Linux
    $ busybox setpriv --nnp sudo uname
    sudo: effective uid is not 0, is /usr/bin/sudo on a file system with
    the 'nosuid' option set or an NFS file system without root privileges?

function                                             old     new   delta
packed_usage                                       31580   31685    +105
setpriv_main                                           -      87     +87
prctl                                                  -      53     +53
static.setpriv_longopts                                -      22     +22
applet_names                                        2620    2628      +8
applet_main                                         1516    1520      +4
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 3/0 up/down: 279/0)             Total: 279 bytes

Signed-off-by: Assaf Gordon <assafgordon@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-14 11:46:52 +02:00
Denys Vlasenko
10ad622dc2 Spelling fixes in comments, documentation, tests and examples
By klemens <ka7@github.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17 16:13:32 +02:00
Kaarle Ritvanen
835ad3a984 libbb: GETOPT_RESET macro
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 20:11:34 +02:00
Denys Vlasenko
0cecbe7d5d Sort more misplaced applets into coreutils or util-linux
No code changes

Surprisingly, nice and renice are coming from different packages :)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 14:16:29 +02:00
Denys Vlasenko
783d57af7b Sort some miscutils/ applets into coreutils or util-linux
No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 13:58:40 +02:00
Denys Vlasenko
67918b32ab fallocate: new applet
NAME
       fallocate - preallocate or deallocate space to a file
SYNOPSIS
       fallocate [-c|-p|-z] [-o offset] -l length [-n] filename
       fallocate -d [-o offset] [-l length] filename
DESCRIPTION
       fallocate  is  used  to manipulate the allocated disk space for a file,
       either to deallocate or preallocate it.  For filesystems which  support
       the  fallocate system call, preallocation is done quickly by allocating
       blocks and marking them as uninitialized, requiring no IO to  the  data
       blocks.   This  is  much faster than creating a file by filling it with
       zeroes.

function                                             old     new   delta
fallocate_main                                         -     179    +179
applet_names                                        2597    2606      +9
applet_main                                         1504    1508      +4
applet_suid                                           94      95      +1
applet_install_loc                                   188     189      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 13:33:54 +02:00
Denys Vlasenko
b9512fa6b3 fsfreeze: new applet
NAME
       fsfreeze - suspend access to a filesystem (Ext3/4, ReiserFS, JFS, XFS)
SYNOPSIS
       fsfreeze --freeze|--unfreeze mountpoint
DESCRIPTION
       fsfreeze suspends or resumes access to a filesystem.
       fsfreeze halts any new access to the filesystem and creates a stable
       image on disk.
AVAILABILITY
       The fsfreeze command is part of the util-linux 2.28

function                                             old     new   delta
fsfreeze_main                                          -      81     +81
applet_names                                        2597    2606      +9
applet_main                                         1504    1508      +4
applet_suid                                           94      95      +1
applet_install_loc                                   188     189      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 11:53:05 +02:00
Andrei Gherzan
e3b65ab43d switch_root: don't bail out when console doesn't exist
Busybox is very often used in initramfs at the end of which usually
there is a switch_root to the actual rootfs. There are many cases where
the console kernel argument is either just a placeholder (for example
RaspberryPi uses serial0 and serial1) or configured as null to avoid any
console messages - usually you would see such of a setup in production
environments.

Currently busybox bails out if can't open the console argument. If this
happenes in initramfs and if the console=null for example, you get in a
blind kernel panic. Avoid this by only warning instead of dying.

function                                             old     new   delta
switch_root_main                                     371     368      -3

Signed-off-by: Andrei Gherzan <andrei@gherzan.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-24 16:39:08 +01:00
Denys Vlasenko
a98db793cf Revert "umount: make -d always active, add -D to suppress it"
This reverts commit 86a03bee1d.

Since now our "mount -oloop" creates AUTOCLEARed loopdevs, we no longer
need our umount to destroy loopdevs to match the usual util-linux behaviour.

Now this revert fixes another, opposite bug: "explicit" mount /dev/loopN
and then umount must not drop loopdevs!

User complaint is as follows:

It seems LOOP_CLR_FD called on a loop-*partition* removes the mapping of
the whole *device* - which results in the following:

root@LEDE:/# loop=$(losetup -f)
root@LEDE:/# echo ${loop}
/dev/loop2
root@LEDE:/# losetup ${loop} /IMAGE
root@LEDE:/# ls -l ${loop}*
brw-------  1 root root     7,   2 Mar  6 20:09 /dev/loop2
root@LEDE:/# partprobe ${loop}
root@LEDE:/# ls -l ${loop}*
brw-------  1 root  root    7,   2 Mar  6 20:09 /dev/loop2
brw-------  1 root  root  259,   8 Mar  6 21:59 /dev/loop2p1
brw-------  1 root  root  259,   9 Mar  6 21:59 /dev/loop2p2
brw-------  1 root  root  259,  10 Mar  6 21:59 /dev/loop2p3
brw-------  1 root  root  259,  11 Mar  6 21:59 /dev/loop2p4
brw-------  1 root  root  259,  12 Mar  6 21:59 /dev/loop2p5
brw-------  1 root  root  259,  13 Mar  6 21:59 /dev/loop2p6
brw-------  1 root  root  259,  14 Mar  6 21:59 /dev/loop2p7
brw-------  1 root  root  259,  15 Mar  6 21:59 /dev/loop2p8
root@LEDE:/# mount ${loop}p8 /MOUNT       # mount loop partition
root@LEDE:/# losetup -a | grep $loop      # loop dev mapping still there
/dev/loop2: 0 /mnt/IMAGE
root@LEDE:/# strace umount /MOUNT 2> /log # unmount loop partition
root@LEDE:/# losetup -a | grep ${loop}    # loop device mapping is gone
root@LEDE:/# grep -i loop /log
open("/dev/loop2p7", O_RDONLY|O_LARGEFILE) = 3
ioctl(3, LOOP_CLR_FD)                   = 0
root@LEDE:/#

The strace was done to figure out, if maybe umount wrongly ioctl()'s the
parent device instead of the partition - it doesn't.

I already wasn't a fan of umount implicitly removing the mapping in the
first place (as I usually setup and release loop devices with `losetup`
and scripts needed to call umount differently in order to work and
outside busybox).

However taking above (kernel-)behaviour into account - umount calling
ioctl(LOOP_CLR_FD) unconditionally potentially causes some nasty side
effects

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-16 17:51:06 +01:00
Denys Vlasenko
ab518eea9c mount: create loop devices with LO_FLAGS_AUTOCLEAR flag
The "autolooped" mount (mount [-oloop] IMAGE /DIR/DIR)
always creates AUTOCLEARed loopdevs, so that umounting
drops them (and this does not require any code in the
umount userspace).
This happens since circa linux-2.6.25:
	commit 96c5865559cee0f9cbc5173f3c949f6ce3525581
	Date:    Wed Feb 6 01:36:27 2008 -0800
	Subject: Allow auto-destruction of loop devices
IOW: in this case, umount does not have to use -d
to drop the loopdev.

The explicit loop mount (mount /dev/loopN /DIR/DIR)
does not do this. In this case, umount without -d
should not drop loopdev.
Unfortunately, bbox umount currently always implies -d,
this probably needs fixing.

function                                             old     new   delta
set_loop                                             537     597     +60
singlemount                                         1101    1138     +37
losetup_main                                         419     432     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 110/0)             Total: 110 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-16 16:55:47 +01:00
Denys Vlasenko
35b54a3c24 libbb: match_fstype() is unreadable in the extreme, fixing it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-30 00:45:05 +01:00
Denys Vlasenko
205d48e948 *: add comment about APPLET_ODDNAME format
It confused me more than once

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-29 14:57:33 +01:00
Denys Vlasenko
7dd906a388 xxd: make -p output lines actually end with a newline
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 17:00:38 +01:00
Denys Vlasenko
62a9b18547 xxd: implement -p
While at it, tweaked hexdump --help

function                                             old     new   delta
xxd_main                                             364     414     +50
packed_usage                                       31097   31114     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 16:50:30 +01:00
Denys Vlasenko
8a2657cbf5 hexdump/xxd: a bit more condensed formats
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 03:07:39 +01:00
Denys Vlasenko
0f4364775f xxd: new applet
Yet Another Hexdumper

function                                             old     new   delta
xxd_main                                               -     364    +364
packed_usage                                       31046   31116     +70
applet_names                                        2560    2564      +4
applet_main                                         1476    1480      +4
rewrite                                             1022    1013      -9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/1 up/down: 442/-9)            Total: 433 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 01:58:00 +01:00
Denys Vlasenko
bbc7bee966 make --help texts more uniform
function                                             old     new   delta
packed_usage                                       31062   31035     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-21 02:49:58 +01:00
Denys Vlasenko
6e511393f9 rdate: time(NULL) is shorter than time(&var)
function                                             old     new   delta
rdate_main                                           251     246      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 16:07:14 +01:00
Denys Vlasenko
179e88bec9 rdate: make it do something remotely sane, facing 32-bit time overflow
function                                             old     new   delta
rdate_main                                           251     254      +3
packed_usage                                       31029   31023      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 16:03:48 +01:00
Denys Vlasenko
704c606f48 fdisk: add typical values of -H and -S to --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 14:29:42 +01:00
Denys Vlasenko
01ccdd1d3c libbb: consolidate the code to set termios unbuffered mode
function                                             old     new   delta
set_termios_to_raw                                     -     116    +116
count_lines                                           72      74      +2
powertop_main                                       1458    1430     -28
top_main                                             943     914     -29
more_main                                            759     714     -45
fsck_minix_main                                     2969    2921     -48
conspy_main                                         1197    1135     -62
rawmode                                               99      36     -63
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 118/-275)         Total: -157 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 16:17:59 +01:00
Denys Vlasenko
c5891fe1af more: hardcode FEATURE_USE_TERMIOS=y in this applet; code shrink
function                                             old     new   delta
get_wh                                                 -      27     +27
tcsetattr_tty_TCSANOW                                  -      18     +18
gotsig                                                35      27      -8
more_main                                            835     759     -76
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 45/-84)            Total: -39 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 10:38:52 +01:00
Denys Vlasenko
f560422fa0 Big cleanup in config help and description
Redundant help texts (one which only repeats the description)
are deleted.

Descriptions and help texts are trimmed.

Some config options are moved, even across menus.

No config option _names_ are changed.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 14:58:54 +01:00
Denys Vlasenko
e184a88356 df: implement -B n<suff> and -B <suff> formats of -B option
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 19:56:31 +01:00
Denys Vlasenko
1d3a04a3a4 Code style fixes, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-28 01:22:57 +01:00
Denys Vlasenko
710b6ce9b0 fdisk_gpt: simplify GPT partition name printing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27 20:47:01 +01:00
Denys Vlasenko
29516ac0e4 fdisk: sanitize partition name printing; drop "Code" column; get rid of one static var
function                                             old     new   delta
list_table                                          2335    2373     +38
fill_bounds                                          131     128      -3
part_array_len                                         4       -      -4
get_boot                                            1584    1574     -10
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 38/-17)             Total: 21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27 06:13:43 +01:00
Denys Vlasenko
5b966c6180 Make "hd" independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 11:53:12 +01:00
Denys Vlasenko
dd898c9f33 Convert all util-linux/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 11:46:32 +01:00
Denys Vlasenko
10880cc20f Make mkfs.vfat and mkdosfs individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-16 16:18:50 +01:00
Denys Vlasenko
0581a2f304 Make mke2fs and mkfs.ext2 individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-16 16:12:11 +01:00
Denys Vlasenko
f417ffd88f Make swapon and swapoff individually selectable.
For example, without swapoff, code shrinks by 277 bytes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-14 17:30:50 +01:00
Denys Vlasenko
c314ca9016 Make setarch/linux32/linux64 independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-13 22:56:04 +01:00
Denys Vlasenko
713b513353 more: accept and ignore a bunch of options
Alpine Linux stumbled over "more -s":
http://bugs.alpinelinux.org/issues/5190

function                                             old     new   delta
more_main                                            857     872     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-11 15:29:38 +02:00
Denys Vlasenko
b09ab448b8 mount: for cifs, dont insert "ip=ADDR" option if user gave it explicitly
This makes it possible to use scoped IPv6 addresses:

mount -t cifs -o ip=<ADDR>%<iface_id> //<ADDR>/test test

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-27 21:02:35 +02:00
Denys Vlasenko
5093c8c4aa mount: tweak "IPv6 scoped addr" commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-26 20:36:30 +02:00
Denys Vlasenko
3c18e3051d libbb: make xmalloc_sockaddr2dotted use NI_NUMERICSCOPE
Gives "mount -t cifs //fe80::6a05:caff:fe3e:dbf5%eth0/test test"
a chance to work: mount must pass "ip=numeric_IPv6%numeric_iface_id"
in the omunt option string. Currently, it does not.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-26 19:53:04 +02:00
Denys Vlasenko
b157eb13cb fdisk: fix CONFIG_FEATURE_SUN_LABEL=y build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-17 21:05:06 +02:00
Denys Vlasenko
20a3262cd7 mdev: create devices from /sys/dev
Currently some new devices that have a bus but no class will
be missed by mdev coldplug device creation after boot. This
happens because mdev recursively searches /sys/class which will
by definition only find class devices.

Some important devices such as iio and gpiochip does not have
a class. But users will need them.

This switches from using /sys/class as the place to look for
devices to create to using /sys/dev where all char and block
devices are listed.

The subsystem lookup code that provide the G.subsystem
environment variable is changed from using the directory
name of the class device to instead dereference the
"subsystem" symlink for the device, and look at the last
element of the path of the symlink for the subsystem, which
will work with class devices and bus devices alike. (The new
bus-only devices only symlink to the /sys/bus/* hierarchy.)

We delete the legacy kernel v2.6.2x /sys/block device path
code as part of this change. It's too old to be kept alive.

Tested on kernel v4.6-rc2 with a bunch of devices, including
some IIO and gpiochip devices.

With a print inserted before make_device() the log looks
like so:

Create device from "/sys/dev/char/1:1", subsystem "mem"
Create device from "/sys/dev/char/1:2", subsystem "mem"
Create device from "/sys/dev/char/1:3", subsystem "mem"
Create device from "/sys/dev/char/1:5", subsystem "mem"
(...)
Create device from "/sys/dev/block/179:56", subsystem "block"
Create device from "/sys/dev/block/179:64", subsystem "block"

function                                             old     new   delta
mdev_main                                           1388    1346     -42
dirAction                                            134      14    -120
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-162)           Total: -162 bytes

Cc: Isaac Dunham <ibid.ag@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-07 14:09:01 +02:00
Serj Kalichev
d42cdc2222 volume_id: Add support for UBIFS
Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-06 18:31:01 +02:00
Denys Vlasenko
29483ffb07 fdisk: tweak some messages
"Total allocated sectors 2021315 greater than the maximum 2020356"

maximum what?

Turns out, that's the CHS size of the disk.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-23 17:18:45 +02:00
Denys Vlasenko
607f2b404e fdisk: print much less cryptic partition table
Before:

   Device Boot      Start         End      Blocks  Id System
/dev/sdb1   *           1         998      255471+  6 FAT16

What are "blocks"? What is that "+"?
How big is this partition?
Is start/end shown came from LBA fields or CHS fields?
Why are we torturing the user??

After:

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sdb1 *  0,1,1       996,15,32           32     510974     510943  249M  6 FAT16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-23 16:13:33 +02:00
Denys Vlasenko
2cf9fa6e59 unshare: --network should be --net. Closes 9116
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22 20:19:34 +02:00
Denys Vlasenko
237bedd499 getopt32: add new syntax of 'o:+' and 'o:*' for -o NUM and -o LIST
In many cases, this aqllows to drop use of opt_complementary.
Approximately -400 bytes:

function                                             old     new   delta
getopt32                                            1423    1502     +79
opt_string                                            17      18      +1
OPT_STR                                               24      25      +1
uniq_main                                            416     406     -10
timeout_main                                         279     269     -10
sulogin_main                                         270     260     -10
readprofile_main                                    1825    1815     -10
ps_main                                              543     533     -10
pidof_main                                           245     235     -10
pgrep_main                                           611     601     -10
od_main                                             2600    2590     -10
mkfs_minix_main                                     2684    2674     -10
mkfs_ext2_main                                      2603    2593     -10
microcom_main                                        712     702     -10
makemime_main                                        315     305     -10
ionice_main                                          282     272     -10
inetd_main                                          2074    2064     -10
ifplugd_main                                        1144    1134     -10
halt_main                                            353     343     -10
getopt_main                                          636     626     -10
fdisk_main                                          2854    2844     -10
env_main                                             206     196     -10
dmesg_main                                           319     309     -10
conspy_main                                         1214    1204     -10
awk_main                                             981     971     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/22 up/down: 81/-220)         Total: -139 bytes
   text	   data	    bss	    dec	    hex	filename
 919373	    906	  14060	 934339	  e41c3	busybox_old
 918969	    906	  14060	 933935	  e402f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-06 21:58:02 +02:00
Denys Vlasenko
ecf25cb5bc randomconfig fixes 5: false positive for tar; mount emits corrupted message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:04:04 +02:00