Commit Graph

16557 Commits

Author SHA1 Message Date
Denys Vlasenko
e880b1fea8 ash: expand: Use HOME in tilde expansion when it is empty
Upstream commit:

    Date: Sun, 27 May 2018 17:31:57 +0800
    expand: Use HOME in tilde expansion when it is empty

    Currently if HOME is set to empty tilde expansion will fail, i.e.,
    it will remain as a literal tilde.  This patch changes it to
    return the empty string as required by POSIX.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:16:35 +01:00
Denys Vlasenko
a7b97e367c ash: builtin: Mark more regular built-ins
Upstream commit:

    Date: Sat, 19 May 2018 02:39:49 +0800
    builtin: Mark more regular built-ins

    This patch marks the following built-ins as regular, meaning that
    they cannot be overriden using PATH search:

            hash
            pwd
            type
            ulimit

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
2bad3a305b ash: jobs: Replace some uses of fmtstr with stpcpy/stpncpy
Upstream commit:

    Date: Sat, 19 May 2018 02:39:45 +0800
    jobs: Replace some uses of fmtstr with stpcpy/stpncpy

    Some uses of fmtstr, particularly the ones without a format string,
    can be replaced with stpcpy or stpncpy.  This patch does that so
    we don't have to introduce unnecessary format strings in order to
    silence compiler warnings.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
3f7fb2c89a ash: output: Fix fmtstr return value
Upstream commit:

    Date: Sat, 19 May 2018 02:39:44 +0800
    output: Fix fmtstr return value

    The function fmtstr is meant to return the actual length of output
    produced, rather than the untruncated length.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
970470e235 ash: main: Only set savestatus in exitcmd
Upstream commit:

    Date: Sat, 19 May 2018 02:39:38 +0800
    main: Only set savestatus in exitcmd

    Currently exitcmd sets exitstatus and then savestatus if the latter
    was previously set.  In fact, as exitcmd always raises an exception
    and will either end up in the setjmp call in main() or exitshell(),
    where exitstatus is always replaced by savestatus if set, we only
    need to set savestatus.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
4ccddc8fb3 ash: [BUILTIN] Exit without arguments in a trap should use status outside traps
Upstream commit:

    Date:   Mon Oct 6 10:39:47 2014 +0800
    [BUILTIN] Exit without arguments in a trap should use status outside traps

    POSIX now requires that exit without arguments in a trap should
    return the last command status prior to executing traps.  This
    patch implements this behaviour.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
f7eea8c235 ash: parser: Fix incorrect eating of backslash newlines
Keeping up with upstream (in our case, 'before patch' code is not buggy).
Upstream commit:

    Date: Fri, 11 May 2018 23:41:25 +0800
    parser: Fix incorrect eating of backslash newlines

    With the introduction of synstack->syntax, a number of references
    to the syntax variable was missed during the conversion.  This
    causes backslash newlines to be incorrectly removed in single
    quote context.

    This patch also combines these calls into a new helper function
    pgetc_top.

    Fixes: ab1cecb40478 ("parser: Add syntax stack for recursive...")
    Reported-by: Leah Neukirchen <leah@vuxu.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
acf79f9913 ash: use pgetc_eatbnl() in more places, take 2
Adding previously skipped "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes
from upstream commit:

    Date:   Thu Mar 8 08:37:11 2018 +0100
    Author: Harald van Dijk <harald@gigawatt.nl>
    parser: use pgetc_eatbnl() in more places

    dash has a pgetc_eatbnl function in parser.c which skips any
    backslash-newline combinations. It's not used everywhere it could be.
    There is also some duplicated backslash-newline handling elsewhere in
    parser.c. Replace most of the calls to pgetc() with calls to
    pgetc_eatbnl() and remove the duplicated backslash-newline handling.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16 19:14:45 +01:00
Denys Vlasenko
a6e48dead3 fdisk: add HFS / HFS+ partition type
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-14 13:57:41 +01:00
Denys Vlasenko
adc540f0db tftp: on download, open local file only when first bit of data arrived
No reason to potentially clobber existing file before absolutely necessary.

function                                             old     new   delta
tftp_protocol                                       1947    2020     +73
tftp_main                                            393     376     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 73/-17)             Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-13 15:27:23 +01:00
Denys Vlasenko
0c4e5977df tftp: fix thinko in code shrink
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-13 15:03:12 +01:00
Denys Vlasenko
779df9f228 tftp: code shrink
function                                             old     new   delta
tftp_protocol                                       1949    1947      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-13 13:01:43 +01:00
Denys Vlasenko
260bd21169 tftpd: show requested file name in open error message
function                                             old     new   delta
tftp_protocol                                       1902    1949     +47

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-13 12:58:46 +01:00
Denys Vlasenko
bd8b05ba1b awk: fix more "length" cases, closes 12486
function                                             old     new   delta
next_token                                           808     831     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-02 23:28:55 +01:00
Ron Yorston
9e2a5668fd ash,hush: allow builtins to be tab-completed, closes 7532
function                                             old     new   delta
complete_cmd_dir_file                                678     830    +152
get_builtin_name                                       -      35     +35
optschanged                                          125     132      +7
hush_main                                           1069    1076      +7
save_command_ps_at_cur_history                        76      78      +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/0 up/down: 203/0)             Total: 203 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29 15:23:17 +01:00
Ron Yorston
1ff7002b1d xargs: fix handling of quoted arguments, closes 11441
As reported in bug 11441 when presented with a large number of quoted
arguments xargs can return 'argument line too long':

   seq 10000 29999 | sed -e 's/^/"/' -e 's/$/"/' | busybox xargs echo

This happens because the variant of process_stdin() which handles quoted
arguments doesn't preserve state between calls.  If the allowed number
of characters is exceeded part way through a quoted argument the next
call to process_stdin() incorrectly treats the terminating quote as a
starting quote, thus quoting all of the argument separators.

function                                             old     new   delta
process_stdin                                        274     303     +29
xargs_main                                           731     745     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 43/0)               Total: 43 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29 14:39:13 +01:00
Ron Yorston
16bcd504a3 vi: fixes to string search in colon commands, closes 10321
Handling of string searches in colon commands (e.g ':/pat1/,/pat2/cmd')
differ from standard vi:

- As reported in bug 10321 such searches can't be repeated using the
  'n' command.  This is because the last search pattern isn't updated.

- The search also can't be repeated using the command '://' because
  an empty search pattern doesn't imply the use of the last search
  pattern.

- Such searches should start on the line after the current line,
  otherwise '://' never moves to the next occurrence of the pattern.
  This can also affect other cases where line ranges are specified
  using search patterns.

Fix these various issues.

function                                             old     new   delta
get_one_address                                      325     342     +17

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29 14:01:50 +01:00
Ron Yorston
b0c711e64f ash: improve expandstr()
The dash maintainer recently posted a fix for issues with expanding
PS1.  These had already been fixed differently in BusyBox ash.  Borrow
a couple of improvements:

- Use a single call to setjmp() to trap errors in both readtoken1()
  and expandarg().

- In case of error set the prompt to the literal value of PS1 rather
  than the half-digested nonsense in stackblock() which might include
  ugly control characters.

function                                             old     new   delta
expandstr                                            353     300     -53

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29 13:59:45 +01:00
Peter Korsgaard
eb7f9acda1 syslogd: add config option to include milliseconds in timestamps
For some use cases, having logs with more than 1 second accuracy can be
helpful.  Add an option to include milliseconds when adding a timestamp in
HH:MM:SS.mmm format, similar to syslog-ng with fraq_digits(3) or journalctl
-o short-precise.

For simplicity, abuse the remaining space in the buffer used by ctime to add
the millieconds (overwriting year).

function                                             old     new   delta
timestamp_and_log                                    401     448     +47

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29 13:56:36 +01:00
Denys Vlasenko
020abc8856 udhcpd: mangle hostnames starting with dash ("-option")
function                                             old     new   delta
add_lease                                            316     328     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-14 17:07:18 +01:00
Denys Vlasenko
9ec836c033 whois: limit total length of response to 32+2 kb
function                                             old     new   delta
query                                                517     554     +37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-12-03 14:52:17 +01:00
Denys Vlasenko
356f23de20 init: improve handling of signals racing with each other
Before this change, a request to reboot could be "overwritten" by e.g.
SIGHUP.

function                                             old     new   delta
init_main                                            709     793     +84
packed_usage                                       33273   33337     +64
run_actions                                          109     117      +8
stop_handler                                          87      88      +1
check_delayed_sigs                                   340     335      -5
run                                                  214     198     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/2 up/down: 157/-21)           Total: 136 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-12-03 14:05:32 +01:00
Denys Vlasenko
113c776f4d init: if tcgetattr() fails, don't even try to tcsetattr()
function                                             old     new   delta
set_sane_term                                        111     114      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-12-02 16:39:54 +01:00
Denys Vlasenko
259747caa7 hush: fix preprocessor directives indentation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-28 10:28:14 +01:00
Tomi Leppanen
1b76ffaae4 grep: add -R
This adds -R option to grep similar to GNU grep. It is the same as -r
but also dereferences symbolic links to directories.

function                                             old     new   delta
grep_main                                            834     850     +16
packed_usage                                       33362   33368      +6
grep_file                                           1440    1441      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 23/0)               Total: 23 bytes

Signed-off-by: Tomi Leppanen <tomi.leppanen@jolla.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-27 17:11:09 +01:00
Denys Vlasenko
008413754b bc: fix comparison bug, closes 12336
function                                             old     new   delta
bc_num_cmp                                           249     259     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-23 17:25:21 +01:00
Alistair Francis
d3539be8f2 Remove stime() function calls
stime() has been deprecated in glibc 2.31 and replaced with
clock_settime(). Let's replace the stime() function calls with
clock_settime() in preperation.

function                                             old     new   delta
rdate_main                                           197     224     +27
clock_settime                                          -      27     +27
date_main                                            926     941     +15
stime                                                 37       -     -37
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/0 up/down: 69/-37)             Total: 32 bytes

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-19 13:08:25 +01:00
Denys Vlasenko
419d0294e9 Updated inittab example documentation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-17 17:48:53 +01:00
Liu, Shuang (ADITG/ESM)
af6bc54fde chgrp: correct the usage for non-desktop chgrp calls
When IF_DESKTOP is not defined, chown and chgrp only takes option -R -h,
However the usage output of chgrp is wrong:

	$ ./busybox.nosuid chown
	Usage: chown [-Rh]... USER[:[GRP]] FILE...

	$ ./busybox.nosuid chgrp
	Usage: chgrp [-RhLHP]... GROUP FILE...

	$ ./busybox.nosuid chgrp -H group dummy
	chgrp: invalid option -- 'H'
	Usage: chgrp [-RhLHP]... GROUP FILE...

The chgrp is now a wrapper of chown, so the recognized options shall be the same.
This is introduced by 34425389e0

I would expect the correct behavior shall be the same as chown.
So suggest the below patch, the behavior shall be:

	$ ./busybox.nosuid chgrp
	Usage: chgrp [-Rh]... GROUP FILE...

Signed-off-by: Shuang Liu <sliu@de.adit-jv.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-17 17:06:31 +01:00
Denys Vlasenko
b230fdfa9d taskset: tighten the check for stride values
function                                             old     new   delta
taskset_main                                         986     987      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-09 17:32:43 +01:00
Denys Vlasenko
a82fb1b9d8 taskset: implement stride argument
function                                             old     new   delta
taskset_main                                         925     986     +61

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-09 17:07:44 +01:00
Denys Vlasenko
2f57b5139e unxz: show -t in --help
function                                             old     new   delta
packed_usage                                       33236   33247     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-08 16:37:28 +01:00
Denys Vlasenko
e5586605ca taskset: update comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-08 16:32:37 +01:00
Denys Vlasenko
162ac7f45e taskset: add support for taking/printing CPU list (-c option)
function                                             old     new   delta
taskset_main                                         511     855    +344

Based on patch by Fryderyk Wrobel <frd1996@gmail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-01 15:44:49 +01:00
Denys Vlasenko
21806562ca hush: restore redirected stdin
function                                             old     new   delta
restore_redirects                                     52      95     +43
save_fd_on_redirect                                  243     253     +10
hfopen                                                90      99      +9
fgetc_interactive                                    259     261      +2
builtin_type                                         117     115      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 64/-2)              Total: 62 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-01 14:16:07 +01:00
Denys Vlasenko
ea096d6c13 ntpd: decrease MIN_FREQHOLD by 2, increase "penalty" for largish offset x2
> 2018-07-25:
> ntpd: increase MIN_FREQHOLD by 3
> This means we'll start correcting frequency ~5 minutes after start,
> not ~3.5 ones.
> With previous settings I still often see largish ~0.7s initial offsets
> only about 1/2 corrected before frequency correction kicks in,
> resulting in ~200ppm "correction" which is then slowly undone.

Review of real-world results of the above shows that with small
initial offsets, freq correction can be allowed to kick in sooner,
whereas with large (~0.8s) offsets, we still start freq correction
a bit too soon.

Let's rebalance this a bit.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-30 12:18:07 +01:00
Jo-Philipp Wich
6b4960155e nslookup: implement support for SRV records
Add support for querying and parsing SRV DNS records.

function                                             old     new   delta
send_queries                                        1711    1865    +154
qtypes                                                72      80      +8

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-27 17:07:35 +01:00
Jo-Philipp Wich
8c3b520d4f nslookup: handle replies without RRs
Under some circumstances, a DNS reply might contain no resource records,
e.g. when a valid domain is queried that does not have records of the
requested type.

Example with nslookup from BIND dnsutils:

    $ nslookup -q=SRV example.org
    Server:	10.11.12.13
    Address:	10.11.12.13#53

    Non-authoritative answer:
    *** Can't find example.org: No answer

Currently the busybox nslookup applet simply prints nothing after the
"Non-authoritative answer:" line in the same situation.

This change modifies nslookup to either print "Parse error" or "No answer"
diagnostics, depending on the parse_reply() return value.

function                                             old     new   delta
send_queries                                        1676    1711     +35

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-27 17:02:08 +01:00
Denys Vlasenko
caf5ee0dd9 gunzip: fix incorrect decoding of "fixed" inflate blocks
function                                             old     new   delta
huft_build                                          1008    1022     +14
inflate_block                                       1253    1256      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 17/0)               Total: 17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-26 20:04:34 +02:00
Denys Vlasenko
122a8cbd4a hdparm: placate "warning: taking the absolute value of unsigned type"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 17:47:22 +02:00
Denys Vlasenko
9a0c404d5f vi: placate "warning: shifting a negative signed value is undefined"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 17:42:23 +02:00
Denys Vlasenko
f39a71817e read_key(): placate "warning: shifting a negative signed value is undefined"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 17:40:57 +02:00
Denys Vlasenko
d6ff27de15 ntpd: abs(tmx.offset) was truncating a "long" typed value
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 17:35:58 +02:00
Denys Vlasenko
b4ad1d86b6 tc: array address is never NULL
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 13:41:31 +02:00
Denys Vlasenko
e076162897 traceroute: fix gcc-ism
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 13:39:41 +02:00
Denys Vlasenko
e5897d041d suppress a few "unused function" warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 13:05:15 +02:00
Denys Vlasenko
1f1492bb96 netstat: suppress a warning (conversion from 'int' to 'smallint' changes value)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 13:00:01 +02:00
Denys Vlasenko
b4ef2e3467 Makefile.flags: suppress some clang-9 warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 12:56:51 +02:00
Denys Vlasenko
af7169b4a7 clang/llvm 9 fix - do not eliminate a store to a fake "const"
This is *much* better (9 kbytes better) than dropping "*const"
optimization trick.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 12:12:22 +02:00
Denys Vlasenko
e1a7c97ac6 tar: fix fallout of: change -a from meaning "lzma" to mean "autodetect by extension"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 10:30:53 +02:00