Compare commits

...
413 Commits
Author SHA1 Message Date
Denys Vlasenko b84194b133 Bump version to 1.29.3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-09 20:56:49 +02:00
Denys Vlasenko 2993551efc Revert "libbb: remove unnecessary variable in xmalloc_fgets"
The variable is in fact necessary.

    commit 2da9724b56
    Author: Quentin Rameau <quinq@fifth.space>
    Date:   Sun Apr 1 17:05:35 2018 +0200
        libbb: remove unnecessary variable in xmalloc_fgets

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-02 18:48:50 +02:00
Denys Vlasenko ab4caf099c Bump version to 1.29.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-31 14:31:12 +02:00
Denys Vlasenko 1c3bcfc79f fdisk: sync up with some util-linux 2.31 behavior
= display default is no longer in cylinders
= +sizeC is no longer supported
= add +sizeT suffix - terabytes are here
= K,M,G,T and k,m,g,t suffixes all are binary, not decimal
= +sizeM results in last sector +(size * 1Mbyte - 1), not +(size * 1Mbyte)
= fix comparison to "YES" answer for sgi/sun

function                                             old     new   delta
read_int                                             492     519     +27
fdisk_main                                          2644    2640      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 27/-4)              Total: 23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-30 18:02:27 +02:00
Denys Vlasenko 096ccd6a69 fdisk: use strtoul[l] instead of atoi, closes 11176
Couldn't create partitions bigger than 1TB (when using 512 bytes sectors,
on 32 bits architectures).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-30 18:02:27 +02:00
Denys Vlasenko d674b2e2ae gzip: unbreak FEATURE_GZIP_LEVELS, closes 11171
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-30 18:02:27 +02:00
Denys Vlasenko abe8fc3663 hexedit: fixes for redraw and down movement causing SEGV on attempt to access
"Go to:" command was not updating row position, making next "down" movements
for one screenful print empty lines instead of showing the contents.

If the file is whole pages long, "down" movement at EOF was advancing position
+16 bytes, mapping the next portion (entirely past the end of the file),
then finding out that the new position is beyond the EOF, rolling it back
-16 bytes... ending up with this postion pointing *before* the mapped portion.
Any next access (e.g. "move right" key) SEGVs.

function                                             old     new   delta
hexedit_main                                        1170    1184     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-30 18:02:27 +02:00
Denys Vlasenko 981c0b109d Bump version to 1.29.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-15 14:55:20 +02:00
Raffaello D. Di Napoli 6673497d3b sendmail: fix parsing of addresses in angle brackets
Pointer e needs to be wound back in order to overwrite '>' with '\0'.
Regression introduced in 20077c1429

Signed-off-by: Raffaello D. Di Napoli <rafdev@dinapo.li>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-15 14:52:21 +02:00
Denys Vlasenko 7236b6d717 wget: fix fetching of https URLs without http proxy
The "fix fetching of https URLs with http proxy" commit
broke the usual http-to-https redirect:

$ wget http://busybox.net/downloads/busybox-1.29.0.tar.bz2
Connecting to busybox.net (140.211.167.122:80)
Connecting to busybox.net (140.211.167.122:443)
wget: server returned error: HTTP/1.1 400 Bad Request

Fixing...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-15 14:52:21 +02:00
Denys Vlasenko 10a3817440 Bump version to 1.29.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-01 16:38:52 +02:00
Denys Vlasenko 335766602b testsuite/mount.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-28 14:10:00 +02:00
Denys Vlasenko 8825cb6660 vi: placate "warning: variable orig_buf set but not used"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 15:11:36 +02:00
Denys Vlasenko 4c58f246d4 testsuite/pidof.tests: fix false positive take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:50:00 +02:00
Denys Vlasenko 39043ad25e vi: placate "warning: statement with no effect"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:46:08 +02:00
Denys Vlasenko 2f7738e474 nslookup: placate "warning: unused variable i"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:44:35 +02:00
Denys Vlasenko 332a191e7f testsuite/tar.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:35:56 +02:00
Denys Vlasenko 33eae28710 testsuite/pidof.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:26:21 +02:00
Denys Vlasenko 94593799f7 testsuite/bzcat.tests: fix false positive take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 13:15:10 +02:00
Denys Vlasenko d8799b90f3 testsuite/unexpand/unexpand-works-like-GNU: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 12:54:57 +02:00
Denys Vlasenko a429d5d0f3 testsuite/bzcat.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 10:35:45 +02:00
Denys Vlasenko 5738823dff testsuite/tar.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 10:01:49 +02:00
Denys Vlasenko 751005020d testsuite/cat.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 09:57:30 +02:00
Denys Vlasenko 57dbe4d5ac libbb: crypt() in newer glibc requires include <crypt.h>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 09:45:20 +02:00
Denys Vlasenko 35a017c0c5 hush: unset_local_var_len is only used by unset_local_var
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 18:27:54 +02:00
Denys Vlasenko b2b14cbd4c hush: fix compile problem found by randomconfig
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 18:09:22 +02:00
Denys Vlasenko 762440b20e scripts/randomtest: disable CONFIG_NSLOOKUP for uclibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 17:22:35 +02:00
Denys Vlasenko 185326613d scripts/randomtest: disable CONFIG_FEATURE_INETD_RPC for glibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 16:08:22 +02:00
Denys Vlasenko 5f5119be97 scripts/randomtest: disable CONFIG_FEATURE_MOUNT_NFS for glibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 16:03:24 +02:00
Denys Vlasenko d1a83234c0 hush: fix dup_CLOEXEC() call without "avoid_fd" parameter
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 15:50:33 +02:00
Denys Vlasenko 8ef9effaa5 fdisk: placate warning of strncpy not copying NUL byte
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 15:44:58 +02:00
Denys Vlasenko c96bb2c5ab hush: fix for !ENABLE_HUSH_MODE_X configuration
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 15:43:56 +02:00
Denys Vlasenko 99496dc716 hush: variable nesting code is used also if HUSH_FUNCTIONS is not enabled
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 15:36:58 +02:00
Denys Vlasenko 817a20296f randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 15:35:17 +02:00
Ivan Abrea 5cb4f9081f tls: fix to handle X.509 v1 certificates correctly
The syntax of public key certificates can be found in RFC 5280 section
4.1. The relevant part of the syntax is the following:

  TBSCertificate  ::=  SEQUENCE  {
    version         [0]  EXPLICIT Version DEFAULT v1,
    serialNumber         CertificateSerialNumber,
    ... remaining fields omitted ...
  }

The version field has a default value of v1. RFC 5280 section 4.1.2.1
says the following:

  If only basic fields are present, the version SHOULD be 1 (the value
  is omitted from the certificate as the default value); however, the
  version MAY be 2 or 3.

To help detect if the version field is present or not, the type of the
version field has an explicit tag of [0]. Due to this tag, if the
version field is present, its encoding will have an identifier octet
that is distinct from that of the serialNumber field.

ITU-T X.690 specifies how a value of such a type should be encoded with
DER. There is a PDF of X.690 freely available from ITU-T. X.690 section
8.1.2 specifies the format of identifier octets which is the first
component of every encoded value. Identifier octets encode the tag of a
type. Bits 8 and 7 encode the tag class. Bit 6 will be 0 if the encoding
is primitive and 1 if the encoding is constructed. Bits 5 to 1 encode
the tag number.

X.690 section 8.14 specifies what the identifier octet should be for
explicitly tagged types. Section 8.14.3 says if implicit tagging is not
used, then the encoding shall be constructed. The version field uses
explicit tagging and not implicit tagging, so its encoding will be
constructed. This means bit 6 of the identifier octet should be 1.

X.690 section 8.14 and Annex A provide examples. Note from their
examples that the notation for tags could look like [APPLICATION 2]
where both the tag class and tag number are given. For this example, the
tag class is 1 (application) and the tag number is 2. For notation like
[0] where the tag class is omitted and only the tag number is given, the
tag class will be context-specific.

Putting this all together, the identifier octet for the DER encoding of
the version field should have a tag class of 2 (context-specific), bit 6
as 1 (constructed), and a tag number of 0.

Signed-off-by: Ivan Abrea <ivan@algosolutions.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-24 20:05:24 +02:00
Codarren Velvindron 7c43d43117 ntpd: deprecate IPTOS_LOWDELAY in favor of IPTOS_DSCP_AF21
Update QoS markers.
Use DSCP AF21 for interactive traffic. DSCP is defined in RFC2474.
Many modern equipment no longer support IPTOS.

Signed-off-by: Codarren Velvindron <codarren@hackers.mu>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-24 20:03:55 +02:00
Denys Vlasenko e56e091d65 examples: update /var/service/getty for Unicode ttys
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-23 13:55:13 +02:00
Denys Vlasenko 34254f9dde install: fix "-D -t DIR1/DIR2/DIR3" creating only DIR1/DIR2, closes 11106
function                                             old     new   delta
install_main                                         758     767      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-22 18:59:10 +02:00
Denys Vlasenko 148788eb0e udhcpc: remove code which requires server ID to be on local network
This reverts "udhcpc: paranoia when using kernel UDP mode
for sending renew: server ID may be bogus".

Users complain that they do have servers behind routers
(with DHCP relays).

function                                             old     new   delta
send_packet                                          168     166      -2
bcast_or_ucast                                        25      23      -2
udhcp_send_kernel_packet                             301     295      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-10)             Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-21 17:38:14 +02:00
Eli Schwartz 6fb8bd795c Update release script to generate detached signatures and checksum files
This is more usable for programmatically checking the validity of a
release.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-09 21:19:35 +02:00
Kartik Agaram 43b17b1cd0 restore documentation on the build config language
Kconfig-language.txt was deleted in commit 4fa499a17b back in 2006.
Move to docs/ as suggested by Xabier Oneca:
  http://lists.busybox.net/pipermail/busybox/2014-May/080914.html
Also update references to it everywhere.

Signed-off-by: Kartik Agaram <akkartik@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-06 15:16:48 +02:00
Denys Vlasenko 0972c7f7a5 wget: emit a message that certificate verification is not implemented
function                                             old     new   delta
spawn_ssl_client                                     185     209     +24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-28 14:36:26 +02:00
Denys Vlasenko 8bc418f07e fdisk: remove "Partition N does not end on cylinder boundary" message
fdisk from util-linux 2.31 (maybe earlier) does not print this.

function                                             old     new   delta
check_consistency                                    449     399     -50

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-26 18:51:18 +02:00
Denys Vlasenko bf7f103ffb whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-26 17:42:00 +02:00
Denys Vlasenko a36986bb80 unlzma: close another SEGV possibility
function                                             old     new   delta
unpack_lzma_stream                                  2669    2686     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-25 17:03:46 +02:00
David Decotigny 8f48fc01e9 udhcpc6: carry along length of packet when parsing it.
This is to avoid parsing garbage past packet's actual end.

Also const-ize params to a few functions.

function                                             old     new   delta
d6_run_script_no_option                                -      12     +12
option_to_env                                        791     798      +7
d6_run_script                                        253     255      +2
perform_d6_release                                    95      93      -2
udhcpc6_main                                        2596    2592      -4
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 21/-6)              Total: 15 bytes

Signed-off-by: David Decotigny <ddecotig@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-24 18:34:56 +02:00
David Decotigny a174c791ec udhcpc6: ignore invalid OPTION_IAADDR
Signed-off-by: David Decotigny <ddecotig@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-24 18:26:01 +02:00
Denys Vlasenko 747162109f realpath,readlink -f: coreutils compat, closes 11021
function                                             old     new   delta
xmalloc_realpath_coreutils                             -     121    +121

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-24 17:31:00 +02:00
Denys Vlasenko 3f91e662f2 nc: fix the !NC_SERVER configuration
The symptom is the "nc: NO OPT l!" message.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-24 16:38:40 +02:00
Denys Vlasenko ccb8e4bc4f fsck: fix incorrect handling of child exit
In commit

  c4fb8c6a - fsck: do not use statics

not only statics were changed but also a couple of
statics-unrelated changes were made.

This included the handling of the child termination status
as follows:

    - if (WIFEXITED(status))
    -   status = WEXITSTATUS(status);
    - else if (WIFSIGNALED(status)) {
    + status = WEXITSTATUS(status);
    + if (WIFSIGNALED(status)) {

This is wrong, should have used a different variable to hold exit code.

Reported by Niklas Hambüchen <mail@nh2.me>.

function                                             old     new   delta
wait_one                                             294     282     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-24 15:29:15 +02:00
Harald van Dijk 8c24af9dcf tar: fix interaction of delayed symlink and hardlink creation
function                                             old     new   delta
create_or_remember_link                                -     106    +106
create_links_from_list                                 -      93     +93
find_applet_by_name                                  124     128      +4
unzip_main                                          2724    2726      +2
data_extract_all                                     891     873     -18
create_symlinks_from_list                             64       -     -64
create_or_remember_symlink                            94       -     -94
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/1 up/down: 205/-176)           Total: 29 bytes

Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-22 17:34:31 +02:00
Denys Vlasenko a40a661d97 tweak /var/service example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-20 22:43:42 +02:00
Denys Vlasenko 2ccd352281 popmaildir: placate gcc8 "warning: 'strncpy' output truncated"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 11:14:58 +02:00
Denys Vlasenko 6027597fd1 udhcpc6: set -x options in request
Last foru commits:

function                                             old     new   delta
option_to_env                                        621     791    +170
.rodata                                           168351  168505    +154
attach_option                                        431     506     +75
add_d6_client_options                                112     167     +55
d6_option_strings                                     30      84     +54
udhcp_str2optset                                     644     660     +16
d6_optflags                                           12      20      +8
udhcpc6_main                                        2590    2596      +6
udhcpc_main                                         2648    2651      +3
read_optset                                           15      18      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 10/0 up/down: 544/0)            Total: 544 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 11:11:08 +02:00
Samuel Mendoza-Jonas 30f4d52ed1 udhcpc6: add PXELINUX options
Add support for the PXELINUX options 209 ("ConfigFile") and 210
("PathPrefix") in the DHCPv6 client.

See also: RFC5071, "Dynamic Host Configuration Protocol Options Used by
PXELINUX".

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 10:46:00 +02:00
Samuel Mendoza-Jonas 23cbd7d5bb udhcpc6: add DHCPv6 boot options
Add support for 'bootfile-url' and 'bootfile-params' as defined by
RFC5970 "DHCPv6 Options for Network Boot".

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 10:46:00 +02:00
Samuel Mendoza-Jonas bcdec1a8b8 udhcpc6: add DHCPv6 env helper
Add string_option_to_env() to easily generate environment variables for
known simple options.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 10:46:00 +02:00
Samuel Mendoza-Jonas 43b9235f66 udhcp: fix use of trim() in udhcp_str2optset()
trim() modifies the string in place if needed and returns a pointer to
the end of the resulting string. Update udhcp_str2optset() so it no
longer sets the value of 'val' to the return value of trim().

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-14 10:46:00 +02:00
Euan Harris 254e47372f nsenter: fix parsing of -t, -S and -G options
-t, -S and -G each take mandatory integer arguments.   getopt32long()'s
option string syntax for this type of argument is 'c:+', however nsenter's
opt_str uses 'c+', which specifies two options 'c' and '+' which do not
take arguments.   This means that giving a target PID causes nsenter to
exit and print the usage string:

  # nsenter -t1 sh
  nsenter: unrecognized option: 1
  BusyBox v1.27.2 (2017-12-12 10:41:50 GMT) multi-call binary.
  ...

The long form options are also broken:

  # nsenter --setuid=1000 --setgid=1000 sh
  BusyBox v1.29.0.git (2018-05-04 13:56:49 UTC) multi-call binary.
  ...

`nsenter --target=<pid> sh` parses correctly and appears to work, but
<pid> is ignored and set to 0.   This doesn't raise an error unless one
of the namespace arguments is also given:

  # ./busybox_unstripped nsenter --target=42 sh
  # exit

  # ./busybox_unstripped nsenter -n --target=42 sh
  BusyBox v1.29.0.git (2018-05-04 13:56:49 UTC) multi-call binary.
  ...

This has caused problems in a couple of places:

  https://github.com/linuxkit/linuxkit/issues/567
  https://github.com/gliderlabs/docker-alpine/issues/359
  https://github.com/kontena/pharos-cluster/pull/81

Signed-off-by: Euan Harris <euan.harris@docker.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-13 20:14:07 +02:00
Euan Harris 40394cb1c9 nsenter: Rename --network option to --net
In nsenter from util-linux, the long version of the -n option is
--net=<path>.   BusyBox's version expects --network=<path>, so scripts
and examples written for util-linux's version cause BusyBox's version
to exit with the usage message.

Confusingly, until commit 036585a911, the usage message erroneously
claimed that the long option was indeed called --net; after that commit
long options are not listed at all.

Signed-off-by: Euan Harris <euan.harris@docker.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-13 18:58:23 +02:00
Denys Vlasenko d80eecb868 cat: fix cat -e and cat -v erroneously numbering 1st line
function                                             old     new   delta
cat_main                                             418     421      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-29 14:05:43 +02:00
Denys Vlasenko bc2e70b4a2 ifplugd: close signal race
function                                             old     new   delta
ifplugd_main                                        1109    1117      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-29 13:46:49 +02:00
Denys Vlasenko 77bf05dfe3 unlzma: do emit the error message on bad input, when we exit with 1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-24 13:49:12 +02:00
Denys Vlasenko df45eb49ac wget: handle URLs with @ or hash differently
If server replied with 302 and

Location: ?foo

we used to underflow the allocated space while trying to form the "@foo"
filename. Switch to forming "foo" filename.

function                                             old     new   delta
packed_usage                                       32795   32799      +4
parse_url                                            387     352     -35
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-35)             Total: -31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-24 13:35:32 +02:00
Denys Vlasenko f4eaccbfae free: improve --help for type option
Patch by Fred Friedrich.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-24 10:13:45 +02:00
Denys Vlasenko 2454e678cb awk: do not allow $(-1)
function                                             old     new   delta
EMSG_NEGATIVE_FIELD                                    -      25     +25
evaluate                                            3390    3403     +13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 38/0)               Total: 38 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-23 10:53:18 +02:00
Denys Vlasenko c21dfaf836 examples/shutdown-1.0: an example of reboot which does not signal init
For one, my inits know nothing about the concept of "shutting down the system".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-20 15:12:52 +02:00
Denys Vlasenko e09c426456 unlzma: fix another SEGV case
function                                             old     new   delta
unpack_lzma_stream                                  1705    1717     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-19 19:30:51 +02:00
Denys Vlasenko 2aeb201c97 libbb: new option FEATURE_ETC_SERVICES: if off, /etc/services reads often avoided
In practice, "wget http://host.com/" always uses port 80.
People explicitly set non-standard ports via options or parameters
("telnet 1.2.3.4 567" or "telnet 1.2.3.4 ftp") instead of modifying
/etc/services.

function                                             old     new   delta
telnet_main                                         1466    1464      -2
rdate_main                                           215     198     -17
fakeidentd_main                                      269     252     -17
parse_url                                            459     392     -67
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-103)           Total: -103 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-17 12:43:54 +02:00
Denys Vlasenko 816d8d7a66 setlogcons: open /dev/ttyN for "setlogcons N", not /dev/tty1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-16 21:48:32 +02:00
Denys Vlasenko fa87abe807 build system: FEATURE_NSLOOKUP_BIG needs -lresolv
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-16 11:04:03 +02:00
Denys Vlasenko 058a153b69 less: fix fallout from "use common routine to set raw termios"
Testcase: (sleep 10; ls) | busybox less

[...]
~           LICENSE
~                  Makefile
~                          Makefile.custom
~                                         Makefile.flags
[...]

less did not want this part:
+		/* dont convert NL to CR+NL on output */
+		newterm->c_oflag &= ~(ONLCR);

function                                             old     new   delta
get_termios_and_make_raw                             108     115      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-16 10:24:48 +02:00
Denys Vlasenko c72499584a nslookup: simplify make_ptr
function                                             old     new   delta
nslookup_main                                       2644    2611     -33

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 20:04:57 +02:00
Denys Vlasenko 71e4b3f482 nslookup: get rid of query::rlen field
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 19:51:42 +02:00
Denys Vlasenko b74e490629 ar: stop using static data
function                                             old     new   delta
static.ar_long_names                                   4       -      -4
static.ar_long_name_size                               4       -      -4
get_header_ar                                        546     532     -14
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-22)             Total: -22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 14:18:16 +02:00
Denys Vlasenko 58e43a4c40 nslookup: move array of queries to "globals"
function                                             old     new   delta
add_query                                             95      89      -6
nslookup_main                                       2692    2641     -51
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-57)             Total: -57 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 14:10:45 +02:00
Denys Vlasenko 50aea2786b less: remove unnecessary message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 13:14:51 +02:00
Aaro Koskinen 36941503bd less: implement -F
Implement -F option: Exit if entire file fits on first screen.

function                                             old     new   delta
buffer_print                                         622     633     +11
less_main                                           2446    2449      +3
buffer_fill_and_print                                169     172      +3
packed_usage                                       32258   32236     -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 17/-22)             Total: -5 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 13:13:34 +02:00
Denys Vlasenko 4b6091f92c nslookup: accept lowercase -type=soa, document query types
Usage: nslookup [-type=QUERY_TYPE] [-debug] HOST [DNS_SERVER]

    Query DNS about HOST

    QUERY_TYPE: soa,ns,a,aaaa,cname,mx,txt,ptr,any

function                                             old     new   delta
packed_usage                                       32189   32258     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 12:58:15 +02:00
Denys Vlasenko 6cdc3195a6 nslookup: change -stats to -debug (it's a bug in bind that it accepts -s)
function                                             old     new   delta
packed_usage                                       32211   32189     -22
nslookup_main                                       2754    2692     -62
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-84)             Total: -84 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 12:50:28 +02:00
Yann E. MORIN 296381ff4f applets/install: don't try to install nothing
Commit 952d5a6024 (applets/install: accept more than one install
option) changed the way we handle install options: before that commit, a
missing install type would mean to install nothing; after, we would
iterate over options, so we would never notice there was a mising
option.

Fix that by introducing an explicit --none option to specify to install
nothing.

Reported-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 12:07:22 +02:00
Denys Vlasenko d4461ef9fb nslookup: rework option parsing
function                                             old     new   delta
nslookup_main                                       2715    2754     +39
packed_usage                                       32179   32211     +32
add_ns                                                65      66      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 72/0)               Total: 72 bytes
   text	   data	    bss	    dec	    hex	filename
 926262	    555	   5740	 932557	  e3acd	busybox_old
 926239	    555	   5740	 932534	  e3ab6	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 12:01:46 +02:00
Denys Vlasenko a980109c6a nslookup: smaller qtypes[] array
function                                             old     new   delta
nslookup_main                                       2708    2715      +7
qtypes                                                80      72      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-8)               Total: -1 bytes
   text	   data	    bss	    dec	    hex	filename
 926277	    555	   5740	 932572	  e3adc	busybox_old
 926262	    555	   5740	 932557	  e3acd	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 10:52:11 +02:00
Denys Vlasenko 2cf75b3c81 nslookup: process replies immediately, do not store them
function                                             old     new   delta
nslookup_main                                       1837    2708    +871
parse_reply                                          852       -    -852
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 871/-852)           Total: 19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 10:46:44 +02:00
Denys Vlasenko 4e73c0f659 nslookup: fix output corruption for "nslookup 1.2.3.4"
function                                             old     new   delta
nslookup_main                                       1832    1837      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 23:18:34 +02:00
Denys Vlasenko cf950cd3ea nslookup: more closely resemble output format of bind-utils-9.11.3
function                                             old     new   delta
nslookup_main                                       1880    1832     -48
parse_reply                                         1022     852    -170
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-218)           Total: -218 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 23:08:23 +02:00
Denys Vlasenko 71e016d806 nslookup: shrink send_queries()
function                                             old     new   delta
rcodes                                                68      64      -4
nslookup_main                                       2007    1880    -127
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-131)           Total: -131 bytes
   text	   data	    bss	    dec	    hex	filename
 926735	    555	   5740	 933030	  e3ca6	busybox_old
 926525	    555	   5740	 932820	  e3bd4	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 22:53:39 +02:00
Denys Vlasenko db93b21ec9 nslookup: use xmalloc_sockaddr2dotted() instead of homegrown function
function                                             old     new   delta
nslookup_main                                       2091    2007     -84

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 18:11:35 +02:00
Denys Vlasenko 55bc8e8826 nslookup: usee bbox network functions instead of opne-coded mess
function                                             old     new   delta
nslookup_main                                       2363    2091    -272
add_ns                                               663      65    -598
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-870)           Total: -870 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 17:55:54 +02:00
Denys Vlasenko 75568354f6 patch: implement --dry-run
function                                             old     new   delta
static.patch_longopts                                  -     137    +137
patch_main                                          2053    2135     +82
fail_hunk                                            132     139      +7
finish_oldfile                                       119     124      +5
packed_usage                                       32807   32787     -20
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 231/-20)           Total: 211 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 16:05:26 +02:00
Denys Vlasenko d5f5045b43 ash: expand: Fix buffer overflow in expandmeta
Upstream commit:

    Date: Sun, 25 Mar 2018 16:38:00 +0800
    expand: Fix buffer overflow in expandmeta

    The native version of expandmeta allocates a buffer that may be
    overrun for two reasons.  First of all the size is 1 byte too small
    but this is normally hidden because the minimum size is rounded
    up to 2048 bytes.  Secondly, if the directory level is deep enough,
    any buffer can be overrun.

    This patch fixes both problems by calling realloc when necessary.

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

function                                             old     new   delta
expmeta                                              517     635    +118
expandarg                                            990     996      +6
mklocal                                              288     290      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 126/0)             Total: 126 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 14:50:47 +02:00
Denys Vlasenko 0dd3be8c09 nslookup: add openwrt / lede version
Needs work on size reduction

function                                             old     new   delta
nslookup_main                                        114    2363   +2249
parse_reply                                            -    1022   +1022
add_ns                                                 -     663    +663
ns_parserr                                             -     486    +486
ns_initparse                                           -     184    +184
ns_skiprr                                              -     117    +117
add_query                                              -      95     +95
qtypes                                                 -      80     +80
rcodes                                                 -      68     +68
dn_skipname                                            -      58     +58
ns_name_uncompress                                     -      56     +56
ns_get16                                               -      13     +13
v4_mapped                                              -      12     +12
ns_get32                                               -       9      +9
res_init                                               3       -      -3
__res_state                                            6       -      -6
xmalloc_sockaddr2hostonly_noport                      10       -     -10
gai_strerror                                          47       -     -47
set_default_dns                                       95       -     -95
print_host                                           199       -    -199
static.res                                           512       -    -512
------------------------------------------------------------------------------
(add/remove: 15/10 grow/shrink: 1/0 up/down: 5112/-872)      Total: 4240 bytes
   text	   data	    bss	    dec	    hex	filename
 921944	    555	   6252	 928751	  e2bef	busybox_old
 927375	    555	   5740	 933670	  e3f26	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 14:05:45 +02:00
Michael Olbrich 43dd006222 build system: fix parallel building issue
The files generated by the include/config/MARKER target are in the
dependency list for applets/applet_tables.
If applets/applet_tables is created first during applets_dir then it will
be created again later as part of $(busybox-dirs).
As a result include/applet_tables.h is created again. This time while other
build commands may need it.

Let applets_dir depend on include/config/MARKER to avoid this particular
race condition and create the header files atomically to ensure that the
compiler never sees incomplete files.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 01:55:51 +02:00
Denys Vlasenko c783cf78af tart_stop_daemon: another fix to disabled OLDER_VERSION_OF_X code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 01:29:01 +02:00
Denys Vlasenko 837913fc54 start_stop_daemon: fix normally disabled OLDER_VERSION_OF_X code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14 01:27:05 +02:00
Denys Vlasenko dd56921e2d dpkg: fix symlink creation, closes 10941
function                                             old     new   delta
get_header_ar                                        434     442      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-13 13:27:52 +02:00
Denys Vlasenko 266f6f1973 udhcp: support string user options, closes 10946
function                                             old     new   delta
udhcp_str2optset                                     536     628     +92
packed_usage                                       32757   32760      +3
udhcpc_main                                         2708    2692     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 95/-16)             Total: 79 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-13 13:27:52 +02:00
Denys Vlasenko 46158dc833 shell: add 6856 $IFS tests to testsuites
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 20:24:58 +02:00
Denys Vlasenko f693b606b7 hush: fix recent breakage from parse_stream() changes
function                                             old     new   delta
parse_stream                                        3808    3821     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 20:00:43 +02:00
Denys Vlasenko 44257ad5d0 hush: fix IFS handling in read
$ echo "X:Y:" | (IFS=": " read x y; echo "|$x|$y|")
|X|Y|
$ echo "X:Y  :  " | (IFS=": " read x y; echo "|$x|$y|")
|X|Y|

function                                             old     new   delta
shell_builtin_read                                  1320    1426    +106

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 17:18:34 +02:00
Denys Vlasenko 9678636911 hush: IFS fixes
$ IFS=": "; x=" "; set x $x; for v; do echo "|$v|"; done
|x|
$ IFS=": "; x=":"; set x $x; for v; do echo "|$v|"; done
|x|
||

function                                             old     new   delta
run_pipe                                            1789    1870     +81
expand_on_ifs                                        310     361     +51
pseudo_exec_argv                                     588     591      +3
builtin_local                                         50      53      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 138/0)             Total: 138 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 16:02:58 +02:00
Denys Vlasenko 34179956f9 hush: fix "$v" expansion in case patterns when v='[a]'
function                                             old     new   delta
run_list                                            1053    1063     +10
setup_redirects                                      311     320      +9
encode_then_expand_string                            135     142      +7
run_pipe                                            1784    1789      +5
expand_assignments                                    81      86      +5
expand_string_to_string                              124     125      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 37/0)               Total: 37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 13:47:59 +02:00
Denys Vlasenko 680c3016a2 ash: parser: Allow newlines within parameter substitution
Upstream commit:

Date: Thu, 22 Mar 2018 21:41:24 +0800
parser: Allow newlines within parameter substitution

    On Fri, Mar 16, 2018 at 11:27:22AM +0800, Herbert Xu wrote:
    > On Thu, Mar 15, 2018 at 10:49:15PM +0100, Harald van Dijk wrote:
    > >
    > > Okay, it can be trivially modified to something that does work in other
    > > shells (even if it were actually executed), but gets rejected at parse time
    > > by dash:
    > >
    > >   if false; then
    > >     : ${$+
    > >   }
    > >   fi
    >
    > That's just a bug in dash's parser with ${} in general, because
    > it bombs out without the if clause too:
    >
    > 	: ${$+
    > 	}

    This patch fixes the parsing of newlines with parameter substitution.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 12:39:18 +02:00
Denys Vlasenko 0403bedccc hush: optimize parse_stream()
Since we check for '\' anyway when we determine whether we can look ahead,
we can just check for *and handle* it there.

function                                             old     new   delta
parse_stream                                        2751    2740     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 01:34:46 +02:00
Denys Vlasenko 89e9d5534d hush: do not drop backslash from eval 'echo ok\'
newer bash does not drop it, most other shells too

function                                             old     new   delta
unbackslash                                           39      57     +18
parse_stream                                        2753    2751      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-2)              Total: 16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 01:15:33 +02:00
Denys Vlasenko 3632cb15f1 shell: add comments about [[, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 15:25:41 +02:00
Denys Vlasenko 4709df0f15 hush: fix handling of \<eof> in double-quoted strings
function                                             old     new   delta
encode_string                                        268     250     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 14:49:01 +02:00
Denys Vlasenko bcf56114fa hush: fix eval 'echo ok\'
function                                             old     new   delta
parse_stream                                        2762    2753      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 14:40:23 +02:00
Denys Vlasenko 92a930b4e8 hush: simplify \<newline> code, part 3
function                                             old     new   delta
parse_stream                                        2780    2762     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 14:27:08 +02:00
Denys Vlasenko e8b1bc0481 hush: simplify \<newline> code, part 2
function                                             old     new   delta
parse_stream                                        2787    2780      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 14:23:49 +02:00
Denys Vlasenko 1c57269b5d hush: simplify \<newline> code, part 1
function                                             old     new   delta
parse_stream                                        2919    2787    -132

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 14:23:49 +02:00
Denys Vlasenko 09b7a7ec0e hush: put "current word" structure into parsing context
function                                             old     new   delta
done_word                                            790     767     -23
parse_stream                                        3018    2919     -99
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-122)           Total: -122 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 03:22:10 +02:00
Denys Vlasenko e93031e6dc ash: if "[[" bashism is not supported, do not handle it anywhere
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 01:23:19 +02:00
Denys Vlasenko 57b7efb0d5 ash: trivial code shrink
function                                             old     new   delta
parse_command                                       1677    1674      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10 01:20:26 +02:00
Ron Yorston 1f27fa9838 testsuite: allow tests to work in paths containing spaces
Tweak some tests so they work when the path to the test directory or
$HOME contains spaces.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-09 20:35:48 +02:00
Denys Vlasenko 9db344a0f4 hush: fix var_leaks.tests and var_preserved.tests on NOMMU
function                                             old     new   delta
remove_nested_vars                                     -      77     +77
run_pipe                                            1756    1786     +30
pseudo_exec_argv                                     376     379      +3
leave_var_nest_level                                  98      32     -66
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/1 up/down: 110/-66)            Total: 44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-09 19:05:11 +02:00
Denys Vlasenko eb0de05d68 hush: fix func_return2.tests on NOMMU
function                                             old     new   delta
hush_main                                           1714    1718      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-09 17:54:07 +02:00
Denys Vlasenko a1870f4807 unlzma: fix segfault on bad archive
function                                             old     new   delta
unpack_lzma_stream                                  2647    2653      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 20:45:16 +02:00
Denys Vlasenko 38ccd6af8a bzip2: fix two crashes on corrupted archives
As it turns out, longjmp'ing into freed stack is not healthy...

function                                             old     new   delta
unpack_usage_messages                                  -      97     +97
unpack_bz2_stream                                    369     409     +40
get_next_block                                      1667    1677     +10
get_bits                                             156     155      -1
start_bunzip                                         212     183     -29
bb_show_usage                                        181     120     -61
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/3 up/down: 147/-91)            Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 20:05:04 +02:00
Denys Vlasenko 8e2174e9bd wget: check chunk length for overflowing off_t
function                                             old     new   delta
retrieve_file_data                                   428     465     +37
wget_main                                           2386    2389      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0)               Total: 40 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 18:06:24 +02:00
Denys Vlasenko 7bcde5f00d libbb.h: always include sys/resource.h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 17:23:27 +02:00
Denys Vlasenko 87a08e476b lzop: remove method checks which are always true/false
function                                             old     new   delta
do_lzo_compress                                      232     224      -8
lzo_compress                                         531     488     -43
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-51)             Total: -51 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 16:44:45 +02:00
Denys Vlasenko 3d4f688a19 lzop: buffer several 32-bit writes when we start a new compressed block
function                                             old     new   delta
lzo_compress                                         483     531     +48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 16:31:02 +02:00
Denys Vlasenko 24ef5c6375 lzop: reuse strings
function                                             old     new   delta
lzo_compress                                         470     483     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes
   text    data     bss     dec     hex filename
 940011     477    7284  947772   e763c busybox_old
 939976     477    7284  947737   e7619 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 14:00:03 +02:00
Denys Vlasenko 15684bf545 lzop: checksum reads do not need to be checksummed
function                                             old     new   delta
do_lzo_decompress                                    404     427     +23
f_read32                                              22       -     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 13:45:04 +02:00
Denys Vlasenko 3a7d16d488 lzop: don't support ancient versions < 0.94 (15 Oct 1997)
0.94 came only 2 months after initial 0.90:

    0.90 (10 Aug 1997): First public release of lzop
    ...
    0.94 (15 Oct 1997): Header format change

function                                             old     new   delta
do_lzo_decompress                                    411     404      -7
f_read8                                               24       -     -24
f_read16                                              31       -     -31
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-62)             Total: -62 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 13:35:28 +02:00
Denys Vlasenko 434f95960a lzop: code shrink by using header_t matching on-disk layout
function                                             old     new   delta
add_bytes_to_chksum                                   37      47     +10
lzo_decompress                                       524     532      +8
init_chksum                                           14      21      +7
chksum_getresult                                      13      17      +4
f_read                                                33      28      -5
f_write8                                              20       -     -20
f_write32                                             22       -     -22
f_write16                                             25       -     -25
f_write                                               36       -     -36
do_lzo_compress                                      328     232     -96
do_lzo_decompress                                    526     411    -115
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 4/3 up/down: 29/-319)          Total: -290 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 13:33:43 +02:00
Denys Vlasenko 7924b69f99 tar: trim help text
Usage: tar c|x|t [-ZzJjahmvokO] [-f TARFILE] [-C DIR] [-T FILE] [-X FILE] [--exclude PATTERN]... [FILE]...

Create, extract, or list files from a tar file

Operation:  <============== DELETED
    c	Create
    x	Extract
    t	List
    -f FILE	Name of TARFILE ('-' for stdin/out)
    -C DIR	Change to DIR before operation
    -v	Verbose
    -O	Extract to stdout
    -m	Don't restore mtime
    -o	Don't restore user:group
    -k	Don't replace existing files
    -Z	(De)compress using compress
    -z	(De)compress using gzip
    -J	(De)compress using xz
    -j	(De)compress using bzip2
    -a	(De)compress using lzma
    -h	Follow symlinks
    -T FILE	File with names to include
    -X FILE	File with glob patterns to exclude
    --exclude PATTERN	Glob pattern to exclude

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 21:04:39 +02:00
Denys Vlasenko 8d6eab3225 hush: fix prompt in multi-line $(())
Now shows PS2 in this case:

/path/to/dir $ a=b; echo $((
> _

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 17:01:31 +02:00
Denys Vlasenko 17058a06c4 libbb: switch bb_ask_noecho() to "mallocing" string return API
function                                             old     new   delta
bb_ask_noecho                                        313     330     +17
get_cred_or_die                                      125     115     -10
passwd_main                                          995     958     -37
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 17/-47)            Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 15:50:30 +02:00
Denys Vlasenko bae8fc4436 xargs: use bb_ask_y_confirmation_FILE() instead of homegrown copy
function                                             old     new   delta
bb_ask_y_confirmation_FILE                             -      83     +83
inetd_main                                          2033    2043     +10
udhcp_send_kernel_packet                             295     301      +6
rmescapes                                            306     310      +4
send_tree                                            353     355      +2
i2cdetect_main                                       674     672      -2
confirm_or_abort                                      43      38      -5
get_terminal_width_height                            242     234      -8
bb_ask_y_confirmation                                 76      10     -66
xargs_main                                           823     755     -68
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/5 up/down: 105/-149)          Total: -44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 15:23:10 +02:00
Denys Vlasenko 77cb6b99a4 libbb: rename bb_ask -> bb_ask_noecho, bb_ask_confirmation -> bb_ask_y_confirmation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 15:08:12 +02:00
Denys Vlasenko 2f094ae821 telnet: move winsize detection closer to I/O loop, delete non-functioning debug code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 15:02:20 +02:00
Denys Vlasenko e0afe0a9fd ftpd: allow -A if !FTPD_AUTHENTICATION as well
Users will be able to use "ftpd -A" in scripts regardless of build config

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 14:18:42 +02:00
Denys Vlasenko 8edaaced16 ftpd: added -A option to disable all authentication, closes 10921
function                                             old     new   delta
packed_usage                                       32745   32777     +32
ftpd_main                                           2162    2156      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 32/-6)              Total: 26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 14:02:21 +02:00
Denys Vlasenko 32c3e3a44c wget,ftpd: shorten and reuse strings
function                                             old     new   delta
wget_main                                           2382    2386      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 4/0)                 Total: 4 bytes
   text	   data	    bss	    dec	    hex	filename
 934228	    477	   7296	 942001	  e5fb1	busybox_old
 934202	    477	   7296	 941975	  e5f97	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 13:22:52 +02:00
Denys Vlasenko 9fe8bd8d61 httpd: do not default to Content-type: application/octet-stream
Instead, simply don't send this header.

On Mon, Apr 2, 2018 at 8:17 PM, xisd <xisd-dev@riseup.net> wrote:
> I had some trouble using busybox httpd to serve a static website and I
> thought the issue might be of interest.
>
> My problem is related to something that seem quite common for static
> site generator :  the use of html files without the '.html' extension
> (it is called 'clean url'...)
>
> Most web server guess that these files are html and display them like
> any other .html files.
>
> From what I understood, the MIME type for files without extension in
> busybox htttp default settings is 'application/octet-stream', and
> because of that 'clean url' pages are not displayed.
>
> It is only trouble because I wanted to deploy my website on freshly
> installed linux without editing any configuration.
>
> The default MIME setting make sense to me as it is, I just thought that
> might be worth mentioning since the use of 'clean url' seem to be a
> common practice for static sites generators (the one I use is callled
> 'yellow' (https://github.com/datenstrom/yellow))
>
> Here is a link for the related issue on github :
> https://github.com/datenstrom/yellow/issues/317

function                                             old     new   delta
send_headers                                         702     718     +16
send_headers_and_exit                                 23      20      -3
handle_incoming_and_exit                            2794    2791      -3
send_file_and_exit                                   772     756     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 16/-22)             Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 01:13:30 +02:00
Denys Vlasenko 6b6a3d9339 scripts/kconfig/mconf.c: survive is SIGWINCH is not defined
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-06 19:05:53 +02:00
Denys Vlasenko 2c99702810 i386: make stack size optimization selectable, and allow i486 insns (bswap)
It's hard to imagine someone still using non-bswap equipped CPU

function                                             old     new   delta
xmalloc_optname_optval                               888     879      -9
write_leases                                         214     205      -9
write32                                               36      27      -9
update_status                                        612     603      -9
udhcpd_main                                         1468    1459      -9
udhcpc_main                                         2708    2699      -9
udhcp_run_script                                     804     795      -9
sha256_process_block64                               423     414      -9
sha1_process_block64                                 337     328      -9
sha1_end                                              80      71      -9
send_ACK                                             161     152      -9
select_lease_time                                     64      55      -9
rpm_getint                                           118     109      -9
readprofile_main                                    1719    1710      -9
read32                                                33      24      -9
rdate_main                                           236     227      -9
machtime                                              39      30      -9
inet_addr_match                                      103      94      -9
get_prefix                                           344     335      -9
f_write32                                             31      22      -9
f_read32                                              31      22      -9
dumpleases_main                                      620     611      -9
KeyExpansion                                         197     188      -9
udhcp_str2optset                                     536     518     -18
read_config                                          222     204     -18
lfp_to_d                                              55      37     -18
ipaddr_modify                                       1226    1208     -18
dnsd_main                                           1278    1260     -18
des_crypt                                           1344    1326     -18
d_to_lfp                                             106      88     -18
bb_bswap_64                                           29      11     -18
INET_setroute                                        827     809     -18
read_leases                                          330     309     -21
zcip_main                                           1256    1229     -27
send_offer                                           476     449     -27
ipcalc_main                                          534     507     -27
handle_incoming_and_exit                            2821    2794     -27
fmt_time_bernstein_25                                131     104     -27
common_traceroute_main                              3804    3768     -36
rpm_gettags                                          451     397     -54
parse_args                                          1412    1358     -54
volume_id_probe_hfs_hfsplus                          627     564     -63
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/42 up/down: 0/-732)          Total: -732 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-06 19:01:51 +02:00
Denys Vlasenko 2ab994f707 placate gcc-8.0.1 warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-06 18:26:33 +02:00
Denys Vlasenko f5018dac21 hush: fix "unset PS1/PS2", and put them into initial variable set
"unset PS1/PS2" causes prompts to be empty strings

function                                             old     new   delta
hush_main                                           1031    1089     +58
goto_new_line                                         27      33      +6
fgetc_interactive                                    244     245      +1
unset_local_var                                      155     149      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 65/-6)              Total: 59 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-06 17:58:21 +02:00
Denys Vlasenko d1d6d9c5d8 sort: smaller and more agressive FEATURE_SORT_OPTIMIZE_MEMORY
function                                             old     new   delta
sort_main                                           1098    1037     -61

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-06 16:44:50 +02:00
Denys Vlasenko 00bd76728d hush: if we did match "LINENO" or "OPTIND", stop further comparisons
function                                             old     new   delta
handle_changed_special_names                          99     101      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-06 14:57:53 +02:00
Denys Vlasenko cf079ffe1c hush: consolidate handling of setting/unsetting of PSn, LINENO, OPTIND
function                                             old     new   delta
handle_changed_special_names                           -      99     +99
unset_local_var                                      256     155    -101
set_local_var                                        557     437    -120
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 99/-221)          Total: -122 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-06 14:50:12 +02:00
Denys Vlasenko de02625985 hush: update to correctly handle changed var_bash[346].tests
function                                             old     new   delta
expand_one_var                                      1612    1604      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 17:04:53 +02:00
Denys Vlasenko f2ed39b930 hush: implement "hush -s"
function                                             old     new   delta
hush_main                                           1015    1031     +16
packed_usage                                       32757   32745     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-12)              Total: 4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 16:46:49 +02:00
Denys Vlasenko d878ccca9c placate gcc 8.0.1 sprintf overflow warnings in config tools
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 15:21:34 +02:00
Denys Vlasenko 21b7f1b6b6 hush: fix a few more corner cases with empty-expanding cmds
See added testcases

function                                             old     new   delta
run_pipe                                            1723    1784     +61

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 15:15:53 +02:00
Denys Vlasenko 41d8f10813 hush: fix corner cases with exec in empty expansions
Cases like these:

var=val exec >redir

var=val `` >redir

function                                             old     new   delta
run_pipe                                            1701    1723     +22
redirect_and_varexp_helper                            56      55      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 22/-1)              Total: 21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 14:41:21 +02:00
Denys Vlasenko 929a41d577 hush: less mind-bending set_vars_and_save_old()
function                                             old     new   delta
run_pipe                                            1651    1701     +50
set_local_var                                        510     557     +47
pseudo_exec_argv                                     544     581     +37
redirect_and_varexp_helper                            64      56      -8
set_vars_and_save_old                                164     149     -15
unset_local_var                                      274     256     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/3 up/down: 134/-41)            Total: 93 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 14:09:14 +02:00
Denys Vlasenko 4e1dc539e9 hush: "no logic changes" in last commit was not true, fix it up
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 13:10:34 +02:00
Denys Vlasenko 34f6b12330 hush: make run_pipe code simpler to understand, no logic changes
function                                             old     new   delta
run_pipe                                            1641    1651     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 11:30:17 +02:00
Denys Vlasenko d358b0b65d hush: fix a bug where we don't properly handle f() { a=A; b=B; }; a= f
function                                             old     new   delta
unset_local_var                                       20     274    +254
leave_var_nest_level                                   -      98     +98
set_vars_and_save_old                                128     164     +36
enter_var_nest_level                                   -      32     +32
builtin_local                                         46      50      +4
pseudo_exec_argv                                     554     544     -10
redirect_and_varexp_helper                            77      64     -13
run_pipe                                            1890    1641    -249
unset_local_var_len                                  267       -    -267
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 3/3 up/down: 424/-539)         Total: -115 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-05 00:51:55 +02:00
Denys Vlasenko 332e4115c9 hush: make var nesting code independent of "local" support
Also, add code to abort at ~65000 function recursion depth.
SEGVing is not as nice as exiting with a message (and restoring termios!):

$ f() { echo -n .; f; }; f
....<many dots later>....hush: fatal recursion (depth 65281)

function                                             old     new   delta
run_pipe                                            1826    1890     +64
pseudo_exec_argv                                     544     554     +10
parse_and_run_file                                    71      80      +9
i_getch                                              104     107      +3
done_command                                          99     102      +3
set_local_var                                        508     510      +2
helper_export_local                                  214     215      +1
builtin_local                                         49      46      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/1 up/down: 92/-3)              Total: 89 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-04 22:35:13 +02:00
Denys Vlasenko 61407807ab hush: fix for readonly vars in "ro=A ro=B cmd" case
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-04 21:14:28 +02:00
Denys Vlasenko 759ca8a4cb sort: move misplaced comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-04 17:07:21 +02:00
Denys Vlasenko c29c2e60d8 sort: FEATURE_SORT_OPTIMIZE_MEMORY
On sorting all kernel/linux/arch/ *.[ch] files,
this reduces memory usage by 6%.

	yes | head -99999999 | sort

goes down from 1900Mb to 380 Mb.

function                                             old     new   delta
sort_main                                            862    1098    +236

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-04 17:03:41 +02:00
Denys Vlasenko ee1fd1246e ash: unbreak PS1 parsing after "ash: parser: Add syntax stack..." commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-04 13:59:53 +02:00
Denys Vlasenko fbf44854a3 hush: support "f() (cmd)" functions
Many other shells support this construct

function                                             old     new   delta
parse_stream                                        2950    3018     +68

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 14:56:52 +02:00
Denys Vlasenko 49015a60cb hush: fix mishandling of "true | f() { echo QWE; }"
function                                             old     new   delta
run_pipe                                            1820    1826      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 13:02:43 +02:00
Denys Vlasenko 5fa0505f8a hush: fix "set -e; false || x=1; echo OK"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 11:21:13 +02:00
Denys Vlasenko 11752d46d1 hush: one-word, no-globbing handling of local/export/readonly args
function                                             old     new   delta
done_word                                            738     790     +52

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 08:20:58 +02:00
Denys Vlasenko f50e14632f ash: parser: Fix parameter expansion inside inner double quotes
Upstream email:

    parser: Fix parameter expansion inside inner double quotes

    The parsing of parameter expansion inside inner double quotes
    breaks because we never look for ENDVAR while innerdq is true.

            echo "${x#"${x+''}"''}

    This patch fixes it by pushing the syntax stack if innerdq is
    true and we enter a new parameter expansion.

    This patch also fixes a corner case where a bad substitution error
    occurs within arithmetic expansion.

    Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
    Fixes: ab1cecb40478 (" parser: Add syntax stack for recursive...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
readtoken1                                          2880    2898     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 21:00:59 +02:00
Denys Vlasenko abf755615e hush: fix a backslash-removal bug in case
function                                             old     new   delta
run_list                                            1270    1053    -217

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 17:25:18 +02:00
Denys Vlasenko 9a95df9046 ash: expand: Fix bugs with words connected to the right of $@
Upstream email:

    This is actually composed of two bugs.  First of all our tracking
    of quotemark is wrong so anything after "$@" becomes quoted.  Once
    we fix that then the problem is that the first space character
    after "$@" is not recognised as an IFS.

    This patch fixes both.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 14:27:50 +02:00
Denys Vlasenko 355ec353be ash: redir: Fix typo in noclobber code
Upstream commit "redir: Fix typo in noclobber code"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:34:57 +02:00
Denys Vlasenko c4c2012284 ash: parser: Fix single-quoted patterns in here-documents
Upstream commit:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Fri, 9 Mar 2018 23:07:53 +0800
    parser: Fix single-quoted patterns in here-documents

    The script

            x=*
            cat <<- EOF
                    ${x#'*'}
            EOF

    prints * instead of nothing as it should.  The problem is that
    when we're in sqsyntax context in a here-document, we won't add
    CTLESC as we should.  This patch fixes it:

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:29:20 +02:00
Denys Vlasenko 8b536eb40d hush: remove stray debugging printout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:26:16 +02:00
Denys Vlasenko 216913c290 ash: parser: Add syntax stack for recursive parsing
This closes 10821.

Upstream patch:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Fri, 9 Mar 2018 00:14:02 +0800
    parser: Add syntax stack for recursive parsing

    Without a stack of syntaxes we cannot correctly these two cases
    together:

            "${a#'$$'}"
            "${a#"${b-'$$'}"}"

    A recursive parser also helps in some other corner cases such
    as nested arithmetic expansion with paratheses.

    This patch adds a syntax stack allocated from the stack using
    alloca.  As a side-effect this allows us to remove the naked
    backslashes for patterns within double-quotes, which means that
    EXP_QPAT also has to go.

    This patch also fixes removes any backslashes that precede right
    braces when they are present within a parameter expansion context,
    and backslashes that precede double quotes within inner double
    quotes inside a parameter expansion in a here-document context.

    The idea of a recursive parser is based on a patch by Harald van
    Dijk.

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

var_bash3, var_bash4 and var_bash6 tests are updated
with the output given by bash-4.3.43

With this patch, the following tests now pass for ash:

    dollar_repl_slash_bash2.tests
    squote_in_varexp2.tests
    squote_in_varexp.tests
    var_bash4.tests

function                                             old     new   delta
readtoken1                                          2615    2874    +259
synstack_push                                          -      54     +54
evalvar                                              574     571      -3
rmescapes                                            330     310     -20
subevalvar                                          1279    1258     -21
argstr                                              1146    1107     -39
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/4 up/down: 313/-83)           Total: 230 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:15:37 +02:00
Denys Vlasenko e84212f834 hush: update information comment about heredoc discrepancy
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 20:11:23 +02:00
Denys Vlasenko 899ae5337a libbb: new function bb_die_memory_exhausted
function                                             old     new   delta
bb_die_memory_exhausted                                -      10     +10
xstrdup                                               28      23      -5
xsetenv                                               27      22      -5
xrealloc                                              32      27      -5
xputenv                                               22      17      -5
xmalloc                                               30      25      -5
xfdopen_helper                                        40      35      -5
xasprintf                                             44      39      -5
wget_main                                           2387    2382      -5
open_socket                                           54      49      -5
glob_brace                                           419     414      -5
bb_get_chunk_from_file                               146     141      -5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/11 up/down: 10/-55)           Total: -45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 19:59:37 +02:00
Quentin Rameau e2afae6303 sed: prevent overflow of length from bb_get_chunk_from_file
This fragment did not work right:

                temp = bb_get_chunk_from_file(fp, &len);
                if (temp) {
                        /* len > 0 here, it's ok to do temp[len-1] */
                        char c = temp[len-1];

With "int len" _sign-extending_, temp[len-1] can refer to a wrong location
if len > 0x7fffffff.

Signed-off-by: Quentin Rameau <quinq@fifth.space>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 19:51:14 +02:00
Quentin Rameau 2da9724b56 libbb: remove unnecessary variable in xmalloc_fgets
Signed-off-by: Quentin Rameau <quinq@fifth.space>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 19:45:36 +02:00
Denys Vlasenko bb6f573ad2 hush: add a comment where we differ from bash wrt heredoc EOF mark handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 18:55:00 +02:00
Denys Vlasenko 41fddb4372 parser: Fix backquote support in here-document EOF mark
Upstream commit:

    Author: Herbert Xu <herbert@gondor.apana.org.au>
    Date:   Thu Mar 15 18:27:30 2018 +0800
    parser: Fix backquote support in here-document EOF mark

    Currently using backquotes in a here-document EOF mark is broken
    because dash tries to do command substitution on it.  This patch
    fixes it by checking whether we're looking for an EOF mark during
    tokenisation.

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

With added fix for quoted-ness of the EOF mark.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 16:38:32 +02:00
Denys Vlasenko 1e5111b0f8 ash,hush: handle a few more bkslash-newline cases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 03:04:55 +02:00
Denys Vlasenko 32e183e63e shells: fix var_LINENO1.tests false positive, add it to ash tests too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 20:31:13 +02:00
Denys Vlasenko a94eeb0b42 hush: fix heredoc_bkslash_newline1.tests failure
function                                             old     new   delta
parse_stream                                        2787    2827     +40
builtin_type                                         117     115      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 20:16:31 +02:00
Denys Vlasenko 220be537a0 ash: use pgetc_eatbnl() in more places
Part of 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>

Not adding "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes, since
readtoken1() handles the "starts with backslash + newline" case itself.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 19:40:56 +02:00
Martijn Dekker ad4e961352 ash: 'nolog' and 'debug' options cause "$-" to wreak havoc
Upstream commit:

    Date:   Tue Mar 6 17:40:37 2018 +0000
    expand: 'nolog' and 'debug' options cause "$-" to wreak havoc

    Op 29-03-17 om 20:02 schreef Martijn Dekker:
    > Bug: if either the 'nolog' or the 'debug' option is set, trying to
    > expand "$-" silently aborts parsing of an entire argument.
    >
    > $ dash -o nolog -c 'set -fuC; echo "|$- are the options|"; set +o nolog; echo "|$- are the options|"'
    > |
    > |uCf are the options|
    > $ dash -o debug -c 'set -fuC; echo "|$- are the options|"; set +o debug; echo "|$- are the options|"'
    > |
    > |uCf are the options|

    This turned out to be easy to fix. The routine producing the "$-"
    expansion failed to skip options for which there is no option letter,
    but only a long-form name. In dash, 'nolog' and 'debug' are currently
    the only two such options. Patch below.

    - Martijn

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

In bbox ash, pipefail is the option which exhibited this.

Signed-off-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 18:30:27 +02:00
Denys Vlasenko 7bf304f371 stat: fix a typo: s/romfs/ramfs/, closes 10876
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 02:45:22 +02:00
Denys Vlasenko 6ffaa00338 hush: fix a signedness bug
Testcase:

set -- a ""; space=" "; printf "<%s>\n" "$@"$space

Before:
<a >
After:
<a>
<>

It usually does not bite since bbox forces -funsigned-char build.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 00:48:18 +02:00
Denys Vlasenko 73523079a2 ash,hush: new test dollar_repl_slash_bash2.tests
This fails for ash. hush works.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 23:25:24 +02:00
Denys Vlasenko ac61f44704 ash: fix "char == CTLfoo" comparison signedness bug
It usually does not bite since bbox forces -funsigned-char build.
But for some reason void linux people disabled that.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 23:04:39 +02:00
Denys Vlasenko 60fb98e51d ash: use F_DUPFD_CLOEXEC and O_CLOEXEC
function                                             old     new   delta
setjobctl                                            371     367      -4
setinputfile                                         226     220      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10)             Total: -10 bytes

Based on patch by Mark Marshall <mark.marshall@omicronenergy.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 22:15:14 +02:00
Denys Vlasenko df65dc89b4 examples/var_service: new example: dnsmasq service
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 20:49:16 +02:00
Natanael Copa d9503224c8 cpio: extract "unsafe" symlinks the same way tar/unzip does
function                                             old     new   delta
cpio_main                                            588     596      +8

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 20:18:12 +02:00
Denys Vlasenko 0d79d7709d svok: new applet (daemontools compat)
function                                             old     new   delta
svok_main                                              -     127    +127
packed_usage                                       32705   32757     +52
applet_names                                        2756    2761      +5
applet_main                                         1588    1592      +4
bb_banner                                             46      47      +1
sv                                                  1286    1284      -2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/1 up/down: 189/-2)            Total: 187 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 20:02:33 +02:00
Denys Vlasenko d892f7137f ifplugd service example: always run up/down script on startup
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 11:14:46 +02:00
Stefan Agner 2adaa90534 ifplugd: if SIOCSIFFLAGS fails with EADDRNOTAVAIL, don't die
When using ifplugd on a RNDIS interface with monitor mode, using
SIOCSIFFLAGS seems to fail with EADDRNOTAVAIL. Treat it the same
as if iface disappeared again.

This has been observed on a Tegra TK1 using Linux 4.14. There seem
to be a race when the kernel is creating the device:
  ifplugd(usb0): started: BusyBox v1.24.1 (2018-03-27 09:47:48 CEST)
  ifplugd(usb0): interface doesn't exist, waiting
  ifplugd(usb0): interface appeared
  ifplugd(usb0): upping interface
  ifplugd(usb0): setting interface flags failed: Cannot assign requested address
  <exit>

With this patch ifplugd is successful in upping the device the second
time around:

  ifplugd(usb0): upping interface
  ifplugd(usb0): using SIOCETHTOOL detection mode
  ifplugd(usb0): interface appeared
  ifplugd(usb0): upping interface
  ifplugd(usb0): setting interface flags failed: Cannot assign requested address
  ifplugd(usb0): interface appeared
  ifplugd(usb0): upping interface
  ifplugd(usb0): using SIOCETHTOOL detection mode
  ifplugd(usb0): link is up
  ifplugd(usb0): executing '/etc/ifplugd/ifplugd.usb.action usb0 up'
  ifplugd up
  ifplugd(usb0): exit code: 0

function                                             old     new   delta
up_iface                                             120     127      +7

Signed-off-by: Stefan Agner <stefan@agner.ch>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-29 18:45:11 +02:00
Peter Korsgaard a82fe671f5 fbsplash: support configurable image position
For some setups (E.G. for supporting different screen resolutions),
positioning the image somewhere else than the top left corner may be
interesting.

Add support for IMG_LEFT/IMG_TOP settings to specify the image location,
similar to how it is done for the progress bar.

function                                             old     new   delta
fbsplash_main                                        994    1038     +44
static.param_names                                    57      74     +17
packed_usage                                       32631   32647     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 77/0)               Total: 77 bytes

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-29 18:42:11 +02:00
Denys Vlasenko 03fd7e06f8 grep: fix echo "aa" | busybox grep -F -w "a" (should not match)
function                                             old     new   delta
grep_file                                           1461    1470      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-29 18:03:50 +02:00
Denys Vlasenko 3be4b9b0de fstrim: do not check that specified file is on a block device
Kernel will surely inform us in FITRIM does not make sense on a given file.

function                                             old     new   delta
fstrim_main                                          241     221     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-29 16:05:10 +02:00
Denys Vlasenko d1b845706d hush: add a FIXME comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-28 18:42:54 +02:00
Denys Vlasenko 9acd63c92c ash,hush: fix "saved" redirected fds still visible in children
Based on a patch by Mark Marshall <mark.marshall@omicronenergy.com>

function                                             old     new   delta
dup_CLOEXEC                                            -      49     +49
fcntl_F_DUPFD                                         46       -     -46

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-28 18:35:07 +02:00
Denys Vlasenko e4defe826b libbb: use BUILD_BUG_ON in utoa_to_buf()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-28 17:12:56 +02:00
Kaarle Ritvanen 123fdda0a4 ifupdown: do not fail if interface disappears during ifdown
Interface may not exist because it got deleted by an ifdown hook script
earlier. This may happen when a virtual interface, such as VLAN, has multiple
iface blocks defined.

function                                             old     new   delta
static_down6                                          14      40     +26
static_down                                           54      70     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 42/0)               Total: 42 bytes

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-28 00:02:52 +02:00
Denys Vlasenko 46ba2468a3 ioctl(SIOCGIFINDEX) does not require clearing of entire ifr
function                                             old     new   delta
INET6_setroute                                       492     472     -20
do_iplink                                           1357    1330     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-47)             Total: -47 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-27 23:55:43 +02:00
Mark Marshall 98592db323 netstat: produce numeric-ip output for non-resolved names
If we don't ask for numerical output, and the symbolic look-up failed
we used to get "(null)", but the numeric output would be better.

function                                             old     new   delta
ip_port_str                                          109     121     +12

Signed-off-by: Mark Marshall <mark.marshall@omicronenergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-27 23:28:53 +02:00
Ron Yorston b5820d9fd8 ssl_client: fix option parsing
The wrong character was used to indicate options taking an integer
parameter.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-20 11:41:51 +01:00
Denys Vlasenko b3e98b1ccc top: fix "warning: unused variable new_mask"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-19 20:00:10 +01:00
Denys Vlasenko 3c08437db7 tar: add -o and -k to short --help too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-16 04:02:23 +01:00
Denys Vlasenko 1ee222e1bf tar: add -k and -o to --help
-o	Don't restore user:group
    -k	Don't replace existing files

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-16 03:55:14 +01:00
Denys Vlasenko bbe47d9b9a tcpsvd: fix fallout from opt_complementary removal
text	   data	    bss	    dec	    hex	filename
 933035	    473	   6836	 940344	  e5938	busybox_old
 933051	    473	   6836	 940360	  e5948	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-11 23:02:50 +01:00
Denys Vlasenko 0e09ded2f1 readprofile: code shrink
function                                             old     new   delta
defaultpro                                            14       -     -14
defaultmap                                            17       -     -17
readprofile_main                                    1762    1719     -43
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-74)             Total: -74 bytes
   text	   data	    bss	    dec	    hex	filename
 933081	    473	   6836	 940390	  e5966	busybox_old
 933035	    473	   6836	 940344	  e5938	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-11 19:35:58 +01:00
Denys Vlasenko 448fdcc17d ntpd: choose initial FREQHOLD_cnt dynamically
function                                             old     new   delta
update_local_clock                                   834     858     +24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-11 17:08:02 +01:00
Denys Vlasenko 3d306bffc5 udhcpd: clamp down huge auto_times to ~2M seconds, better EINTR poll handling
EINTR _should_ only happen on two signals we trap, and safe_poll
_should_ work here just fine, but there were kernel bugs where spurious EINTRs
happen (e.g. on ptrace attach). Be safe.

function                                             old     new   delta
udhcpd_main                                         1437    1468     +31

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-11 11:39:05 +01:00
Denys Vlasenko 39dfb4de38 ntpd: suppress in-kernel frequency correction in first 8 adjtimex calls
In other words: try to correct initially existing clock offset first,
before assuming that our clock drifts.

function                                             old     new   delta
update_local_clock                                   826     834      +8
ntp_init                                             550     557      +7
filter_datapoints                                    179     173      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 15/-6)               Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-10 21:25:53 +01:00
Denys Vlasenko 3293bc1469 udhcpd: fix "not dying on SIGTERM"
Fixes:
	commit 52a515d187
	"udhcp: use poll() instead of select()"
	Feb 16 2017

udhcp_sp_read() is meant to check whether signal pipe indeed has some data to read.
In the above commit, it was changed as follows:

-	if (!FD_ISSET(signal_pipe.rd, rfds))
+	if (!pfds[0].revents)
		return 0;

The problem is, the check was working for select() purely by accident.
Caught signal interrupts select()/poll() syscalls, they return with EINTR
(regardless of SA_RESTART flag in sigaction). _Then_ signal handler is invoked.
IOW: they can't see any changes to fd state caused by signal haldler
(in our case, signal handler makes signal pipe ready to be read).

For select(), it means that rfds[] bit array is unmodified, bit of signal
pipe's read fd is still set, and the above check "works": it thinks select()
says there is data to read.

This accident does not work for poll(): .revents stays clear, and we do not
try reading signal pipe as we should. In udhcpd, we fall through and block
in socket read. Further SIGTERM signals simply cause socket read to be
interrupted and then restarted (since SIGTERM handler has SA_RESTART=1).

Fixing this as follows: remove the check altogether. Set signal pipe read fd
to nonblocking mode. Always read it in udhcp_sp_read().
If read fails, assume it's EAGAIN and return 0 ("no signal seen").

udhcpd avoids reading signal pipe on every recvd packet by looping if EINTR
(using safe_poll()) - thus ensuring we have correct .revents for all fds -
and calling udhcp_sp_read() only if pfds[0].revents!=0.

udhcpc performs much fewer reads (typically it sleeps >99.999% of the time),
there is no need to optimize it: can call udhcp_sp_read() after each poll
unconditionally.

To robustify socket reads, unconditionally set pfds[1].revents=0
in udhcp_sp_fd_set() (which is before poll), and check it before reading
network socket in udhcpd.

TODO:
This might still fail: if pfds[1].revents=POLLIN, socket read may still block.
There are rare cases when select/poll indicates that data can be read,
but then actual read still blocks (one such case is UDP packets with
wrong checksum). General advise is, if you use a poll/select loop,
keep all your fds nonblocking.
Maybe we should also do that to our network sockets?

function                                             old     new   delta
udhcp_sp_setup                                        55      65     +10
udhcp_sp_fd_set                                       54      60      +6
udhcp_sp_read                                         46      36     -10
udhcpd_main                                         1451    1437     -14
udhcpc_main                                         2723    2708     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/3 up/down: 16/-39)            Total: -23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-10 19:34:39 +01:00
Denys Vlasenko 3936222a0a remove stray newline in "iplink --help"
function                                             old     new   delta
packed_usage                                       32547   32550      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-08 16:06:18 +01:00
Denys Vlasenko db169f2538 ip: fix "ip -oneline a"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-08 15:55:07 +01:00
Denys Vlasenko 7798282db2 ipcs: further code shrink
function                                             old     new   delta
packed_usage                                       32543   32547      +4
ipcs_main                                           1014     980     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-34)             Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-08 13:23:06 +01:00
Denys Vlasenko f7fa8001b7 ipcs: code shrink
function                                             old     new   delta
packed_usage                                       32539   32543      +4
format                                                 1       -      -1
do_shm                                               883     880      -3
do_sem                                               636     633      -3
do_msg                                               782     779      -3
ipcs_main                                           1049    1014     -35
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/4 up/down: 4/-45)             Total: -41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-08 13:10:23 +01:00
Denys Vlasenko 694bc06345 md5sum: use config help text similar to other "sum" tools
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-08 12:49:39 +01:00
Denys Vlasenko a2cae937d0 top: much faster cursor key navigation by avoiding process rescan
function                                             old     new   delta
handle_input                                         549     560     +11
top_main                                             889     891      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-07 04:47:52 +01:00
Denys Vlasenko 75e56a3db9 top: do unsigned rather than signed division in do_stats()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-07 04:20:22 +01:00
Denys Vlasenko 86107d6dc7 top: handle much larger VSZ values
function                                             old     new   delta
display_process_list                                1018     999     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-07 03:59:52 +01:00
Denys Vlasenko e1b1b79269 use gmtime_r() instead of gmtime()
This avoids pulling in gmtime's static buffer:

function                                             old     new   delta
svlogd_main                                         1401    1412     +11
send_headers                                         668     678     +10
gmtime                                                21       -     -21
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/0 up/down: 21/-21)              Total: 0 bytes
   text	   data	    bss	    dec	    hex	filename
 920221	    555	   5804	 926580	  e2374	busybox_old
 920221	    555	   5740	 926516	  e2334	busybox_unstripped
                   ^^^^

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-06 18:11:47 +01:00
Denys Vlasenko 33f7c8f200 hush: code shrink
function                                             old     new   delta
run_pipe                                            1589    1591      +2
pseudo_exec_argv                                     374     375      +1
builtin_type                                         114     115      +1
find_function                                          8       -      -8
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/0 up/down: 4/-8)               Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-06 17:21:57 +01:00
Denys Vlasenko d51ba0b5ab networking/interface.c: get rid of global data
These were data/bss:

static.proc_read                                       1       -      -1
int_list                                               4       -      -4
int_last                                               4       -      -4

We never call display_interfaces() twice, thus code to not scan /proc twice
never triggers.

function                                             old     new   delta
do_if_print                                            -    1998   +1998
display_interfaces                                   145     249    +104
static.proc_read                                       1       -      -1
add_interface                                        104     103      -1
int_list                                               4       -      -4
int_last                                               4       -      -4
if_readlist_proc                                     560     542     -18
if_readconf                                          141       -    -141
do_if_fetch                                          643       -    -643
ife_print                                           1296       -   -1296
------------------------------------------------------------------------------
(add/remove: 1/6 grow/shrink: 1/2 up/down: 2102/-2108)         Total: -6 bytes
   text	   data	    bss	    dec	    hex	filename
 933084	    473	   6844	 940401	  e5971	busybox_old
 933087	    473	   6836	 940396	  e596c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-05 18:30:33 +01:00
Denys Vlasenko 82ec89480d networking/interface.c: get rid of global "smallint interface_opt_a"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-05 17:46:17 +01:00
Denys Vlasenko 8a5299fcfd networking/interface.c: code shrink
function                                             old     new   delta
ife_print                                           1293    1296      +3
display_interfaces                                   145     146      +1
if_readconf                                          162     141     -21
if_readlist_proc                                     631     560     -71
do_if_fetch                                          753     643    -110
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/3 up/down: 4/-202)           Total: -198 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-05 16:56:16 +01:00
Peter Lloyd 804ce5a6fe wget: fix fetching of https URLs with http proxy
When fetching a https:// URL with HTTP proxy configured
(e.g. with environment variable http_proxy=http://your-proxy:3128)
busybox was making a https connection to the proxy.

This was because the protocol scheme for the target URL was used to determine whether to connect to the proxy over SSL or not.

When the proxy is in use, the decision on whether to connect to the proxy over https
should based on the proxy URL not on the target URL.

function                                             old     new   delta
wget_main                                           2381    2387      +6

Signed-off-by: Peter Lloyd <l-busybox@pgl22.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-05 00:19:33 +01:00
Sean MacLennan d9aabfe578 make busybox more portable
Move some distro specific include files into the appropriate #ifdef
blocks to make the code more portable.

Signed-off-by: Sean MacLennan <seanm@seanm.ca>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-04 23:15:59 +01:00
Denys Vlasenko d4802c6243 hush: fix a='a\\'; echo "${a%\\\\}"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02 20:48:36 +01:00
Denys Vlasenko 55f8133a4f shell: tweak bkslash_in_varexp.tests, add bkslash_in_varexp1.tests
It turns out bkslash_in_varexp.tests was a bash bug :]

ash and hush fail "corrected" bkslash_in_varexp.tests as well,
just not as badly as I thought (hush gets half of the cases right).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02 18:12:12 +01:00
Denys Vlasenko 744a20d8f9 shell: two new tests, both fail for ash and hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02 17:13:22 +01:00
Andy Shevchenko cc222747ae libbb: Use return value from is_prefixed_with()
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5 (-5)
Function                                     old     new   delta
skip_dev_pfx                                  30      25      -5
Total: Before=779966, After=779961, chg -0.00%

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-27 13:35:40 +01:00
Denys Vlasenko d82ea2ba8f tcpudp: shrink per-host rate-limiting code
function                                             old     new   delta
tcpudpsvd_main                                      1775    1780      +5
ipsvd_perhost_add                                    108     107      -1
cclen                                                  4       -      -4
cc                                                     4       -      -4
ipsvd_perhost_init                                    30      25      -5
ipsvd_perhost_remove                                  80      44     -36
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/3 up/down: 5/-50)             Total: -45 bytes
   text	   data	    bss	    dec	    hex	filename
 933358	    473	   6852	 940683	  e5a8b	busybox_old
 933326	    473	   6844	 940643	  e5a63	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-27 13:03:44 +01:00
Denys Vlasenko 0e0209ac53 less: accept -R option. Closes 10816
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-27 11:47:51 +01:00
Ron Yorston 23286900da lineedit: allow window size tracking to be disabled
function                                             old     new   delta
lineedit_read_key                                    269     261      -8
win_changed                                           47       -     -47
read_line_input                                     3884    3821     -63
cmdedit_setwidth                                      63       -     -63
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-181)           Total: -181 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-25 20:09:54 +01:00
Denys Vlasenko e20a703fd3 df: do "rootfs" check sooner
function                                             old     new   delta
df_main                                             1065    1064      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-23 17:08:32 +01:00
Denys Vlasenko 58cd6e1ade df: 4TB+ support on 32 bits arch
Reported for Pascal Bellard.

function                                             old     new   delta
df_main                                             1054    1065     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-23 17:00:23 +01:00
Denys Vlasenko bf39d97e9d Fix install with hardlinks and a custom PREFIX. Closes 10801
Trying to install busybox with hardlinks and a custom PREFIX will fail
for applets not in the /bin directory, because relative pathnames are
used. applets/install.sh is *supposed to* use the absolute pathname
for hardlinks but it fails to do so because the wrong check is used
in the if statement.

While fixing it, shore up other sloppy coding in applets/install.sh

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-23 16:29:26 +01:00
Denys Vlasenko 3177626033 od: move address_fmt[] from data to globals. 8 less bytes in data section
function                                             old     new   delta
od_main                                             2164    2179     +15
address_fmt                                            8       -      -8
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 15/-8)               Total: 7 bytes
   text    data     bss     dec     hex filename
 930954     481    6852  938287   e512f busybox_old
 930977     473    6852  938302   e513e busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-22 12:14:55 +01:00
Denys Vlasenko 2709acbbda sort: fix potentially buggy use of OPT_STR
This also makes OPT_STR reused:

   text	   data	    bss	    dec	    hex	filename
 930979	    481	   6852	 938312	  e5148	busybox_old
 930954	    481	   6852	 938287	  e512f	busybox_unstripped
 ^^^^^^

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-22 11:03:23 +01:00
Denys Vlasenko 427ae18348 sort: in -s handling, return 1/-1, not 1/0 compare result
function                                             old     new   delta
compare_keys                                         794     795      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-22 10:54:55 +01:00
Denys Vlasenko 2af5e3fac3 libbb: compile capability code only if FEATURE_SETPRIV_CAPABILITIES or RUN_INIT
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-21 20:13:39 +01:00
Denys Vlasenko 7d285c78a3 sort: fix -s. Closes 10671
function                                             old     new   delta
sort_main                                            786     862     +76
compare_keys                                         720     794     +74
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 150/0)             Total: 150 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-21 20:08:54 +01:00
Jan Luebbe e789c3bea1 iplink: implement support for selecting a master interface
Attaching an interface to a VRF is done by setting the interface's
master. Besides VRF, this can also be used for bridges.

function                                             old     new   delta
set_master                                             -     142    +142
do_iplink                                           1262    1357     +95
packed_usage                                       32546   32539      -7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 237/-7)            Total: 230 bytes

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-20 19:43:32 +01:00
Jan Luebbe 79cda9522a ip link: support "add TYPE vrf", improve --help
VRF interfaces have a mandatory table parameter, which needs to be
specified using a RTNL attribute.

function                                             old     new   delta
do_add_or_delete                                    1150    1254    +104
packed_usage                                       32444   32546    +102
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 206/0)             Total: 206 bytes

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-20 19:29:05 +01:00
Denys Vlasenko b083e8cc53 umount: fix "umount -t FSTYPE MNTPOINT" acting as if -a is specified
While at it, add -t to --help, and fix comments which say that -t is ignored

function                                             old     new   delta
packed_usage                                       32427   32444     +17
umount_main                                          558     552      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 17/-6)              Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-20 17:58:19 +01:00
Denys Vlasenko a84db18fc7 tar,unzip: postpone creation of symlinks with "suspicious" targets
This mostly reverts commit bc9bbeb2b8
"libarchive: do not extract unsafe symlinks unless $EXTRACT_UNSAFE_SYMLINKS=1"

Users report that it is somewhat too restrictive. See
https://bugs.busybox.net/show_bug.cgi?id=8411

In particular, this interferes with unpacking of busybox-based
filesystems with links like "sbin/applet" -> "../bin/busybox".

The change is made smaller by deleting ARCHIVE_EXTRACT_QUIET flag -
it is unused since 2010, and removing conditionals on it
allows commonalizing some error message codes.

function                                             old     new   delta
create_or_remember_symlink                             -      94     +94
create_symlinks_from_list                              -      64     +64
tar_main                                            1002    1006      +4
unzip_main                                          2732    2724      -8
data_extract_all                                     984     891     -93
unsafe_symlink_target                                147       -    -147
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/2 up/down: 162/-248)          Total: -86 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-20 16:06:53 +01:00
Denys Vlasenko 95121d98e6 poweroff: add a config option for people needing VERY early poweroff
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-19 15:52:35 +01:00
Denys Vlasenko 7398892ac0 mkfs_ext2, mkfs_vfat: fix warnings in STORE_LE on big-endian platforms
"warning: large integer implicitly truncated to unsigned type [-Woverflow]"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-15 13:46:34 +01:00
Denys Vlasenko a48eadbc22 tls: remove redundant floor prevention
function                                             old     new   delta
tls_xread_record                                     499     489     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14 17:37:41 +01:00
Denys Vlasenko 256adb0f99 ping: don't call monotonic_us twice per sending the ping
function                                             old     new   delta
sendping6                                             80      85      +5
sendping4                                            106     111      +5
sendping_tail                                        209     204      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 10/-5)               Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13 23:53:24 +01:00
Denys Vlasenko 7189af847f ping: implement -A "adaptive ping"
function                                             old     new   delta
common_ping_main                                    1757    1862    +105
packed_usage                                       32367   32427     +60
sendping_tail                                        236     209     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 165/-27)           Total: 138 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13 23:21:33 +01:00
Denys Vlasenko 4892f3a4c7 inetd,mount: add comment with example of flags to build with libtirpc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13 18:20:28 +01:00
Denys Vlasenko edccc982e5 progress meter: add disabled code for a more stable ETA
Compiles to ~25 bytes if enabled.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13 16:48:52 +01:00
Denys Vlasenko aa617ac097 hush: simplify process_command_subs()
Incidentally, this fixes LINENO bug here:

echo "1:${LINENO}"
echo "2:`echo; echo`"  # was counting lines in the `cmd` output as LINENO++
echo "3:${LINENO}"

function                                             old     new   delta
parse_and_run_file                                    53      71     +18
expand_vars_to_list                                 1187    1164     -23
setup_file_in_str                                     25       -     -25
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 18/-48)            Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13 15:31:19 +01:00
Denys Vlasenko 8de5b9f88b ash : fix double-quoted "\z" handling
function                                             old     new   delta
readtoken1                                          2602    2608      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13 14:44:11 +01:00
Denys Vlasenko 3459024bf4 wget: more thorough sanitization of other side's data
function                                             old     new   delta
get_sanitized_hdr                                      -     156    +156
fgets_trim_sanitize                                    -     128    +128
ftpcmd                                               129     133      +4
parse_url                                            461     454      -7
sanitize_string                                       14       -     -14
wget_main                                           2431    2381     -50
fgets_and_trim                                       119       -    -119
gethdr                                               163       -    -163
------------------------------------------------------------------------------
(add/remove: 2/3 grow/shrink: 1/2 up/down: 288/-353)          Total: -65 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-12 16:46:13 +01:00
Ron Yorston ecaec1dbec testsuite: update busybox and bzcat tests
Test scripts that use CONFIG_* variables need to source .config.
Since this wasn't being done for busybox many tests were skipped.
As a result new failures due to changes in help output were missed.

Also remove some unnecessary echos in the bzcat script.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-12 15:32:02 +01:00
Denys Vlasenko 7f441403cb cp: fix option handling in non-longopt config
the patch getopt32: remove opt_complementary 22542eca18

introduced a regressed in the cp command since it removed all aliases of arguments
if long_opts is not configured.

Patch by Sebastian Gottschall <s.gottschall@dd-wrt.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-11 21:25:23 +01:00
Denys Vlasenko b5257a6701 arping: code shrink
function                                             old     new   delta
catcher                                              310     309      -1
arping_main                                         1668    1641     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-11 21:16:24 +01:00
Denys Vlasenko ba3b9dbf06 libbb: introduce and use bb_getsockname()
function                                             old     new   delta
bb_getsockname                                         -      18     +18
xrtnl_open                                            88      83      -5
do_iplink                                           1216    1209      -7
arping_main                                         1686    1668     -18
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/3 up/down: 18/-30)            Total: -12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-11 14:55:46 +01:00
Denys Vlasenko d3162773d5 arping: move packet buffer, sigset and struct ifreq to malloced "globals"
This way, we can zero them all in one go.
We do malloc() anyway, thus nothing is lost by mallocing "globals"

function                                             old     new   delta
arping_main                                         1683    1686      +3
finish                                               100      86     -14
catcher                                              350     310     -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-54)             Total: -51 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-11 14:35:46 +01:00
Denys Vlasenko e015d0659f arping: fix the case when inherited signal mask masks out ALRM
function                                             old     new   delta
arping_main                                         1629    1635      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-11 13:48:52 +01:00
Denys Vlasenko a3ec3bd0f8 arping: change a few message strings to be closer to iputils arping
ARPING 192.168.1.1 from 192.168.1.172 wlan0
Unicast reply from 192.168.1.1 [F4:F2:6D:52:A8:DE]  1.672ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)

ARPING 192.168.1.1 from 192.168.1.172 wlan0
Unicast reply from 192.168.1.1 [f4:f2:6d:52:a8:de] 1.152ms
Sent 1 probe(s) (1 broadcast(s))
Received 1 response(s) (0 request(s), 0 broadcast(s))

function                                             old     new   delta
finish                                               120     100     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-11 13:37:07 +01:00
Denys Vlasenko f5d50fbd2f arping: code shrink
Do not clear extra bits on option_mask32, it's not necessary.
Move DAD bit to 2, this makes exit logic simpler.

function                                             old     new   delta
arping_main                                         1655    1629     -26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-11 13:27:54 +01:00
Denys Vlasenko 3f52d13647 svlogd: improve --help text
function                                             old     new   delta
packed_usage                                       32278   32367     +89

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-09 20:21:01 +01:00
Denys Vlasenko f786901c4b hush: probably fixing a bug in last LINENO fix
I don't have an example of mishandled script, but the logic looked wrong:
it could sometimes treat newlines as if they are spaces.

function                                             old     new   delta
parse_stream                                        2788    2787      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-08 19:39:42 +01:00
Denys Vlasenko 5807e18f0c hush: LINENO fix
Script triggering the bug:

	t=0
	echo "at line ${LINENO}"
	while [ ${t} -lt 10 ]; do
		echo "at line ${LINENO}"  # LINENO was 3 instead of 4 here
		t=$((t+1))
	done

function                                             old     new   delta
parse_stream                                        2754    2788     +34
done_word                                            711     738     +27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 61/0)               Total: 61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-08 19:19:04 +01:00
Denys Vlasenko 68ae54243c ip: fix crash in "ip neigh show"
parse_rtattr() was using tb[] array without initializing it.

Based on patch by Balaji Punnuru <balaji_punnuru@cable.comcast.com>

function                                             old     new   delta
parse_rtattr                                          85     107     +22
print_route                                         1630    1617     -13
print_linkinfo                                       807     794     -13
iproute_get                                          835     822     -13
print_rule                                           680     665     -15
ll_remember_index                                    263     248     -15
print_addrinfo                                      1223    1197     -26
ipaddr_list_or_flush                                1253    1223     -30
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/7 up/down: 22/-125)          Total: -103 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-08 08:42:37 +01:00
Denys Vlasenko 237a900bc5 wget: do not ask for TLS-encrypted downloads on plain ftp:// URLs
function                                             old     new   delta
wget_main                                           2422    2431      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-08 00:28:30 +01:00
Denys Vlasenko 47529d3f16 libbb: shrink wget/tftp progress indicator code a bit more
This makes size display 5-char wide instead of 6-char, but now it's smarter
(can show sizes in "12.3M" format).

function                                             old     new   delta
bb_progress_update                                   654     622     -32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-07 23:48:34 +01:00
Denys Vlasenko ab843e3244 libbb: shrink wget/tftp progress indicator code for 32-bit
function                                             old     new   delta
bb_progress_update                                   756     654    -102

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-07 17:47:39 +01:00
Denys Vlasenko 2bd5b4e9a0 udhcp: do not setlinebuf(stdout), we don't print to stdout anymore
Since bb_info_msg() was eliminated type of buffering on stdout is not important

function                                             old     new   delta
udhcpd_main                                         1463    1451     -12
udhcpc_main                                         2735    2723     -12
setlinebuf                                            19       -     -19
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-43)             Total: -43 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-07 16:32:30 +01:00
Denys Vlasenko 4cae044b43 bzip2: expose tuning knob for faster/smaller code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-07 01:33:25 +01:00
Denys Vlasenko 2b7515722b wget: attempt to negotiate encrypted data ftps stream ("PROT P")
function                                             old     new   delta
wget_main                                           2382    2422     +40

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 20:49:27 +01:00
Denys Vlasenko 1267770a9d fix compile failure in previous commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 18:01:39 +01:00
Denys Vlasenko 5cdd120f0c unzip: do not set directory mode to 0777
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=882177

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 17:59:32 +01:00
Denys Vlasenko 0a90960f44 ar: hopefully fix out-of-bounds read in get_header_ar()
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=882175

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 17:39:45 +01:00
Denys Vlasenko 8d943175ce fix a thinko in parse_pasv_epsv.c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 17:11:15 +01:00
Denys Vlasenko 1783ffa990 wget: add EPSV support
function                                             old     new   delta
parse_pasv_epsv                                        -     151    +151
wget_main                                           2440    2382     -58
xconnect_ftpdata                                     223      94    -129
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 151/-187)          Total: -36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 15:48:12 +01:00
Denys Vlasenko 403f2999f9 wget: initial support for ftps://
function                                             old     new   delta
spawn_ssl_client                                       -     185    +185
parse_url                                            409     461     +52
packed_usage                                       32259   32278     +19
tls_run_copy_loop                                    293     306     +13
ssl_client_main                                      128     138     +10
showmode                                             330     338      +8
P_FTPS                                                 -       5      +5
filter_datapoints                                    177     179      +2
deflate                                              907     905      -2
decode_one_format                                    723     716      -7
wget_main                                           2591    2440    -151
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 6/3 up/down: 294/-160)          Total: 134 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 15:15:08 +01:00
Denys Vlasenko e999657f6d wget: preparations for ftps:// support (block move, no code changes)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 15:02:16 +01:00
Denys Vlasenko 98066662aa tls: fix hash calculations if client cert is requested and sent
Symptoms: connecting to
    openssl s_server -cert vsftpd.pem -port 990 -debug -cipher AES128-SHA
works, but with "-verify 1" option added it does not.

function                                             old     new   delta
tls_xread_record                                     474     499     +25
tls_handshake                                       1582    1607     +25
bad_record_die                                        98     110     +12
tls_run_copy_loop                                    282     293     +11
tls_xread_handshake_block                             58      51      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 73/-7)              Total: 66 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06 13:33:00 +01:00
Denys Vlasenko 5740e15de5 ftpd: handle restarts past 2147483647 bytes. closes 10741
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-05 19:06:40 +01:00
Denys Vlasenko c2a51b0cf1 bzip2: work around bad compiler optimization
gc-6.1.1 x86_64:
function                                             old     new   delta
generateMTFValues                                    380     367     -13

gcc-4.3.1 386:
function                                             old     new   delta
inner_loop                                             -      41     +41
generateMTFValues                                    357     294     -63
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 41/-63)            Total: -22 bytes

gcc-6.3.0 386:
function                                             old     new   delta
inner_loop                                             -      36     +36
generateMTFValues                                    363     250    -113
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 36/-113)           Total: -77 bytes

The last case, gcc-6.3.0, runs almost 3 times faster after this change.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-05 00:34:08 +01:00
Denys Vlasenko f75a7c0439 ftpd: fix aliasing warning from gcc-6.1.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-04 23:55:14 +01:00
Denys Vlasenko 05b84d4e92 ftpgetput: add EPSV support (PASV-like thing for IPv6)
Based on a patch by Kev Kitchens.

function                                             old     new   delta
xconnect_ftpdata                                     149     223     +74

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-04 19:08:34 +01:00
Denys Vlasenko daa643205f ftpgetput: preparations for ESPV support, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-04 18:49:31 +01:00
Denys Vlasenko 565af23222 ftpd: switch to mallced "globals"
function                                             old     new   delta
cmdio_write_ok                                        45      49      +4
cmdio_write_error                                     45      49      +4
handle_dir_common                                    360     363      +3
handle_cwd                                            40      43      +3
port_or_pasv_was_seen                                 37      39      +2
pasv_active                                           13      15      +2
cmdio_write_raw                                       34      36      +2
cmdio_write                                           78      80      +2
get_remote_transfer_fd                                94      93      -1
port_pasv_cleanup                                     50      45      -5
bind_for_passive_mode                                124     119      -5
cmdio_get_cmd_and_arg                                237     230      -7
timeout_handler                                      104      93     -11
ftpd_main                                           2222    2152     -70
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/6 up/down: 22/-99)            Total: -77 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-04 18:32:21 +01:00
Denys Vlasenko 2598915d43 gunzip: fix from gzip-1.3.12 for gzip file with all zero length codes
Corresponding changelog from gzip-1.3.12 reads:

"""
2006-12-20  Paul Eggert  <eggert@cs.ucla.edu>
        * inflate.c (huft_build): Fix regression that caused gzip to
        refuse to uncompress null input (all zero length codes).  Problem
        reported by Yiorgos Adamopoulos.  This regression was caused by
        the security patch installed 2006-11-20, which in turn came from
        Debian, which in turn apparently came from Thomas Biege of SuSe.
"""

function                                             old     new   delta
huft_build                                          1176    1216     +40

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-04 00:15:29 +01:00
Denys Vlasenko 0e60a36c92 bzip2: move runningOrder[] back to stack - 256 bytes is not much
function                                             old     new   delta
mainSort                                            1119    1108     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 22:52:55 +01:00
Denys Vlasenko 86be6d5ba9 bzip2: move ->origPtr out of struct EState, make a few members smaller
function                                             old     new   delta
BZ2_compressBlock                                    223     228      +5
BZ2_blockSort                                         85      88      +3
generateMTFValues                                    356     357      +1
handle_compress                                      355     349      -6
compressStream                                       538     531      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/2 up/down: 9/-13)              Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 20:51:12 +01:00
Denys Vlasenko c9ae8d770b bzip2: pass sorting params through EState* pointer
function                                             old     new   delta
mainGtU                                              499     515     +16
sendMTFValues                                       2085    2094      +9
mainSort                                            1116    1119      +3
generateMTFValues                                    357     356      -1
fallbackSort                                        1719    1705     -14
mainQSort3                                          1163    1141     -22
BZ2_blockSort                                        118      85     -33
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/4 up/down: 28/-70)            Total: -42 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 20:19:51 +01:00
Denys Vlasenko 10f516500e gzip2: small simplification in mainSimpleSort()
function                                             old     new   delta
mainQSort3                                          1165    1163      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 19:11:00 +01:00
Denys Vlasenko 0599a137ba bzip2: a few more locals converted to generic types
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 18:47:34 +01:00
Denys Vlasenko 8e31412231 bzip2: eliminate one parameter to mainQSort3()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 18:28:10 +01:00
Denys Vlasenko 9431bdd189 bzip2: small simplification in mainSort()
function                                             old     new   delta
mainSort                                            1127    1118      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 18:11:08 +01:00
Denys Vlasenko fe1bab4d35 bzip2: convert some locals to unsigned's
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 18:03:33 +01:00
Denys Vlasenko c364d32ccc bzip2: runningOrder[] values are always 0..255, make it uint8
function                                             old     new   delta
mainSort                                            1171    1124     -47

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 17:44:00 +01:00
Denys Vlasenko df23f55e39 bzip2: remove redundant clearing of an alredy unset bit
function                                             old     new   delta
mainSort                                            1178    1171      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 17:38:23 +01:00
Denys Vlasenko 524fa29a93 bzip2: eliminate write-only local numQSorted
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 17:30:16 +01:00
Denys Vlasenko 2109fce410 bzip2: make locals in mainSort() saner, convert one of them from uint16 to unsigned
function                                             old     new   delta
mainSort                                            1192    1178     -14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 17:22:06 +01:00
Denys Vlasenko aaa3818a75 bzip2: remove redundant loop termination check in mainSort()
function                                             old     new   delta
mainSort                                            1202    1192     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 16:43:33 +01:00
Denys Vlasenko e59e5ff96e bzip2: reduce indentation, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 15:59:46 +01:00
Denys Vlasenko 9e5662ea74 bzip2: reuse zPend processing code
function                                             old     new   delta
generateMTFValues                                    378     357     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 15:53:17 +01:00
Denys Vlasenko 2cfe10a558 bzip2: shrink makeMaps_e()
function                                             old     new   delta
generateMTFValues                                    378     368     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 15:31:54 +01:00
Denys Vlasenko 1cbcb02316 bzip2: optimize zPend variable code
function                                             old     new   delta
generateMTFValues                                    433     378     -55

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 15:26:00 +01:00
Denys Vlasenko fc228b48c9 bzip2: have two separate "store bit 0" and "store bit 1" functions
function                                             old     new   delta
sendMTFValues                                       2051    2085     +34
bsW1_0                                                 -      33     +33
BZ2_compressBlock                                    225     223      -2
bsW1                                                  52       -     -52
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/1 up/down: 67/-54)             Total: 13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 14:56:43 +01:00
Denys Vlasenko feafb3423e bzip2: ~1% speedup by special-casing "store 1 bit" function
function                                             old     new   delta
bsW1                                                   -      52     +52
BZ2_compressBlock                                    230     225      -5
BZ2_blockSort                                        125     118      -7
sendMTFValues                                       2070    2051     -19
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 52/-31)             Total: 21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 04:43:46 +01:00
Denys Vlasenko 982c44d030 bzip2: rewrite bit of code which depends on integer overflow
function                                             old     new   delta
sendMTFValues                                       2093    2070     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 03:34:40 +01:00
Denys Vlasenko 83dd4ff696 bzip2: delete write-only fave[] array
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 03:17:48 +01:00
Denys Vlasenko 3a2c97bd12 bgip2: fewer specifically-sized [u]int32_t's locals in sendMTFValues
Generic ints/unsigneds are usually fine. Yes, really.

function                                             old     new   delta
sendMTFValues                                       2100    2093      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 03:14:07 +01:00
Denys Vlasenko 359230da8e bzip2: code shrink
function                                             old     new   delta
sendMTFValues                                       2111    2100     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 02:03:42 +01:00
Denys Vlasenko e594fb2171 bzip2: code shrink
function                                             old     new   delta
BZ2_compressBlock                                    225     230      +5
handle_compress                                      356     355      -1
bsW16                                                 59      56      -3
bsW                                                   64      61      -3
bsFinishWrite                                         37      32      -5
prepare_new_block                                     48      34     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/5 up/down: 5/-26)             Total: -21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-03 01:30:12 +01:00
Denys Vlasenko 125c3ff4b1 bzip2: code shrink
function                                             old     new   delta
bsW16                                                  -      59     +59
sendMTFValues                                       2116    2111      -5
bsPutU16                                              36       -     -36
bsPutU32                                              76      31     -45
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 59/-86)            Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-02 20:59:28 +01:00
Denys Vlasenko da49e7057a cksum: code shrink
function                                             old     new   delta
cksum_main                                           281     262     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 11:44:52 +01:00
Denys Vlasenko ddacb03e87 libbb: commonalize a bit of little-endian CRC32 table generation code
function                                             old     new   delta
global_crc32_new_table_le                              -      11     +11
crc32_new_table_le                                     -       9      +9
inflate_unzip_internal                               560     556      -4
flash_eraseall_main                                  823     819      -4
unpack_xz_stream                                    2403    2394      -9
lzop_main                                            121     112      -9
gzip_main                                            187     178      -9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/5 up/down: 20/-35)            Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 10:56:19 +01:00
Denys Vlasenko 06076494da udhcpd: use ptr_to_globals for its lone global data (g_leases)
function                                             old     new   delta
udhcpd_main                                         1461    1463      +2
add_lease                                            320     318      -2
g_leases                                               4       -      -4
write_leases                                         223     214      -9
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 2/-15)             Total: -13 bytes
   text	   data	    bss	    dec	    hex	filename
 933232	    481	   6856	 940569	  e5a19	busybox_old
 933223	    481	   6852	 940556	  e5a0c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 10:41:14 +01:00
Aaro Koskinen d15d7a0a4b cp: implement -T
Implement "cp -T". Some Linux kernel Makefiles started using this recently,
so allow also building on systems using busybox cp.

function                                             old     new   delta
cp_main                                              360     428     +68
copy_file                                           1678    1676      -2
packed_usage                                       32290   32259     -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 76/-39)             Total: 35 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 09:30:59 +01:00
Denys Vlasenko d6f0f03b68 libarchive: move bbunpack constants to bb_archive.h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 09:13:14 +01:00
Denys Vlasenko 99ac1759dd lzop: code shrink
function                                             old     new   delta
lzo_decompress                                       526     524      -2
lzo_compress                                         473     470      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 01:41:31 +01:00
Denys Vlasenko 97058d0585 unlzop: fix --help: it has -U instead of -k
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 01:03:50 +01:00
Denys Vlasenko 1b8ac93a20 bzip2: code shrink, stop using global data variable
function                                             old     new   delta
compressStream                                       523     538     +15
level                                                  1       -      -1
bzip2_main                                           110      73     -37
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 15/-38)            Total: -23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-01 01:00:58 +01:00
Denys Vlasenko 54a174eb01 gzip: "compressed_len" is unused, stop wasting code and time calculating it
function                                             old     new   delta
flush_block                                          595     523     -72

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 23:26:11 +01:00
Denys Vlasenko a142926029 gzip: remove unnecessary forward declarations, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 18:16:34 +01:00
Denys Vlasenko 919bc9d43c gzip: flush output buffer after stored blocks only if necessary
function                                             old     new   delta
flush_block                                          671     680      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 17:37:32 +01:00
Denys Vlasenko f21ebeece5 gzip: flush output buffer after stored blocks, they are not 32-bit aligned
function                                             old     new   delta
flush_block                                          665     671      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 17:19:59 +01:00
Denys Vlasenko ba63d70e2d gzip: make debugging of bits_sent less ugly, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 17:00:41 +01:00
Denys Vlasenko 26eea71c87 gzip: code shrink
function                                             old     new   delta
flush_block                                          668     665      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 16:36:17 +01:00
Denys Vlasenko 05251986c7 gzip: code shrink
Use one memset to clear part of G1, and all of G2.

function                                             old     new   delta
pack_gzip                                            838     828     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 16:11:56 +01:00
Denys Vlasenko 8fd35a1fa6 gzip: code shrink
function                                             old     new   delta
pack_gzip                                            861     838     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 15:42:45 +01:00
Denys Vlasenko 468731a86b gzip: code shrink and speedup
function                                             old     new   delta
pack_gzip                                            908     861     -47

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 15:32:32 +01:00
Denys Vlasenko 631c16855a gzip: optionally faster put_32bit()
function                                             old     new   delta
put_32bit                                             22      55     +33

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 00:42:29 +01:00
Denys Vlasenko b7dfbbcdaa gzip: speed up send_bits()
Replace one RMW op with store. This speeds up gzip of a png file by ~2%.

function                                             old     new   delta
send_bits                                             62      66      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-31 00:01:06 +01:00
Denys Vlasenko d7500f856d gzip: use "unsigned" type for bit fields and bit counts
This does not change any logic, those values should always be positive.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-30 23:53:38 +01:00
Denys Vlasenko 6ba6a6f28e gzip: use wider (32-bit, not 16) bi_buf
function                                             old     new   delta
bi_windup                                             76      74      -2
send_bits                                             70      62      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-30 23:47:45 +01:00
Denys Vlasenko e4c4e6ddc3 gzip: code shrink
function                                             old     new   delta
send_bits                                             92      70     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-30 22:37:06 +01:00
Denys Vlasenko 9c499a5af4 gzip: code shrink
function                                             old     new   delta
fill_window_if_needed                                  -     238    +238
deflate                                              924     907     -17
pack_gzip                                            809     790     -19
fill_window                                          216       -    -216
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 238/-252)          Total: -14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-30 18:15:39 +01:00
Denys Vlasenko c6d2a26fac gzip: code shrink (consolidate zeroing on reinit)
function                                             old     new   delta
deflate                                                -     938    +938
pack_gzip                                           1903     923    -980

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-30 17:39:57 +01:00
Denys Vlasenko 749575d3c5 hush: protect against self-modifying trap code
function                                             old     new   delta
check_and_run_traps                                  211     236     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-30 04:29:03 +01:00
Denys Vlasenko 6f9442ff30 ash: make it possible to disable "const global ptr" optimization
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-28 20:41:23 +01:00
Denys Vlasenko f19e3c1c6c shell: handle $((NUM++...) like bash does. Closes 10706
function                                             old     new   delta
evaluate_string                                      680     729     +49

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-28 20:13:33 +01:00
Denys Vlasenko 675d24aeaf ash: add LINENO support
This patch is a backport from dash of the combination of:
    [SHELL] Add preliminary LINENO support
    [VAR] Fix varinit ordering that broke fc
    [SHELL] Improve LINENO support

function                                             old     new   delta
parse_command                                       1604    1677     +73
calcsize                                             156     223     +67
copynode                                             196     258     +62
evalcommand                                         1546    1606     +60
ash_main                                            1046    1103     +57
lookupvar                                             51     106     +55
evalcase                                             269     317     +48
evaltree                                             501     547     +46
evalfor                                              156     200     +44
evalsubshell                                         156     195     +39
raise_error_syntax                                    11      29     +18
varinit_data                                         120     132     +12
evalfun                                              270     280     +10
funcline                                               -       4      +4
cmdtxt                                               569     572      +3
trapcmd                                              306     304      -2
ash_vmsg                                             153     150      -3
startlinno                                             4       -      -4
funcnest                                               4       -      -4
xxreadtoken                                          263     250     -13
readtoken1                                          2645    2602     -43
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 14/4 up/down: 598/-69)          Total: 529 bytes
   text	   data	    bss	    dec	    hex	filename
 932834	    481	   6864	 940179	  e5893	busybox_old
 933375	    481	   6856	 940712	  e5aa8	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27 22:02:05 +01:00
Denys Vlasenko 54c2111781 hush: add HUSH_BASH_SOURCE_CURDIR config option, to be on par with ash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27 20:46:45 +01:00
Denys Vlasenko f7e0feaf97 hush: fix dot builtin to not search current directory
function                                             old     new   delta
builtin_source                                       182     209     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27 19:05:59 +01:00
Denys Vlasenko bb373dbc32 tar: accomodate non-terminated tar.chksum fields as seen from github.com
function                                             old     new   delta
get_header_tar                                      1783    1696     -87

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27 19:04:08 +01:00
Denys Vlasenko 01f7b9e182 ash: introduce a config option to search current directory for sourced files
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-26 15:15:43 +01:00
Denys Vlasenko e503962981 gzip: fix debug code. Closes 10681
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-26 00:21:25 +01:00
Nicholas Clark 77a6678c42 dd: add 'fullblock' iflag
Adds a fullblock iflag for improved compatibility with GNU dd.
The new iflag can be used to ensure that dd calls retrieve the
expected amount of data when reading from pipes or unusual
filesystems.

function                                             old     new   delta
packed_usage                                       32249   32334     +85
dd_main                                             1582    1632     +50
static.iflag_words                                    12      22     +10
------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 145/0)             Total: 145 bytes

Signed-off-by: Nicholas Clark <nicholas.clark@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25 19:00:19 +01:00
Denys Vlasenko 043be55691 ash testsuite: add two hush tests from last commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25 14:09:06 +01:00
Denys Vlasenko cba79a87f8 hush: fix two corner cases in ${v/pattern/repl}. Closes 10686
function                                             old     new   delta
expand_one_var                                      1592    1618     +26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25 14:07:40 +01:00
Denys Vlasenko 0ca3198f93 hush: fix handling of $_ (so far it's an ordinary variable, no special meaning)
function                                             old     new   delta
parse_dollar                                         820     779     -41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25 13:20:50 +01:00
Denys Vlasenko a497231f53 chrt: code shrink
function                                             old     new   delta
show_min_max                                          60      59      -1
policies                                              96      72     -24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-25 09:34:23 +01:00
William Pitcock d8fd88a091 ash: add support for command_not_found_handle hook function (bashism)
This implements support for the command_not_found_handle hook function, which is
useful for allowing package managers to suggest packages which could provide the
command.

Unlike bash, however, we ignore exit codes from the hook function and always return
the correct POSIX error code (EX_NOTFOUND).

function                                             old     new   delta
find_command                                         911     990     +79

Signed-off-by: William Pitcock <nenolod@dereferenced.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-24 18:33:18 +01:00
Denys Vlasenko 14bc965ea9 less: fix help text conditional for -R
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-24 16:47:08 +01:00
Denys Vlasenko 30b290f996 udhcpc6: additional fix for ppp interface type
Invent a fictitious MAC only once

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-23 16:46:31 +01:00
Denys Vlasenko 66ad9be603 chrt: use correct min/max priorities
function                                             old     new   delta
chrt_main                                            369     432     +63
policies                                              48      96     +48
packed_usage                                       32239   32249     +10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 121/0)             Total: 121 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-23 16:04:48 +01:00
Povilas Kanapickas 0f6e4350b3 chrt: add support for SCHED_IDLE
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-23 16:04:48 +01:00
Povilas Kanapickas 1616fb8aca chrt: add support for SCHED_BATCH
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-23 16:04:48 +01:00
Denys Vlasenko 2b9a45b9e8 od_bloaty: fix debug code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-23 14:49:12 +01:00
Denys Vlasenko 8528d3d4f8 less: optional support of -R
Based on patches by Lubomir Rintel <lkundrak@v3.sk>

function                                             old     new   delta
read_lines                                           653     722     +69
less_main                                           2464    2531     +67
packed_usage                                       32202   32239     +37
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 173/0)             Total: 173 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-22 14:38:51 +01:00
Sven-Göran Bergh e411cd071a volume_id: add LittleFS detection
Add support for LittleFS to blkid. Not included if FEATURE_BLKID_TYPE
is not selected (neither UUID nor label).

LittleFS is a small fail-safe filesystem designed for embedded
systems. It has strong copy-on-write guarantees and storage on disk
is always kept in a valid state. It also provides a form of dynamic
wear levelling for systems that can not fit a full flash translation
layer. (https://github.com/geky/littlefs)

ARM has introduced it in its Mbed OS 5.7, so it starts to gain focus.
(https://os.mbed.com/blog/entry/littlefs-high-integrity-embedded-fs/)

function                                             old     new   delta
volume_id_probe_lfs                                    -      62     +62
fs1                                                   20      24      +4

Signed-off-by: Sven-Göran Bergh <sgb@systemaxion.se>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19 20:37:13 +01:00
Denys Vlasenko f6dd9e0215 udhcpc6: fix for ppp interface type
function                                             old     new   delta
d6_read_interface                                    454     600    +146

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19 18:44:19 +01:00
Denys Vlasenko 46f839c3f7 hush: fix a case where EXIT trap may modify its code mid-flight
function                                             old     new   delta
hush_exit                                             93      99      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19 16:58:44 +01:00
Denys Vlasenko b8d076b00b hush: fix build if !BASH_LINENO_VAR
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19 16:00:57 +01:00
Denys Vlasenko 6aad1ddcc9 hush: implement $LINENO bashism
function                                             old     new   delta
run_pipe                                            1697    1774     +77
unset_local_var_len                                  258     301     +43
hush_main                                           1009    1051     +42
set_local_var                                        516     554     +38
parse_and_run_file                                    42      75     +33
i_getch                                               96     116     +20
.rodata                                            18858   18876     +18
done_command                                         106     122     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/0 up/down: 287/0)             Total: 287 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-19 15:52:36 +01:00
Denys Vlasenko 7c44b600f9 udhcpc[6]: remove overzealous timeout clamping code
function                                             old     new   delta
udhcpc_main                                         2840    2826     -14
udhcpc6_main                                        2699    2670     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-17 13:55:51 +01:00
Denys Vlasenko 64211ce6fa udhcpc6: --help fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 22:23:38 +01:00
Denys Vlasenko 438c72ece4 udhcpc6: show only short opts in --help text
function                                             old     new   delta
packed_usage                                       26028   25966     -62

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 22:10:12 +01:00
Denys Vlasenko 6e9e6d8fbe udhcpc6: fix lease time staying very small because -d was not specified
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 21:52:23 +01:00
Denys Vlasenko 14f13205ef udhcpc6: code shrink
function                                             old     new   delta
udhcpc6_main                                        2723    2727      +4
.rodata                                           128695  128561    -134

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 21:47:10 +01:00
Denys Vlasenko ef5207f093 udhcpc6: add support of prefix delegation
Based on patch by DannyAAM <danny@saru.moe>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 21:39:14 +01:00
Denys Vlasenko 1e8d79ba12 udhcpc6: preparatory patch, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 21:35:39 +01:00
Denys Vlasenko 688cb3bc19 udhcpc6: fix ipv6prefix[_lease] envvar value in script invocation
Based on a patch by DannyAAM <danny@saru.moe>.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-16 16:00:13 +01:00
Denys Vlasenko 1750d3afc1 ash: a bit of NOFORK code should only be active if FEATURE_SH_STANDALONE=y
function                                             old     new   delta
evalcommand                                         1546    1420    -126

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-15 00:41:04 +01:00
Denys Vlasenko cefdd4be1f popmaildir: tweak help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 20:48:14 +01:00
Denys Vlasenko c4144ca3a5 renice: add comment about getpwnam/NOFORK interaction
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 19:40:00 +01:00
Denys Vlasenko 9967978551 renice: use BUILD_BUG_ON()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 19:05:02 +01:00
Denys Vlasenko 6f1c942a31 NOFORK_NOEXEC.sh: a script to find "interesting" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 14:44:30 +01:00
Denys Vlasenko 88663e481f mv: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 14:41:52 +01:00
Denys Vlasenko cbdc37cae0 cal: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 14:32:11 +01:00
Denys Vlasenko 586f1ee7cf nandwrite: cope with old headers which have no MTD_FILE_MODE_RAW
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 13:43:31 +01:00
Denys Vlasenko 36495af81f size_single_applets.sh: fix a bug which mishandles e.g. "udhcpc6" name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 12:13:16 +01:00
Denys Vlasenko 38da4c4420 config: add size estimations for a few applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-14 12:03:33 +01:00
Denys Vlasenko 12714ffa27 tc: fix single-applet build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-13 21:37:20 +01:00
Denys Vlasenko aea52e7b2d shell: echo ${?:0} was fixed sometime ago, enable it in tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-13 19:28:19 +01:00
Denys Vlasenko 9809a82b59 hush: fix raw ^C handlisg in single-quoted strings
function                                             old     new   delta
parse_stream                                        2719    2754     +35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-13 19:14:27 +01:00
Denys Vlasenko 6606c519ef hush: add command2.tests from ash tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12 17:58:20 +01:00
Denys Vlasenko afb73a25ea hush: tweak command -vV printing code, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12 16:17:59 +01:00
Denys Vlasenko 5700029c65 hush: implement "command -v -V"
function                                             old     new   delta
pseudo_exec_argv                                     231     374    +143
if_command_vV_print_and_exit                           -     127    +127
builtin_set                                          267     273      +6
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 276/0)             Total: 276 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12 14:41:45 +01:00
Denys Vlasenko cca7c611f2 which: fix TODO with NOFORK+malloc_failure misbehaving
function                                             old     new   delta
find_executable                                       86     104     +18
which_main                                           202     194      -8
executable_exists                                     66      51     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 18/-23)             Total: -5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12 13:21:33 +01:00
Denys Vlasenko 3bb3e1d0a1 hush: implement "command" builtin (no options are supported yet)
function                                             old     new   delta
pseudo_exec_argv                                     194     231     +37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11 18:05:05 +01:00
Denys Vlasenko 1f1911239c hush: fix handling of ^C in eval
function                                             old     new   delta
run_list                                            1044    1259    +215
builtin_eval                                          45     126     +81
expand_strvec_to_string                               91       -     -91
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/0 up/down: 296/-91)           Total: 205 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11 13:17:30 +01:00
Denys Vlasenko 932b9971d0 hush: fix handling of raw ^C in scripts: "echo ^C"
function                                             old     new   delta
expand_vars_to_list                                 1133    1187     +54
parse_stream                                        2690    2719     +29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11 12:39:48 +01:00
Denys Vlasenko aaf7a2e24d hush: remove dead code
function                                             old     new   delta
done_word                                            761     711     -50

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11 11:19:00 +01:00
Denys Vlasenko 03c36e0be1 ash: ALWAYS_INLINE grabstackblock()
function                                             old     new   delta
grabstackblock                                         5       -      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-10 15:18:35 +01:00
Denys Vlasenko f2539c78d2 init: stop using static data
function                                             old     new   delta
init_action_list                                       4       -      -4
new_init_action                                      148     142      -6
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-10)             Total: -10 bytes
   text	   data	    bss	    dec	    hex	filename
 927839	    481	   6832	 935152	  e44f0	busybox_old
 927833	    481	   6824	 935138	  e44e2	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-10 13:32:20 +01:00
Denys Vlasenko baa41c7855 ash: make ${v:N:M} more robust for very large M by clamping to MIN/MAX_INT
Before this patch, "${v:2:0x100000001}" = "${v:2:1}",
and similarly, constructs like "${v:2:9999999999}" may give wrong result
due to int overflows.

function                                             old     new   delta
substr_atoi                                            -      43     +43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-10 13:22:25 +01:00
Denys Vlasenko 2c876774a9 dd: fixed partial count logic
$ busybox dd if=/dev/zero of=/dev/loop0 bs=100M count=8; echo $?
8+0 records in
7+0 records out  <=========== FIXED, was 7+1
805220352 bytes (767.9MB) copied, 0.464010 seconds, 1.6GB/s
1

function                                             old     new   delta
write_and_stats                                       97      99      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-10 11:04:09 +01:00
Denys Vlasenko 5afd63a631 dd: exit with 1 if last write was incomplete
$ busybox dd if=/dev/zero of=/dev/loop0 bs=100M count=8; echo $?
8+0 records in
7+1 records out
805220352 bytes (767.9MB) copied, 0.464010 seconds, 1.6GB/s
1  <=========== FIXED

function                                             old     new   delta
write_and_stats                                       96      97      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-10 10:58:55 +01:00
Denys Vlasenko d1df1a709f ash: add comment explaining last change
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-09 17:25:58 +01:00
Denys Vlasenko 740058b42b ash: fix var_bash5.tests - ${VAR/pattern/repl} construct
function                                             old     new   delta
subevalvar                                          1198    1279     +81
rmescapes                                            308     330     +22
preglob                                                8      10      +2
parsefname                                           152     154      +2
expandarg                                            973     975      +2
argstr                                              1144    1146      +2
mklocal                                              290     288      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/1 up/down: 111/-2)            Total: 109 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-09 17:07:06 +01:00
Shawn Landden 4261341281 umount: ignore -c
"-c, --no-canonicalize: Do not canonicalize paths."

As busybox doesn't canonicalize paths in the first place it is safe to ignore
this option.

See https://github.com/systemd/systemd/issues/7786

Signed-off-by: Shawn Landden <slandden@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-08 13:31:58 +01:00
Denys Vlasenko 2f55404bbc mknod: better --help, much clearer code
function                                             old     new   delta
packed_usage                                       32066   32091     +25
mknod_main                                           173     174      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-08 11:22:37 +01:00
Denys Vlasenko 83c99ab446 less: code shrink
function                                             old     new   delta
less_main                                           2471    2464      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-08 10:27:23 +01:00
Denys Vlasenko 562f63e9a4 dhcprelay: code shrink
function                                             old     new   delta
dhcprelay_main                                       961     958      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-08 10:14:17 +01:00
Denys Vlasenko c9807d787d nice: code shrink
function                                             old     new   delta
nice_main                                            157     152      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-08 10:13:11 +01:00
Denys Vlasenko cb9c3894e5 *: make "argc UNUSED_PARAM" consistent
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-08 09:43:51 +01:00
Denys Vlasenko 844a6c5abd awk: code shrink
function                                             old     new   delta
awk_main                                             955     948      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-07 14:39:34 +01:00
Ingo van Lil 9c8e94bc0a ash: fail if 'shift' operand is out of range
If the numeric argument passed to ash's 'shift' built-in is greater than
'$#' the command performs no operation and exits successfully. It should
return a non-zero exit code instead:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#shift

This is consistent with bash and hush.

function                                             old     new   delta
shiftcmd                                             122     120      -2

Signed-off-by: Ingo van Lil <inguin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-07 14:22:38 +01:00
Denys Vlasenko 6f4a785bd1 awk: fix 'delete array[var--]' decrementing var twice
function                                             old     new   delta
evaluate                                            3395    3390      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-07 01:19:08 +01:00
Denys Vlasenko 7367a949a6 libbb: compile obscure() only if FEATURE_PASSWD_WEAK_CHECK=y
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-04 15:21:25 +01:00
Yann E. MORIN a47375de8c build system: add rule to install without cloberring existing utilities
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-04 14:43:46 +01:00
Yann E. MORIN 952d5a6024 applets/install: accept more than one install option
Currently, it is impossible to pass more than one option to the isntall
script, so it totally prevents using --noclobber.

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-04 14:43:46 +01:00
Yann E. MORIN 84be5ce0d8 applets/install: respect noclobber for script wrappers too
Simplify the handling of --noclobber so that it applies to all types of
installation types, even to script wrappers.

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-04 14:36:17 +01:00
Denys Vlasenko a034cab095 tc: enables this applet
function                                             old     new   delta
tc_main                                                -     946    +946
cbq_print_opt                                          -     517    +517
print_qdisc                                            -     475    +475
print_class                                            -     359    +359
llproto_names                                          -     264    +264
packed_usage                                       31853   32066    +213
ll_proto_a2n                                           -     112    +112
llproto_ids                                            -      86     +86
print_tc_classid                                       -      82     +82
static.objects                                         -      20     +20
static._q_                                             -      16     +16
applet_main                                         1564    1568      +4
print_filter                                           -       3      +3
applet_names                                        2708    2711      +3
------------------------------------------------------------------------------
(add/remove: 13/0 grow/shrink: 3/0 up/down: 3100/0)          Total: 3100 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-04 10:27:51 +01:00
Denys Vlasenko d75f9081d4 Start 1.29.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-02 06:11:19 +01:00
439 changed files with 9536 additions and 4551 deletions

No files matched your search

+9 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
mainmenu "Configuration"
@@ -518,6 +518,14 @@ config USE_PORTABLE_CODE
compiler other than gcc.
If you do use gcc, this option may needlessly increase code size.
config STACK_OPTIMIZATION_386
bool "Use -mpreferred-stack-boundary=2 on i386 arch"
default y
help
This option makes for smaller code, but some libc versions
do not work with it (they use SSE instructions without
ensuring stack alignment).
comment 'Installation Options ("make install" behavior)'
choice
+3 -3
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 28
SUBLEVEL = 0
PATCHLEVEL = 29
SUBLEVEL = 3
EXTRAVERSION =
NAME = Unnamed
@@ -368,7 +368,7 @@ gen_build_files: $(wildcard $(srctree)/*/*.c) $(wildcard $(srctree)/*/*/*.c)
# we depend on scripts_basic, since scripts/basic/fixdep
# must be built before any other host prog
PHONY += applets_dir
applets_dir: scripts_basic gen_build_files
applets_dir: scripts_basic gen_build_files include/config/MARKER
$(Q)$(MAKE) $(build)=applets
applets/%: applets_dir ;
+6
View File
@@ -11,6 +11,9 @@ busybox.cfg.nosuid: $(srctree)/applets/busybox.mksuid $(objtree)/include/autocon
$(Q)-SUID="DROP" $(SHELL) $^ > $@
.PHONY: install
ifeq ($(CONFIG_INSTALL_APPLET_DONT),y)
INSTALL_OPTS:= --none
endif
ifeq ($(CONFIG_INSTALL_APPLET_SYMLINKS),y)
INSTALL_OPTS:= --symlinks
endif
@@ -46,6 +49,9 @@ ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
@echo
endif
install-noclobber: INSTALL_OPTS+=--noclobber
install-noclobber: install
uninstall: busybox.links
rm -f $(CONFIG_PREFIX)/bin/busybox
for i in `cat busybox.links` ; do rm -f $(CONFIG_PREFIX)$$i; done
+4
View File
@@ -156,6 +156,10 @@ CPPFLAGS += $(SELINUX_CFLAGS)
LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%))
endif
ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
LDLIBS += resolv
endif
ifeq ($(CONFIG_EFENCE),y)
LDLIBS += efence
endif
+3 -3
View File
@@ -72,7 +72,7 @@ brctl - noexec
bunzip2 - runner
bzcat - runner
bzip2 - runner
cal - runner: cal -n9999
cal - noexec. can be runner: cal -n9999
cat - runner: cat HUGEFILE
chat - longterm (when used as intended - talking to modem over stdin/out)
chattr - noexec. runner
@@ -89,7 +89,7 @@ clear - NOFORK
cmp - runner
comm - runner
conspy - interactive, longterm
cp - noexec. runner
cp - noexec. sometimes runner
cpio - runner
crond - daemon
crontab - longterm (runs $EDITOR), leaks: open+xasprintf
@@ -255,7 +255,7 @@ mount - suid
mountpoint - noexec. leaks: option -n "print dev name": find_block_device -> readdir+xstrdup
mpstat - longterm: "mpstat 1" runs indefinitely
mt - hardware
mv - noexec candidate, runner
mv - noexec. sometimes runner
nameif - noexec. openlog(), leaks: config_open2+ioctl_or_perror_and_die
nbd-client - noexec
nc - runner
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh
exec >NOFORK_NOEXEC.lst1
false && grep -Fv 'NOFORK' NOFORK_NOEXEC.lst \
| grep -v 'noexec.' | grep -v 'noexec$' \
| grep -v ' suid' \
| grep -v ' daemon' \
| grep -v ' longterm' \
| grep rare
echo === nofork candidate
grep -F 'nofork candidate' NOFORK_NOEXEC.lst \
echo === noexec candidate
grep -F 'noexec candidate' NOFORK_NOEXEC.lst \
echo === ^C
grep -F '^C' NOFORK_NOEXEC.lst \
| grep -F ' - ' \
echo === talks
grep -F 'talks' NOFORK_NOEXEC.lst \
| grep -F ' - ' \
echo ===
grep -Fv 'NOFORK' NOFORK_NOEXEC.lst \
| grep '^[^ ][^ ]* - ' \
| grep -v 'noexec.' | grep -v ' - noexec$' \
| grep -v ' suid' \
| grep -v ' daemon' \
| grep -v 'longterm' \
| grep -v 'interactive' \
| grep -v 'hardware' \
+14 -2
View File
@@ -10,6 +10,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -61,6 +62,7 @@ static int str_isalnum_(const char *s)
int main(int argc, char **argv)
{
int i, j;
char tmp1[PATH_MAX], tmp2[PATH_MAX];
// In find_applet_by_name(), before linear search, narrow it down
// by looking at N "equidistant" names. With ~350 applets:
@@ -84,7 +86,8 @@ int main(int argc, char **argv)
if (!argv[1])
return 1;
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
snprintf(tmp1, PATH_MAX, "%s.%u.new", argv[1], (int) getpid());
i = open(tmp1, O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (i < 0)
return 1;
dup2(i, 1);
@@ -209,12 +212,21 @@ int main(int argc, char **argv)
// fclose(fp);
// }
// if (strcmp(line_old, line_new) != 0) {
fp = fopen(argv[2], "w");
snprintf(tmp2, PATH_MAX, "%s.%u.new", argv[2], (int) getpid());
fp = fopen(tmp2, "w");
if (!fp)
return 1;
fputs(line_new, fp);
if (fclose(fp))
return 1;
// }
}
if (fclose(stdout))
return 1;
if (rename(tmp1, argv[1]))
return 1;
if (rename(tmp2, argv[2]))
return 1;
return 0;
}
+34 -32
View File
@@ -5,9 +5,12 @@ export LC_CTYPE=POSIX
prefix=$1
if [ -z "$prefix" ]; then
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
echo "usage: applets/install.sh DESTINATION TYPE [OPTS ...]"
echo " TYPE is one of: --symlinks --hardlinks --binaries --scriptwrapper --none"
echo " OPTS is one or more of: --cleanup --noclobber"
exit 1
fi
shift # Keep only remaining options
# Source the configuration
. ./.config
@@ -21,20 +24,23 @@ scriptwrapper="n"
binaries="n"
cleanup="0"
noclobber="0"
case "$2" in
--hardlinks) linkopts="-f";;
--symlinks) linkopts="-fs";;
--binaries) binaries="y";;
--scriptwrapper) scriptwrapper="y";swrapall="y";;
--sw-sh-hard) scriptwrapper="y";linkopts="-f";;
--sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
--cleanup) cleanup="1";;
--noclobber) noclobber="1";;
"") h="";;
*) echo "Unknown install option: $2"; exit 1;;
esac
while [ ${#} -gt 0 ]; do
case "$1" in
--hardlinks) linkopts="-f";;
--symlinks) linkopts="-fs";;
--binaries) binaries="y";;
--scriptwrapper) scriptwrapper="y"; swrapall="y";;
--sw-sh-hard) scriptwrapper="y"; linkopts="-f";;
--sw-sh-sym) scriptwrapper="y"; linkopts="-fs";;
--cleanup) cleanup="1";;
--noclobber) noclobber="1";;
--none) h="";;
*) echo "Unknown install option: $1"; exit 1;;
esac
shift
done
if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then
# get the target dir for the libs
# assume it starts with lib
libdir=$($CC -print-file-name=libc.so | \
@@ -54,7 +60,7 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
done
fi
if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
if [ x"$cleanup" = x"1" ] && [ -e "$prefix/bin/busybox" ]; then
inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
sub_shell_it=`
cd "$prefix"
@@ -77,9 +83,13 @@ install -m 755 busybox "$prefix/bin/busybox" || exit 1
for i in $h; do
appdir=`dirname "$i"`
app=`basename "$i"`
if [ x"$noclobber" = x"1" ] && [ -e "$prefix/$i" ]; then
echo " $prefix/$i already exists"
continue
fi
mkdir -p "$prefix/$appdir" || exit 1
if [ "$scriptwrapper" = "y" ]; then
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
if [ x"$scriptwrapper" = x"y" ]; then
if [ x"$swrapall" != x"y" ] && [ x"$i" = x"/bin/sh" ]; then
ln $linkopts busybox "$prefix/$i" || exit 1
else
rm -f "$prefix/$i"
@@ -87,21 +97,17 @@ for i in $h; do
chmod +x "$prefix/$i"
fi
echo " $prefix/$i"
elif [ "$binaries" = "y" ]; then
elif [ x"$binaries" = x"y" ]; then
# Copy the binary over rather
if [ -e $sharedlib_dir/$app ]; then
if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
echo " Copying $sharedlib_dir/$app to $prefix/$i"
cp -pPR $sharedlib_dir/$app $prefix/$i || exit 1
else
echo " $prefix/$i already exists"
fi
if [ -e "$sharedlib_dir/$app" ]; then
echo " Copying $sharedlib_dir/$app to $prefix/$i"
cp -pPR "$sharedlib_dir/$app" "$prefix/$i" || exit 1
else
echo "Error: Could not find $sharedlib_dir/$app"
exit 1
fi
else
if [ "$2" = "--hardlinks" ]; then
if [ x"$linkopts" = x"-f" ]; then
bb_path="$prefix/bin/busybox"
else
case "$appdir" in
@@ -123,12 +129,8 @@ for i in $h; do
;;
esac
fi
if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
echo " $prefix/$i -> $bb_path"
ln $linkopts "$bb_path" "$prefix/$i" || exit 1
else
echo " $prefix/$i already exists"
fi
echo " $prefix/$i -> $bb_path"
ln $linkopts "$bb_path" "$prefix/$i" || exit 1
fi
done
+7 -1
View File
@@ -2,6 +2,12 @@
# Build system
# ==========================================================================
# Allow i486 insns (basically, bswap insn)
# Do not try to tune for 486+ (might add padding)
CFLAGS += $(call cc-option,-march=i486 -mtune=i386,)
ifeq ($(CONFIG_STACK_OPTIMIZATION_386),y)
# -mpreferred-stack-boundary=2 is essential in preventing gcc 4.2.x
# from aligning stack to 16 bytes. (Which is gcc's way of supporting SSE).
CFLAGS += $(call cc-option,-march=i386 -mpreferred-stack-boundary=2,)
CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2,)
endif
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "Archival Utilities"
+22 -35
View File
@@ -21,19 +21,6 @@
#include "libbb.h"
#include "bb_archive.h"
/* Note: must be kept in sync with archival/lzop.c */
enum {
OPT_STDOUT = 1 << 0,
OPT_FORCE = 1 << 1,
/* only some decompressors: */
OPT_KEEP = 1 << 2,
OPT_VERBOSE = 1 << 3,
OPT_QUIET = 1 << 4,
OPT_DECOMPRESS = 1 << 5,
OPT_TEST = 1 << 6,
SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION,
};
static
int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
{
@@ -72,7 +59,7 @@ int FAST_FUNC bbunpack(char **argv,
/* Open src */
if (filename) {
if (!(option_mask32 & SEAMLESS_MAGIC)) {
if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) {
if (stat(filename, &stat_buf) != 0) {
err_name:
bb_simple_perror_msg(filename);
@@ -91,15 +78,15 @@ int FAST_FUNC bbunpack(char **argv,
xmove_fd(fd, STDIN_FILENO);
}
} else
if (option_mask32 & SEAMLESS_MAGIC) {
if (option_mask32 & BBUNPK_SEAMLESS_MAGIC) {
/* "clever zcat" on stdin */
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
goto err;
}
/* Special cases: test, stdout */
if (option_mask32 & (OPT_STDOUT|OPT_TEST)) {
if (option_mask32 & OPT_TEST)
if (option_mask32 & (BBUNPK_OPT_STDOUT|BBUNPK_OPT_TEST)) {
if (option_mask32 & BBUNPK_OPT_TEST)
if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
xfunc_die();
filename = NULL;
@@ -114,7 +101,7 @@ int FAST_FUNC bbunpack(char **argv,
}
/* -f: overwrite existing output files */
if (option_mask32 & OPT_FORCE) {
if (option_mask32 & BBUNPK_OPT_FORCE) {
unlink(new_name);
}
@@ -126,12 +113,12 @@ int FAST_FUNC bbunpack(char **argv,
}
/* Check that the input is sane */
if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) {
if (!(option_mask32 & BBUNPK_OPT_FORCE) && isatty(STDIN_FILENO)) {
bb_error_msg_and_die("compressed data not read from terminal, "
"use -f to force it");
}
if (!(option_mask32 & SEAMLESS_MAGIC)) {
if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) {
init_transformer_state(&xstate);
/*xstate.signature_skipped = 0; - already is */
/*xstate.src_fd = STDIN_FILENO; - already is */
@@ -145,7 +132,7 @@ int FAST_FUNC bbunpack(char **argv,
xfunc_die();
}
if (!(option_mask32 & OPT_STDOUT))
if (!(option_mask32 & BBUNPK_OPT_STDOUT))
xclose(STDOUT_FILENO); /* with error check! */
if (filename) {
@@ -176,7 +163,7 @@ int FAST_FUNC bbunpack(char **argv,
}
/* Extreme bloat for gunzip compat */
/* Some users do want this info... */
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) {
if (ENABLE_DESKTOP && (option_mask32 & BBUNPK_OPT_VERBOSE)) {
unsigned percent = status
? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status)
: 0;
@@ -188,7 +175,7 @@ int FAST_FUNC bbunpack(char **argv,
}
/* Delete _source_ file */
del = filename;
if (option_mask32 & OPT_KEEP) /* ... unless -k */
if (option_mask32 & BBUNPK_OPT_KEEP) /* ... unless -k */
del = NULL;
}
if (del)
@@ -199,7 +186,7 @@ int FAST_FUNC bbunpack(char **argv,
}
} while (*argv && *++argv);
if (option_mask32 & OPT_STDOUT)
if (option_mask32 & BBUNPK_OPT_STDOUT)
xclose(STDOUT_FILENO); /* with error check! */
return exitcode;
@@ -389,9 +376,9 @@ int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int gunzip_main(int argc UNUSED_PARAM, char **argv)
{
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
getopt32long(argv, "cfkvqdtn", gunzip_longopts);
getopt32long(argv, BBUNPK_OPTSTR "dtn", gunzip_longopts);
#else
getopt32(argv, "cfkvqdtn");
getopt32(argv, BBUNPK_OPTSTR "dtn");
#endif
argv += optind;
@@ -400,7 +387,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
* But if seamless magic is enabled, then we are much more clever.
*/
if (ENABLE_ZCAT && (!ENABLE_GUNZIP || applet_name[1] == 'c'))
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
option_mask32 |= BBUNPK_OPT_STDOUT | BBUNPK_SEAMLESS_MAGIC;
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
}
@@ -453,10 +440,10 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, "cfkvqdt");
getopt32(argv, BBUNPK_OPTSTR "dt");
argv += optind;
if (ENABLE_BZCAT && (!ENABLE_BUNZIP2 || applet_name[2] == 'c')) /* bzcat */
option_mask32 |= OPT_STDOUT;
option_mask32 |= BBUNPK_OPT_STDOUT;
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
}
@@ -526,15 +513,15 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlzma_main(int argc UNUSED_PARAM, char **argv)
{
IF_LZMA(int opts =) getopt32(argv, "cfkvqdt");
IF_LZMA(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
# if ENABLE_LZMA
/* lzma without -d or -t? */
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
if (applet_name[2] == 'm' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
bb_show_usage();
# endif
/* lzcat? */
if (ENABLE_LZCAT && applet_name[2] == 'c')
option_mask32 |= OPT_STDOUT;
option_mask32 |= BBUNPK_OPT_STDOUT;
argv += optind;
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
@@ -594,15 +581,15 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unxz_main(int argc UNUSED_PARAM, char **argv)
{
IF_XZ(int opts =) getopt32(argv, "cfkvqdt");
IF_XZ(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
# if ENABLE_XZ
/* xz without -d or -t? */
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
if (applet_name[2] == '\0' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
bb_show_usage();
# endif
/* xzcat? */
if (ENABLE_XZCAT && applet_name[2] == 'c')
option_mask32 |= OPT_STDOUT;
option_mask32 |= BBUNPK_OPT_STDOUT;
argv += optind;
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
+42 -18
View File
@@ -19,6 +19,23 @@
//config: Unless you have a specific application which requires bzip2, you
//config: should probably say N here.
//config:
//config:config BZIP2_SMALL
//config: int "Trade bytes for speed (0:fast, 9:small)"
//config: default 8 # all "fast or small" options default to small
//config: range 0 9
//config: depends on BZIP2
//config: help
//config: Trade code size versus speed.
//config: Approximate values with gcc-6.3.0 "bzip -9" compressing
//config: linux-4.15.tar were:
//config: value time (sec) code size (386)
//config: 9 (smallest) 70.11 7687
//config: 8 67.93 8091
//config: 7 67.88 8405
//config: 6 67.78 8624
//config: 5 67.05 9427
//config: 4-0 (fastest) 64.14 12083
//config:
//config:config FEATURE_BZIP2_DECOMPRESS
//config: bool "Enable decompression"
//config: default y
@@ -48,7 +65,11 @@
#include "libbb.h"
#include "bb_archive.h"
#define CONFIG_BZIP2_FAST 1
#if CONFIG_BZIP2_SMALL >= 4
#define BZIP2_SPEED (9 - CONFIG_BZIP2_SMALL)
#else
#define BZIP2_SPEED 5
#endif
/* Speed test:
* Compiled with gcc 4.2.1, run on Athlon 64 1800 MHz (512K L2 cache).
@@ -56,7 +77,7 @@
* (time to compress gcc-4.2.1.tar is 126.4% compared to bbox).
* At SPEED 5 difference is 32.7%.
*
* Test run of all CONFIG_BZIP2_FAST values on a 11Mb text file:
* Test run of all BZIP2_SPEED values on a 11Mb text file:
* Size Time (3 runs)
* 0: 10828 4.145 4.146 4.148
* 1: 11097 3.845 3.860 3.861
@@ -83,15 +104,13 @@
/* No point in being shy and having very small buffer here.
* bzip2 internal buffers are much bigger anyway, hundreds of kbytes.
* If iobuf is several pages long, malloc() may use mmap,
* making iobuf is page aligned and thus (maybe) have one memcpy less
* making iobuf page aligned and thus (maybe) have one memcpy less
* if kernel is clever enough.
*/
enum {
IOBUF_SIZE = 8 * 1024
};
static uint8_t level;
/* NB: compressStream() has to return -1 on errors, not die.
* bbunpack() will correctly clean up in this case
* (delete incomplete .bz2 file)
@@ -143,6 +162,7 @@ static
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
{
IF_DESKTOP(long long) int total;
unsigned opt, level;
ssize_t count;
bz_stream bzs; /* it's small */
#define strm (&bzs)
@@ -151,6 +171,17 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate U
#define wbuf (iobuf + IOBUF_SIZE)
iobuf = xmalloc(2 * IOBUF_SIZE);
opt = option_mask32 >> (BBUNPK_OPTSTRLEN IF_FEATURE_BZIP2_DECOMPRESS(+ 2) + 2);
/* skipped BBUNPK_OPTSTR, "dt" and "zs" bits */
opt |= 0x100; /* if nothing else, assume -9 */
level = 0;
for (;;) {
level++;
if (opt & 1) break;
opt >>= 1;
}
BZ2_bzCompressInit(strm, level);
while (1) {
@@ -196,26 +227,19 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
*/
opt = getopt32(argv, "^"
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
"cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs"
/* Must match BBUNPK_foo constants! */
BBUNPK_OPTSTR IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs123456789"
"\0" "s2" /* -s means -2 (compatibility) */
);
#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
if (opt & 0x30) // -d and/or -t
if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
return bunzip2_main(argc, argv);
opt >>= 6;
#else
opt >>= 4;
/* clear "decompress" and "test" bits (or bbunpack() can get confused) */
/* in !BZIP2_DECOMPRESS config, these bits are -zs and are unused */
option_mask32 = opt & ~(BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST);
#endif
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
opt |= 0x100; /* if nothing else, assume -9 */
level = 1;
while (!(opt & 1)) {
level++;
opt >>= 1;
}
argv += optind;
option_mask32 &= 0xf; /* ignore all except -cfkv */
return bbunpack(argv, compressStream, append_ext, "bz2");
}
+2
View File
@@ -508,6 +508,8 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
create_links_from_list(archive_handle->link_placeholders);
if (archive_handle->cpio__blocks != (off_t)-1
&& !(opt & OPT_QUIET)
) {
+210 -217
View File
@@ -15,21 +15,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* big objects in bss:
* 00000020 b bl_count
* 00000074 b base_length
* 00000078 b base_dist
* 00000078 b static_dtree
* 0000009c b bl_tree
* 000000f4 b dyn_dtree
* 00000100 b length_code
* 00000200 b dist_code
* 0000023d b depth
* 00000400 b flag_buf
* 0000047a b heap
* 00000480 b static_ltree
* 000008f4 b dyn_ltree
*/
/* TODO: full support for -v for DESKTOP
* "/usr/bin/gzip -v a bogus aa" should say:
a: 85.1% -- replaced with a.gz
@@ -108,12 +93,12 @@ aa: 85.1% -- replaced with aa.gz
#include "libbb.h"
#include "bb_archive.h"
/* ===========================================================================
*/
//#define DEBUG 1
/* Diagnostic functions */
#ifdef DEBUG
static int verbose;
# define Assert(cond,msg) { if (!(cond)) bb_error_msg(msg); }
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x; }
@@ -129,7 +114,6 @@ aa: 85.1% -- replaced with aa.gz
# define Tracecv(c,x)
#endif
/* ===========================================================================
*/
#if CONFIG_GZIP_FAST == 0
@@ -225,7 +209,6 @@ aa: 85.1% -- replaced with aa.gz
# define MAX_SUFFIX 30
#endif
/* ===========================================================================
* Compile with MEDIUM_MEM to reduce the memory requirements or
* with SMALL_MEM to use as little memory as possible. Use BIG_MEM if the
@@ -234,15 +217,14 @@ aa: 85.1% -- replaced with aa.gz
* affects the compression ratio. The compressed output
* is still correct, and might even be smaller in some cases.
*/
#ifdef SMALL_MEM
# define HASH_BITS 13 /* Number of bits used to hash strings */
# define HASH_BITS 13 /* Number of bits used to hash strings */
#endif
#ifdef MEDIUM_MEM
# define HASH_BITS 14
# define HASH_BITS 14
#endif
#ifndef HASH_BITS
# define HASH_BITS 15
# define HASH_BITS 15
/* For portability to 16 bit machines, do not use values above 15. */
#endif
@@ -255,7 +237,6 @@ aa: 85.1% -- replaced with aa.gz
#endif
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
/* ===========================================================================
* These types are not really 'char', 'short' and 'long'
*/
@@ -312,46 +293,10 @@ enum {
#endif /* ENABLE_FEATURE_GZIP_LEVELS */
};
struct globals {
/* =========================================================================== */
/* global buffers, allocated once */
#if ENABLE_FEATURE_GZIP_LEVELS
unsigned max_chain_length;
unsigned max_lazy_match;
unsigned good_match;
unsigned nice_match;
#define max_chain_length (G1.max_chain_length)
#define max_lazy_match (G1.max_lazy_match)
#define good_match (G1.good_match)
#define nice_match (G1.nice_match)
#endif
lng block_start;
/* window position at the beginning of the current output block. Gets
* negative when the window is moved backwards.
*/
unsigned ins_h; /* hash index of string to be inserted */
#define H_SHIFT ((HASH_BITS+MIN_MATCH-1) / MIN_MATCH)
/* Number of bits by which ins_h and del_h must be shifted at each
* input step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is:
* H_SHIFT * MIN_MATCH >= HASH_BITS
*/
unsigned prev_length;
/* Length of the best match at previous step. Matches not greater than this
* are discarded. This is used in the lazy match evaluation.
*/
unsigned strstart; /* start of string to insert */
unsigned match_start; /* start of matching string */
unsigned lookahead; /* number of valid bytes ahead in window */
/* ===========================================================================
*/
#define DECLARE(type, array, size) \
type * array
#define ALLOC(type, array, size) \
@@ -359,8 +304,6 @@ struct globals {
#define FREE(array) \
do { free(array); array = NULL; } while (0)
/* global buffers */
/* buffer for literals or lengths */
/* DECLARE(uch, l_buf, LIT_BUFSIZE); */
DECLARE(uch, l_buf, INBUFSIZ);
@@ -390,6 +333,46 @@ struct globals {
/* DECLARE(Pos, head, 1<<HASH_BITS); */
#define head (G1.prev + WSIZE) /* hash head (see deflate.c) */
#if ENABLE_FEATURE_GZIP_LEVELS
unsigned max_chain_length;
unsigned max_lazy_match;
unsigned good_match;
unsigned nice_match;
#define max_chain_length (G1.max_chain_length)
#define max_lazy_match (G1.max_lazy_match)
#define good_match (G1.good_match)
#define nice_match (G1.nice_match)
#endif
/* =========================================================================== */
/* all members below are zeroed out in pack_gzip() for each next file */
uint32_t crc; /* shift register contents */
/*uint32_t *crc_32_tab;*/
/* window position at the beginning of the current output block. Gets
* negative when the window is moved backwards.
*/
lng block_start;
unsigned ins_h; /* hash index of string to be inserted */
/* Number of bits by which ins_h and del_h must be shifted at each
* input step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is:
* H_SHIFT * MIN_MATCH >= HASH_BITS
*/
#define H_SHIFT ((HASH_BITS+MIN_MATCH-1) / MIN_MATCH)
/* Length of the best match at previous step. Matches not greater than this
* are discarded. This is used in the lazy match evaluation.
*/
unsigned prev_length;
unsigned strstart; /* start of string to insert */
unsigned match_start; /* start of matching string */
unsigned lookahead; /* number of valid bytes ahead in window */
/* number of input bytes */
ulg isize; /* only 32 bits stored in .gz file */
@@ -401,40 +384,35 @@ struct globals {
unsigned insize; /* valid bytes in l_buf */
#endif
unsigned outcnt; /* bytes in output buffer */
smallint eofile; /* flag set at end of input file */
/* ===========================================================================
* Local data used by the "bit string" routines.
*/
unsigned short bi_buf;
/* Output buffer. bits are inserted starting at the bottom (least significant
* bits).
*/
unsigned bi_buf; /* was unsigned short */
#undef BUF_SIZE
#define BUF_SIZE (8 * sizeof(G1.bi_buf))
#define BUF_SIZE (int)(8 * sizeof(G1.bi_buf))
/* Number of bits used within bi_buf. (bi_buf might be implemented on
* more than 16 bits on some systems.)
*/
int bi_valid;
/* Current input function. Set to mem_read for in-memory compression */
unsigned bi_valid;
#ifdef DEBUG
ulg bits_sent; /* bit length of the compressed data */
ulg bits_sent; /* bit length of the compressed data */
# define DEBUG_bits_sent(v) (void)(G1.bits_sent v)
#else
# define DEBUG_bits_sent(v) ((void)0)
#endif
/*uint32_t *crc_32_tab;*/
uint32_t crc; /* shift register contents */
};
#define G1 (*(ptr_to_globals - 1))
/* ===========================================================================
* Write the output buffer outbuf[0..outcnt-1] and update bytes_out.
* (used for the compressed data only)
@@ -448,7 +426,6 @@ static void flush_outbuf(void)
G1.outcnt = 0;
}
/* ===========================================================================
*/
/* put_8bit is used for the compressed output */
@@ -473,12 +450,13 @@ static void put_16bit(ush w)
if (outcnt < OUTBUFSIZ-2) {
/* Common case */
ush *dst16 = (void*) dst;
*dst16 = w; /* unalinged LSB 16-bit store */
*dst16 = w; /* unaligned LSB 16-bit store */
G1.outcnt = outcnt + 2;
return;
}
*dst = (uch)w;
w >>= 8;
G1.outcnt = ++outcnt;
#else
*dst = (uch)w;
w >>= 8;
@@ -488,20 +466,38 @@ static void put_16bit(ush w)
G1.outcnt = outcnt + 2;
return;
}
G1.outcnt = ++outcnt;
#endif
/* Slowpath: we will need to do flush_outbuf() */
G1.outcnt = ++outcnt;
if (outcnt == OUTBUFSIZ)
flush_outbuf();
put_8bit(w);
flush_outbuf(); /* here */
put_8bit(w); /* or here */
}
#define OPTIMIZED_PUT_32BIT (CONFIG_GZIP_FAST > 0 && BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN)
static void put_32bit(ulg n)
{
if (OPTIMIZED_PUT_32BIT) {
unsigned outcnt = G1.outcnt;
if (outcnt < OUTBUFSIZ-4) {
/* Common case */
ulg *dst32 = (void*) &G1.outbuf[outcnt];
*dst32 = n; /* unaligned LSB 32-bit store */
//bb_error_msg("%p", dst32); // store alignment debugging
G1.outcnt = outcnt + 4;
return;
}
}
put_16bit(n);
put_16bit(n >> 16);
}
static ALWAYS_INLINE void flush_outbuf_if_32bit_optimized(void)
{
/* If put_32bit() performs 32bit stores && it is used in send_bits() */
if (OPTIMIZED_PUT_32BIT && BUF_SIZE > 16)
flush_outbuf();
}
/* ===========================================================================
* Run a set of bytes through the crc shift register. If s is a NULL
@@ -513,7 +509,6 @@ static void updcrc(uch * s, unsigned n)
G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/);
}
/* ===========================================================================
* Read a new buffer from the current input file, perform end-of-line
* translation, and update the crc and input file size.
@@ -534,33 +529,44 @@ static unsigned file_read(void *buf, unsigned size)
return len;
}
/* ===========================================================================
* Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits.
*/
static void send_bits(int value, int length)
static void send_bits(unsigned value, unsigned length)
{
unsigned new_buf;
#ifdef DEBUG
Tracev((stderr, " l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length");
G1.bits_sent += length;
DEBUG_bits_sent(+= length);
#endif
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
* unused bits in value.
*/
if (G1.bi_valid > (int) BUF_SIZE - length) {
G1.bi_buf |= (value << G1.bi_valid);
put_16bit(G1.bi_buf);
G1.bi_buf = (ush) value >> (BUF_SIZE - G1.bi_valid);
G1.bi_valid += length - BUF_SIZE;
} else {
G1.bi_buf |= value << G1.bi_valid;
G1.bi_valid += length;
}
}
BUILD_BUG_ON(BUF_SIZE != 32 && BUF_SIZE != 16);
new_buf = G1.bi_buf | (value << G1.bi_valid);
/* NB: the above may sometimes do "<< 32" shift (undefined)
* if check below is changed to "length > BUF_SIZE" instead of >= */
length += G1.bi_valid;
/* If bi_buf is full */
if (length >= BUF_SIZE) {
/* ...use (valid) bits from bi_buf and
* (BUF_SIZE - bi_valid) bits from value,
* leaving (width - (BUF_SIZE-bi_valid)) unused bits in value.
*/
value >>= (BUF_SIZE - G1.bi_valid);
if (BUF_SIZE == 32) {
put_32bit(new_buf);
} else { /* 16 */
put_16bit(new_buf);
}
new_buf = value;
length -= BUF_SIZE;
}
G1.bi_buf = new_buf;
G1.bi_valid = length;
}
/* ===========================================================================
* Reverse the first len bits of a code, using straightforward code (a faster
@@ -579,25 +585,24 @@ static unsigned bi_reverse(unsigned code, int len)
}
}
/* ===========================================================================
* Write out any remaining bits in an incomplete byte.
*/
static void bi_windup(void)
{
if (G1.bi_valid > 8) {
put_16bit(G1.bi_buf);
} else if (G1.bi_valid > 0) {
put_8bit(G1.bi_buf);
unsigned bits = G1.bi_buf;
int cnt = G1.bi_valid;
while (cnt > 0) {
put_8bit(bits);
bits >>= 8;
cnt -= 8;
}
G1.bi_buf = 0;
G1.bi_valid = 0;
#ifdef DEBUG
G1.bits_sent = (G1.bits_sent + 7) & ~7;
#endif
DEBUG_bits_sent(= (G1.bits_sent + 7) & ~7);
}
/* ===========================================================================
* Copy a stored block to the zip file, storing first the length and its
* one's complement if requested.
@@ -607,21 +612,19 @@ static void copy_block(char *buf, unsigned len, int header)
bi_windup(); /* align on byte boundary */
if (header) {
put_16bit(len);
put_16bit(~len);
#ifdef DEBUG
G1.bits_sent += 2 * 16;
#endif
unsigned v = ((uint16_t)len) | ((~len) << 16);
put_32bit(v);
DEBUG_bits_sent(+= 2 * 16);
}
#ifdef DEBUG
G1.bits_sent += (ulg) len << 3;
#endif
DEBUG_bits_sent(+= (ulg) len << 3);
while (len--) {
put_8bit(*buf++);
}
/* The above can 32-bit misalign outbuf */
if (G1.outcnt & 3) /* syscalls are expensive, is it really misaligned? */
flush_outbuf_if_32bit_optimized();
}
/* ===========================================================================
* Fill the window when the lookahead becomes insufficient.
* Updates strstart and lookahead, and sets eofile if end of input file.
@@ -679,7 +682,12 @@ static void fill_window(void)
}
}
}
/* Both users fill window with the same loop: */
static void fill_window_if_needed(void)
{
while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile)
fill_window();
}
/* ===========================================================================
* Set match_start to the longest match starting at the given string and
@@ -770,7 +778,6 @@ static int longest_match(IPos cur_match)
return best_len;
}
#ifdef DEBUG
/* ===========================================================================
* Check that the match at match_start is indeed a match.
@@ -1049,24 +1056,14 @@ struct globals2 {
ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */
ulg compressed_len; /* total bit length of compressed file */
// ulg compressed_len; /* total bit length of compressed file */
};
#define G2ptr ((struct globals2*)(ptr_to_globals))
#define G2 (*G2ptr)
/* ===========================================================================
*/
static void gen_codes(ct_data * tree, int max_code);
static void build_tree(tree_desc * desc);
static void scan_tree(ct_data * tree, int max_code);
static void send_tree(ct_data * tree, int max_code);
static int build_bl_tree(void);
static void send_all_trees(int lcodes, int dcodes, int blcodes);
static void compress_block(ct_data * ltree, ct_data * dtree);
#ifndef DEBUG
/* Send a code of the given tree. c and tree must not have side effects */
# define SEND_CODE(c, tree) send_bits(tree[c].Code, tree[c].Len)
@@ -1086,7 +1083,6 @@ static void compress_block(ct_data * ltree, ct_data * dtree);
* The arguments must not have side effects.
*/
/* ===========================================================================
* Initialize a new block.
*/
@@ -1109,7 +1105,6 @@ static void init_block(void)
G2.flag_bit = 1;
}
/* ===========================================================================
* Restore the heap property by moving down the tree starting at node k,
* exchanging a node with the smallest of its two sons if necessary, stopping
@@ -1147,7 +1142,6 @@ static void pqdownheap(ct_data * tree, int k)
G2.heap[k] = v;
}
/* ===========================================================================
* Compute the optimal bit lengths for a tree and update the total bit length
* for the current block.
@@ -1245,7 +1239,6 @@ static void gen_bitlen(tree_desc * desc)
}
}
/* ===========================================================================
* Generate the codes for a given tree and bit counts (which need not be
* optimal).
@@ -1289,7 +1282,6 @@ static void gen_codes(ct_data * tree, int max_code)
}
}
/* ===========================================================================
* Construct one Huffman tree and assigns the code bit strings and lengths.
* Update the total bit length for the current block.
@@ -1396,7 +1388,6 @@ static void build_tree(tree_desc * desc)
gen_codes((ct_data *) tree, max_code);
}
/* ===========================================================================
* Scan a literal or distance tree to determine the frequencies of the codes
* in the bit length tree. Updates opt_len to take into account the repeat
@@ -1451,7 +1442,6 @@ static void scan_tree(ct_data * tree, int max_code)
}
}
/* ===========================================================================
* Send a literal or distance tree in compressed form, using the codes in
* bl_tree.
@@ -1509,7 +1499,6 @@ static void send_tree(ct_data * tree, int max_code)
}
}
/* ===========================================================================
* Construct the Huffman tree for the bit lengths and return the index in
* bl_order of the last bit length code to send.
@@ -1538,12 +1527,11 @@ static int build_bl_tree(void)
}
/* Update opt_len to include the bit length tree and counts */
G2.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", G2.opt_len, G2.static_len));
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));
return max_blindex;
}
/* ===========================================================================
* Send the header for a block using dynamic Huffman trees: the counts, the
* lengths of the bit length codes, the literal tree and the distance tree.
@@ -1564,16 +1552,15 @@ static void send_all_trees(int lcodes, int dcodes, int blcodes)
Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
send_bits(G2.bl_tree[bl_order[rank]].Len, 3);
}
Tracev((stderr, "\nbl tree: sent %ld", G1.bits_sent));
Tracev((stderr, "\nbl tree: sent %ld", (long)G1.bits_sent));
send_tree((ct_data *) G2.dyn_ltree, lcodes - 1); /* send the literal tree */
Tracev((stderr, "\nlit tree: sent %ld", G1.bits_sent));
Tracev((stderr, "\nlit tree: sent %ld", (long)G1.bits_sent));
send_tree((ct_data *) G2.dyn_dtree, dcodes - 1); /* send the distance tree */
Tracev((stderr, "\ndist tree: sent %ld", G1.bits_sent));
Tracev((stderr, "\ndist tree: sent %ld", (long)G1.bits_sent));
}
/* ===========================================================================
* Save the match info and tally the frequency counts. Return true if
* the current block must be flushed.
@@ -1619,7 +1606,8 @@ static int ct_tally(int dist, int lc)
out_length >>= 3;
Trace((stderr,
"\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
G2.last_lit, G2.last_dist, in_length, out_length,
G2.last_lit, G2.last_dist,
(long)in_length, (long)out_length,
100L - out_length * 100L / in_length));
if (G2.last_dist < G2.last_lit / 2 && out_length < in_length / 2)
return 1;
@@ -1679,13 +1667,12 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
SEND_CODE(END_BLOCK, ltree);
}
/* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static
* trees or store, and output the encoded block to the zip file. This function
* returns the total compressed length for the file so far.
*/
static ulg flush_block(char *buf, ulg stored_len, int eof)
static void flush_block(char *buf, ulg stored_len, int eof)
{
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex; /* index of last bit length code of non zero freq */
@@ -1694,10 +1681,10 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
/* Construct the literal and distance trees */
build_tree(&G2.l_desc);
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", G2.opt_len, G2.static_len));
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));
build_tree(&G2.d_desc);
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", G2.opt_len, G2.static_len));
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));
/* At this point, opt_len and static_len are the total bit lengths of
* the compressed block data, excluding the tree representations.
*/
@@ -1713,7 +1700,9 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
Trace((stderr,
"\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
opt_lenb, G2.opt_len, static_lenb, G2.static_len, stored_len,
(unsigned long)opt_lenb, (unsigned long)G2.opt_len,
(unsigned long)static_lenb, (unsigned long)G2.static_len,
(unsigned long)stored_len,
G2.last_lit, G2.last_dist));
if (static_lenb <= opt_lenb)
@@ -1723,14 +1712,17 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
* and if the zip file can be seeked (to rewrite the local header),
* the whole file is transformed into a stored file:
*/
if (stored_len <= opt_lenb && eof && G2.compressed_len == 0L && seekable()) {
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
if (buf == NULL)
bb_error_msg("block vanished");
copy_block(buf, (unsigned) stored_len, 0); /* without header */
G2.compressed_len = stored_len << 3;
} else if (stored_len + 4 <= opt_lenb && buf != NULL) {
// seekable() is constant FALSE in busybox, and G2.compressed_len is disabled
// (this was the only user)
// if (stored_len <= opt_lenb && eof && G2.compressed_len == 0L && seekable()) {
// /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
// if (buf == NULL)
// bb_error_msg("block vanished");
//
// G2.compressed_len = stored_len << 3;
// copy_block(buf, (unsigned) stored_len, 0); /* without header */
// } else
if (stored_len + 4 <= opt_lenb && buf != NULL) {
/* 4: two words for the lengths */
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
* Otherwise we can't have processed more than WSIZE input bytes since
@@ -1739,35 +1731,35 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
* transform a block into a stored block.
*/
send_bits((STORED_BLOCK << 1) + eof, 3); /* send block type */
G2.compressed_len = (G2.compressed_len + 3 + 7) & ~7L;
G2.compressed_len += (stored_len + 4) << 3;
// G2.compressed_len = ((G2.compressed_len + 3 + 7) & ~7L)
// + ((stored_len + 4) << 3);
copy_block(buf, (unsigned) stored_len, 1); /* with header */
} else if (static_lenb == opt_lenb) {
} else
if (static_lenb == opt_lenb) {
send_bits((STATIC_TREES << 1) + eof, 3);
compress_block((ct_data *) G2.static_ltree, (ct_data *) G2.static_dtree);
G2.compressed_len += 3 + G2.static_len;
// G2.compressed_len += 3 + G2.static_len;
} else {
send_bits((DYN_TREES << 1) + eof, 3);
send_all_trees(G2.l_desc.max_code + 1, G2.d_desc.max_code + 1,
max_blindex + 1);
compress_block((ct_data *) G2.dyn_ltree, (ct_data *) G2.dyn_dtree);
G2.compressed_len += 3 + G2.opt_len;
// G2.compressed_len += 3 + G2.opt_len;
}
Assert(G2.compressed_len == G1.bits_sent, "bad compressed size");
// Assert(G2.compressed_len == G1.bits_sent, "bad compressed size");
init_block();
if (eof) {
bi_windup();
G2.compressed_len += 7; /* align on byte boundary */
// G2.compressed_len += 7; /* align on byte boundary */
}
Tracev((stderr, "\ncomprlen %lu(%lu) ", G2.compressed_len >> 3,
G2.compressed_len - 7 * eof));
// Tracev((stderr, "\ncomprlen %lu(%lu) ",
// (unsigned long)G2.compressed_len >> 3,
// (unsigned long)G2.compressed_len - 7 * eof));
return G2.compressed_len >> 3;
return; /* was "return G2.compressed_len >> 3;" */
}
/* ===========================================================================
* Update a hash value with the given input byte
* IN assertion: all calls to UPDATE_HASH are made with consecutive
@@ -1776,7 +1768,6 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
*/
#define UPDATE_HASH(h, c) (h = (((h)<<H_SHIFT) ^ (c)) & HASH_MASK)
/* ===========================================================================
* Same as above, but achieves better compression. We use a lazy
* evaluation for matches: a match is finally adopted only if there is
@@ -1811,7 +1802,7 @@ do { \
head[G1.ins_h] = (s); \
} while (0)
static ulg deflate(void)
static NOINLINE void deflate(void)
{
IPos hash_head; /* head of hash chain */
IPos prev_match; /* previous match */
@@ -1900,40 +1891,35 @@ static ulg deflate(void)
G1.strstart++;
G1.lookahead--;
}
Assert(G1.strstart <= G1.isize && lookahead <= G1.isize, "a bit too far");
Assert(G1.strstart <= G1.isize && G1.lookahead <= G1.isize, "a bit too far");
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the
* string following the next match.
*/
while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile)
fill_window();
fill_window_if_needed();
}
if (match_available)
ct_tally(0, G1.window[G1.strstart - 1]);
return FLUSH_BLOCK(1); /* eof */
FLUSH_BLOCK(1); /* eof */
}
/* ===========================================================================
* Initialize the bit string routines.
*/
static void bi_init(void)
{
G1.bi_buf = 0;
G1.bi_valid = 0;
#ifdef DEBUG
G1.bits_sent = 0L;
#endif
//G1.bi_buf = 0; // globals are zeroed in pack_gzip()
//G1.bi_valid = 0; // globals are zeroed in pack_gzip()
//DEBUG_bits_sent(= 0L); // globals are zeroed in pack_gzip()
}
/* ===========================================================================
* Initialize the "longest match" routines for a new file
*/
static void lm_init(ush * flagsp)
static void lm_init(unsigned *flags16p)
{
unsigned j;
@@ -1942,11 +1928,11 @@ static void lm_init(ush * flagsp)
/* prev will be initialized on the fly */
/* speed options for the general purpose bit flag */
*flagsp |= 2; /* FAST 4, SLOW 2 */
*flags16p |= 2; /* FAST 4, SLOW 2 */
/* ??? reduce max_chain_length for binary files */
G1.strstart = 0;
G1.block_start = 0L;
//G1.strstart = 0; // globals are zeroed in pack_gzip()
//G1.block_start = 0L; // globals are zeroed in pack_gzip()
G1.lookahead = file_read(G1.window,
sizeof(int) <= 2 ? (unsigned) WSIZE : 2 * WSIZE);
@@ -1956,14 +1942,14 @@ static void lm_init(ush * flagsp)
G1.lookahead = 0;
return;
}
G1.eofile = 0;
//G1.eofile = 0; // globals are zeroed in pack_gzip()
/* Make sure that we always have enough lookahead. This is important
* if input comes from a device such as a tty.
*/
while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile)
fill_window();
fill_window_if_needed();
G1.ins_h = 0;
//G1.ins_h = 0; // globals are zeroed in pack_gzip()
for (j = 0; j < MIN_MATCH - 1; j++)
UPDATE_HASH(G1.ins_h, G1.window[j]);
/* If lookahead < MIN_MATCH, ins_h is garbage, but this is
@@ -1971,7 +1957,6 @@ static void lm_init(ush * flagsp)
*/
}
/* ===========================================================================
* Allocate the match buffer, initialize the various tables and save the
* location of the internal file attribute (ascii/binary) and method
@@ -1985,7 +1970,7 @@ static void ct_init(void)
int code; /* code value */
int dist; /* distance index */
G2.compressed_len = 0L;
// //G2.compressed_len = 0L; // globals are zeroed in pack_gzip()
#ifdef NOT_NEEDED
if (G2.static_dtree[0].Len != 0)
@@ -2026,27 +2011,33 @@ static void ct_init(void)
Assert(dist == 256, "ct_init: 256+dist != 512");
/* Construct the codes of the static literal tree */
/* already zeroed - it's in bss
for (n = 0; n <= MAX_BITS; n++)
G2.bl_count[n] = 0; */
//for (n = 0; n <= MAX_BITS; n++) // globals are zeroed in pack_gzip()
// G2.bl_count[n] = 0;
n = 0;
while (n <= 143) {
G2.static_ltree[n++].Len = 8;
G2.bl_count[8]++;
//G2.bl_count[8]++;
}
//G2.bl_count[8] = 143 + 1;
while (n <= 255) {
G2.static_ltree[n++].Len = 9;
G2.bl_count[9]++;
//G2.bl_count[9]++;
}
//G2.bl_count[9] = 255 - 143;
while (n <= 279) {
G2.static_ltree[n++].Len = 7;
G2.bl_count[7]++;
//G2.bl_count[7]++;
}
//G2.bl_count[7] = 279 - 255;
while (n <= 287) {
G2.static_ltree[n++].Len = 8;
G2.bl_count[8]++;
//G2.bl_count[8]++;
}
//G2.bl_count[8] += 287 - 279;
G2.bl_count[7] = 279 - 255;
G2.bl_count[8] = (143 + 1) + (287 - 279);
G2.bl_count[9] = 255 - 143;
/* Codes 286 and 287 do not exist, but we must include them in the
* tree construction to get a canonical Huffman tree (longest code
* all ones)
@@ -2063,17 +2054,15 @@ static void ct_init(void)
init_block();
}
/* ===========================================================================
* Deflate in to out.
* IN assertions: the input and output buffers are cleared.
*/
static void zip(void)
{
ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
unsigned deflate_flags;
G1.outcnt = 0;
//G1.outcnt = 0; // globals are zeroed in pack_gzip()
/* Write the header to the gzip file. See algorithm.doc for the format */
/* magic header for gzip files: 1F 8B */
@@ -2087,10 +2076,13 @@ static void zip(void)
bi_init();
ct_init();
deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
lm_init(&deflate_flags);
put_8bit(deflate_flags); /* extra flags */
put_8bit(3); /* OS identifier = 3 (Unix) */
put_16bit(deflate_flags | 0x300); /* extra flags. OS id = 3 (Unix) */
/* The above 32-bit misaligns outbuf (10 bytes are stored), flush it */
flush_outbuf_if_32bit_optimized();
deflate();
@@ -2101,20 +2093,21 @@ static void zip(void)
flush_outbuf();
}
/* ======================================================================== */
static
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
{
/* Reinit G1.xxx except pointers to allocated buffers, and entire G2 */
memset(&G1.crc, 0, (sizeof(G1) - offsetof(struct globals, crc)) + sizeof(G2));
/* Clear input and output buffers */
G1.outcnt = 0;
//G1.outcnt = 0;
#ifdef DEBUG
G1.insize = 0;
//G1.insize = 0;
#endif
G1.isize = 0;
//G1.isize = 0;
/* Reinit G2.xxx */
memset(&G2, 0, sizeof(G2));
G2.l_desc.dyn_tree = G2.dyn_ltree;
G2.l_desc.static_tree = G2.static_ltree;
G2.l_desc.extra_bits = extra_lbits;
@@ -2218,16 +2211,16 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
opt = getopt32long(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789", gzip_longopts);
opt = getopt32long(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789", gzip_longopts);
#else
opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789");
opt = getopt32(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789");
#endif
#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
if (opt & 0x30) // -d and/or -t
if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
return gunzip_main(argc, argv);
#endif
#if ENABLE_FEATURE_GZIP_LEVELS
opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 8 : 6; /* drop cfkv[dt]qn bits */
opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */
if (opt == 0)
opt = 1 << 6; /* default: 6 */
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
@@ -2236,7 +2229,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
max_lazy_match = gzip_level_config[opt].lazy2 * 2;
nice_match = gzip_level_config[opt].nice2 * 2;
#endif
option_mask32 &= 0xf; /* retain only -cfkv */
option_mask32 &= BBUNPK_OPTSTRMASK; /* retain only -cfkvq */
/* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, G1.l_buf, INBUFSIZ);
@@ -2246,7 +2239,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
ALLOC(ush, G1.prev, 1L << BITS);
/* Initialize the CRC32 table */
global_crc32_table = crc32_filltable(NULL, 0);
global_crc32_new_table_le();
argv += optind;
return bbunpack(argv, pack_gzip, append_ext, "gz");
+159 -152
View File
@@ -113,9 +113,8 @@ void fallbackQSort3(uint32_t* fmap,
int32_t loSt,
int32_t hiSt)
{
int32_t unLo, unHi, ltLo, gtHi, n, m;
int32_t sp, lo, hi;
uint32_t med, r, r3;
int32_t sp;
uint32_t r;
int32_t stackLo[FALLBACK_QSORT_STACK_SIZE];
int32_t stackHi[FALLBACK_QSORT_STACK_SIZE];
@@ -125,6 +124,11 @@ void fallbackQSort3(uint32_t* fmap,
fpush(loSt, hiSt);
while (sp > 0) {
int32_t unLo, unHi, ltLo, gtHi, n, m;
int32_t lo, hi;
uint32_t med;
uint32_t r3;
AssertH(sp < FALLBACK_QSORT_STACK_SIZE - 1, 1004);
fpop(lo, hi);
@@ -161,7 +165,7 @@ void fallbackQSort3(uint32_t* fmap,
ltLo++;
unLo++;
continue;
};
}
if (n > 0) break;
unLo++;
}
@@ -172,7 +176,7 @@ void fallbackQSort3(uint32_t* fmap,
mswap(fmap[unHi], fmap[gtHi]);
gtHi--; unHi--;
continue;
};
}
if (n < 0) break;
unHi--;
}
@@ -227,17 +231,19 @@ void fallbackQSort3(uint32_t* fmap,
#define UNALIGNED_BH(zz) ((zz) & 0x01f)
static
void fallbackSort(uint32_t* fmap,
uint32_t* eclass,
uint32_t* bhtab,
int32_t nblock)
void fallbackSort(EState* state)
{
int32_t ftab[257];
int32_t ftabCopy[256];
int32_t H, i, j, k, l, r, cc, cc1;
int32_t nNotDone;
int32_t nBhtab;
uint8_t* eclass8 = (uint8_t*)eclass;
/* params */
uint32_t *const fmap = state->arr1;
uint32_t *const eclass = state->arr2;
#define eclass8 ((uint8_t*)eclass)
uint32_t *const bhtab = state->ftab;
const int32_t nblock = state->nblock;
/*
* Initial 1-char radix sort to generate
@@ -326,7 +332,7 @@ void fallbackSort(uint32_t* fmap,
if (cc != cc1) {
SET_BH(i);
cc = cc1;
};
}
}
}
}
@@ -349,6 +355,7 @@ void fallbackSort(uint32_t* fmap,
eclass8[fmap[i]] = (uint8_t)j;
}
AssertH(j < 256, 1005);
#undef eclass8
}
#undef SET_BH
@@ -367,25 +374,25 @@ void fallbackSort(uint32_t* fmap,
/*---------------------------------------------*/
static
NOINLINE
int mainGtU(
int mainGtU(EState* state,
uint32_t i1,
uint32_t i2,
uint8_t* block,
uint16_t* quadrant,
uint32_t nblock,
int32_t* budget)
uint32_t i2)
{
int32_t k;
uint8_t c1, c2;
uint16_t s1, s2;
uint8_t *const block = state->block;
uint16_t *const quadrant = state->quadrant;
const int32_t nblock = state->nblock;
/* Loop unrolling here is actually very useful
* (generated code is much simpler),
* code size increase is only 270 bytes (i386)
* but speeds up compression 10% overall
*/
#if CONFIG_BZIP2_FAST >= 1
#if BZIP2_SPEED >= 1
#define TIMES_8(code) \
code; code; code; code; \
@@ -435,7 +442,7 @@ int mainGtU(
if (i1 >= nblock) i1 -= nblock;
if (i2 >= nblock) i2 -= nblock;
(*budget)--;
state->budget--;
k -= 8;
} while (k >= 0);
@@ -452,42 +459,45 @@ int mainGtU(
* usually small, typically <= 20.
*/
static
const int32_t incs[14] = {
const uint32_t incs[14] = {
1, 4, 13, 40, 121, 364, 1093, 3280,
9841, 29524, 88573, 265720,
797161, 2391484
};
static
void mainSimpleSort(uint32_t* ptr,
uint8_t* block,
uint16_t* quadrant,
int32_t nblock,
void mainSimpleSort(EState* state,
int32_t lo,
int32_t hi,
int32_t d,
int32_t* budget)
int32_t d)
{
int32_t i, j, h, bigN, hp;
uint32_t v;
uint32_t *const ptr = state->ptr;
bigN = hi - lo + 1;
if (bigN < 2) return;
hp = 0;
while (incs[hp] < bigN) hp++;
hp--;
/* At which increment to start? */
int hp = 0;
{
int bigN = hi - lo;
if (bigN <= 0)
return;
while (incs[hp] <= bigN)
hp++;
hp--;
}
for (; hp >= 0; hp--) {
h = incs[hp];
int32_t i;
unsigned h;
h = incs[hp];
i = lo + h;
while (1) {
/*-- copy 1 --*/
unsigned j;
unsigned v;
if (i > hi) break;
v = ptr[i];
j = i;
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
while (mainGtU(state, ptr[j-h]+d, v+d)) {
ptr[j] = ptr[j-h];
j = j - h;
if (j <= (lo + h - 1)) break;
@@ -496,24 +506,23 @@ void mainSimpleSort(uint32_t* ptr,
i++;
/* 1.5% overall speedup, +290 bytes */
#if CONFIG_BZIP2_FAST >= 3
#if BZIP2_SPEED >= 3
/*-- copy 2 --*/
if (i > hi) break;
v = ptr[i];
j = i;
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
while (mainGtU(state, ptr[j-h]+d, v+d)) {
ptr[j] = ptr[j-h];
j = j - h;
if (j <= (lo + h - 1)) break;
}
ptr[j] = v;
i++;
/*-- copy 3 --*/
if (i > hi) break;
v = ptr[i];
j = i;
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
while (mainGtU(state, ptr[j-h]+d, v+d)) {
ptr[j] = ptr[j-h];
j = j - h;
if (j <= (lo + h - 1)) break;
@@ -521,7 +530,7 @@ void mainSimpleSort(uint32_t* ptr,
ptr[j] = v;
i++;
#endif
if (*budget < 0) return;
if (state->budget < 0) return;
}
}
}
@@ -545,7 +554,7 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
t = a;
a = b;
b = t;
};
}
/* here b >= a */
if (b > c) {
b = c;
@@ -586,15 +595,12 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
#define MAIN_QSORT_STACK_SIZE 100
static NOINLINE
void mainQSort3(uint32_t* ptr,
uint8_t* block,
uint16_t* quadrant,
int32_t nblock,
void mainQSort3(EState* state,
int32_t loSt,
int32_t hiSt,
int32_t dSt,
int32_t* budget)
int32_t hiSt
/*int32_t dSt*/)
{
enum { dSt = BZ_N_RADIX };
int32_t unLo, unHi, ltLo, gtHi, n, m, med;
int32_t sp, lo, hi, d;
@@ -606,6 +612,9 @@ void mainQSort3(uint32_t* ptr,
int32_t nextHi[3];
int32_t nextD [3];
uint32_t *const ptr = state->ptr;
uint8_t *const block = state->block;
sp = 0;
mpush(loSt, hiSt, dSt);
@@ -616,8 +625,8 @@ void mainQSort3(uint32_t* ptr,
if (hi - lo < MAIN_QSORT_SMALL_THRESH
|| d > MAIN_QSORT_DEPTH_THRESH
) {
mainSimpleSort(ptr, block, quadrant, nblock, lo, hi, d, budget);
if (*budget < 0)
mainSimpleSort(state, lo, hi, d);
if (state->budget < 0)
return;
continue;
}
@@ -638,8 +647,8 @@ void mainQSort3(uint32_t* ptr,
ltLo++;
unLo++;
continue;
};
if (n > 0) break;
}
if (n > 0) break;
unLo++;
}
while (1) {
@@ -651,8 +660,8 @@ void mainQSort3(uint32_t* ptr,
gtHi--;
unHi--;
continue;
};
if (n < 0) break;
}
if (n < 0) break;
unHi--;
}
if (unLo > unHi)
@@ -721,28 +730,24 @@ void mainQSort3(uint32_t* ptr,
#define CLEARMASK (~(SETMASK))
static NOINLINE
void mainSort(EState* state,
uint32_t* ptr,
uint8_t* block,
uint16_t* quadrant,
uint32_t* ftab,
int32_t nblock,
int32_t* budget)
void mainSort(EState* state)
{
int32_t i, j, k, ss, sb;
uint8_t c1;
int32_t numQSorted;
uint16_t s;
int32_t i, j;
Bool bigDone[256];
uint8_t runningOrder[256];
/* bbox: moved to EState to save stack
int32_t runningOrder[256];
int32_t copyStart[256];
int32_t copyEnd [256];
*/
#define runningOrder (state->mainSort__runningOrder)
#define copyStart (state->mainSort__copyStart)
#define copyEnd (state->mainSort__copyEnd)
uint32_t *const ptr = state->ptr;
uint8_t *const block = state->block;
uint32_t *const ftab = state->ftab;
const int32_t nblock = state->nblock;
uint16_t *const quadrant = state->quadrant;
/*-- set up the 2-byte frequency table --*/
/* was: for (i = 65536; i >= 0; i--) ftab[i] = 0; */
memset(ftab, 0, 65537 * sizeof(ftab[0]));
@@ -750,25 +755,25 @@ void mainSort(EState* state,
j = block[0] << 8;
i = nblock - 1;
/* 3%, +300 bytes */
#if CONFIG_BZIP2_FAST >= 2
#if BZIP2_SPEED >= 2
for (; i >= 3; i -= 4) {
quadrant[i] = 0;
j = (j >> 8) | (((uint16_t)block[i]) << 8);
j = (j >> 8) | (((unsigned)block[i]) << 8);
ftab[j]++;
quadrant[i-1] = 0;
j = (j >> 8) | (((uint16_t)block[i-1]) << 8);
j = (j >> 8) | (((unsigned)block[i-1]) << 8);
ftab[j]++;
quadrant[i-2] = 0;
j = (j >> 8) | (((uint16_t)block[i-2]) << 8);
j = (j >> 8) | (((unsigned)block[i-2]) << 8);
ftab[j]++;
quadrant[i-3] = 0;
j = (j >> 8) | (((uint16_t)block[i-3]) << 8);
j = (j >> 8) | (((unsigned)block[i-3]) << 8);
ftab[j]++;
}
#endif
for (; i >= 0; i--) {
quadrant[i] = 0;
j = (j >> 8) | (((uint16_t)block[i]) << 8);
j = (j >> 8) | (((unsigned)block[i]) << 8);
ftab[j]++;
}
@@ -785,33 +790,36 @@ void mainSort(EState* state,
ftab[i] = j;
}
s = block[0] << 8;
i = nblock - 1;
#if CONFIG_BZIP2_FAST >= 2
for (; i >= 3; i -= 4) {
s = (s >> 8) | (block[i] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i;
s = (s >> 8) | (block[i-1] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i-1;
s = (s >> 8) | (block[i-2] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i-2;
s = (s >> 8) | (block[i-3] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i-3;
}
{
unsigned s;
s = block[0] << 8;
i = nblock - 1;
#if BZIP2_SPEED >= 2
for (; i >= 3; i -= 4) {
s = (s >> 8) | (block[i] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i;
s = (s >> 8) | (block[i-1] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i-1;
s = (s >> 8) | (block[i-2] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i-2;
s = (s >> 8) | (block[i-3] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i-3;
}
#endif
for (; i >= 0; i--) {
s = (s >> 8) | (block[i] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i;
for (; i >= 0; i--) {
s = (s >> 8) | (block[i] << 8);
j = ftab[s] - 1;
ftab[s] = j;
ptr[j] = i;
}
}
/*
@@ -825,24 +833,23 @@ void mainSort(EState* state,
}
{
int32_t vv;
/* bbox: was: int32_t h = 1; */
/* do h = 3 * h + 1; while (h <= 256); */
uint32_t h = 364;
unsigned h = 364;
do {
/*h = h / 3;*/
h = (h * 171) >> 9; /* bbox: fast h/3 */
for (i = h; i <= 255; i++) {
vv = runningOrder[i];
unsigned vv, jh;
vv = runningOrder[i]; /* uint8[] */
j = i;
while (BIGFREQ(runningOrder[j-h]) > BIGFREQ(vv)) {
runningOrder[j] = runningOrder[j-h];
j = j - h;
if (j <= (h - 1))
goto zero;
while (jh = j - h, BIGFREQ(runningOrder[jh]) > BIGFREQ(vv)) {
runningOrder[j] = runningOrder[jh];
j = jh;
if (j < h)
break;
}
zero:
runningOrder[j] = vv;
}
} while (h != 1);
@@ -852,9 +859,8 @@ void mainSort(EState* state,
* The main sorting loop.
*/
numQSorted = 0;
for (i = 0; i <= 255; i++) {
for (i = 0; /*i <= 255*/; i++) {
unsigned ss;
/*
* Process big buckets, starting with the least full.
@@ -874,17 +880,14 @@ void mainSort(EState* state,
*/
for (j = 0; j <= 255; j++) {
if (j != ss) {
unsigned sb;
sb = (ss << 8) + j;
if (!(ftab[sb] & SETMASK)) {
int32_t lo = ftab[sb] & CLEARMASK;
int32_t lo = ftab[sb] /*& CLEARMASK (redundant)*/;
int32_t hi = (ftab[sb+1] & CLEARMASK) - 1;
if (hi > lo) {
mainQSort3(
ptr, block, quadrant, nblock,
lo, hi, BZ_N_RADIX, budget
);
if (*budget < 0) return;
numQSorted += (hi - lo + 1);
mainQSort3(state, lo, hi /*,BZ_N_RADIX*/);
if (state->budget < 0) return;
}
}
ftab[sb] |= SETMASK;
@@ -906,6 +909,8 @@ void mainSort(EState* state,
copyEnd [j] = (ftab[(j << 8) + ss + 1] & CLEARMASK) - 1;
}
for (j = ftab[ss << 8] & CLEARMASK; j < copyStart[ss]; j++) {
unsigned c1;
int32_t k;
k = ptr[j] - 1;
if (k < 0)
k += nblock;
@@ -914,6 +919,8 @@ void mainSort(EState* state,
ptr[copyStart[c1]++] = k;
}
for (j = (ftab[(ss+1) << 8] & CLEARMASK) - 1; j > copyEnd[ss]; j--) {
unsigned c1;
int32_t k;
k = ptr[j]-1;
if (k < 0)
k += nblock;
@@ -933,6 +940,9 @@ void mainSort(EState* state,
for (j = 0; j <= 255; j++)
ftab[(j << 8) + ss] |= SETMASK;
if (i == 255)
break;
/*
* Step 3:
* The [ss] big bucket is now done. Record this fact,
@@ -974,15 +984,15 @@ void mainSort(EState* state,
*/
bigDone[ss] = True;
if (i < 255) {
int32_t bbStart = ftab[ss << 8] & CLEARMASK;
int32_t bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
int32_t shifts = 0;
{
unsigned bbStart = ftab[ss << 8] & CLEARMASK;
unsigned bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
unsigned shifts = 0;
while ((bbSize >> shifts) > 65534) shifts++;
for (j = bbSize-1; j >= 0; j--) {
int32_t a2update = ptr[bbStart + j];
unsigned a2update = ptr[bbStart + j]; /* uint32[] */
uint16_t qVal = (uint16_t)(j >> shifts);
quadrant[a2update] = qVal;
if (a2update < BZ_N_OVERSHOOT)
@@ -1015,31 +1025,24 @@ void mainSort(EState* state,
* arr1[0 .. nblock-1] holds sorted order
*/
static NOINLINE
void BZ2_blockSort(EState* s)
int32_t BZ2_blockSort(EState* state)
{
/* In original bzip2 1.0.4, it's a parameter, but 30
* (which was the default) should work ok. */
enum { wfact = 30 };
unsigned i;
int32_t origPtr = origPtr;
uint32_t* ptr = s->ptr;
uint8_t* block = s->block;
uint32_t* ftab = s->ftab;
int32_t nblock = s->nblock;
uint16_t* quadrant;
int32_t budget;
int32_t i;
if (nblock < 10000) {
fallbackSort(s->arr1, s->arr2, ftab, nblock);
} else {
if (state->nblock >= 10000) {
/* Calculate the location for quadrant, remembering to get
* the alignment right. Assumes that &(block[0]) is at least
* 2-byte aligned -- this should be ok since block is really
* the first section of arr2.
*/
i = nblock + BZ_N_OVERSHOOT;
if (i & 1) i++;
quadrant = (uint16_t*)(&(block[i]));
i = state->nblock + BZ_N_OVERSHOOT;
if (i & 1)
i++;
state->quadrant = (uint16_t*) &(state->block[i]);
/* (wfact-1) / 3 puts the default-factor-30
* transition point at very roughly the same place as
@@ -1048,22 +1051,26 @@ void BZ2_blockSort(EState* s)
* resulting compressed stream is now the same regardless
* of whether or not we use the main sort or fallback sort.
*/
budget = nblock * ((wfact-1) / 3);
state->budget = state->nblock * ((wfact-1) / 3);
mainSort(state);
if (state->budget >= 0)
goto good;
}
fallbackSort(state);
good:
mainSort(s, ptr, block, quadrant, ftab, nblock, &budget);
if (budget < 0) {
fallbackSort(s->arr1, s->arr2, ftab, nblock);
#if BZ_LIGHT_DEBUG
origPtr = -1;
#endif
for (i = 0; i < state->nblock; i++) {
if (state->ptr[i] == 0) {
origPtr = i;
break;
}
}
s->origPtr = -1;
for (i = 0; i < s->nblock; i++)
if (ptr[i] == 0) {
s->origPtr = i;
break;
};
AssertH(s->origPtr != -1, 1003);
AssertH(origPtr != -1, 1003);
return origPtr;
}
+10 -10
View File
@@ -55,8 +55,9 @@ void prepare_new_block(EState* s)
{
int i;
s->nblock = 0;
s->numZ = 0;
s->state_out_pos = 0;
//indexes into s->zbits[], initialzation moved to init of s->zbits
//s->posZ = s->zbits; // was: s->numZ = 0;
//s->state_out_pos = s->zbits;
BZ_INITIALISE_CRC(s->blockCRC);
/* inlined memset would be nice to have here */
for (i = 0; i < 256; i++)
@@ -86,7 +87,7 @@ int isempty_RL(EState* s)
static
void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
{
int32_t n;
unsigned n;
EState* s;
s = xzalloc(sizeof(EState));
@@ -237,11 +238,10 @@ void /*Bool*/ copy_output_until_stop(EState* s)
if (s->strm->avail_out == 0) break;
/*-- block done? --*/
if (s->state_out_pos >= s->numZ) break;
if (s->state_out_pos >= s->posZ) break;
/*progress_out = True;*/
*(s->strm->next_out) = s->zbits[s->state_out_pos];
s->state_out_pos++;
*(s->strm->next_out) = *s->state_out_pos++;
s->strm->avail_out--;
s->strm->next_out++;
s->strm->total_out++;
@@ -261,7 +261,7 @@ void /*Bool*/ handle_compress(bz_stream *strm)
while (1) {
if (s->state == BZ_S_OUTPUT) {
/*progress_out |=*/ copy_output_until_stop(s);
if (s->state_out_pos < s->numZ) break;
if (s->state_out_pos < s->posZ) break;
if (s->mode == BZ_M_FINISHING
//# && s->avail_in_expect == 0
&& s->strm->avail_in == 0
@@ -336,7 +336,7 @@ int BZ2_bzCompress(bz_stream *strm, int action)
/*if (s->avail_in_expect != s->strm->avail_in)
return BZ_SEQUENCE_ERROR;*/
/*progress =*/ handle_compress(strm);
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
return BZ_FLUSH_OK;
s->mode = BZ_M_RUNNING;
return BZ_RUN_OK;
@@ -349,9 +349,9 @@ int BZ2_bzCompress(bz_stream *strm, int action)
return BZ_SEQUENCE_ERROR;*/
/*progress =*/ handle_compress(strm);
/*if (!progress) return BZ_SEQUENCE_ERROR;*/
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
//# return BZ_FINISH_OK;
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
return BZ_FINISH_OK;
/*s->mode = BZ_M_IDLE;*/
return BZ_STREAM_END;
+16 -12
View File
@@ -120,8 +120,11 @@ typedef struct EState {
/* mode this stream is in, and whether inputting */
/* or outputting data */
int32_t mode;
int32_t state;
uint8_t mode;
uint8_t state;
/* misc administratium */
uint8_t blockSize100k;
/* remembers avail_in when flush/finish requested */
/* bbox: not needed, strm->avail_in always has the same value */
@@ -129,20 +132,19 @@ typedef struct EState {
/* uint32_t avail_in_expect; */
/* for doing the block sorting */
int32_t origPtr;
uint32_t *arr1;
uint32_t *arr2;
uint32_t *ftab;
uint16_t *quadrant;
int32_t budget;
/* aliases for arr1 and arr2 */
uint32_t *ptr;
uint8_t *block;
uint16_t *mtfv;
uint8_t *zbits;
/* guess what */
uint32_t *crc32table;
/* run-length-encoding of the input */
uint32_t state_in_ch;
int32_t state_in_len;
@@ -150,20 +152,23 @@ typedef struct EState {
/* input and output limits and current posns */
int32_t nblock;
int32_t nblockMAX;
int32_t numZ;
int32_t state_out_pos;
//int32_t numZ; // index into s->zbits[], replaced by pointer:
uint8_t *posZ;
uint8_t *state_out_pos;
/* the buffer for bit stream creation */
uint32_t bsBuff;
int32_t bsLive;
/* guess what */
uint32_t *crc32table;
/* block and combined CRCs */
uint32_t blockCRC;
uint32_t combinedCRC;
/* misc administratium */
int32_t blockNo;
int32_t blockSize100k;
/* stuff for coding the MTF values */
int32_t nMTF;
@@ -183,7 +188,7 @@ typedef struct EState {
/* stack-saving measures: these can be local, but they are too big */
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
#if CONFIG_BZIP2_FAST >= 5
#if BZIP2_SPEED >= 5
/* second dimension: only 3 needed; 4 makes index calculations faster */
uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
#endif
@@ -191,7 +196,6 @@ typedef struct EState {
int32_t BZ2_hbMakeCodeLengths__weight[BZ_MAX_ALPHA_SIZE * 2];
int32_t BZ2_hbMakeCodeLengths__parent[BZ_MAX_ALPHA_SIZE * 2];
int32_t mainSort__runningOrder[256];
int32_t mainSort__copyStart[256];
int32_t mainSort__copyEnd[256];
} EState;
@@ -199,7 +203,7 @@ typedef struct EState {
/*-- compression. --*/
static void
static int32_t
BZ2_blockSort(EState*);
static void
+206 -131
View File
@@ -32,6 +32,12 @@ in the file LICENSE.
/* #include "bzlib_private.h" */
#if BZIP2_SPEED >= 5
# define ALWAYS_INLINE_5 ALWAYS_INLINE
#else
# define ALWAYS_INLINE_5 /*nothing*/
#endif
/*---------------------------------------------------*/
/*--- Bit stream I/O ---*/
/*---------------------------------------------------*/
@@ -50,8 +56,7 @@ static NOINLINE
void bsFinishWrite(EState* s)
{
while (s->bsLive > 0) {
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
s->numZ++;
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
s->bsBuff <<= 8;
s->bsLive -= 8;
}
@@ -61,39 +66,74 @@ void bsFinishWrite(EState* s)
/*---------------------------------------------------*/
static
/* Helps only on level 5, on other levels hurts. ? */
#if CONFIG_BZIP2_FAST >= 5
ALWAYS_INLINE
#endif
ALWAYS_INLINE_5
void bsW(EState* s, int32_t n, uint32_t v)
{
while (s->bsLive >= 8) {
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
s->numZ++;
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
s->bsBuff <<= 8;
s->bsLive -= 8;
}
s->bsBuff |= (v << (32 - s->bsLive - n));
s->bsLive += n;
}
/* Same with n == 16: */
static
ALWAYS_INLINE_5
void bsW16(EState* s, uint32_t v)
{
while (s->bsLive >= 8) {
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
s->bsBuff <<= 8;
s->bsLive -= 8;
}
s->bsBuff |= (v << (16 - s->bsLive));
s->bsLive += 16;
}
/* Same with n == 1: */
static
ALWAYS_INLINE /* one callsite */
void bsW1_1(EState* s)
{
/* need space for only 1 bit, no need for loop freeing > 8 bits */
if (s->bsLive >= 8) {
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
s->bsBuff <<= 8;
s->bsLive -= 8;
}
s->bsBuff |= (1 << (31 - s->bsLive));
s->bsLive += 1;
}
static
ALWAYS_INLINE_5
void bsW1_0(EState* s)
{
/* need space for only 1 bit, no need for loop freeing > 8 bits */
if (s->bsLive >= 8) {
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
s->bsBuff <<= 8;
s->bsLive -= 8;
}
//s->bsBuff |= (0 << (31 - s->bsLive));
s->bsLive += 1;
}
/*---------------------------------------------------*/
static ALWAYS_INLINE
void bsPutU16(EState* s, unsigned u)
{
bsW16(s, u);
}
/*---------------------------------------------------*/
static
void bsPutU32(EState* s, unsigned u)
{
bsW(s, 8, (u >> 24) & 0xff);
bsW(s, 8, (u >> 16) & 0xff);
bsW(s, 8, (u >> 8) & 0xff);
bsW(s, 8, u & 0xff);
}
/*---------------------------------------------------*/
static
void bsPutU16(EState* s, unsigned u)
{
bsW(s, 8, (u >> 8) & 0xff);
bsW(s, 8, u & 0xff);
//bsW(s, 32, u); // can't use: may try "uint32 << -n"
bsW16(s, (u >> 16) & 0xffff);
bsW16(s, u & 0xffff);
}
@@ -106,25 +146,57 @@ static
void makeMaps_e(EState* s)
{
int i;
s->nInUse = 0;
unsigned cnt = 0;
for (i = 0; i < 256; i++) {
if (s->inUse[i]) {
s->unseqToSeq[i] = s->nInUse;
s->nInUse++;
s->unseqToSeq[i] = cnt;
cnt++;
}
}
s->nInUse = cnt;
}
/*---------------------------------------------------*/
/*
* This bit of code is performance-critical.
* On 32bit x86, gcc-6.3.0 was observed to spill ryy_j to stack,
* resulting in abysmal performance (x3 slowdown).
* Forcing it into a separate function alleviates register pressure,
* and spillage no longer happens.
* Other versions of gcc do not exhibit this problem, but out-of-line code
* seems to be helping them too (code is both smaller and faster).
* Therefore NOINLINE is enabled for the entire 32bit x86 arch for now,
* without a check for gcc version.
*/
static
#if defined __i386__
NOINLINE
#endif
int inner_loop(uint8_t *yy, uint8_t ll_i)
{
register uint8_t rtmp;
register uint8_t* ryy_j;
rtmp = yy[1];
yy[1] = yy[0];
ryy_j = &(yy[1]);
while (ll_i != rtmp) {
register uint8_t rtmp2;
ryy_j++;
rtmp2 = rtmp;
rtmp = *ryy_j;
*ryy_j = rtmp2;
}
yy[0] = rtmp;
return ryy_j - &(yy[0]);
}
static NOINLINE
void generateMTFValues(EState* s)
{
uint8_t yy[256];
int32_t i, j;
int32_t zPend;
int i;
int zPend;
int32_t wr;
int32_t EOB;
/*
* After sorting (eg, here),
@@ -148,95 +220,74 @@ void generateMTFValues(EState* s)
* compressBlock().
*/
uint32_t* ptr = s->ptr;
uint8_t* block = s->block;
uint16_t* mtfv = s->mtfv;
makeMaps_e(s);
EOB = s->nInUse+1;
for (i = 0; i <= EOB; i++)
s->mtfFreq[i] = 0;
wr = 0;
zPend = 0;
for (i = 0; i <= s->nInUse+1; i++)
s->mtfFreq[i] = 0;
for (i = 0; i < s->nInUse; i++)
yy[i] = (uint8_t) i;
for (i = 0; i < s->nblock; i++) {
uint8_t ll_i;
uint8_t ll_i = ll_i; /* gcc 4.3.1 thinks it may be used w/o init */
int32_t j;
AssertD(wr <= i, "generateMTFValues(1)");
j = ptr[i] - 1;
if (j < 0)
j += s->nblock;
ll_i = s->unseqToSeq[block[j]];
ll_i = s->unseqToSeq[s->block[j]];
AssertD(ll_i < s->nInUse, "generateMTFValues(2a)");
if (yy[0] == ll_i) {
zPend++;
} else {
if (zPend > 0) {
zPend--;
while (1) {
if (zPend & 1) {
mtfv[wr] = BZ_RUNB; wr++;
s->mtfFreq[BZ_RUNB]++;
} else {
mtfv[wr] = BZ_RUNA; wr++;
s->mtfFreq[BZ_RUNA]++;
}
if (zPend < 2) break;
zPend = (uint32_t)(zPend - 2) / 2;
/* bbox: unsigned div is easier */
};
zPend = 0;
}
{
register uint8_t rtmp;
register uint8_t* ryy_j;
register uint8_t rll_i;
rtmp = yy[1];
yy[1] = yy[0];
ryy_j = &(yy[1]);
rll_i = ll_i;
while (rll_i != rtmp) {
register uint8_t rtmp2;
ryy_j++;
rtmp2 = rtmp;
rtmp = *ryy_j;
*ryy_j = rtmp2;
};
yy[0] = rtmp;
j = ryy_j - &(yy[0]);
mtfv[wr] = j+1;
wr++;
s->mtfFreq[j+1]++;
}
continue;
}
}
if (zPend > 0) {
zPend--;
while (1) {
if (zPend & 1) {
mtfv[wr] = BZ_RUNB;
if (zPend > 0) {
process_zPend:
zPend--;
while (1) {
#if 0
if (zPend & 1) {
s->mtfv[wr] = BZ_RUNB; wr++;
s->mtfFreq[BZ_RUNB]++;
} else {
s->mtfv[wr] = BZ_RUNA; wr++;
s->mtfFreq[BZ_RUNA]++;
}
#else /* same as above, since BZ_RUNA is 0 and BZ_RUNB is 1 */
unsigned run = zPend & 1;
s->mtfv[wr] = run;
wr++;
s->mtfFreq[BZ_RUNB]++;
} else {
mtfv[wr] = BZ_RUNA;
wr++;
s->mtfFreq[BZ_RUNA]++;
s->mtfFreq[run]++;
#endif
zPend -= 2;
if (zPend < 0)
break;
zPend = (unsigned)zPend / 2;
/* bbox: unsigned div is easier */
}
if (zPend < 2)
break;
zPend = (uint32_t)(zPend - 2) / 2;
/* bbox: unsigned div is easier */
};
zPend = 0;
if (i < 0) /* came via "goto process_zPend"? exit */
goto end;
zPend = 0;
}
j = inner_loop(yy, ll_i);
s->mtfv[wr] = j+1;
wr++;
s->mtfFreq[j+1]++;
}
mtfv[wr] = EOB;
i = -1;
if (zPend > 0)
goto process_zPend; /* "process it and come back here" */
end:
s->mtfv[wr] = s->nInUse+1;
wr++;
s->mtfFreq[EOB]++;
s->mtfFreq[s->nInUse+1]++;
s->nMTF = wr;
}
@@ -249,8 +300,11 @@ void generateMTFValues(EState* s)
static NOINLINE
void sendMTFValues(EState* s)
{
int32_t v, t, i, j, gs, ge, bt, bc, iter;
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
int32_t t, i;
unsigned iter;
unsigned gs;
int32_t alphaSize;
unsigned nSelectors, selCtr;
int32_t nGroups;
/*
@@ -266,39 +320,49 @@ void sendMTFValues(EState* s)
#define rfreq sendMTFValues__rfreq
#define len_pack sendMTFValues__len_pack
uint16_t cost[BZ_N_GROUPS];
int32_t fave[BZ_N_GROUPS];
unsigned /*uint16_t*/ cost[BZ_N_GROUPS];
uint16_t* mtfv = s->mtfv;
alphaSize = s->nInUse + 2;
for (t = 0; t < BZ_N_GROUPS; t++)
for (t = 0; t < BZ_N_GROUPS; t++) {
unsigned v;
for (v = 0; v < alphaSize; v++)
s->len[t][v] = BZ_GREATER_ICOST;
}
/*--- Decide how many coding tables to use ---*/
AssertH(s->nMTF > 0, 3001);
if (s->nMTF < 200) nGroups = 2; else
if (s->nMTF < 600) nGroups = 3; else
if (s->nMTF < 1200) nGroups = 4; else
if (s->nMTF < 2400) nGroups = 5; else
nGroups = 6;
// 1..199 = 2
// 200..599 = 3
// 600..1199 = 4
// 1200..2399 = 5
// 2400..99999 = 6
nGroups = 2;
nGroups += (s->nMTF >= 200);
nGroups += (s->nMTF >= 600);
nGroups += (s->nMTF >= 1200);
nGroups += (s->nMTF >= 2400);
/*--- Generate an initial set of coding tables ---*/
{
int32_t nPart, remF, tFreq, aFreq;
unsigned nPart, remF;
nPart = nGroups;
remF = s->nMTF;
gs = 0;
while (nPart > 0) {
unsigned v;
unsigned ge;
unsigned tFreq, aFreq;
tFreq = remF / nPart;
ge = gs - 1;
ge = gs;
aFreq = 0;
while (aFreq < tFreq && ge < alphaSize-1) {
ge++;
aFreq += s->mtfFreq[ge];
while (aFreq < tFreq && ge < alphaSize) {
aFreq += s->mtfFreq[ge++];
}
ge--;
if (ge > gs
&& nPart != nGroups && nPart != 1
@@ -324,19 +388,19 @@ void sendMTFValues(EState* s)
* Iterate up to BZ_N_ITERS times to improve the tables.
*/
for (iter = 0; iter < BZ_N_ITERS; iter++) {
for (t = 0; t < nGroups; t++)
fave[t] = 0;
for (t = 0; t < nGroups; t++)
for (t = 0; t < nGroups; t++) {
unsigned v;
for (v = 0; v < alphaSize; v++)
s->rfreq[t][v] = 0;
}
#if CONFIG_BZIP2_FAST >= 5
#if BZIP2_SPEED >= 5
/*
* Set up an auxiliary length table which is used to fast-track
* the common case (nGroups == 6).
*/
if (nGroups == 6) {
unsigned v;
for (v = 0; v < alphaSize; v++) {
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
@@ -347,6 +411,9 @@ void sendMTFValues(EState* s)
nSelectors = 0;
gs = 0;
while (1) {
unsigned ge;
unsigned bt, bc;
/*--- Set group start & end marks. --*/
if (gs >= s->nMTF)
break;
@@ -360,7 +427,7 @@ void sendMTFValues(EState* s)
*/
for (t = 0; t < nGroups; t++)
cost[t] = 0;
#if CONFIG_BZIP2_FAST >= 5
#if BZIP2_SPEED >= 5
if (nGroups == 6 && 50 == ge-gs+1) {
/*--- fast track the common case ---*/
register uint32_t cost01, cost23, cost45;
@@ -390,7 +457,7 @@ void sendMTFValues(EState* s)
{
/*--- slow version which correctly handles all situations ---*/
for (i = gs; i <= ge; i++) {
uint16_t icv = mtfv[i];
unsigned /*uint16_t*/ icv = mtfv[i];
for (t = 0; t < nGroups; t++)
cost[t] += s->len[t][icv];
}
@@ -409,7 +476,6 @@ void sendMTFValues(EState* s)
bt = t;
}
}
fave[bt]++;
s->selector[nSelectors] = bt;
nSelectors++;
@@ -417,7 +483,7 @@ void sendMTFValues(EState* s)
* Increment the symbol frequencies for the selected table.
*/
/* 1% faster compress. +800 bytes */
#if CONFIG_BZIP2_FAST >= 4
#if BZIP2_SPEED >= 4
if (nGroups == 6 && 50 == ge-gs+1) {
/*--- fast track the common case ---*/
#define BZ_ITUR(nn) s->rfreq[bt][mtfv[gs + (nn)]]++
@@ -464,6 +530,7 @@ void sendMTFValues(EState* s)
for (i = 0; i < nGroups; i++)
pos[i] = i;
for (i = 0; i < nSelectors; i++) {
unsigned j;
ll_i = s->selector[i];
j = 0;
tmp = pos[j];
@@ -472,16 +539,16 @@ void sendMTFValues(EState* s)
tmp2 = tmp;
tmp = pos[j];
pos[j] = tmp2;
};
}
pos[0] = tmp;
s->selectorMtf[i] = j;
}
};
}
/*--- Assign actual codes for the tables. --*/
for (t = 0; t < nGroups; t++) {
minLen = 32;
maxLen = 0;
unsigned minLen = 32; //todo: s->len[t][0];
unsigned maxLen = 0; //todo: s->len[t][0];
for (i = 0; i < alphaSize; i++) {
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
if (s->len[t][i] < minLen) minLen = s->len[t][i];
@@ -509,15 +576,16 @@ void sendMTFValues(EState* s)
}
}
bsW(s, 16, inUse16);
bsW16(s, inUse16);
inUse16 <<= (sizeof(int)*8 - 16); /* move 15th bit into sign bit */
for (i = 0; i < 16; i++) {
if (inUse16 < 0) {
unsigned v16 = 0;
unsigned j;
for (j = 0; j < 16; j++)
v16 = v16*2 + s->inUse[i * 16 + j];
bsW(s, 16, v16);
bsW16(s, v16);
}
inUse16 <<= 1;
}
@@ -527,19 +595,20 @@ void sendMTFValues(EState* s)
bsW(s, 3, nGroups);
bsW(s, 15, nSelectors);
for (i = 0; i < nSelectors; i++) {
unsigned j;
for (j = 0; j < s->selectorMtf[i]; j++)
bsW(s, 1, 1);
bsW(s, 1, 0);
bsW1_1(s);
bsW1_0(s);
}
/*--- Now the coding tables. ---*/
for (t = 0; t < nGroups; t++) {
int32_t curr = s->len[t][0];
unsigned curr = s->len[t][0];
bsW(s, 5, curr);
for (i = 0; i < alphaSize; i++) {
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ };
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ };
bsW(s, 1, 0);
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ }
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ }
bsW1_0(s);
}
}
@@ -547,6 +616,8 @@ void sendMTFValues(EState* s)
selCtr = 0;
gs = 0;
while (1) {
unsigned ge;
if (gs >= s->nMTF)
break;
ge = gs + BZ_G_SIZE - 1;
@@ -605,17 +676,21 @@ void sendMTFValues(EState* s)
static
void BZ2_compressBlock(EState* s, int is_last_block)
{
int32_t origPtr = origPtr;
if (s->nblock > 0) {
BZ_FINALISE_CRC(s->blockCRC);
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
s->combinedCRC ^= s->blockCRC;
if (s->blockNo > 1)
s->numZ = 0;
s->posZ = s->zbits; // was: s->numZ = 0;
BZ2_blockSort(s);
origPtr = BZ2_blockSort(s);
}
s->zbits = &((uint8_t*)s->arr2)[s->nblock];
s->posZ = s->zbits;
s->state_out_pos = s->zbits;
/*-- If this is the first block, create the stream header. --*/
if (s->blockNo == 1) {
@@ -649,9 +724,9 @@ void BZ2_compressBlock(EState* s, int is_last_block)
* so as to maintain backwards compatibility with
* older versions of bzip2.
*/
bsW(s, 1, 0);
bsW1_0(s);
bsW(s, 24, s->origPtr);
bsW(s, 24, origPtr);
generateMTFValues(s);
sendMTFValues(s);
}
+2 -2
View File
@@ -48,7 +48,7 @@ in the file LICENSE.
/* 90 bytes, 0.3% of overall compress speed */
#if CONFIG_BZIP2_FAST >= 1
#if BZIP2_SPEED >= 1
/* macro works better than inline (gcc 4.2.1) */
#define DOWNHEAP1(heap, weight, Heap) \
@@ -217,7 +217,7 @@ void BZ2_hbAssignCodes(int32_t *code,
if (length[i] == n) {
code[i] = vec;
vec++;
};
}
}
vec <<= 1;
}
+11 -27
View File
@@ -107,9 +107,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
}
else if (existing_sb.st_mtime >= file_header->mtime) {
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
&& !S_ISDIR(file_header->mode)
) {
if (!S_ISDIR(file_header->mode)) {
bb_error_msg("%s not created: newer or "
"same age file exists", dst_name);
}
@@ -124,13 +122,10 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
/* Handle hard links separately */
if (hard_link) {
res = link(hard_link, dst_name);
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
/* shared message */
bb_perror_msg("can't create %slink '%s' to '%s'",
"hard", dst_name, hard_link
);
}
create_or_remember_link(&archive_handle->link_placeholders,
hard_link,
dst_name,
1);
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
goto ret;
}
@@ -165,10 +160,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
case S_IFDIR:
res = mkdir(dst_name, file_header->mode);
if ((res == -1)
if ((res != 0)
&& (errno != EISDIR) /* btw, Linux doesn't return this */
&& (errno != EEXIST)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't make dir %s", dst_name);
}
@@ -198,27 +192,17 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
*
* Untarring bug.tar would otherwise place evil.py in '/tmp'.
*/
if (!unsafe_symlink_target(file_header->link_target)) {
res = symlink(file_header->link_target, dst_name);
if (res != 0
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
/* shared message */
bb_perror_msg("can't create %slink '%s' to '%s'",
"sym",
dst_name, file_header->link_target
);
}
}
create_or_remember_link(&archive_handle->link_placeholders,
file_header->link_target,
dst_name,
0);
break;
case S_IFSOCK:
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
res = mknod(dst_name, file_header->mode, file_header->device);
if ((res == -1)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
if (res != 0) {
bb_perror_msg("can't create node %s", dst_name);
}
break;
@@ -37,7 +37,7 @@ static const char *const tar_var[] = {
static void xputenv(char *str)
{
if (putenv(str))
bb_error_msg_and_die(bb_msg_memory_exhausted);
bb_die_memory_exhausted();
}
static void str2env(char *env[], int idx, const char *str)
+56 -22
View File
@@ -100,7 +100,7 @@ struct bunzip_data {
unsigned dbufSize;
/* For I/O error handling */
jmp_buf jmpbuf;
jmp_buf *jmpbuf;
/* Big things go last (register-relative addressing can be larger for big offsets) */
uint32_t crc32Table[256];
@@ -127,7 +127,7 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
/* if "no input fd" case: in_fd == -1, read fails, we jump */
bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE);
if (bd->inbufCount <= 0)
longjmp(bd->jmpbuf, RETVAL_UNEXPECTED_INPUT_EOF);
longjmp(*bd->jmpbuf, RETVAL_UNEXPECTED_INPUT_EOF);
bd->inbufPos = 0;
}
@@ -151,12 +151,12 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
return bits;
}
//#define get_bits(bd, n) (dbg("%d:get_bits()", __LINE__), get_bits(bd, n))
/* Unpacks the next block and sets up for the inverse Burrows-Wheeler step. */
static int get_next_block(bunzip_data *bd)
{
struct group_data *hufGroup;
int groupCount, *base, *limit, selector,
int groupCount, selector,
i, j, symCount, symTotal, nSelectors, byteCount[256];
uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
uint32_t *dbuf;
@@ -179,15 +179,19 @@ static int get_next_block(bunzip_data *bd)
i = get_bits(bd, 24);
j = get_bits(bd, 24);
bd->headerCRC = get_bits(bd, 32);
if ((i == 0x177245) && (j == 0x385090)) return RETVAL_LAST_BLOCK;
if ((i != 0x314159) || (j != 0x265359)) return RETVAL_NOT_BZIP_DATA;
if ((i == 0x177245) && (j == 0x385090))
return RETVAL_LAST_BLOCK;
if ((i != 0x314159) || (j != 0x265359))
return RETVAL_NOT_BZIP_DATA;
/* We can add support for blockRandomised if anybody complains. There was
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
it didn't actually work. */
if (get_bits(bd, 1)) return RETVAL_OBSOLETE_INPUT;
if (get_bits(bd, 1))
return RETVAL_OBSOLETE_INPUT;
origPtr = get_bits(bd, 24);
if (origPtr > bd->dbufSize) return RETVAL_DATA_ERROR;
if (origPtr > bd->dbufSize)
return RETVAL_DATA_ERROR;
/* mapping table: if some byte values are never used (encoding things
like ascii text), the compression code removes the gaps to have fewer
@@ -231,13 +235,21 @@ static int get_next_block(bunzip_data *bd)
/* Get next value */
int n = 0;
while (get_bits(bd, 1)) {
if (n >= groupCount) return RETVAL_DATA_ERROR;
if (n >= groupCount)
return RETVAL_DATA_ERROR;
n++;
}
/* Decode MTF to get the next selector */
tmp_byte = mtfSymbol[n];
while (--n >= 0)
mtfSymbol[n + 1] = mtfSymbol[n];
//We catch it later, in the second loop where we use selectors[i].
//Maybe this is a better place, though?
// if (tmp_byte >= groupCount) {
// dbg("%d: selectors[%d]:%d groupCount:%d",
// __LINE__, i, tmp_byte, groupCount);
// return RETVAL_DATA_ERROR;
// }
mtfSymbol[0] = selectors[i] = tmp_byte;
}
@@ -248,6 +260,8 @@ static int get_next_block(bunzip_data *bd)
uint8_t length[MAX_SYMBOLS];
/* 8 bits is ALMOST enough for temp[], see below */
unsigned temp[MAX_HUFCODE_BITS+1];
struct group_data *hufGroup;
int *base, *limit;
int minLen, maxLen, pp, len_m1;
/* Read Huffman code lengths for each symbol. They're stored in
@@ -283,8 +297,10 @@ static int get_next_block(bunzip_data *bd)
/* Find largest and smallest lengths in this group */
minLen = maxLen = length[0];
for (i = 1; i < symCount; i++) {
if (length[i] > maxLen) maxLen = length[i];
else if (length[i] < minLen) minLen = length[i];
if (length[i] > maxLen)
maxLen = length[i];
else if (length[i] < minLen)
minLen = length[i];
}
/* Calculate permute[], base[], and limit[] tables from length[].
@@ -320,7 +336,8 @@ static int get_next_block(bunzip_data *bd)
/* Count symbols coded for at each bit length */
/* NB: in pathological cases, temp[8] can end ip being 256.
* That's why uint8_t is too small for temp[]. */
for (i = 0; i < symCount; i++) temp[length[i]]++;
for (i = 0; i < symCount; i++)
temp[length[i]]++;
/* Calculate limit[] (the largest symbol-coding value at each bit
* length, which is (previous limit<<1)+symbols at this level), and
@@ -363,12 +380,22 @@ static int get_next_block(bunzip_data *bd)
runPos = dbufCount = selector = 0;
for (;;) {
struct group_data *hufGroup;
int *base, *limit;
int nextSym;
uint8_t ngrp;
/* Fetch next Huffman coding group from list. */
symCount = GROUP_SIZE - 1;
if (selector >= nSelectors) return RETVAL_DATA_ERROR;
hufGroup = bd->groups + selectors[selector++];
if (selector >= nSelectors)
return RETVAL_DATA_ERROR;
ngrp = selectors[selector++];
if (ngrp >= groupCount) {
dbg("%d selectors[%d]:%d groupCount:%d",
__LINE__, selector-1, ngrp, groupCount);
return RETVAL_DATA_ERROR;
}
hufGroup = bd->groups + ngrp;
base = hufGroup->base - 1;
limit = hufGroup->limit - 1;
@@ -403,7 +430,8 @@ static int get_next_block(bunzip_data *bd)
}
/* Figure how many bits are in next symbol and unget extras */
i = hufGroup->minLen;
while (nextSym > limit[i]) ++i;
while (nextSym > limit[i])
++i;
j = hufGroup->maxLen - i;
if (j < 0)
return RETVAL_DATA_ERROR;
@@ -671,7 +699,10 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* Because bunzip2 is used for help text unpacking, and because bb_show_usage()
should work for NOFORK applets too, we must be extremely careful to not leak
any allocations! */
int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd,
int FAST_FUNC start_bunzip(
void *jmpbuf,
bunzip_data **bdp,
int in_fd,
const void *inbuf, int len)
{
bunzip_data *bd;
@@ -683,11 +714,14 @@ int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd,
/* Figure out how much data to allocate */
i = sizeof(bunzip_data);
if (in_fd != -1) i += IOBUF_SIZE;
if (in_fd != -1)
i += IOBUF_SIZE;
/* Allocate bunzip_data. Most fields initialize to zero. */
bd = *bdp = xzalloc(i);
bd->jmpbuf = jmpbuf;
/* Setup input buffer */
bd->in_fd = in_fd;
if (-1 == in_fd) {
@@ -702,10 +736,6 @@ int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd,
/* Init the CRC32 table (big endian) */
crc32_filltable(bd->crc32Table, 1);
/* Setup for I/O error handling via longjmp */
i = setjmp(bd->jmpbuf);
if (i) return i;
/* Ensure that file starts with "BZh['1'-'9']." */
/* Update: now caller verifies 1st two bytes, makes .gz/.bz2
* integration easier */
@@ -752,8 +782,12 @@ unpack_bz2_stream(transformer_state_t *xstate)
outbuf = xmalloc(IOBUF_SIZE);
len = 0;
while (1) { /* "Process one BZ... stream" loop */
jmp_buf jmpbuf;
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
/* Setup for I/O error handling via longjmp */
i = setjmp(jmpbuf);
if (i == 0)
i = start_bunzip(&jmpbuf, &bd, xstate->src_fd, outbuf + 2, len);
if (i == 0) {
while (1) { /* "Produce some output bytes" loop */
+12 -6
View File
@@ -32,7 +32,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include <setjmp.h>
#include "libbb.h"
#include "bb_archive.h"
@@ -280,8 +279,8 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
/* Given a list of code lengths and a maximum table size, make a set of
* tables to decode that set of codes. Return zero on success, one if
* the given code set is incomplete (the tables are still built in this
* case), two if the input is invalid (all zero length codes or an
* oversubscribed set of lengths) - in this case stores NULL in *t.
* case), two if the input is invalid (an oversubscribed set of lengths)
* - in this case stores NULL in *t.
*
* b: code lengths in bits (all assumed <= BMAX)
* n: number of codes (assumed <= N_MAX)
@@ -330,8 +329,15 @@ static int huft_build(const unsigned *b, const unsigned n,
p++; /* can't combine with above line (Solaris bug) */
} while (--i);
if (c[0] == n) { /* null input - all zero length codes */
*m = 0;
return 2;
q = xzalloc(3 * sizeof(*q));
//q[0].v.t = NULL;
q[1].e = 99; /* invalid code marker */
q[1].b = 1;
q[2].e = 99; /* invalid code marker */
q[2].b = 1;
*t = q + 1;
*m = 1;
return 0;
}
/* Find minimum and maximum length, bound *m by those */
@@ -1000,7 +1006,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
gunzip_bb = 0;
/* Create the crc table */
gunzip_crc_table = crc32_filltable(NULL, 0);
gunzip_crc_table = crc32_new_table_le();
gunzip_crc = ~0;
error_msg = "corrupted data";
+29 -3
View File
@@ -11,6 +11,13 @@
#include "libbb.h"
#include "bb_archive.h"
#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
#else
# define dbg(...) ((void)0)
#endif
#if ENABLE_FEATURE_LZMA_FAST
# define speed_inline ALWAYS_INLINE
# define size_inline
@@ -217,6 +224,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
rc_t *rc;
int i;
uint8_t *buffer;
uint32_t buffer_size;
uint8_t previous_byte = 0;
size_t buffer_pos = 0, global_pos = 0;
int len = 0;
@@ -246,7 +254,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
if (header.dict_size == 0)
header.dict_size++;
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
buffer_size = MIN(header.dst_size, header.dict_size);
buffer = xmalloc(buffer_size);
{
int num_probs;
@@ -341,8 +350,12 @@ unpack_lzma_stream(transformer_state_t *xstate)
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
pos = buffer_pos - rep0;
if ((int32_t)pos < 0)
if ((int32_t)pos < 0) {
pos += header.dict_size;
/* see unzip_bad_lzma_2.zip: */
if (pos >= buffer_size)
goto bad;
}
previous_byte = buffer[pos];
goto one_byte1;
#else
@@ -417,6 +430,10 @@ unpack_lzma_stream(transformer_state_t *xstate)
for (; num_bits2 != LZMA_NUM_ALIGN_BITS; num_bits2--)
rep0 = (rep0 << 1) | rc_direct_bit(rc);
rep0 <<= LZMA_NUM_ALIGN_BITS;
if ((int32_t)rep0 < 0) {
dbg("%d rep0:%d", __LINE__, rep0);
goto bad;
}
prob3 = p + LZMA_ALIGN;
}
i2 = 1;
@@ -453,7 +470,10 @@ unpack_lzma_stream(transformer_state_t *xstate)
if ((int32_t)pos < 0) {
pos += header.dict_size;
/* bug 10436 has an example file where this triggers: */
if ((int32_t)pos < 0)
//if ((int32_t)pos < 0)
// goto bad;
/* more stringent test (see unzip_bad_lzma_1.zip): */
if (pos >= buffer_size)
goto bad;
}
previous_byte = buffer[pos];
@@ -482,6 +502,12 @@ unpack_lzma_stream(transformer_state_t *xstate)
IF_DESKTOP(total_written += buffer_pos;)
if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
bad:
/* One of our users, bbunpack(), expects _us_ to emit
* the error message (since it's the best place to give
* potentially more detailed information).
* Do not fail silently.
*/
bb_error_msg("corrupted data");
total_written = -1; /* failure */
}
rc_free(rc);
+1 -1
View File
@@ -52,7 +52,7 @@ unpack_xz_stream(transformer_state_t *xstate)
IF_DESKTOP(long long) int total = 0;
if (!global_crc32_table)
global_crc32_table = crc32_filltable(NULL, /*endian:*/ 0);
global_crc32_new_table_le();
memset(&iobuf, 0, sizeof(iobuf));
membuf = xmalloc(2 * BUFSIZ);
+10 -12
View File
@@ -34,10 +34,6 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
char raw[60];
struct ar_header formatted;
} ar;
#if ENABLE_FEATURE_AR_LONG_FILENAMES
static char *ar_long_names;
static unsigned ar_long_name_size;
#endif
/* dont use xread as we want to handle the error ourself */
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
@@ -81,10 +77,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
* stores long filename for multiple entries, they are stored
* in static variable long_names for use in future entries
*/
ar_long_name_size = size;
free(ar_long_names);
ar_long_names = xmalloc(size);
xread(archive_handle->src_fd, ar_long_names, size);
archive_handle->ar__long_name_size = size;
free(archive_handle->ar__long_names);
archive_handle->ar__long_names = xzalloc(size + 1);
xread(archive_handle->src_fd, archive_handle->ar__long_names, size);
archive_handle->offset += size;
/* Return next header */
return get_header_ar(archive_handle);
@@ -107,13 +103,13 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
unsigned long_offset;
/* The number after the '/' indicates the offset in the ar data section
* (saved in ar_long_names) that conatains the real filename */
* (saved in ar__long_names) that contains the real filename */
long_offset = read_num(&ar.formatted.name[1], 10,
sizeof(ar.formatted.name) - 1);
if (long_offset >= ar_long_name_size) {
if (long_offset >= archive_handle->ar__long_name_size) {
bb_error_msg_and_die("can't resolve long filename");
}
typed->name = xstrdup(ar_long_names + long_offset);
typed->name = xstrdup(archive_handle->ar__long_names + long_offset);
} else
#endif
{
@@ -127,8 +123,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
archive_handle->action_header(typed);
#if ENABLE_DPKG || ENABLE_DPKG_DEB
if (archive_handle->dpkg__sub_archive) {
while (archive_handle->dpkg__action_data_subarchive(archive_handle->dpkg__sub_archive) == EXIT_SUCCESS)
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS)
continue;
create_links_from_list(sa->link_placeholders);
} else
#endif
archive_handle->action_data(archive_handle);
+26 -25
View File
@@ -152,6 +152,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header_t *file_header = archive_handle->file_header;
struct tar_header_t tar;
char *cp;
int tar_typeflag; /* can be "char", "int" seems give smaller code */
int i, sum_u, sum;
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
int sum_s;
@@ -253,10 +254,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* POSIX says that checksum is done on unsigned bytes, but
* Sun and HP-UX gets it wrong... more details in
* GNU tar source. */
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
sum_s = ' ' * sizeof(tar.chksum);
#endif
sum_u = ' ' * sizeof(tar.chksum);
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
sum_s = sum_u;
#endif
for (i = 0; i < 148; i++) {
sum_u += ((unsigned char*)&tar)[i];
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
@@ -269,27 +270,22 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
sum_s += ((signed char*)&tar)[i];
#endif
}
/* This field does not need special treatment (getOctal) */
{
char *endp; /* gcc likes temp var for &endp */
sum = strtoul(tar.chksum, &endp, 8);
if ((*endp != '\0' && *endp != ' ')
|| (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
) {
bb_error_msg_and_die("invalid tar header checksum");
}
}
/* don't use xstrtoul, tar.chksum may have leading spaces */
sum = strtoul(tar.chksum, NULL, 8);
if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
/* Most tarfiles have tar.chksum NUL or space terminated, but
* github.com decided to be "special" and have unterminated field:
* 0090: 30343300 30303031 33323731 30000000 |043.000132710...|
* ^^^^^^^^|
* Need to use GET_OCTAL. This overwrites tar.typeflag ---+
* (the '0' char immediately after chksum in example above) with NUL.
*/
tar_typeflag = (uint8_t)tar.typeflag; /* save it */
sum = GET_OCTAL(tar.chksum);
if (sum_u != sum
IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)
) {
bb_error_msg_and_die("invalid tar header checksum");
}
/* 0 is reserved for high perf file, treat as normal file */
if (!tar.typeflag) tar.typeflag = '0';
parse_names = (tar.typeflag >= '0' && tar.typeflag <= '7');
/* getOctal trashes subsequent field, therefore we call it
/* GET_OCTAL trashes subsequent field, therefore we call it
* on fields in reverse order */
if (tar.devmajor[0]) {
char t = tar.prefix[0];
@@ -299,6 +295,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header->device = makedev(major, minor);
tar.prefix[0] = t;
}
/* 0 is reserved for high perf file, treat as normal file */
if (tar_typeflag == '\0') tar_typeflag = '0';
parse_names = (tar_typeflag >= '0' && tar_typeflag <= '7');
file_header->link_target = NULL;
if (!p_linkname && parse_names && tar.linkname[0]) {
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
@@ -332,7 +333,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* Set bits 12-15 of the files mode */
/* (typeflag was not trashed because chksum does not use getOctal) */
switch (tar.typeflag) {
switch (tar_typeflag) {
case '1': /* hardlink */
/* we mark hardlinks as regular files with zero size and a link name */
file_header->mode |= S_IFREG;
@@ -381,7 +382,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
case 'x': { /* pax extended header */
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
goto skip_ext_hdr;
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
process_pax_hdr(archive_handle, file_header->size, (tar_typeflag == 'g'));
goto again_after_align;
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
@@ -419,7 +420,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
skip_ext_hdr:
{
off_t sz;
bb_error_msg("warning: skipping header '%c'", tar.typeflag);
bb_error_msg("warning: skipping header '%c'", tar_typeflag);
sz = (file_header->size + 511) & ~(off_t)511;
archive_handle->offset += sz;
sz >>= 9; /* sz /= 512 but w/o contortions for signed div */
@@ -429,7 +430,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
goto again_after_align;
}
default:
bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
bb_error_msg_and_die("unknown typeflag: 0x%x", tar_typeflag);
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
+1 -2
View File
@@ -31,8 +31,7 @@
************************************************************************/
/* safe decompression with overrun testing */
int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
uint8_t* out, unsigned* out_len,
void* wrkmem UNUSED_PARAM)
uint8_t* out, unsigned* out_len /*, void* wrkmem */)
{
register uint8_t* op;
register const uint8_t* ip;
+27 -33
View File
@@ -5,44 +5,38 @@
#include "libbb.h"
#include "bb_archive.h"
int FAST_FUNC unsafe_symlink_target(const char *target)
void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
const char *target,
const char *linkname,
int hard_link)
{
const char *dot;
if (target[0] == '/') {
const char *var;
unsafe:
var = getenv("EXTRACT_UNSAFE_SYMLINKS");
if (var) {
if (LONE_CHAR(var, '1'))
return 0; /* pretend it's safe */
return 1; /* "UNSAFE!" */
}
bb_error_msg("skipping unsafe symlink to '%s' in archive,"
" set %s=1 to extract",
target,
"EXTRACT_UNSAFE_SYMLINKS"
if (hard_link || target[0] == '/' || strstr(target, "..")) {
llist_add_to_end(link_placeholders,
xasprintf("%c%s%c%s", hard_link, linkname, '\0', target)
);
/* Prevent further messages */
setenv("EXTRACT_UNSAFE_SYMLINKS", "0", 0);
return 1; /* "UNSAFE!" */
return;
}
if (symlink(target, linkname) != 0) {
/* shared message */
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
"sym", linkname, target
);
}
}
dot = target;
for (;;) {
dot = strchr(dot, '.');
if (!dot)
return 0; /* safe target */
void FAST_FUNC create_links_from_list(llist_t *list)
{
while (list) {
char *target;
/* Is it a path component starting with ".."? */
if ((dot[1] == '.')
&& (dot == target || dot[-1] == '/')
/* Is it exactly ".."? */
&& (dot[2] == '/' || dot[2] == '\0')
) {
goto unsafe;
target = list->data + 1 + strlen(list->data + 1) + 1;
if ((*list->data ? link : symlink) (target, list->data + 1)) {
/* shared message */
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
*list->data ? "hard" : "sym",
list->data + 1, target
);
}
/* NB: it can even be trailing ".", should only add 1 */
dot += 1;
list = list->link;
}
}
+216 -226
View File
@@ -80,7 +80,7 @@
//usage: "\n -F Don't verify checksum"
//usage:
//usage:#define unlzop_trivial_usage
//usage: "[-cfkvF] [FILE]..."
//usage: "[-cfUvF] [FILE]..."
//usage:#define unlzop_full_usage "\n\n"
//usage: " -c Write to stdout"
//usage: "\n -f Force"
@@ -141,8 +141,7 @@ static void copy3(uint8_t* ip, const uint8_t* m_pos, unsigned off)
#define TEST_OP (op <= op_end)
static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
uint8_t *out, unsigned *out_len,
void* wrkmem UNUSED_PARAM)
uint8_t *out, unsigned *out_len /*, void* wrkmem */)
{
uint8_t* op;
uint8_t* ip;
@@ -439,36 +438,33 @@ typedef struct chksum_t {
} chksum_t;
typedef struct header_t {
unsigned version;
unsigned lib_version;
unsigned version_needed_to_extract;
uint32_t flags;
uint32_t mode;
uint32_t mtime;
uint32_t gmtdiff;
uint32_t header_checksum;
/* used to have auxiliary fields here */
uint32_t extra_field_len;
uint32_t extra_field_checksum;
unsigned char method;
unsigned char level;
/* info */
char name[255+1];
/* Starting from here, the layout and endianness
* are exactly in on-disk format.
*/
uint16_t version_be16;
uint16_t lib_version_be16;
uint16_t version_needed_to_extract_be16;
uint8_t method;
uint8_t level;
uint32_t flags32; /* be32 on disk, but we keep this field in native order */
uint32_t mode_be32;
uint32_t mtime_be32;
uint32_t gmtdiff_be32;
char len_and_name[1+255+1];
} header_t;
struct globals {
/*const uint32_t *lzo_crc32_table;*/
chksum_t chksum_in;
chksum_t chksum_out;
chksum_t chksum;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
//#define G (*ptr_to_globals)
//#define INIT_G() do {
// SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
//} while (0)
#define INIT_G() do { \
setup_common_bufsiz(); \
/*SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));*/ \
} while (0)
/**********************************************************************/
@@ -549,24 +545,24 @@ lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len)
}
/**********************************************************************/
static void init_chksum(chksum_t *ct)
static void init_chksum(void)
{
ct->f_adler32 = ADLER32_INIT_VALUE;
ct->f_crc32 = CRC32_INIT_VALUE;
G.chksum.f_adler32 = ADLER32_INIT_VALUE;
G.chksum.f_crc32 = CRC32_INIT_VALUE;
}
static void add_bytes_to_chksum(chksum_t *ct, const void* buf, int cnt)
static void add_bytes_to_chksum(const void* buf, int cnt)
{
/* We need to handle the two checksums at once, because at the
* beginning of the header, we don't know yet which one we'll
* eventually need */
ct->f_adler32 = lzo_adler32(ct->f_adler32, (const uint8_t*)buf, cnt);
ct->f_crc32 = lzo_crc32(ct->f_crc32, (const uint8_t*)buf, cnt);
G.chksum.f_adler32 = lzo_adler32(G.chksum.f_adler32, (const uint8_t*)buf, cnt);
G.chksum.f_crc32 = lzo_crc32(G.chksum.f_crc32, (const uint8_t*)buf, cnt);
}
static uint32_t chksum_getresult(chksum_t *ct, const header_t *h)
static uint32_t chksum_getresult(uint32_t h_flags32)
{
return (h->flags & F_H_CRC32) ? ct->f_crc32 : ct->f_adler32;
return (h_flags32 & F_H_CRC32) ? G.chksum.f_crc32 : G.chksum.f_adler32;
}
/**********************************************************************/
@@ -576,50 +572,23 @@ static uint32_t read32(void)
xread(0, &v, 4);
return ntohl(v);
}
static void write32(uint32_t v)
{
v = htonl(v);
xwrite(1, &v, 4);
}
static void f_write(const void* buf, int cnt)
{
xwrite(1, buf, cnt);
add_bytes_to_chksum(&G.chksum_out, buf, cnt);
}
static void f_read(void* buf, int cnt)
{
xread(0, buf, cnt);
add_bytes_to_chksum(&G.chksum_in, buf, cnt);
add_bytes_to_chksum(buf, cnt);
}
static int f_read8(void)
{
uint8_t v;
f_read(&v, 1);
return v;
}
static void f_write8(uint8_t v)
{
f_write(&v, 1);
}
static unsigned f_read16(void)
{
uint16_t v;
f_read(&v, 2);
return ntohs(v);
}
static void f_write16(uint16_t v)
{
v = htons(v);
f_write(&v, 2);
}
//static int f_read8(void)
//{
// uint8_t v;
// f_read(&v, 1);
// return v;
//}
//static unsigned f_read16(void)
//{
// uint16_t v;
// f_read(&v, 2);
// return ntohs(v);
//}
static uint32_t f_read32(void)
{
uint32_t v;
@@ -627,34 +596,30 @@ static uint32_t f_read32(void)
return ntohl(v);
}
static void f_write32(uint32_t v)
static void write32(uint32_t v)
{
v = htonl(v);
f_write(&v, 4);
xwrite(1, &v, 4);
}
/**********************************************************************/
static int lzo_get_method(header_t *h)
static void f_write(const void* buf, int cnt)
{
/* check method */
if (h->method == M_LZO1X_1) {
if (h->level == 0)
h->level = 3;
} else if (h->method == M_LZO1X_1_15) {
if (h->level == 0)
h->level = 1;
} else if (h->method == M_LZO1X_999) {
if (h->level == 0)
h->level = 9;
} else
return -1; /* not a LZO method */
/* check compression level */
if (h->level < 1 || h->level > 9)
return 15;
return 0;
xwrite(1, buf, cnt);
add_bytes_to_chksum(buf, cnt);
}
//static void f_write8(uint8_t v)
//{
// f_write(&v, 1);
//}
//static void f_write16(uint16_t v)
//{
// v = htons(v);
// f_write(&v, 2);
//}
//static void f_write32(uint32_t v)
//{
// v = htonl(v);
// f_write(&v, 4);
//}
/**********************************************************************/
#define LZO_BLOCK_SIZE (256 * 1024l)
@@ -672,86 +637,101 @@ static NOINLINE int lzo_compress(const header_t *h)
int r = 0; /* LZO_E_OK */
uint8_t *const b1 = xzalloc(block_size);
uint8_t *const b2 = xzalloc(MAX_COMPRESSED_SIZE(block_size));
unsigned src_len = 0, dst_len = 0;
uint32_t d_adler32 = ADLER32_INIT_VALUE;
uint32_t d_crc32 = CRC32_INIT_VALUE;
int l;
uint8_t *wrk_mem = NULL;
/* Only these methods are possible, see lzo_set_method():
* -1: M_LZO1X_1_15
* -2..6: M_LZO1X_1
* -7..9: M_LZO1X_999 if ENABLE_LZOP_COMPR_HIGH
*/
if (h->method == M_LZO1X_1)
wrk_mem = xzalloc(LZO1X_1_MEM_COMPRESS);
else if (h->method == M_LZO1X_1_15)
wrk_mem = xzalloc(LZO1X_1_15_MEM_COMPRESS);
else if (h->method == M_LZO1X_999)
else /* check only if it's not the only possibility */
IF_LZOP_COMPR_HIGH(if (h->method == M_LZO1X_1_15))
wrk_mem = xzalloc(LZO1X_1_15_MEM_COMPRESS);
#if ENABLE_LZOP_COMPR_HIGH
else /* must be h->method == M_LZO1X_999 */
wrk_mem = xzalloc(LZO1X_999_MEM_COMPRESS);
#endif
for (;;) {
unsigned src_len, dst_len;
int l;
uint32_t wordbuf[6];
uint32_t *wordptr = wordbuf;
/* read a block */
l = full_read(0, b1, block_size);
src_len = (l > 0 ? l : 0);
/* write uncompressed block size */
write32(src_len);
/* exit if last block */
if (src_len == 0)
if (src_len == 0) {
write32(0);
break;
}
*wordptr++ = htonl(src_len);
/* compute checksum of uncompressed block */
if (h->flags & F_ADLER32_D)
if (h->flags32 & F_ADLER32_D)
d_adler32 = lzo_adler32(ADLER32_INIT_VALUE, b1, src_len);
if (h->flags & F_CRC32_D)
if (h->flags32 & F_CRC32_D)
d_crc32 = lzo_crc32(CRC32_INIT_VALUE, b1, src_len);
/* compress */
if (h->method == M_LZO1X_1)
r = lzo1x_1_compress(b1, src_len, b2, &dst_len, wrk_mem);
else if (h->method == M_LZO1X_1_15)
else IF_LZOP_COMPR_HIGH(if (h->method == M_LZO1X_1_15))
r = lzo1x_1_15_compress(b1, src_len, b2, &dst_len, wrk_mem);
#if ENABLE_LZOP_COMPR_HIGH
else if (h->method == M_LZO1X_999)
else /* must be h->method == M_LZO1X_999 */
r = lzo1x_999_compress_level(b1, src_len, b2, &dst_len,
wrk_mem, h->level);
#endif
else
bb_error_msg_and_die("internal error");
if (r != 0) /* not LZO_E_OK */
bb_error_msg_and_die("internal error - compression failed");
bb_error_msg_and_die("%s: %s", "internal error", "compression");
/* write compressed block size */
if (dst_len < src_len) {
/* optimize */
if (h->method == M_LZO1X_999) {
unsigned new_len = src_len;
r = lzo1x_optimize(b2, dst_len, b1, &new_len, NULL);
r = lzo1x_optimize(b2, dst_len, b1, &new_len /*, NULL*/);
if (r != 0 /*LZO_E_OK*/ || new_len != src_len)
bb_error_msg_and_die("internal error - optimization failed");
bb_error_msg_and_die("%s: %s", "internal error", "optimization");
}
write32(dst_len);
*wordptr++ = htonl(dst_len);
} else {
/* data actually expanded => store data uncompressed */
write32(src_len);
*wordptr++ = htonl(src_len);
}
/* write checksum of uncompressed block */
if (h->flags & F_ADLER32_D)
write32(d_adler32);
if (h->flags & F_CRC32_D)
write32(d_crc32);
if (h->flags32 & F_ADLER32_D)
*wordptr++ = htonl(d_adler32);
if (h->flags32 & F_CRC32_D)
*wordptr++ = htonl(d_crc32);
if (dst_len < src_len) {
/* write checksum of compressed block */
if (h->flags & F_ADLER32_C)
write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
if (h->flags & F_CRC32_C)
write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
if (h->flags32 & F_ADLER32_C)
*wordptr++ = htonl(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
if (h->flags32 & F_CRC32_C)
*wordptr++ = htonl(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
}
xwrite(1, wordbuf, ((char*)wordptr) - ((char*)wordbuf));
if (dst_len < src_len) {
/* write compressed block data */
xwrite(1, b2, dst_len);
} else {
/* write uncompressed block data */
xwrite(1, b1, src_len);
}
// /* if full_read() was nevertheless "short", it was EOF */
// if (src_len < block_size)
// break;
}
free(wrk_mem);
@@ -778,7 +758,9 @@ static FAST_FUNC void lzo_check(
/**********************************************************************/
// decompress a file
/**********************************************************************/
static NOINLINE int lzo_decompress(const header_t *h)
// used to have "const header_t *h" parameter, but since it uses
// only flags32 field, changed to receive only that.
static NOINLINE int lzo_decompress(uint32_t h_flags32)
{
unsigned block_size = LZO_BLOCK_SIZE;
int r;
@@ -823,16 +805,16 @@ static NOINLINE int lzo_decompress(const header_t *h)
}
/* read checksum of uncompressed block */
if (h->flags & F_ADLER32_D)
if (h_flags32 & F_ADLER32_D)
d_adler32 = read32();
if (h->flags & F_CRC32_D)
if (h_flags32 & F_CRC32_D)
d_crc32 = read32();
/* read checksum of compressed block */
if (src_len < dst_len) {
if (h->flags & F_ADLER32_C)
if (h_flags32 & F_ADLER32_C)
c_adler32 = read32();
if (h->flags & F_CRC32_C)
if (h_flags32 & F_CRC32_C)
c_crc32 = read32();
}
@@ -847,11 +829,11 @@ static NOINLINE int lzo_decompress(const header_t *h)
if (!(option_mask32 & OPT_F)) {
/* verify checksum of compressed block */
if (h->flags & F_ADLER32_C)
if (h_flags32 & F_ADLER32_C)
lzo_check(ADLER32_INIT_VALUE,
b1, src_len,
lzo_adler32, c_adler32);
if (h->flags & F_CRC32_C)
if (h_flags32 & F_CRC32_C)
lzo_check(CRC32_INIT_VALUE,
b1, src_len,
lzo_crc32, c_crc32);
@@ -859,9 +841,9 @@ static NOINLINE int lzo_decompress(const header_t *h)
/* decompress */
// if (option_mask32 & OPT_F)
// r = lzo1x_decompress(b1, src_len, b2, &d, NULL);
// r = lzo1x_decompress(b1, src_len, b2, &d /*, NULL*/);
// else
r = lzo1x_decompress_safe(b1, src_len, b2, &d, NULL);
r = lzo1x_decompress_safe(b1, src_len, b2, &d /*, NULL*/);
if (r != 0 /*LZO_E_OK*/ || dst_len != d) {
bb_error_msg_and_die("corrupted data");
@@ -874,11 +856,11 @@ static NOINLINE int lzo_decompress(const header_t *h)
if (!(option_mask32 & OPT_F)) {
/* verify checksum of uncompressed block */
if (h->flags & F_ADLER32_D)
if (h_flags32 & F_ADLER32_D)
lzo_check(ADLER32_INIT_VALUE,
dst, dst_len,
lzo_adler32, d_adler32);
if (h->flags & F_CRC32_D)
if (h_flags32 & F_CRC32_D)
lzo_check(CRC32_INIT_VALUE,
dst, dst_len,
lzo_crc32, d_crc32);
@@ -918,7 +900,7 @@ static NOINLINE int lzo_decompress(const header_t *h)
* -00000020 00 00 2d 67 04 17 00 04 00 00 00 03 ed ec 9d 6d
* +00000020 00 00 10 5f 00 c1 00 04 00 00 00 03 ed ec 9d 6d
* ^^^^^^^^^^^
* chksum_out
* chksum
* The rest is identical.
*/
static const unsigned char lzop_magic[9] ALIGN1 = {
@@ -937,138 +919,138 @@ static void check_magic(void)
/**********************************************************************/
// lzop file header
/**********************************************************************/
static void write_header(const header_t *h)
static void write_header(header_t *h)
{
int l;
char *end;
xwrite(1, lzop_magic, sizeof(lzop_magic));
init_chksum(&G.chksum_out);
init_chksum();
f_write16(h->version);
f_write16(h->lib_version);
f_write16(h->version_needed_to_extract);
f_write8(h->method);
f_write8(h->level);
f_write32(h->flags);
f_write32(h->mode);
f_write32(h->mtime);
f_write32(h->gmtdiff);
/* Our caller leaves name zero-filled, so len == 0 */
end = h->len_and_name+1 + 0; /* 0 is strlen(h->len_and_name+1) */
/* Store length byte */
/*h->len_and_name[0] = end - (h->len_and_name+1); - zero already */
l = (int) strlen(h->name);
f_write8(l);
if (l)
f_write(h->name, l);
f_write(&h->version_be16, end - (char*)&h->version_be16);
f_write32(chksum_getresult(&G.chksum_out, h));
h->flags32 = htonl(h->flags32); /* native endianness for lzo_compress() */
write32(chksum_getresult(h->flags32));
}
static int read_header(header_t *h)
{
int r;
int l;
uint32_t checksum;
/* As it stands now, only h->flags32 is used by our caller.
* Therefore we don't store many fields in h->FIELD.
*/
unsigned h_version;
unsigned h_version_needed_to_extract;
memset(h, 0, sizeof(*h));
h->version_needed_to_extract = 0x0900; /* first lzop version */
h->level = 0;
init_chksum();
init_chksum(&G.chksum_in);
/* We don't support versions < 0.94, since 0.94
* came only 2 months after 0.90:
* 0.90 (10 Aug 1997): First public release of lzop
* 0.94 (15 Oct 1997): Header format change
*/
h->version = f_read16();
if (h->version < 0x0900)
/* Read up to and including name length byte */
f_read(&h->version_be16, ((char*)&h->len_and_name[1]) - ((char*)&h->version_be16));
h_version = htons(h->version_be16);
if (h_version < 0x0940)
return 3;
h_version_needed_to_extract = htons(h->version_needed_to_extract_be16);
if (h_version_needed_to_extract > LZOP_VERSION)
return 16;
if (h_version_needed_to_extract < 0x0940)
return 3;
h->lib_version = f_read16();
if (h->version >= 0x0940) {
h->version_needed_to_extract = f_read16();
if (h->version_needed_to_extract > LZOP_VERSION)
return 16;
if (h->version_needed_to_extract < 0x0900)
return 3;
}
h->method = f_read8();
if (h->version >= 0x0940)
h->level = f_read8();
h->flags = f_read32();
if (h->flags & F_H_FILTER)
return 16; /* filter not supported */
h->mode = f_read32();
h->mtime = f_read32();
if (h->version >= 0x0940)
h->gmtdiff = f_read32();
l = f_read8();
if (l > 0)
f_read(h->name, l);
h->name[l] = 0;
checksum = chksum_getresult(&G.chksum_in, h);
h->header_checksum = f_read32();
if (h->header_checksum != checksum)
return 2;
if (h->method <= 0)
return 14;
r = lzo_get_method(h);
if (r != 0)
return r;
/* former lzo_get_method(h): */
if (h->method == M_LZO1X_1) {
if (h->level == 0)
h->level = 3;
} else if (h->method == M_LZO1X_1_15) {
if (h->level == 0)
h->level = 1;
} else if (h->method == M_LZO1X_999) {
if (h->level == 0)
h->level = 9;
} else
return -1; /* not a LZO method */
/* check compression level */
if (h->level < 1 || h->level > 9)
return 15;
h->flags32 = ntohl(h->flags32);
if (h->flags32 & F_H_FILTER)
return 16; /* filter not supported */
/* check reserved flags */
if (h->flags & F_RESERVED)
if (h->flags32 & F_RESERVED)
return -13;
l = h->len_and_name[0];
if (l > 0)
/* UNUSED */ f_read(h->len_and_name+1, l);
/* UNUSED h->len_and_name[1+l] = 0; */
checksum = chksum_getresult(h->flags32);
if (read32() != checksum)
return 2;
/* skip extra field [not used yet] */
if (h->flags & F_H_EXTRA_FIELD) {
if (h->flags32 & F_H_EXTRA_FIELD) {
uint32_t extra_field_len;
uint32_t extra_field_checksum;
uint32_t k;
char dummy;
/* note: the checksum also covers the length */
init_chksum(&G.chksum_in);
h->extra_field_len = f_read32();
for (k = 0; k < h->extra_field_len; k++)
f_read8();
checksum = chksum_getresult(&G.chksum_in, h);
h->extra_field_checksum = f_read32();
if (h->extra_field_checksum != checksum)
init_chksum();
extra_field_len = f_read32();
for (k = 0; k < extra_field_len; k++)
f_read(&dummy, 1);
checksum = chksum_getresult(h->flags32);
extra_field_checksum = read32();
if (extra_field_checksum != checksum)
return 3;
}
return 0;
}
static void p_header(header_t *h)
{
int r;
r = read_header(h);
if (r == 0)
return;
bb_error_msg_and_die("header_error %d", r);
}
/**********************************************************************/
// compress
/**********************************************************************/
static void lzo_set_method(header_t *h)
{
int level = 1;
smallint level;
/* levels 2..6 or none (defaults to level 3) */
h->method = M_LZO1X_1;
level = 5; /* levels 2-6 are actually the same */
if (option_mask32 & OPT_1) {
h->method = M_LZO1X_1_15;
} else if (option_mask32 & OPT_789) {
level = 1;
}
if (option_mask32 & OPT_789) {
#if ENABLE_LZOP_COMPR_HIGH
h->method = M_LZO1X_999;
level = 9;
if (option_mask32 & OPT_7)
level = 7;
else if (option_mask32 & OPT_8)
level = 8;
else
level = 9;
#else
bb_error_msg_and_die("high compression not compiled in");
#endif
} else { /* levels 2..6 or none (defaults to level 3) */
h->method = M_LZO1X_1;
level = 5; /* levels 2-6 are actually the same */
}
h->level = level;
@@ -1083,18 +1065,21 @@ static int do_lzo_compress(void)
lzo_set_method(h);
h->version = (LZOP_VERSION & 0xffff);
h->version_needed_to_extract = 0x0940;
h->lib_version = lzo_version() & 0xffff;
h->version_be16 = htons(LZOP_VERSION & 0xffff);
h->version_needed_to_extract_be16 = htons(0x0940);
h->lib_version_be16 = htons(lzo_version() & 0xffff);
h->flags = (F_OS & F_OS_MASK) | (F_CS & F_CS_MASK);
h->flags32 = htonl((F_OS & F_OS_MASK) | (F_CS & F_CS_MASK));
if (!(option_mask32 & OPT_F) || h->method == M_LZO1X_999) {
h->flags |= F_ADLER32_D;
h->flags32 |= htonl(F_ADLER32_D);
if (option_mask32 & OPT_C)
h->flags |= F_ADLER32_C;
h->flags32 |= htonl(F_ADLER32_C);
}
/* write_header() also converts h->flags32 to native endianness */
write_header(h);
return lzo_compress(h);
#undef h
}
@@ -1104,11 +1089,14 @@ static int do_lzo_compress(void)
/**********************************************************************/
static int do_lzo_decompress(void)
{
int r;
header_t header;
check_magic();
p_header(&header);
return lzo_decompress(&header);
r = read_header(&header);
if (r != 0)
bb_error_msg_and_die("header_error %d", r);
return lzo_decompress(header.flags32);
}
static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_ext UNUSED_PARAM)
@@ -1133,6 +1121,8 @@ static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate
int lzop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int lzop_main(int argc UNUSED_PARAM, char **argv)
{
INIT_G();
getopt32(argv, OPTION_STRING);
argv += optind;
/* -U is "anti -k", invert bit for bbunpack(): */
@@ -1149,6 +1139,6 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
if (ENABLE_UNLZOP && applet_name[4] == 'o')
option_mask32 |= OPT_DECOMPRESS;
global_crc32_table = crc32_filltable(NULL, 0);
global_crc32_new_table_le();
return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL);
}
+12 -10
View File
@@ -759,15 +759,15 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_SEAMLESS_LZMA("a")
//usage: IF_FEATURE_TAR_CREATE("h")
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
//usage: "vO] "
//usage: "vokO] "
//usage: "[-f TARFILE] [-C DIR] "
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[--exclude PATTERN]... "))
//usage: "[FILE]..."
//usage:#define tar_full_usage "\n\n"
//usage: IF_FEATURE_TAR_CREATE("Create, extract, ")
//usage: IF_NOT_FEATURE_TAR_CREATE("Extract ")
//usage: "or list files from a tar file\n"
//usage: "\nOperation:"
//usage: "or list files from a tar file"
//usage: "\n"
//usage: IF_FEATURE_TAR_CREATE(
//usage: "\n c Create"
//usage: )
@@ -776,6 +776,13 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: "\n -f FILE Name of TARFILE ('-' for stdin/out)"
//usage: "\n -C DIR Change to DIR before operation"
//usage: "\n -v Verbose"
//usage: "\n -O Extract to stdout"
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME(
//usage: "\n -m Don't restore mtime"
//usage: )
//usage: "\n -o Don't restore user:group"
///////:-p - accepted but ignored, restores mode (aliases in GNU tar: --preserve-permissions, --same-permissions)
//usage: "\n -k Don't replace existing files"
//usage: IF_FEATURE_SEAMLESS_Z(
//usage: "\n -Z (De)compress using compress"
//usage: )
@@ -791,13 +798,9 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_SEAMLESS_LZMA(
//usage: "\n -a (De)compress using lzma"
//usage: )
//usage: "\n -O Extract to stdout"
//usage: IF_FEATURE_TAR_CREATE(
//usage: "\n -h Follow symlinks"
//usage: )
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME(
//usage: "\n -m Don't restore mtime"
//usage: )
//usage: IF_FEATURE_TAR_FROM(
//usage: "\n -T FILE File with names to include"
//usage: "\n -X FILE File with glob patterns to exclude"
@@ -811,9 +814,6 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: "$ tar -cf /tmp/tarball.tar /usr/local\n"
// Supported but aren't in --help:
// o no-same-owner
// p same-permissions
// k keep-old
// no-recursion
// numeric-owner
// no-same-permissions
@@ -1244,6 +1244,8 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
create_links_from_list(tar_handle->link_placeholders);
/* Check that every file that should have been extracted was */
while (tar_handle->accept) {
if (!find_list_entry(tar_handle->reject, tar_handle->accept->data)
+18 -12
View File
@@ -336,14 +336,18 @@ static void unzip_create_leading_dirs(const char *fn)
{
/* Create all leading directories */
char *name = xstrdup(fn);
if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
/* mode of -1: set mode according to umask */
if (bb_make_directory(dirname(name), -1, FILEUTILS_RECUR)) {
xfunc_die(); /* bb_make_directory is noisy */
}
free(name);
}
#if ENABLE_FEATURE_UNZIP_CDF
static void unzip_extract_symlink(zip_header_t *zip, const char *dst_fn)
static void unzip_extract_symlink(llist_t **symlink_placeholders,
zip_header_t *zip,
const char *dst_fn)
{
char *target;
@@ -368,15 +372,10 @@ static void unzip_extract_symlink(zip_header_t *zip, const char *dst_fn)
target[xstate.mem_output_size] = '\0';
#endif
}
if (!unsafe_symlink_target(target)) {
//TODO: libbb candidate
if (symlink(target, dst_fn)) {
/* shared message */
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
"sym", dst_fn, target
);
}
}
create_or_remember_link(symlink_placeholders,
target,
dst_fn,
0);
free(target);
}
#endif
@@ -488,6 +487,9 @@ int unzip_main(int argc, char **argv)
llist_t *zaccept = NULL;
llist_t *zreject = NULL;
char *base_dir = NULL;
#if ENABLE_FEATURE_UNZIP_CDF
llist_t *symlink_placeholders = NULL;
#endif
int i;
char key_buf[80]; /* must match size used by my_fgets80 */
@@ -952,7 +954,7 @@ int unzip_main(int argc, char **argv)
#if ENABLE_FEATURE_UNZIP_CDF
if (S_ISLNK(file_mode)) {
if (dst_fd != STDOUT_FILENO) /* not -p? */
unzip_extract_symlink(&zip, dst_fn);
unzip_extract_symlink(&symlink_placeholders, &zip, dst_fn);
} else
#endif
{
@@ -988,6 +990,10 @@ int unzip_main(int argc, char **argv)
total_entries++;
}
#if ENABLE_FEATURE_UNZIP_CDF
create_links_from_list(symlink_placeholders);
#endif
if ((opts & OPT_l) && quiet <= 1) {
if (!verbose) {
// " Length Date Time Name\n"
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "Console Utilities"
+9 -1
View File
@@ -41,6 +41,7 @@
int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setlogcons_main(int argc UNUSED_PARAM, char **argv)
{
char *devname;
struct {
char fn;
char subarg;
@@ -52,7 +53,14 @@ int setlogcons_main(int argc UNUSED_PARAM, char **argv)
if (argv[1])
arg.subarg = xatou_range(argv[1], 0, 63);
xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
/* Can just call it on "/dev/tty1" always, but...
* in my testing, inactive (never opened) VTs are not
* redirected to, despite ioctl not failing.
*
* By using "/dev/ttyN", ensure it is activated.
*/
devname = xasprintf("/dev/tty%u", arg.subarg);
xioctl(xopen(devname, O_RDONLY), TIOCLINUX, &arg);
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "Coreutils"
+3 -3
View File
@@ -112,10 +112,10 @@ static int catv(unsigned opts, char **argv)
int retval = EXIT_SUCCESS;
int fd;
#if ENABLE_FEATURE_CATN
unsigned lineno = 0;
unsigned eol_char = (opts & (CAT_OPT_n|CAT_OPT_b)) ? '\n' : 0x100;
bool eol_seen = (opts & (CAT_OPT_n|CAT_OPT_b));
unsigned eol_char = (eol_seen ? '\n' : 0x100);
unsigned skip_num_on = (opts & CAT_OPT_b) ? '\n' : 0x100;
bool eol_seen = 1;
unsigned lineno = 0;
#endif
BUILD_BUG_ON(CAT_OPT_e != VISIBLE_ENDLINE);
+24 -23
View File
@@ -31,9 +31,6 @@ int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cksum_main(int argc UNUSED_PARAM, char **argv)
{
uint32_t *crc32_table = crc32_filltable(NULL, 1);
uint32_t crc;
off_t length, filesize;
int bytes_read;
int exit_code = EXIT_SUCCESS;
#if ENABLE_DESKTOP
@@ -45,38 +42,42 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
setup_common_bufsiz();
do {
uint32_t crc;
off_t filesize;
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
if (fd < 0) {
exit_code = EXIT_FAILURE;
continue;
}
crc = 0;
length = 0;
filesize = 0;
#define read_buf bb_common_bufsiz1
while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) {
length += bytes_read;
for (;;) {
uoff_t t;
int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE);
if (bytes_read > 0) {
filesize += bytes_read;
} else {
/* Checksum filesize bytes, LSB first, and exit */
close(fd);
fd = -1; /* break flag */
t = filesize;
bytes_read = 0;
while (t != 0) {
read_buf[bytes_read++] = (uint8_t)t;
t >>= 8;
}
}
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
if (fd < 0)
break;
}
close(fd);
filesize = length;
while (length) {
crc = (crc << 8) ^ crc32_table[(uint8_t)(crc >> 24) ^ (uint8_t)length];
/* must ensure that shift is unsigned! */
if (sizeof(length) <= sizeof(unsigned))
length = (unsigned)length >> 8;
else if (sizeof(length) <= sizeof(unsigned long))
length = (unsigned long)length >> 8;
else
length = (unsigned long long)length >> 8;
}
crc = ~crc;
printf((*argv ? "%"PRIu32" %"OFF_FMT"i %s\n" : "%"PRIu32" %"OFF_FMT"i\n"),
crc, filesize, *argv);
printf((*argv ? "%u %"OFF_FMT"u %s\n" : "%u %"OFF_FMT"u\n"),
(unsigned)crc, filesize, *argv);
} while (*argv && *++argv);
fflush_stdout_and_exit(exit_code);
+19 -3
View File
@@ -26,6 +26,7 @@
//config: Also add support for --parents option.
//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
/* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */
//kbuild:lib-$(CONFIG_CP) += cp.o
@@ -47,6 +48,7 @@
//usage: "\n -f Overwrite"
//usage: "\n -i Prompt before overwrite"
//usage: "\n -l,-s Create (sym)links"
//usage: "\n -T Treat DEST as a normal file"
//usage: "\n -u Copy only newer files"
#include "libbb.h"
@@ -92,13 +94,18 @@ int cp_main(int argc, char **argv)
"no-dereference\0" No_argument "P"
"recursive\0" No_argument "R"
"symbolic-link\0" No_argument "s"
"no-target-directory\0" No_argument "T"
"verbose\0" No_argument "v"
"update\0" No_argument "u"
"remove-destination\0" No_argument "\xff"
"parents\0" No_argument "\xfe"
);
#else
flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
flags = getopt32(argv, "^"
FILEUTILS_CP_OPTSTR
"\0"
"-2:l--s:s--l:Pd:rRd:Rd:apdR"
);
#endif
/* Options of cp from GNU coreutils 6.10:
* -a, --archive
@@ -121,6 +128,8 @@ int cp_main(int argc, char **argv)
* remove each existing destination file before attempting to open
* --parents
* use full source file name under DIRECTORY
* -T, --no-target-directory
* treat DEST as a normal file
* NOT SUPPORTED IN BBOX:
* --backup[=CONTROL]
* make a backup of each existing destination file
@@ -139,8 +148,6 @@ int cp_main(int argc, char **argv)
* override the usual backup suffix
* -t, --target-directory=DIRECTORY
* copy all SOURCE arguments into DIRECTORY
* -T, --no-target-directory
* treat DEST as a normal file
* -x, --one-file-system
* stay on this file system
* -Z, --context=CONTEXT
@@ -175,6 +182,12 @@ int cp_main(int argc, char **argv)
if (d_flags < 0)
return EXIT_FAILURE;
if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
if (!(s_flags & 2) && (d_flags & 2))
/* cp -T NOTDIR DIR */
bb_error_msg_and_die("'%s' is a directory", last);
}
#if ENABLE_FEATURE_CP_LONG_OPTIONS
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
// flags, FILEUTILS_RMDEST, OPT_parents);
@@ -192,11 +205,14 @@ int cp_main(int argc, char **argv)
if (!((s_flags | d_flags) & 2)
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|| (flags & FILEUTILS_NO_TARGET_DIR)
) {
/* Do a simple copy */
dest = last;
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
}
} else if (flags & FILEUTILS_NO_TARGET_DIR) {
bb_error_msg_and_die("too many arguments");
}
while (1) {
+32 -15
View File
@@ -37,7 +37,7 @@
//config: elapsed time and speed.
//config:
//config:config FEATURE_DD_IBS_OBS
//config: bool "Enable ibs, obs and conv options"
//config: bool "Enable ibs, obs, iflag and conv options"
//config: default y
//config: depends on DD
//config: help
@@ -57,7 +57,7 @@
//usage:#define dd_trivial_usage
//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n"
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes]")
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes|fullblock]")
//usage:#define dd_full_usage "\n\n"
//usage: "Copy a file with converting and formatting\n"
//usage: "\n if=FILE Read from FILE instead of stdin"
@@ -79,6 +79,7 @@
//usage: "\n conv=fsync Physically write data out before finishing"
//usage: "\n conv=swab Swap every pair of bytes"
//usage: "\n iflag=skip_bytes skip=N is in bytes"
//usage: "\n iflag=fullblock Read full blocks"
//usage: )
//usage: IF_FEATURE_DD_STATUS(
//usage: "\n status=noxfer Suppress rate output"
@@ -130,11 +131,12 @@ enum {
/* start of input flags */
FLAG_IFLAG_SHIFT = 5,
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of input flags */
FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 7,
FLAG_STATUS_NONE = 1 << 8,
FLAG_STATUS_NOXFER = 1 << 9,
FLAG_TWOBUFS = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 8,
FLAG_STATUS_NONE = 1 << 9,
FLAG_STATUS_NOXFER = 1 << 10,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -195,14 +197,18 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
ssize_t n = full_write_or_warn(buf, len, filename);
if (n < 0)
return 1;
if ((size_t)n == obs)
G.out_full++;
else if (n) /* > 0 */
G.out_part++;
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
G.total_bytes += n;
#endif
return 0;
if ((size_t)n == obs) {
G.out_full++;
return 0;
}
if ((size_t)n == len) {
G.out_part++;
return 0;
}
return 1;
}
#if ENABLE_LFS
@@ -251,7 +257,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
static const char conv_words[] ALIGN1 =
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
static const char iflag_words[] ALIGN1 =
"skip_bytes\0";
"skip_bytes\0""fullblock\0";
#endif
#if ENABLE_FEATURE_DD_STATUS
static const char status_words[] ALIGN1 =
@@ -290,6 +296,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
/* Partially implemented: */
//swab swap every pair of input bytes: will abort on non-even reads
OP_iflag_skip_bytes,
OP_iflag_fullblock,
#endif
};
smallint exitcode = EXIT_FAILURE;
@@ -450,7 +457,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
do {
ssize_t n = safe_read(ifd, ibuf, blocksz);
ssize_t n;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_FULLBLOCK)
n = full_read(ifd, ibuf, blocksz);
else
#endif
n = safe_read(ifd, ibuf, blocksz);
if (n < 0)
goto die_infile;
if (n == 0)
@@ -465,8 +478,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
ssize_t n;
n = safe_read(ifd, ibuf, ibs);
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_FULLBLOCK)
n = full_read(ifd, ibuf, ibs);
else
#endif
n = safe_read(ifd, ibuf, ibs);
if (n == 0)
break;
if (n < 0) {
+20 -12
View File
@@ -91,8 +91,6 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int df_main(int argc UNUSED_PARAM, char **argv)
{
unsigned long blocks_used;
unsigned blocks_percent_used;
unsigned long df_disp_hr = 1024;
int status = EXIT_SUCCESS;
unsigned opt;
@@ -208,6 +206,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
}
device = mount_entry->mnt_fsname;
/* GNU coreutils 6.10 skips certain mounts, try to be compatible */
if (ENABLE_FEATURE_SKIP_ROOTFS && strcmp(device, "rootfs") == 0)
continue;
mount_point = mount_entry->mnt_dir;
fs_type = mount_entry->mnt_type;
@@ -222,26 +225,31 @@ int df_main(int argc UNUSED_PARAM, char **argv)
s.f_frsize = s.f_bsize;
if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
unsigned long long blocks_used;
unsigned long long blocks_total;
unsigned blocks_percent_used;
if (opt & OPT_INODE) {
s.f_blocks = s.f_files;
s.f_bavail = s.f_bfree = s.f_ffree;
s.f_frsize = 1;
if (df_disp_hr)
df_disp_hr = 1;
}
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = 0;
if (blocks_used + s.f_bavail) {
blocks_percent_used = (blocks_used * 100ULL
+ (blocks_used + s.f_bavail)/2
) / (blocks_used + s.f_bavail);
blocks_total = blocks_used + s.f_bavail;
blocks_percent_used = blocks_total; /* 0% if blocks_total == 0, else... */
if (blocks_total != 0) {
/* Downscale sizes for narrower division */
unsigned u;
while (blocks_total >= INT_MAX / 101) {
blocks_total >>= 1;
blocks_used >>= 1;
}
u = (unsigned)blocks_used * 100u + (unsigned)blocks_total / 2;
blocks_percent_used = u / (unsigned)blocks_total;
}
/* GNU coreutils 6.10 skips certain mounts, try to be compatible. */
if (ENABLE_FEATURE_SKIP_ROOTFS && strcmp(device, "rootfs") == 0)
continue;
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
if (strcmp(device, "/dev/root") == 0) {
/* Adjusts device to be the real root device,
+5 -1
View File
@@ -214,7 +214,11 @@ int install_main(int argc, char **argv)
dest = last;
if (opts & OPT_MKDIR_LEADING) {
char *ddir = xstrdup(dest);
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
/*
* -D -t DIR1/DIR2/F3 FILE: create DIR1/DIR2/F3, copy FILE there
* -D FILE DIR1/DIR2/F3: create DIR1/DIR2, copy FILE there as F3
*/
bb_make_directory((opts & OPT_TARGET) ? ddir : dirname(ddir), 0755, mkdir_flags);
/* errors are not checked. copy_file
* will fail if dir is not created.
*/
+1 -1
View File
@@ -9,7 +9,7 @@
//config: bool "md5sum (6.8 kb)"
//config: default y
//config: help
//config: md5sum is used to print or check MD5 checksums.
//config: Compute and check MD5 message digest
//config:
//config:config SHA1SUM
//config: bool "sha1sum (6 kb)"
+28 -28
View File
@@ -20,7 +20,7 @@
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
//usage:#define mknod_trivial_usage
//usage: "[-m MODE] " IF_SELINUX("[-Z] ") "NAME TYPE MAJOR MINOR"
//usage: "[-m MODE] " IF_SELINUX("[-Z] ") "NAME TYPE [MAJOR MINOR]"
//usage:#define mknod_full_usage "\n\n"
//usage: "Create a special file (block, character, or pipe)\n"
//usage: "\n -m MODE Creation mode (default a=rw)"
@@ -30,7 +30,7 @@
//usage: "\nTYPE:"
//usage: "\n b Block device"
//usage: "\n c or u Character device"
//usage: "\n p Named pipe (MAJOR and MINOR are ignored)"
//usage: "\n p Named pipe (MAJOR MINOR must be omitted)"
//usage:
//usage:#define mknod_example_usage
//usage: "$ mknod /dev/fd0 b 2 0\n"
@@ -47,40 +47,40 @@ static const char modes_chars[] ALIGN1 = { 'p', 'c', 'u', 'b', 0, 1, 1, 2 };
static const mode_t modes_cubp[] = { S_IFIFO, S_IFCHR, S_IFBLK };
int mknod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mknod_main(int argc, char **argv)
int mknod_main(int argc UNUSED_PARAM, char **argv)
{
mode_t mode;
dev_t dev;
const char *name;
const char *type, *arg;
mode = getopt_mk_fifo_nod(argv);
argv += optind;
argc -= optind;
//argc -= optind;
if (argc >= 2) {
name = strchr(modes_chars, argv[1][0]);
if (name != NULL) {
mode |= modes_cubp[(int)(name[4])];
if (!argv[0] || !argv[1])
bb_show_usage();
type = strchr(modes_chars, argv[1][0]);
if (!type)
bb_show_usage();
dev = 0;
if (*name != 'p') {
argc -= 2;
if (argc == 2) {
/* Autodetect what the system supports; these macros should
* optimize out to two constants. */
dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
xatoul_range(argv[3], 0, minor(UINT_MAX)));
}
}
mode |= modes_cubp[(int)(type[4])];
if (argc == 2) {
name = *argv;
if (mknod(name, mode, dev) == 0) {
return EXIT_SUCCESS;
}
bb_simple_perror_msg_and_die(name);
}
}
dev = 0;
arg = argv[2];
if (*type != 'p') {
if (!argv[2] || !argv[3])
bb_show_usage();
/* Autodetect what the system supports; these macros should
* optimize out to two constants. */
dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
xatoul_range(argv[3], 0, minor(UINT_MAX)));
arg = argv[4];
}
bb_show_usage();
if (arg)
bb_show_usage();
if (mknod(argv[0], mode, dev) != 0) {
bb_simple_perror_msg_and_die(argv[0]);
}
return EXIT_SUCCESS;
}
+3 -2
View File
@@ -17,7 +17,8 @@
//config: help
//config: mv is used to move or rename files or directories.
//applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP))
//applet:IF_MV(APPLET_NOEXEC(mv, mv, BB_DIR_BIN, BB_SUID_DROP, mv))
/* NOEXEC despite cases when it can be a "runner" (mv LARGE_DIR OTHER_FS) */
//kbuild:lib-$(CONFIG_MV) += mv.o
@@ -100,7 +101,7 @@ int mv_main(int argc, char **argv)
if (fprintf(stderr, "mv: overwrite '%s'? ", dest) < 0) {
goto RET_1; /* Ouch! fprintf failed! */
}
if (!bb_ask_confirmation()) {
if (!bb_ask_y_confirmation()) {
goto RET_0;
}
}
+12 -10
View File
@@ -22,11 +22,10 @@
//usage: "Change scheduling priority, run PROG\n"
//usage: "\n -n ADJUST Adjust priority by ADJUST"
#include <sys/resource.h>
#include "libbb.h"
int nice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nice_main(int argc, char **argv)
int nice_main(int argc UNUSED_PARAM, char **argv)
{
int old_priority, adjustment;
@@ -40,18 +39,21 @@ int nice_main(int argc, char **argv)
adjustment = 10; /* Set default adjustment. */
if (argv[0][0] == '-') {
if (argv[0][1] == 'n') { /* -n */
if (argv[0][2]) { /* -nNNNN (w/o space) */
argv[0] += 2; argv--; argc++;
char *nnn = argv[0] + 1;
if (nnn[0] == 'n') { /* -n */
nnn += 1;
if (!nnn[0]) { /* "-n NNN" */
nnn = *++argv;
}
} else { /* -NNN (NNN may be negative) == -n NNN */
argv[0] += 1; argv--; argc++;
/* else: "-nNNN" (w/o space) */
}
if (argc < 4) { /* Missing priority and/or utility! */
/* else: "-NNN" (NNN may be negative) - same as "-n NNN" */
if (!nnn || !argv[1]) { /* Missing priority or PROG! */
bb_show_usage();
}
adjustment = xatoi_range(argv[1], INT_MIN/2, INT_MAX/2);
argv += 2;
adjustment = xatoi_range(nnn, INT_MIN/2, INT_MAX/2);
argv++;
}
{ /* Set our priority. */
+17 -11
View File
@@ -211,7 +211,14 @@ struct globals {
bool not_first;
bool prev_pair_equal;
char address_fmt[sizeof("%0n"OFF_FMT"xc")];
} FIX_ALIASING;
/* Corresponds to 'x' above */
#define address_base_char G.address_fmt[sizeof(G.address_fmt)-3]
/* Corresponds to 'n' above */
#define address_pad_len_char G.address_fmt[2]
#if !ENABLE_LONG_OPTS
enum { G_pseudo_offset = 0 };
#endif
@@ -220,6 +227,7 @@ enum { G_pseudo_offset = 0 };
setup_common_bufsiz(); \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
G.bytes_per_block = 32; \
strcpy(G.address_fmt, "%0n"OFF_FMT"xc"); \
} while (0)
@@ -844,18 +852,12 @@ format_address_none(off_t address UNUSED_PARAM, char c UNUSED_PARAM)
{
}
static char address_fmt[] ALIGN1 = "%0n"OFF_FMT"xc";
/* Corresponds to 'x' above */
#define address_base_char address_fmt[sizeof(address_fmt)-3]
/* Corresponds to 'n' above */
#define address_pad_len_char address_fmt[2]
static void
format_address_std(off_t address, char c)
{
/* Corresponds to 'c' */
address_fmt[sizeof(address_fmt)-2] = c;
printf(address_fmt, address);
G.address_fmt[sizeof(G.address_fmt)-2] = c;
printf(G.address_fmt, address);
}
#if ENABLE_LONG_OPTS
@@ -1371,9 +1373,13 @@ int od_main(int argc UNUSED_PARAM, char **argv)
}
#ifdef DEBUG
for (i = 0; i < G.n_specs; i++) {
printf("%d: fmt=\"%s\" width=%d\n",
i, spec[i].fmt_string, width_bytes[spec[i].size]);
{
int i;
for (i = 0; i < G.n_specs; i++) {
printf("%d: fmt='%s' width=%d\n",
i, G.spec[i].fmt_string,
width_bytes[G.spec[i].size]);
}
}
#endif
+1 -1
View File
@@ -86,7 +86,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv)
/* NOFORK: only one alloc is allowed; must free */
if (opt & 1) { /* -f */
buf = xmalloc_realpath(fname);
buf = xmalloc_realpath_coreutils(fname);
} else {
buf = xmalloc_readlink_or_warn(fname);
}
+1 -1
View File
@@ -38,7 +38,7 @@ int realpath_main(int argc UNUSED_PARAM, char **argv)
do {
/* NOFORK: only one alloc is allowed; must free */
char *resolved_path = xmalloc_realpath(*argv);
char *resolved_path = xmalloc_realpath_coreutils(*argv);
if (resolved_path != NULL) {
puts(resolved_path);
free(resolved_path);
+155 -32
View File
@@ -18,16 +18,24 @@
//config: sort is used to sort lines of text in specified files.
//config:
//config:config FEATURE_SORT_BIG
//config: bool "Full SuSv3 compliant sort (support -ktcsbdfiozgM)"
//config: bool "Full SuSv3 compliant sort (support -ktcbdfiogM)"
//config: default y
//config: depends on SORT
//config: help
//config: Without this, sort only supports -r, -u, and an integer version
//config: Without this, sort only supports -rusz, and an integer version
//config: of -n. Selecting this adds sort keys, floating point support, and
//config: more. This adds a little over 3k to a nonstatic build on x86.
//config:
//config: The SuSv3 sort standard is available at:
//config: http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
//config:
//config:config FEATURE_SORT_OPTIMIZE_MEMORY
//config: bool "Use less memory (but might be slower)"
//config: default n # defaults to N since we are size-paranoid tribe
//config: depends on SORT
//config: help
//config: Attempt to use less memory (by storing only one copy
//config: of duplicated lines, and such). Useful if you work on huge files.
//applet:IF_SORT(APPLET_NOEXEC(sort, sort, BB_DIR_USR_BIN, BB_SUID_DROP, sort))
@@ -46,26 +54,22 @@
//usage: "\n -f Ignore case"
//usage: "\n -i Ignore unprintable characters"
//usage: "\n -d Dictionary order (blank or alphanumeric only)"
//usage: "\n -g General numerical sort"
//usage: "\n -M Sort month"
//usage: )
//-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G)
//usage: "\n -n Sort numbers"
//usage: IF_FEATURE_SORT_BIG(
//usage: "\n -g General numerical sort"
//usage: "\n -M Sort month"
//usage: "\n -t CHAR Field separator"
//usage: "\n -k N[,M] Sort by Nth field"
//usage: )
//usage: "\n -r Reverse sort order"
//usage: IF_FEATURE_SORT_BIG(
//usage: "\n -s Stable (don't sort ties alphabetically)"
//usage: )
//usage: "\n -u Suppress duplicate lines"
//usage: IF_FEATURE_SORT_BIG(
//usage: "\n -z Lines are terminated by NUL, not newline"
////usage: "\n -m Ignored for GNU compatibility"
////usage: "\n -S BUFSZ Ignored for GNU compatibility"
////usage: "\n -T TMPDIR Ignored for GNU compatibility"
//usage: )
///////: "\n -m Ignored for GNU compatibility"
///////: "\n -S BUFSZ Ignored for GNU compatibility"
///////: "\n -T TMPDIR Ignored for GNU compatibility"
//usage:
//usage:#define sort_example_usage
//usage: "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n"
@@ -85,16 +89,7 @@
#include "libbb.h"
/* This is a NOEXEC applet. Be very careful! */
/*
sort [-m][-o output][-bdfinru][-t char][-k keydef]... [file...]
sort -c [-bdfinru][-t char][-k keydef][file]
*/
/* These are sort types */
#define OPT_STR "ngMucszbrdfimS:T:o:k:*t:"
enum {
FLAG_n = 1, /* Numeric sort */
FLAG_g = 2, /* Sort using strtod() */
@@ -117,8 +112,18 @@ enum {
FLAG_k = 0x10000,
FLAG_t = 0x20000,
FLAG_bb = 0x80000000, /* Ignore trailing blanks */
FLAG_no_tie_break = 0x40000000,
};
static const char sort_opt_str[] ALIGN1 = "^"
"ngMucszbrdfimS:T:o:k:*t:"
"\0" "o--o:t--t"/*-t, -o: at most one of each*/;
/*
* OPT_STR must not be string literal, needs to have stable address:
* code uses "strchr(OPT_STR,c) - OPT_STR" idiom.
*/
#define OPT_STR (sort_opt_str + 1)
#if ENABLE_FEATURE_SORT_BIG
static char key_separator;
@@ -128,6 +133,10 @@ static struct sort_key {
unsigned flags;
} *key_list;
/* This is a NOEXEC applet. Be very careful! */
static char *get_key(char *str, struct sort_key *key, int flags)
{
int start = start; /* for compiler */
@@ -340,10 +349,35 @@ static int compare_keys(const void *xarg, const void *yarg)
#endif
} /* for */
/* Perform fallback sort if necessary */
if (!retval && !(option_mask32 & FLAG_s)) {
flags = option_mask32;
retval = strcmp(*(char **)xarg, *(char **)yarg);
if (retval == 0) {
/* So far lines are "the same" */
if (option_mask32 & FLAG_s) {
/* "Stable sort": later line is "greater than",
* IOW: do not allow qsort() to swap equal lines.
*/
uint32_t *p32;
uint32_t x32, y32;
char *line;
unsigned len;
line = *(char**)xarg;
len = (strlen(line) + 4) & (~3u);
p32 = (void*)(line + len);
x32 = *p32;
line = *(char**)yarg;
len = (strlen(line) + 4) & (~3u);
p32 = (void*)(line + len);
y32 = *p32;
/* If x > y, 1, else -1 */
retval = (x32 > y32) * 2 - 1;
} else
if (!(option_mask32 & FLAG_no_tie_break)) {
/* fallback sort */
flags = option_mask32;
retval = strcmp(*(char **)xarg, *(char **)yarg);
}
}
if (flags & FLAG_r)
@@ -368,21 +402,52 @@ static unsigned str2u(char **str)
int sort_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int sort_main(int argc UNUSED_PARAM, char **argv)
{
char *line, **lines;
char **lines;
char *str_ignored, *str_o, *str_t;
llist_t *lst_k = NULL;
int i;
int linecount;
unsigned opts;
#if ENABLE_FEATURE_SORT_OPTIMIZE_MEMORY
bool can_drop_dups;
size_t prev_len = 0;
char *prev_line = (char*) "";
/* Postpone optimizing if the input is small, < 16k lines:
* even just free()ing duplicate lines takes time.
*/
size_t count_to_optimize_dups = 0x3fff;
#endif
xfunc_error_retval = 2;
/* Parse command line options */
opts = getopt32(argv, "^"
OPT_STR
"\0" "o--o:t--t"/*-t, -o: at most one of each*/,
opts = getopt32(argv,
sort_opt_str,
&str_ignored, &str_ignored, &str_o, &lst_k, &str_t
);
#if ENABLE_FEATURE_SORT_OPTIMIZE_MEMORY
/* Can drop dups only if -u but no "complicating" options,
* IOW: if we do a full line compares. Safe options:
* -o FILE Output to FILE
* -z Lines are terminated by NUL, not newline
* -r Reverse sort order
* -s Stable (don't sort ties alphabetically)
* Not sure about these:
* -b Ignore leading blanks
* -f Ignore case
* -i Ignore unprintable characters
* -d Dictionary order (blank or alphanumeric only)
* -n Sort numbers
* -g General numerical sort
* -M Sort month
*/
can_drop_dups = ((opts & ~(FLAG_o|FLAG_z|FLAG_r|FLAG_s)) == FLAG_u);
/* Stable sort needs every line to be uniquely allocated,
* disable optimization to reuse strings:
*/
if (opts & FLAG_s)
count_to_optimize_dups = (size_t)-1L;
#endif
/* global b strips leading and trailing spaces */
if (opts & FLAG_b)
option_mask32 |= FLAG_bb;
@@ -457,9 +522,47 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
* do not continue to next file: */
FILE *fp = xfopen_stdin(*argv);
for (;;) {
line = GET_LINE(fp);
char *line = GET_LINE(fp);
if (!line)
break;
#if ENABLE_FEATURE_SORT_OPTIMIZE_MEMORY
if (count_to_optimize_dups != 0)
count_to_optimize_dups--;
if (count_to_optimize_dups == 0) {
size_t len;
char *new_line;
/* On kernel/linux/arch/ *.[ch] files,
* this reduces memory usage by 6%.
* yes | head -99999999 | sort
* goes down from 1900Mb to 380 Mb.
*/
len = strlen(line);
if (len <= prev_len) {
new_line = prev_line + (prev_len - len);
if (strcmp(line, new_line) == 0) {
/* it's a tail of the prev line */
if (can_drop_dups && prev_len == len) {
/* it's identical to prev line */
free(line);
continue;
}
free(line);
line = new_line;
/* continue using longer prev_line
* for future tail tests.
*/
goto skip;
}
}
prev_len = len;
prev_line = line;
skip: ;
}
#else
//TODO: lighter version which only drops total dups if can_drop_dups == true
#endif
lines = xrealloc_vector(lines, 6, linecount);
lines[linecount++] = line;
}
@@ -482,15 +585,35 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
return EXIT_SUCCESS;
}
#endif
/* For stable sort, store original line position beyond terminating NUL */
if (option_mask32 & FLAG_s) {
for (i = 0; i < linecount; i++) {
uint32_t *p32;
char *line;
unsigned len;
line = lines[i];
len = (strlen(line) + 4) & (~3u);
lines[i] = line = xrealloc(line, len + 4);
p32 = (void*)(line + len);
*p32 = i;
}
/*option_mask32 |= FLAG_no_tie_break;*/
/* ^^^redundant: if FLAG_s, compare_keys() does no tie break */
}
/* Perform the actual sort */
qsort(lines, linecount, sizeof(lines[0]), compare_keys);
/* Handle -u */
if (option_mask32 & FLAG_u) {
int j = 0;
/* coreutils 6.3 drop lines for which only key is the same */
/* -- disabling last-resort compare... */
option_mask32 |= FLAG_s;
/* coreutils 6.3 drop lines for which only key is the same
* -- disabling last-resort compare, or else compare_keys()
* will be the same only for completely identical lines.
*/
option_mask32 |= FLAG_no_tie_break;
for (i = 1; i < linecount; i++) {
if (compare_keys(&lines[j], &lines[i]) == 0)
free(lines[i]);
+1 -1
View File
@@ -212,7 +212,7 @@ static const char *human_fstype(uint32_t f_type)
{ 0x52654973, "reiserfs" },
{ 0x28cd3d45, "cramfs" },
{ 0x7275, "romfs" },
{ 0x858458f6, "romfs" },
{ 0x858458f6, "ramfs" },
{ 0x73717368, "squashfs" },
{ 0x62656572, "sysfs" },
{ 0, "UNKNOWN" }
+4 -1
View File
@@ -76,7 +76,6 @@
//usage: "1\n"
#include "libbb.h"
#include <setjmp.h>
/* This is a NOFORK applet. Be very careful! */
@@ -314,6 +313,9 @@ static const struct operator_t ops_table[] = {
{ /* "-L" */ FILSYM , UNOP },
{ /* "-S" */ FILSOCK , UNOP },
{ /* "=" */ STREQ , BINOP },
/* "==" is bashism, http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
* lists only "=" as comparison operator.
*/
{ /* "==" */ STREQ , BINOP },
{ /* "!=" */ STRNE , BINOP },
{ /* "<" */ STRLT , BINOP },
@@ -358,6 +360,7 @@ static const char ops_texts[] ALIGN1 =
"-L" "\0"
"-S" "\0"
"=" "\0"
/* "==" is bashism */
"==" "\0"
"!=" "\0"
"<" "\0"
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "Debian Utilities"
+8 -10
View File
@@ -116,8 +116,6 @@ Misc options:
//usage: )
//usage: "\n -q Quiet"
#include <sys/resource.h>
/* Override ENABLE_FEATURE_PIDFILE */
#define WANT_PIDFILE 1
#include "libbb.h"
@@ -159,6 +157,9 @@ struct globals {
unsigned execname_sizeof;
int user_id;
smallint signal_nr;
#ifdef OLDER_VERSION_OF_X
struct stat execstat;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define userspec (G.userspec )
@@ -186,13 +187,12 @@ static int pid_is_exec(pid_t pid)
sprintf(buf, "/proc/%u/exe", (unsigned)pid);
if (stat(buf, &st) < 0)
return 0;
if (st.st_dev == execstat.st_dev
&& st.st_ino == execstat.st_ino)
if (st.st_dev == G.execstat.st_dev
&& st.st_ino == G.execstat.st_ino)
return 1;
return 0;
}
#endif
#else
static int pid_is_exec(pid_t pid)
{
ssize_t bytes;
@@ -216,6 +216,7 @@ static int pid_is_exec(pid_t pid)
}
return 0;
}
#endif
static int pid_is_name(pid_t pid)
{
@@ -410,9 +411,6 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
char *signame;
char *startas;
char *chuid;
#ifdef OLDER_VERSION_OF_X
struct stat execstat;
#endif
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
// char *retry_arg = NULL;
// int retries = -1;
@@ -481,7 +479,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
#ifdef OLDER_VERSION_OF_X
if (execname)
xstat(execname, &execstat);
xstat(execname, &G.execstat);
#endif
*--argv = startas;
+8 -8
View File
@@ -30,12 +30,15 @@
int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int which_main(int argc UNUSED_PARAM, char **argv)
{
const char *env_path;
char *env_path;
int status = 0;
/* This sizeof(): bb_default_root_path is shorter than BB_PATH_ROOT_PATH */
char buf[sizeof(BB_PATH_ROOT_PATH)];
env_path = getenv("PATH");
if (!env_path)
env_path = bb_default_root_path;
/* env_path must be writable, and must not alloc, so... */
env_path = strcpy(buf, bb_default_root_path);
getopt32(argv, "^" "a" "\0" "-1"/*at least one arg*/);
argv += optind;
@@ -51,20 +54,17 @@ int which_main(int argc UNUSED_PARAM, char **argv)
}
} else {
char *path;
char *tmp;
char *p;
path = tmp = xstrdup(env_path);
//NOFORK FIXME: nested xmallocs (one is inside find_executable())
//can leak memory on failure
while ((p = find_executable(*argv, &tmp)) != NULL) {
path = env_path;
/* NOFORK NB: xmalloc inside find_executable(), must have no allocs above! */
while ((p = find_executable(*argv, &path)) != NULL) {
missing = 0;
puts(p);
free(p);
if (!option_mask32) /* -a not set */
break;
}
free(path);
}
status |= missing;
} while (*++argv);
+255
View File
@@ -0,0 +1,255 @@
Introduction
------------
The configuration database is collection of configuration options
organized in a tree structure:
+- Code maturity level options
| +- Prompt for development and/or incomplete code/drivers
+- General setup
| +- Networking support
| +- System V IPC
| +- BSD Process Accounting
| +- Sysctl support
+- Loadable module support
| +- Enable loadable module support
| +- Set version information on all module symbols
| +- Kernel module loader
+- ...
Every entry has its own dependencies. These dependencies are used
to determine the visible of an entry. Any child entry is only
visible if its parent entry is also visible.
Menu entries
------------
Most entries define a config option, all other entries help to organize
them. A single configuration option is defined like this:
config MODVERSIONS
bool "Set version information on all module symbols"
depends MODULES
help
Usually, modules have to be recompiled whenever you switch to a new
kernel. ...
Every line starts with a key word and can be followed by multiple
arguments. "config" starts a new config entry. The following lines
define attributes for this config option. Attributes can be the type of
the config option, input prompt, dependencies, help text and default
values. A config option can be defined multiple times with the same
name, but every definition can have only a single input prompt and the
type must not conflict.
Menu attributes
---------------
A menu entry can have a number of attributes. Not all of them are
applicable everywhere (see syntax).
- type definition: "bool"/"tristate"/"string"/"hex"/"integer"
Every config option must have a type. There are only two basic types:
tristate and string, the other types base on these two. The type
definition optionally accepts an input prompt, so these two examples
are equivalent:
bool "Networking support"
and
bool
prompt "Networking support"
- input prompt: "prompt" <prompt> ["if" <expr>]
Every menu entry can have at most one prompt, which is used to display
to the user. Optionally dependencies only for this prompt can be added
with "if".
- default value: "default" <symbol> ["if" <expr>]
A config option can have any number of default values. If multiple
default values are visible, only the first defined one is active.
Default values are not limited to the menu entry, where they are
defined, this means the default can be defined somewhere else or be
overridden by an earlier definition.
The default value is only assigned to the config symbol if no other
value was set by the user (via the input prompt above). If an input
prompt is visible the default value is presented to the user and can
be overridden by him.
Optionally dependencies only for this default value can be added with
"if".
- dependencies: "depends on"/"requires" <expr>
This defines a dependency for this menu entry. If multiple
dependencies are defined they are connected with '&&'. Dependencies
are applied to all other options within this menu entry (which also
accept "if" expression), so these two examples are equivalent:
bool "foo" if BAR
default y if BAR
and
depends on BAR
bool "foo"
default y
- help text: "help"
This defines a help text. The end of the help text is determined by
the level indentation, this means it ends at the first line which has
a smaller indentation than the first line of the help text.
Menu dependencies
-----------------
Dependencies define the visibility of a menu entry and can also reduce
the input range of tristate symbols. The tristate logic used in the
expressions uses one more state than normal boolean logic to express the
module state. Dependency expressions have the following syntax:
<expr> ::= <symbol> (1)
<symbol> '=' <symbol> (2)
<symbol> '!=' <symbol> (3)
'(' <expr> ')' (4)
'!' <expr> (5)
<expr> '||' <expr> (6)
<expr> '&&' <expr> (7)
Expressions are listed in decreasing order of precedence.
(1) Convert the symbol into an expression. Boolean and tristate symbols
are simply converted into the respective expression values. All
other symbol types result in 'n'.
(2) If the values of both symbols are equal, it returns 'y',
otherwise 'n'.
(3) If the values of both symbols are equal, it returns 'n',
otherwise 'y'.
(4) Returns the value of the expression. Used to override precedence.
(5) Returns the result of (2-/expr/).
(6) Returns the result of min(/expr/, /expr/).
(7) Returns the result of max(/expr/, /expr/).
An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2
respectively for calculations). A menu entry becomes visible when it's
expression evaluates to 'm' or 'y'.
There are two type of symbols: constant and nonconstant symbols.
Nonconstant symbols are the most common ones and are defined with the
'config' statement. Nonconstant symbols consist entirely of alphanumeric
characters or underscores.
Constant symbols are only part of expressions. Constant symbols are
always surrounded by single or double quotes. Within the quote any
other character is allowed and the quotes can be escaped using '\'.
Menu structure
--------------
The position of a menu entry in the tree is determined in two ways. First
it can be specified explicitely:
menu "Network device support"
depends NET
config NETDEVICES
...
endmenu
All entries within the "menu" ... "endmenu" block become a submenu of
"Network device support". All subentries inherit the dependencies from
the menu entry, e.g. this means the dependency "NET" is added to the
dependency list of the config option NETDEVICES.
The other way to generate the menu structure is done by analyzing the
dependencies. If a menu entry somehow depends on the previous entry, it
can be made a submenu of it. First the the previous (parent) symbol must
be part of the dependency list and then one of these two condititions
must be true:
- the child entry must become invisible, if the parent is set to 'n'
- the child entry must only be visible, if the parent is visible
config MODULES
bool "Enable loadable module support"
config MODVERSIONS
bool "Set version information on all module symbols"
depends MODULES
comment "module support disabled"
depends !MODULES
MODVERSIONS directly depends on MODULES, this means it's only visible if
MODULES is different from 'n'. The comment on the other hand is always
visible when MODULES it's visible (the (empty) dependency of MODULES is
also part of the comment dependencies).
Kconfig syntax
--------------
The configuration file describes a series of menu entries, where every
line starts with a keyword (except help texts). The following keywords
end a menu entry:
- config
- choice/endchoice
- comment
- menu/endmenu
- if/endif
- source
The first four also start the definition of a menu entry.
config:
"config" <symbol>
<config options>
This defines a config symbol <symbol> and accepts any of above
attributes as options.
choices:
"choice"
<choice options>
<choice block>
"endchoice"
This defines a choice group and accepts any of above attributes as
options. A choice can only be of type bool or tristate, while a boolean
choice only allows a single config entry to be selected, a tristate
choice also allows any number of config entries to be set to 'm'. This
can be used if multiple drivers for a single hardware exists and only a
single driver can be compiled/loaded into the kernel, but all drivers
can be compiled as modules.
A choice accepts another option "optional", which allows to set the
choice to 'n' and no entry needs to be selected.
comment:
"comment" <prompt>
<comment options>
This defines a comment which is displayed to the user during the
configuration process and is also echoed to the output files. The only
possible options are dependencies.
menu:
"menu" <prompt>
<menu options>
<menu block>
"endmenu"
This defines a menu block, see "Menu structure" above for more
information. The only possible options are dependencies.
if:
"if" <expr>
<if block>
"endif"
This defines an if block. The dependency expression <expr> is appended
to all enclosed menu entries.
source:
"source" <prompt>
This reads the specified configuration file. This file is always parsed.
+3 -2
View File
@@ -178,9 +178,10 @@ dd POSIX options:
conv=noerror | yes | |
conv=notrunc | yes | |
conv=sync | yes | |
dd compatibility options:
conv=fsync | yes | |
iflag=skip_bytes| yes | |
dd Busybox specific options:
conv=fsync
iflag=fullblock | yes | |
df POSIX options
option | exists | compliant | remarks
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "Linux Ext2 FS Progs"
+9 -8
View File
@@ -414,7 +414,7 @@ static void kill_all_if_got_signal(void)
static int wait_one(int flags)
{
int status;
int sig;
int exitcode;
struct fsck_instance *inst, *prev;
pid_t pid;
@@ -448,15 +448,16 @@ static int wait_one(int flags)
}
child_died:
status = WEXITSTATUS(status);
exitcode = WEXITSTATUS(status);
if (WIFSIGNALED(status)) {
unsigned sig;
sig = WTERMSIG(status);
status = EXIT_UNCORRECTED;
exitcode = EXIT_UNCORRECTED;
if (sig != SIGINT) {
printf("Warning: %s %s terminated "
"by signal %d\n",
"by signal %u\n",
inst->prog, inst->device, sig);
status = EXIT_ERROR;
exitcode = EXIT_ERROR;
}
}
@@ -492,12 +493,12 @@ static int wait_one(int flags)
else
G.instance_list = inst->next;
if (G.verbose > 1)
printf("Finished with %s (exit status %d)\n",
inst->device, status);
printf("Finished with %s (exit status %u)\n",
inst->device, exitcode);
G.num_running--;
free_instance(inst);
return status;
return exitcode;
}
/*
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "Editors"
+37 -27
View File
@@ -598,6 +598,7 @@ static const char EMSG_NOT_ARRAY[] ALIGN1 = "Not an array";
static const char EMSG_POSSIBLE_ERROR[] ALIGN1 = "Possible syntax error";
static const char EMSG_UNDEF_FUNC[] ALIGN1 = "Call to undefined function";
static const char EMSG_NO_MATH[] ALIGN1 = "Math support is not compiled in";
static const char EMSG_NEGATIVE_FIELD[] ALIGN1 = "Access to negative field";
static void zero_out_var(var *vp)
{
@@ -2514,6 +2515,32 @@ static var *evaluate(node *op, var *res)
op1 = op->l.n;
debug_printf_eval("opinfo:%08x opn:%08x\n", opinfo, opn);
/* "delete" is special:
* "delete array[var--]" must evaluate index expr only once,
* must not evaluate it in "execute inevitable things" part.
*/
if (XC(opinfo & OPCLSMASK) == XC(OC_DELETE)) {
uint32_t info = op1->info & OPCLSMASK;
var *v;
debug_printf_eval("DELETE\n");
if (info == OC_VAR) {
v = op1->l.v;
} else if (info == OC_FNARG) {
v = &fnargs[op1->l.aidx];
} else {
syntax_error(EMSG_NOT_ARRAY);
}
if (op1->r.n) { /* array ref? */
const char *s;
s = getvar_s(evaluate(op1->r.n, v1));
hash_remove(iamarray(v), s);
} else {
clear_array(iamarray(v));
}
goto next;
}
/* execute inevitable things */
if (opinfo & OF_RES1)
L.v = evaluate(op1, v1);
@@ -2621,28 +2648,7 @@ static var *evaluate(node *op, var *res)
break;
}
case XC( OC_DELETE ): {
uint32_t info = op1->info & OPCLSMASK;
var *v;
if (info == OC_VAR) {
v = op1->l.v;
} else if (info == OC_FNARG) {
v = &fnargs[op1->l.aidx];
} else {
syntax_error(EMSG_NOT_ARRAY);
}
if (op1->r.n) {
const char *s;
clrvar(L.v);
s = getvar_s(evaluate(op1->r.n, v1));
hash_remove(iamarray(v), s);
} else {
clear_array(iamarray(v));
}
break;
}
/* case XC( OC_DELETE ): - moved to happen before arg evaluation */
case XC( OC_NEWSOURCE ):
g_progname = op->l.new_progname;
@@ -2666,12 +2672,14 @@ static var *evaluate(node *op, var *res)
/* -- recursive node type -- */
case XC( OC_VAR ):
debug_printf_eval("VAR\n");
L.v = op->l.v;
if (L.v == intvar[NF])
split_f0();
goto v_cont;
case XC( OC_FNARG ):
debug_printf_eval("FNARG[%d]\n", op->l.aidx);
L.v = &fnargs[op->l.aidx];
v_cont:
res = op->r.n ? findvar(iamarray(L.v), R.s) : L.v;
@@ -2942,6 +2950,8 @@ static var *evaluate(node *op, var *res)
case XC( OC_FIELD ): {
int i = (int)getvar_i(R.v);
if (i < 0)
syntax_error(EMSG_NEGATIVE_FIELD);
if (i == 0) {
res = intvar[F0];
} else {
@@ -3035,7 +3045,8 @@ static var *evaluate(node *op, var *res)
default:
syntax_error(EMSG_POSSIBLE_ERROR);
}
} /* switch */
next:
if ((opinfo & OPCLSMASK) <= SHIFT_TIL_THIS)
op = op->a.n;
if ((opinfo & OPCLSMASK) >= RECUR_FROM_THIS)
@@ -3141,7 +3152,7 @@ static rstream *next_input_file(void)
}
int awk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int awk_main(int argc, char **argv)
int awk_main(int argc UNUSED_PARAM, char **argv)
{
unsigned opt;
char *opt_F;
@@ -3210,7 +3221,7 @@ int awk_main(int argc, char **argv)
}
opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL);
argv += optind;
argc -= optind;
//argc -= optind;
if (opt & OPT_W)
bb_error_msg("warning: option -W is ignored");
if (opt & OPT_F) {
@@ -3247,15 +3258,14 @@ int awk_main(int argc, char **argv)
if (!*argv)
bb_show_usage();
parse_program(*argv++);
argc--;
}
/* fill in ARGV array */
setvar_i(intvar[ARGC], argc + 1);
setari_u(intvar[ARGV], 0, "awk");
i = 0;
while (*argv)
setari_u(intvar[ARGV], ++i, *argv++);
setvar_i(intvar[ARGC], i + 1);
evaluate(beginseq.first, &tv);
if (!mainseq.first && !endseq.first)
+86 -43
View File
@@ -15,7 +15,6 @@
* -D define wrap #ifdef and #ifndef around changes
* -o outfile output here instead of in place
* -r rejectfile write rejected hunks to this file
* --dry-run (regression!)
*
* -f force (no questions asked)
* -F fuzz (number, default 2)
@@ -34,23 +33,15 @@
//usage:#define patch_trivial_usage
//usage: "[OPTIONS] [ORIGFILE [PATCHFILE]]"
//usage:#define patch_full_usage "\n\n"
//usage: IF_LONG_OPTS(
//usage: " -p,--strip N Strip N leading components from file names"
//usage: "\n -i,--input DIFF Read DIFF instead of stdin"
//usage: "\n -R,--reverse Reverse patch"
//usage: "\n -N,--forward Ignore already applied patches"
/*usage: "\n --dry-run Don't actually change files" - TODO */
//usage: "\n -E,--remove-empty-files Remove output files if they become empty"
//usage: )
//usage: IF_NOT_LONG_OPTS(
//usage: " -p N Strip N leading components from file names"
//usage: "\n -i DIFF Read DIFF instead of stdin"
//usage: "\n -R Reverse patch"
//usage: "\n -N Ignore already applied patches"
//usage: "\n -E Remove output files if they become empty"
//usage: IF_LONG_OPTS(
//usage: "\n --dry-run Don't actually change files"
//usage: )
/* -u "interpret as unified diff" is supported but not documented: this info is not useful for --help */
/* -x "debug" is supported but does nothing */
//usage:
//usage:#define patch_example_usage
//usage: "$ patch -p1 < example.diff\n"
@@ -58,6 +49,7 @@
#include "libbb.h"
#define PATCH_DEBUG 0
// libbb candidate?
@@ -122,16 +114,18 @@ struct globals {
} while (0)
#define FLAG_STR "Rup:i:NEx"
#define FLAG_STR "Rup:i:NEfg"
/* FLAG_REVERSE must be == 1! Code uses this fact. */
#define FLAG_REVERSE (1 << 0)
#define FLAG_u (1 << 1)
#define FLAG_PATHLEN (1 << 2)
#define FLAG_INPUT (1 << 3)
#define FLAG_IGNORE (1 << 4)
#define FLAG_RMEMPTY (1 << 5)
/* Enable this bit and use -x for debug output: */
#define FLAG_DEBUG (0 << 6)
#define FLAG_REVERSE (1 << 0)
#define FLAG_u (1 << 1)
#define FLAG_PATHLEN (1 << 2)
#define FLAG_INPUT (1 << 3)
#define FLAG_IGNORE (1 << 4)
#define FLAG_RMEMPTY (1 << 5)
#define FLAG_f_unused (1 << 6)
#define FLAG_g_unused (1 << 7)
#define FLAG_dry_run ((1 << 8) * ENABLE_LONG_OPTS)
// Dispose of a line of input, either by writing it out or discarding it.
@@ -140,8 +134,6 @@ struct globals {
// state = 3: write whole line to fileout
// state > 3: write line+1 to fileout when *line != state
#define PATCH_DEBUG (option_mask32 & FLAG_DEBUG)
static void do_line(void *data)
{
struct double_list *dlist = data;
@@ -168,12 +160,14 @@ static void finish_oldfile(void)
}
xclose(TT.fileout);
temp = xstrdup(TT.tempname);
temp[strlen(temp) - 6] = '\0';
rename(TT.tempname, temp);
free(temp);
if (!ENABLE_LONG_OPTS || TT.tempname[0]) { /* not --dry-run? */
temp = xstrdup(TT.tempname);
temp[strlen(temp) - 6] = '\0';
rename(TT.tempname, temp);
free(temp);
free(TT.tempname);
}
free(TT.tempname);
TT.tempname = NULL;
}
TT.fileout = TT.filein = -1;
@@ -197,8 +191,10 @@ static void fail_hunk(void)
// Abort the copy and delete the temporary file.
close(TT.filein);
close(TT.fileout);
unlink(TT.tempname);
free(TT.tempname);
if (!ENABLE_LONG_OPTS || TT.tempname[0]) { /* not --dry-run? */
unlink(TT.tempname);
free(TT.tempname);
}
TT.tempname = NULL;
TT.state = 0;
@@ -239,6 +235,7 @@ static int apply_one_hunk(void)
plist = TT.current_hunk;
buf = NULL;
if (reverse ? TT.oldlen : TT.newlen) for (;;) {
//FIXME: this performs 1-byte reads:
char *data = xmalloc_reads(TT.filein, NULL);
TT.linenum++;
@@ -369,9 +366,45 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
long oldlen = oldlen; /* for compiler */
long newlen = newlen; /* for compiler */
#if ENABLE_LONG_OPTS
static const char patch_longopts[] ALIGN1 =
"reverse\0" No_argument "R"
"unified\0" No_argument "u"
"strip\0" Required_argument "p"
"input\0" Required_argument "i"
"forward\0" No_argument "N"
# if ENABLE_DESKTOP
"remove-empty-files\0" No_argument "E" /*ignored*/
/* "debug" Required_argument "x" */
# endif
/* "Assume user knows what [s]he is doing, do not ask any questions": */
"force\0" No_argument "f" /*ignored*/
# if ENABLE_DESKTOP
/* "Controls actions when a file is under RCS or SCCS control,
* and does not exist or is read-only and matches the default version,
* or when a file is under ClearCase control and does not exist..."
* IOW: rather obscure option.
* But Gentoo's portage does use -g0
*/
"get\0" Required_argument "g" /*ignored*/
# endif
"dry-run\0" No_argument "\xfd"
# if ENABLE_DESKTOP
"backup-if-mismatch\0" No_argument "\xfe" /*ignored*/
"no-backup-if-mismatch\0" No_argument "\xff" /*ignored*/
# endif
;
#endif
INIT_TT();
#if ENABLE_LONG_OPTS
opts = getopt32long(argv, FLAG_STR, patch_longopts, &opt_p, &opt_i);
#else
opts = getopt32(argv, FLAG_STR, &opt_p, &opt_i);
#endif
//bb_error_msg_and_die("opts:%x", opts);
argv += optind;
reverse = opts & FLAG_REVERSE;
TT.prefix = (opts & FLAG_PATHLEN) ? xatoi(opt_p) : 0; // can be negative!
@@ -517,10 +550,12 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
if (option_mask32 & FLAG_RMEMPTY) {
// If flag -E or --remove-empty-files is set
printf("removing %s\n", name);
xunlink(name);
if (!(opts & FLAG_dry_run))
xunlink(name);
} else {
printf("patching file %s\n", name);
xclose(xopen(name, O_WRONLY | O_TRUNC));
if (!(opts & FLAG_dry_run))
xclose(xopen(name, O_WRONLY | O_TRUNC));
}
// If we've got a file to open, do so.
} else if (!(option_mask32 & FLAG_PATHLEN) || i <= TT.prefix) {
@@ -529,24 +564,32 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
// If the old file was null, we're creating a new one.
if (strcmp(oldname, "/dev/null") == 0 || !oldsum) {
printf("creating %s\n", name);
s = strrchr(name, '/');
if (s) {
*s = 0;
bb_make_directory(name, -1, FILEUTILS_RECUR);
*s = '/';
if (!(opts & FLAG_dry_run)) {
s = strrchr(name, '/');
if (s) {
*s = '\0';
bb_make_directory(name, -1, FILEUTILS_RECUR);
*s = '/';
}
TT.filein = xopen(name, O_CREAT|O_EXCL|O_RDWR);
} else {
TT.filein = xopen("/dev/null", O_RDONLY);
}
TT.filein = xopen(name, O_CREAT|O_EXCL|O_RDWR);
} else {
printf("patching file %s\n", name);
TT.filein = xopen(name, O_RDONLY);
}
TT.tempname = xasprintf("%sXXXXXX", name);
TT.fileout = xmkstemp(TT.tempname);
// Set permissions of output file
fstat(TT.filein, &statbuf);
fchmod(TT.fileout, statbuf.st_mode);
if (!(opts & FLAG_dry_run)) {
TT.tempname = xasprintf("%sXXXXXX", name);
TT.fileout = xmkstemp(TT.tempname);
// Set permissions of output file
fstat(TT.filein, &statbuf);
fchmod(TT.fileout, statbuf.st_mode);
} else {
TT.tempname = (char*)"";
TT.fileout = xopen("/dev/null", O_WRONLY);
}
TT.linenum = 0;
TT.hunknum = 0;
}
+1 -1
View File
@@ -988,7 +988,7 @@ static void flush_append(char *last_puts_char)
static char *get_next_line(char *gets_char, char *last_puts_char)
{
char *temp = NULL;
int len;
size_t len;
char gc;
flush_append(last_puts_char);
+35 -26
View File
@@ -750,7 +750,10 @@ static int query_screen_dimensions(void)
return err;
}
#else
# define query_screen_dimensions() (0)
static ALWAYS_INLINE int query_screen_dimensions(void)
{
return 0;
}
#endif
static void edit_file(char *fn)
@@ -1067,10 +1070,13 @@ static void colon(char *buf)
not_implemented(p);
#else
char c, *orig_buf, *buf1, *q, *r;
char c, *buf1, *q, *r;
char *fn, cmd[MAX_INPUT_LEN], args[MAX_INPUT_LEN];
int i, l, li, b, e;
int useforce;
# if ENABLE_FEATURE_VI_SEARCH || ENABLE_FEATURE_ALLOW_EXEC
char *orig_buf;
# endif
// :3154 // if (-e line 3154) goto it else stay put
// :4,33w! foo // write a portion of buffer to file "foo"
@@ -1102,8 +1108,10 @@ static void colon(char *buf)
// look for optional address(es) :. :1 :1,9 :'q,'a :%
buf = get_address(buf, &b, &e);
# if ENABLE_FEATURE_VI_SEARCH || ENABLE_FEATURE_ALLOW_EXEC
// remember orig command line
orig_buf = buf;
# endif
// get the COMMAND into cmd[]
buf1 = cmd;
@@ -1147,7 +1155,7 @@ static void colon(char *buf)
dot_skip_over_ws();
}
}
#if ENABLE_FEATURE_ALLOW_EXEC
# if ENABLE_FEATURE_ALLOW_EXEC
else if (cmd[0] == '!') { // run a cmd
int retcode;
// :!ls run the <cmd>
@@ -1159,7 +1167,7 @@ static void colon(char *buf)
rawmode();
Hit_Return(); // let user see results
}
#endif
# endif
else if (cmd[0] == '=' && !cmd[1]) { // where is the address
if (b < 0) { // no addr given- use defaults
b = e = count_lines(text, dot);
@@ -1194,7 +1202,7 @@ static void colon(char *buf)
size = init_text_buffer(fn);
#if ENABLE_FEATURE_VI_YANKMARK
# if ENABLE_FEATURE_VI_YANKMARK
if (Ureg >= 0 && Ureg < 28) {
free(reg[Ureg]); // free orig line reg- for 'U'
reg[Ureg] = NULL;
@@ -1203,7 +1211,7 @@ static void colon(char *buf)
free(reg[YDreg]); // free default yank/delete register
reg[YDreg] = NULL;
}
#endif
# endif
// how many lines in text[]?
li = count_lines(text, end - 1);
status_line("'%s'%s"
@@ -1350,16 +1358,16 @@ static void colon(char *buf)
optind = -1; /* start from 0th file */
editing = 0;
}
#if ENABLE_FEATURE_VI_SET
# if ENABLE_FEATURE_VI_SET
} else if (strncmp(cmd, "set", i) == 0) { // set or clear features
#if ENABLE_FEATURE_VI_SETOPTS
# if ENABLE_FEATURE_VI_SETOPTS
char *argp;
#endif
# endif
i = 0; // offset into args
// only blank is regarded as args delimiter. What about tab '\t'?
if (!args[0] || strcasecmp(args, "all") == 0) {
// print out values of all options
#if ENABLE_FEATURE_VI_SETOPTS
# if ENABLE_FEATURE_VI_SETOPTS
status_line_bold(
"%sautoindent "
"%sflash "
@@ -1372,10 +1380,10 @@ static void colon(char *buf)
showmatch ? "" : "no",
tabstop
);
#endif
# endif
goto ret;
}
#if ENABLE_FEATURE_VI_SETOPTS
# if ENABLE_FEATURE_VI_SETOPTS
argp = args;
while (*argp) {
if (strncmp(argp, "no", 2) == 0)
@@ -1393,16 +1401,17 @@ static void colon(char *buf)
argp = skip_non_whitespace(argp);
argp = skip_whitespace(argp);
}
#endif /* FEATURE_VI_SETOPTS */
#endif /* FEATURE_VI_SET */
#if ENABLE_FEATURE_VI_SEARCH
# endif /* FEATURE_VI_SETOPTS */
# endif /* FEATURE_VI_SET */
# if ENABLE_FEATURE_VI_SEARCH
} else if (cmd[0] == 's') { // substitute a pattern with a replacement pattern
char *F, *R, *flags;
size_t len_F, len_R;
int gflag; // global replace flag
#if ENABLE_FEATURE_VI_UNDO
# if ENABLE_FEATURE_VI_UNDO
int dont_chain_first_item = ALLOW_UNDO;
#endif
# endif
// F points to the "find" pattern
// R points to the "replace" pattern
@@ -1439,9 +1448,9 @@ static void colon(char *buf)
// we found the "find" pattern - delete it
// For undo support, the first item should not be chained
text_hole_delete(found, found + len_F - 1, dont_chain_first_item);
#if ENABLE_FEATURE_VI_UNDO
# if ENABLE_FEATURE_VI_UNDO
dont_chain_first_item = ALLOW_UNDO_CHAIN;
#endif
# endif
// insert the "replace" patern
bias = string_insert(found, R, ALLOW_UNDO_CHAIN);
found += bias;
@@ -1457,7 +1466,7 @@ static void colon(char *buf)
}
q = next_line(ls);
}
#endif /* FEATURE_VI_SEARCH */
# endif /* FEATURE_VI_SEARCH */
} else if (strncmp(cmd, "version", i) == 0) { // show software version
status_line(BB_VER);
} else if (strncmp(cmd, "write", i) == 0 // write text to file
@@ -1472,12 +1481,12 @@ static void colon(char *buf)
if (args[0]) {
fn = args;
}
#if ENABLE_FEATURE_VI_READONLY
# if ENABLE_FEATURE_VI_READONLY
if (readonly_mode && !useforce) {
status_line_bold("'%s' is read only", fn);
goto ret;
}
#endif
# endif
//if (useforce) {
// if "fn" is not write-able, chmod u+w
// sprintf(syscmd, "chmod u+w %s", fn);
@@ -1517,7 +1526,7 @@ static void colon(char *buf)
}
}
}
#if ENABLE_FEATURE_VI_YANKMARK
# if ENABLE_FEATURE_VI_YANKMARK
} else if (strncmp(cmd, "yank", i) == 0) { // yank lines
if (b < 0) { // no addr given- use defaults
q = begin_line(dot); // assume .,. for the range
@@ -1527,7 +1536,7 @@ static void colon(char *buf)
li = count_lines(q, r);
status_line("Yank %d lines (%d chars) into [%c]",
li, strlen(reg[YDreg]), what_reg());
#endif
# endif
} else {
// cmd unknown
not_implemented(cmd);
@@ -1535,10 +1544,10 @@ static void colon(char *buf)
ret:
dot = bound_dot(dot); // make sure "dot" is valid
return;
#if ENABLE_FEATURE_VI_SEARCH
# if ENABLE_FEATURE_VI_SEARCH
colon_s_fail:
status_line(":s expression missing delimiters");
#endif
# endif
#endif /* FEATURE_VI_COLON */
}
+30
View File
@@ -0,0 +1,30 @@
# Replaces traditional overdesigned shutdown mechanism.
#
# No communication with init is necessary:
# just ask all processes to exit.
# Then unmount everything. Then reboot or power off.
# Install /sbin/ symlinks named halt, reboot, poweroff
# (and also possibly shutdown) to e.g.
# /app/shutdown-1.0/script/shutdown:
#
ln -s /app/shutdown-1.0/script/shutdown /sbin/halt
ln -s /app/shutdown-1.0/script/shutdown /sbin/reboot
ln -s /app/shutdown-1.0/script/shutdown /sbin/poweroff
#
# shutdown spawns do_shutdown in new session, redirected to /dev/null,
# tells user that shutdown is in progress, and sleeps
# (for cosmetic reasons: do not confuse user by letting him
# type more commands in this terminal).
#
# do_shutdown tries to switch to a VT console.
# Then, (only if -r) it spawns a hardshutdown child, to reboot
# unconditionally in 30 seconds if something later goes seriously bad.
# Then it runs stop_tasks, writing to /var/log/reboot/YYYYMMDDhhmmss.log,
# then it runs stop_storage.
# Then it commands kernel to halt/reboot/poweroff, if requested.
# Then it sleeps forever.
#
# Build the hardshutdown binary:
#
cd script && ./hardshutdown.make.sh
+54
View File
@@ -0,0 +1,54 @@
#!/bin/sh
# We are called with stdin/out/err = /dev/null
resetgracetime=60
logfile="/var/log/reboot/`date '+%Y%m%d%H%M%S'`.log"
mkdir -p /var/log/reboot
PATH=/sbin:/bin
say() {
printf "\r%s\n\r" "$*"
}
# Since there is a potential for various fuckups during umount,
# we start delayed hard reboot here which will forcibly
# reboot hung box in a remote datacenter a thousand miles away ;)
if test "$1" = "-r"; then
./hardshutdown -r "$resetgracetime" &
fi
# Now, (try to) switch away from X and open a console. I've seen reboots
# hung on open("/dev/console"), therefore we do it _after_ hardshutdown
exec >/dev/console 2>&1
if test "$1" = "-r"; then
say "* `date '+%H:%M:%S'` Scheduled hard reboot in $resetgracetime seconds"
fi
say "* `date '+%H:%M:%S'` Stopping tasks (see /var/log/reboot/* files)"
# log reboot event to file. %Y%m%d%H%M%S: YYYYMMDDHHMMSS
./stop_tasks >"$logfile" 2>&1
# Dying X tends to leave us at semi-random vt. Try to fix that,
# but if it doesn't work, proceed anyway.
exec >/dev/null 2>&1
chvt 1 & sleep 1
exec >/dev/console 2>&1
command -v ctrlaltdel >/dev/null && {
say "* `date '+%H:%M:%S'` Setting Ctrl-Alt-Del to 'hard'"
ctrlaltdel hard
}
say "* `date '+%H:%M:%S'` Stopping storage devices"
# we can't log this: we are about to unmount everything!
./stop_storage "$@"
# If we have cmdline params, start hardshutdown with them
test "$*" && ./hardshutdown "$@"
# Just sleep endlessly...
say "* `date '+%H:%M:%S'` You may now power off or press Ctrl-Alt-Del to reboot"
while true; do sleep 32000; done
+168
View File
@@ -0,0 +1,168 @@
/* Including <unistd.h> makes sure that on a glibc system
* <features.h> is included, which again defines __GLIBC__
*/
#include <unistd.h>
#include <stdio.h> /* puts */
#include <time.h> /* nanosleep */
#include <errno.h>
#include <stdlib.h>
#include <string.h>
/*
* Magic values required to use _reboot() system call.
*/
#define LINUX_REBOOT_MAGIC1 0xfee1dead
#define LINUX_REBOOT_MAGIC2 672274793
#define LINUX_REBOOT_MAGIC2A 85072278
#define LINUX_REBOOT_MAGIC2B 369367448
/*
* Commands accepted by the _reboot() system call.
*
* RESTART Restart system using default command and mode.
* HALT Stop OS and give system control to ROM monitor, if any.
* CAD_ON Ctrl-Alt-Del sequence causes RESTART command.
* CAD_OFF Ctrl-Alt-Del sequence sends SIGINT to init task.
* POWER_OFF Stop OS and remove all power from system, if possible.
* RESTART2 Restart system using given command string.
*/
#define LINUX_REBOOT_CMD_RESTART 0x01234567
#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
#define USE_LIBC
#ifdef USE_LIBC
/* libc version */
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <sys/reboot.h>
# define REBOOT(cmd) reboot(cmd)
#else
extern int reboot(int, int, int);
# define REBOOT(cmd) reboot(LINUX_REBOOT_MAGIC1,LINUX_REBOOT_MAGIC2,(cmd))
#endif
static int my_reboot(int cmd)
{
return REBOOT(cmd);
}
#else /* no USE_LIBC */
/* direct syscall version */
#include <linux/unistd.h>
#ifdef _syscall3
_syscall3(int, reboot, int, magic, int, magic_too, int, cmd);
#else
/* Let us hope we have a 3-argument reboot here */
extern int reboot(int, int, int);
#endif
static int my_reboot(int cmd)
{
return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd);
}
#endif
static void do_reboot(void)
{
my_reboot(LINUX_REBOOT_CMD_RESTART);
}
static void do_poweroff(void)
{
my_reboot(LINUX_REBOOT_CMD_POWER_OFF);
}
static void do_halt(void)
{
my_reboot(LINUX_REBOOT_CMD_HALT);
}
static void usage(void)
{
puts(
"Usage: hardshutdown -h|-r|-p [NN]\n"
" NN - seconds to sleep before requested action"
);
exit(1);
}
enum action_t {
SHUTDOWN, // do nothing
HALT,
POWEROFF,
REBOOT
};
int main(int argc, char *argv[])
{
struct timespec t = {0,0};
enum action_t action = SHUTDOWN;
int c, i;
char *prog, *ptr;
//if (*argv[0] == '-') argv[0]++; /* allow shutdown as login shell */
prog = argv[0];
ptr = strrchr(prog,'/');
if (ptr)
prog = ptr+1;
for (c=1; c < argc; c++) {
if (argv[c][0] >= '0' && argv[c][0] <= '9') {
t.tv_sec = strtol(argv[c], NULL, 10);
continue;
}
if (argv[c][0] != '-') {
usage();
return 1;
}
for (i=1; argv[c][i]; i++) {
switch (argv[c][i]) {
case 'h':
action = HALT;
break;
case 'p':
action = POWEROFF;
break;
case 'r':
action = REBOOT;
break;
default:
usage();
return 1;
}
}
}
if (action==SHUTDOWN) {
usage();
return 1;
}
chdir("/");
while (nanosleep(&t,&t)<0)
if (errno!=EINTR) break;
switch (action) {
case HALT:
do_halt();
break;
case POWEROFF:
do_poweroff();
break;
case REBOOT:
do_reboot();
break;
default: /* SHUTDOWN */
break;
}
return 1;
}
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
gcc -Wall -Os -o hardshutdown hardshutdown.c
strip hardshutdown
#or:
#diet gcc -Wall -o hardshutdown hardshutdown.c
#elftrunc hardshutdown
+64
View File
@@ -0,0 +1,64 @@
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# Usually, /sbin/ has symlinks named halt, reboot, poweroff
# (and also possibly shutdown) to e.g.
# /app/shutdown-1.0/script/shutdown (this file).
cd /app/shutdown-1.0/script || exit 1
test -x ./do_shutdown || exit 1
test -x ./hardshutdown || exit 1
# "reboot -f" -> "shutdown -f -r" -> "hardshutdown -r" -> immediate reboot
# "reboot" -> "shutdown -r" -> "do_shutdown -r"
# ^^^^^^^^^^^^^^^^^^ similarly for halt, poweroff.
# "shutdown" -> "do_shutdown" (everything killed/unmounted, but kernel not asked to do any poweroff etc)
force=""
test x"$1" = x"-f" && {
force="-f"
shift
}
test ! "$*" && test x"${0##*/}" = x"halt" && exec "$0" $force -h
test ! "$*" && test x"${0##*/}" = x"reboot" && exec "$0" $force -r
test ! "$*" && test x"${0##*/}" = x"poweroff" && exec "$0" $force -p
# We have something else than allowed parameters?
test x"$*" = x"" || test x"$*" = x"-h" || test x"$*" = x"-r" || test x"$*" = x"-p" || {
echo "Syntax: $0 [-f] [-h/-r/-p]"
exit 1
}
# Emergency shutdown?
test "$force" && {
exec ./hardshutdown "$@"
exit 1
}
# Normal shutdown
# We must have these executables on root fs
# (mount/umount aren't checked, all systems are ok versus that):
test -x /bin/killall5 -o -x /sbin/killall5 || exit 1
test -x /bin/ps -o -x /sbin/ps || exit 1
test -x /bin/date -o -x /sbin/date || exit 1
test -x /bin/xargs -o -x /sbin/xargs || exit 1
test -x /bin/wc -o -x /sbin/wc || exit 1
test -x /bin/cat -o -x /sbin/cat || exit 1
test -x /bin/sort -o -x /sbin/sort || exit 1
i="`ulimit -n`"
echo -n "Closing file descriptors $i-3... "
while test "$i" -ge 3; do
eval "exec $i>&-"
i=$((i-1))
done
echo "Shutting down. Please stand by..."
# setsid & /dev/null:
# make it a process leader & detach it from current tty.
# Why /dev/null and not /dev/console?
# I have seen a system which locked up while opening /dev/console
# due to the bug (?) in keyboard driver.
setsid env - PATH="$PATH" ./do_shutdown "$@" </dev/null >/dev/null 2>&1 &
while true; do read junk; done
+81
View File
@@ -0,0 +1,81 @@
#!/bin/sh
# Do unmount/remount-ro. Wait.
# KILL everybody. Wait.
# Repeat.
umountcnt=2
writeout=0 # increase if your kernel doesn ot guarantee writes to complete
# No /usr - we are expecting all binaries to be accessible
# from root fs alone
PATH=/sbin:/bin
say() {
printf "\r%s\n\r" "$*"
}
showps() {
# sleep 1 ensures that xargs will have time to start up
# this makes pslist less prone to random jitter
pslist=`{ sleep 1; ps -A -o comm=; } | sort | xargs`
pscnt=$(( `say "$pslist" | wc -w` + 0 ))
if test x"$VERBOSE" = x; then
say "* `date '+%H:%M:%S'` $pscnt processes"
else
say "* `date '+%H:%M:%S'` Processes ($pscnt): $pslist"
fi
}
say "<*> `date '+%Y-%m-%d %H:%M:%S'` Executing '$0 $*'"
showps
i="$umountcnt"
while test "$i" -gt 0; do
say "* `date '+%H:%M:%S'` Unmounting filesystems"
umount -a -n -r -f
# In case we unmounted proc...
test -e /proc/version || mount -t proc none /proc
# Remounting / RO isn't necessary when /etc/mtab is linked to /proc/mounts:
# already done. But let's be more paranoid here...
say "* `date '+%H:%M:%S'` Remounting root filesystem read-only"
mount -n -o remount,ro /
say "* `date '+%H:%M:%S'` Freeing loop devices"
for a in /dev/loop*; do
test -b "$a" && losetup -d "$a"
done
say "* `date '+%H:%M:%S'` Syncing"
sync
say "* `date '+%H:%M:%S'` Executing: killall5 -KILL"
killall5 -9
showps
i=$((i-1))
done
say "* `date '+%H:%M:%S'` Filesystem status (/proc/mounts)"
cat /proc/mounts \
| {
bad=false
while read dev mntpoint fstype opt n1 n2; do
case "$fstype" in
( proc | sysfs | usbfs | devpts | rpc_pipefs | binfmt_misc | autofs | rootfs | tmpfs | ramfs )
say "$dev $mntpoint $fstype $opt $n1 $n2"
continue
;;
esac
if test "${opt:0:2}" = "rw"; then
say "$dev $mntpoint $fstype $opt $n1 $n2 - RW!"
bad=true
else
say "$dev $mntpoint $fstype $opt $n1 $n2"
fi
done
if $bad; then
say "ERROR: we have filesystems mounted RW! Press <Enter> (^J)..."
read junk </dev/console
#sh </dev/console >&0 2>&0 # debug
fi
}
# Disk cache writeout
sleep "$writeout"
+70
View File
@@ -0,0 +1,70 @@
#!/bin/sh
# We are trying to be nice.
# TERM everybody. Give them some time to die.
# KILL might make some filesystems non-unmountable,
# so we'll do it in stop_storage instead.
killcnt=30
PATH=/sbin:/usr/sbin:/bin:/usr/bin
echo "<*> `date '+%Y-%m-%d %H:%M:%S'` Executing '$0 $*'"
showps() {
# sleep 1 ensures that xargs will have time to start up.
# This makes pslist less prone to random jitter.
pslist=`{ sleep 1; ps -A -o comm=; } | sort | xargs`
pscnt=$(( `echo "$pslist" | wc -w` + 0 ))
if test x"$VERBOSE" = x; then
echo "* `date '+%H:%M:%S'` $pscnt processes"
else
echo "* `date '+%H:%M:%S'` Processes ($pscnt): $pslist"
fi
}
# Sync.
# Rationale: sometimes buggy root processes can
# hang the system when killed (X for example may have problems
# with restoring text mode on a poorly supported hardware).
# These are bugs and must be fixed, but until then users will lose
# dirty data on shutdown! Let's make that less likely.
sync &
# Send SIGTERMs. If list of processes changes, proceed slower.
# If it has stabilised (all who wanted to, exited), proceed faster.
showps
i="$killcnt"
while test "$i" -gt 0; do
echo "* `date '+%H:%M:%S'` Sending CONT, TERM" #, HUP"
# I've seen "killall5 2.86" which doesn't grok signal names!
killall5 -18
killall5 -15
#killall5 -1 # HUP: because interactive bash does not die on TERM...
# but init will reread /etc/inittab on HUP and my /etc is on non root fs!
# -> umounts will complain.
oldpslist="$pslist"
showps
if test x"$pslist" = x"$oldpslist"; then
i=$((i-8))
fi
i=$((i-2))
done
echo "* `date '+%H:%M:%S'` Turning off swap"
swapoff -a
cat /proc/swaps | grep -v ^Filename | cut -d ' ' -f1 \
| while read -r line; do
test "$line" && {
echo swapoff "$line"
swapoff "$line"
}
done
echo "* /proc/swaps:"
cat /proc/swaps
echo "* /proc/mounts:"
cat /proc/mounts
echo "* ps -A e:"
ps -A e
echo "* top -bn1:"
top -bn1
+2 -1
View File
@@ -70,8 +70,9 @@ option domain local
option lease 864000 # default: 10 days
option msstaticroutes 10.0.0.0/8 10.127.0.1 # single static route
option staticroutes 10.0.0.0/8 10.127.0.1, 10.11.12.0/24 10.11.12.1
# Arbitrary option in hex form:
# Arbitrary option in hex or string form:
option 0x08 01020304 # option 8: "cookie server IP addr: 1.2.3.4"
option 14 "dumpfile"
# Currently supported options (for more info, see options.c):
#opt lease NUM
@@ -246,7 +246,8 @@ relative to the system-wide service directory.
This proposal asks developers of other daemontools implementations
to add "svc" command to their projects]
The "svok DIR" tool exits 0 if service is running, and nonzero if not.
The "svok DIR" tool exits 0 if service supervisor is running
(with service itself either running or stopped), and nonzero if not.
Other tools with different names and APIs may exist; however
for portability scripts should use the above tools.
+2 -2
View File
@@ -11,13 +11,13 @@ echo "* Upping iface $if"
ip link set dev $if up
>>udhcpd.leases
sed 's/^interface.*$/interface '"$if/" -i udhcpc.conf
sed 's/^interface.*$/interface '"$if/" -i udhcpd.conf
echo "* Starting udhcpd"
exec \
env - PATH="$PATH" \
softlimit \
setuidgid root \
udhcpd -f -vv udhcpc.conf
udhcpd -f -vv udhcpd.conf
exit $?
+10
View File
@@ -0,0 +1,10 @@
Local DNS cache service.
This service is useful if you have more than 3 DNS servers,
or if you need a finer-grained control of which servers
can serve which domain.
To make programs use local DNS server, make sure
/etc/resolv.conf says:
nameserver 127.0.0.1
+76
View File
@@ -0,0 +1,76 @@
keep-in-foreground
# "-" is stderr:
log-facility=-
# May also try log-queries=extra
log-queries
# No param = pidfile disabled:
pid-file
interface=lo
listen-address=127.0.0.1
bind-interfaces
cache-size=999
servers-file=/etc/dnsmasq_servers.conf
# Don’t read /etc/resolv.conf and /etc/hosts:
no-resolv
#no-hosts
# All reverse lookups for private IP ranges (ie 192.168.x.x, etc)
# which are not found in /etc/hosts or the DHCP leases file are
# answered with "no such domain" rather than being forwarded
# upstream. The set of prefixes affected is the list given in
# RFC6303.
#bogus-priv
#−T, --local-ttl=<time>
# When replying with information from /etc/hosts or configuration
# or the DHCP leases file dnsmasq by default sets the time-to-live
# field to zero, meaning that the requester should not itself
# cache the information. This is the correct thing to do in almost
# all situations. This option allows a time-to-live (in seconds)
# to be given for these replies. This will reduce the load on the
# server at the expense of clients using stale data under some
# circumstances.
local-ttl=67
#--dhcp-ttl=<time>
# As for --local-ttl, but affects only replies with information
# from DHCP leases. If both are given, --dhcp-ttl applies for DHCP
# information, and --local-ttl for others. Setting this to zero
# eliminates the effect of --local-ttl for DHCP.
#
#--neg-ttl=<time>
# Negative replies from upstream servers normally contain time-to-
# live information in SOA records which dnsmasq uses for caching.
# If the replies from upstream servers omit this information, dns-
# masq does not cache the reply. This option gives a default value
# for time-to-live (in seconds) which dnsmasq uses to cache nega-
# tive replies even in the absence of an SOA record.
neg-ttl=67
#--max-ttl=<time>
# Set a maximum TTL value that will be handed out to clients. The
# specified maximum TTL will be given to clients instead of the
# true TTL value if it is lower. The true TTL value is however
# kept in the cache to avoid flooding the upstream DNS servers.
#
#--max-cache-ttl=<time>
# Set a maximum TTL value for entries in the cache.
#
#--min-cache-ttl=<time>
# Extend short TTL values to the time given when caching them.
# Note that artificially extending TTL values is in general a bad
# idea, do not do it unless you have a good reason, and understand
# what you are doing. Dnsmasq limits the value of this option to
# one hour, unless recompiled.
min-cache-ttl=67
#--auth-ttl=<time>
# Set the TTL value returned in answers from the authoritative
# server.
+21
View File
@@ -0,0 +1,21 @@
#!/bin/sh
user=logger
logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger
chmod a+rX .
exec >/dev/null
exec 2>&1
exec \
env - PATH="$PATH" \
softlimit \
setuidgid "$user" \
svlogd -tt "$logdir"
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
cd log/logdir || exit 1
cat @* current | $PAGER
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
#exec >/dev/null
exec 2>&1
exec </dev/null
echo "* Starting dnsmasq"
exec \
env - PATH="$PATH" \
softlimit \
setuidgid root \
dnsmasq -C dnsmasq.conf
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
cd log/logdir || exit 1
watch -n2 'w=`ttysize w`; h=`ttysize h`; tail -$((h-3)) current 2>&1 | cut -b1-$((w-2))'
@@ -0,0 +1,38 @@
#!/bin/bash
empty=true
prio=0
i=0; while test "${if[$i]}"; do
test x"${dns_prio[$i]}" != x"" \
&& test "${dns_prio[$i]}" -gt "$prio" \
&& prio="${dns_prio[$i]}"
let i++; done
i=0; while test "${if[$i]}"; do
if test "${dnsmasq[$i]}"; then
for d in ${dnsmasq[$i]}; do
echo "$d"
empty=false
done
let i++;
continue
fi
# This iface has no dnsmasq-extended config.
# Use simple DNS names instead, if those exist.
for d in ${dns[$i]}; do
p="${dns_prio[$i]}"
test x"$p" == x"" && p=0
test x"$p" == x"$prio" || continue
echo "server=$d"
empty=false
done
let i++;
done
# Use Google DNS servers if nothing else is configured
$empty && echo "server=8.8.8.8"
$empty && echo "server=8.8.4.4"
# SIGHUP: make dnsmasq reload config
sv h dnsmasq
+4 -4
View File
@@ -10,7 +10,7 @@ ttyname=`tty`
ttybase="${ttyname%%[0123456789]*}" # strip numeric tail
if test x"$ttybase" = x"/dev/vc/" -o x"$ttybase" = x"/dev/tty"; then
echo "* Activating Cyrillic KOI8-R -> CP866 font map"
echo "* Activating font map"
echo -ne "\033(K" >"$ttyname"
echo "* Loading screen font"
@@ -18,9 +18,9 @@ if test x"$ttybase" = x"/dev/vc/" -o x"$ttybase" = x"/dev/tty"; then
-C "$ttyname" \
-m "$PWD/koi8r_to_uni.trans" \
"$PWD/alt08x16+unimap.fnt" \
|| echo "! setfont failure"
|| echo "setfont exit code: $?"
echo "* Loading keymap"
loadkeys "$PWD/ru_koi8r.keymap" \
|| echo "! loadkeys failure"
loadkeys "$PWD/unicode_cyrillic.keymap" \
|| echo "loadkeys exit code: $?"
fi
+2 -1
View File
@@ -6,7 +6,8 @@ ttybase="${ttyname%%[0123456789]*}" # strip numeric tail
if test "$ttybase" = "/dev/tty"; then
tail="${ttyname:8}"
echo "* Setting terminal device's owner to $LOGIN_UID:$LOGIN_GID"
chown "$LOGIN_UID:$LOGIN_GID" "/dev/vcs$tail" "/dev/vcsa$tail"
test -c "/dev/vcs$tail" && chown "$LOGIN_UID:$LOGIN_GID" "/dev/vcs$tail"
test -c "/dev/vcsa$tail" && chown "$LOGIN_UID:$LOGIN_GID" "/dev/vcsa$tail"
fi
# We can do this also, but login does it itself
# chown "$LOGIN_UID:$LOGIN_GID" "$ttyname"
@@ -1,183 +0,0 @@
keymaps 0,1, 2,3, 4,6, 8,10, 12,14
#
# This one is for generating koi8r Russian chars
# Cyr/Lat switches: RightAlt, Shift+Ctrl, Ctrl+Shift
# (last one does not work for dark and obscure reasons 8( )
#
# plain,shift, plain,shift, ctrl,ctrl alt,alt ctrlalt,ctrlalt
# lat-------- cyr-------- lat cyr lat cyr lat cyr
#
#Shift 1
#AltGr (cyr) 2
#Control 4
#Alt 8
#ShiftL 16
#ShiftR 32
#CtrlL 64
#CtrlR 128
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 1 = Escape Escape Escape Escape Escape Escape Meta_Escape Meta_Escape SAK SAK
keycode 2 = one exclam one exclam exclam exclam Meta_one Meta_one
keycode 3 = two at two at nul nul Meta_two Meta_two
keycode 4 = three numbersign three numbersign three three Meta_three Meta_three
keycode 5 = four dollar four dollar Control_backslash Control_backslash Meta_four Meta_four
keycode 6 = five percent five percent Control_bracketright Control_bracketright Meta_five Meta_five
keycode 7 = six asciicircum six asciicircum Control_asciicircum Control_asciicircum Meta_six Meta_six
keycode 8 = seven ampersand seven ampersand Control_underscore Control_underscore Meta_seven Meta_seven
keycode 9 = eight asterisk eight asterisk eight eight Meta_eight Meta_eight
keycode 10 = nine parenleft nine parenleft nine nine Meta_nine Meta_nine
keycode 11 = zero parenright zero parenright zero zero Meta_zero Meta_zero
keycode 12 = minus underscore minus underscore Control_underscore Control_underscore Meta_minus Meta_minus
keycode 13 = equal plus equal plus equal equal Meta_equal Meta_equal
keycode 14 = Delete Delete Delete Delete BackSpace BackSpace Meta_Delete Meta_Delete
keycode 15 = Tab Tab Tab Tab Tab Tab Meta_Tab Meta_Tab
keycode 16 = q Q 202 234 Control_q Control_q Meta_q Meta_q Meta_Control_q Meta_Control_q
keycode 17 = w W 195 227 Control_w Control_w Meta_w Meta_w Meta_Control_w Meta_Control_w
keycode 18 = e E 213 245 Control_e Control_e Meta_e Meta_e Meta_Control_e Meta_Control_e
keycode 19 = r R 203 235 Control_r Control_r Meta_r Meta_r Meta_Control_r Meta_Control_r
keycode 20 = t T 197 229 Control_t Control_t Meta_t Meta_t Meta_Control_t Meta_Control_t
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 21 = y Y 206 238 Control_y Control_y Meta_y Meta_y Meta_Control_y Meta_Control_y
keycode 22 = u U 199 231 Control_u Control_u Meta_u Meta_u Meta_Control_u Meta_Control_u
keycode 23 = i I 219 251 Control_i Control_i Meta_i Meta_i Meta_Control_i Meta_Control_i
keycode 24 = o O 221 253 Control_o Control_o Meta_o Meta_o Meta_Control_o Meta_Control_o
keycode 25 = p P 218 250 Control_p Control_p Meta_p Meta_p Meta_Control_p Meta_Control_p
keycode 26 = bracketleft braceleft 200 232 Escape Escape Meta_bracketleft Meta_bracketleft
keycode 27 = bracketright braceright 223 255 Control_bracketright Control_bracketright
keycode 28 = Return
# Shift+Ctrl - Cyrillic
keycode 29 = Control AltGr_Lock Control AltGr_Lock Control Control Control Control Control Control
keycode 30 = a A 198 230 Control_a Control_a Meta_a Meta_a Meta_Control_a Meta_Control_a
keycode 31 = s S 217 249 Control_s Control_s Meta_s Meta_s Meta_Control_s Meta_Control_s
keycode 32 = d D 215 247 Control_d Control_d Meta_d Meta_d Meta_Control_d Meta_Control_d
keycode 33 = f F 193 225 Control_f Control_f Meta_f Meta_f Meta_Control_f Meta_Control_f
keycode 34 = g G 208 240 Control_g Control_g Meta_g Meta_g Meta_Control_g Meta_Control_g
keycode 35 = h H 210 242 Control_h Control_h Meta_h Meta_h Meta_Control_h Meta_Control_h
keycode 36 = j J 207 239 Control_j Control_j Meta_j Meta_j Meta_Control_j Meta_Control_j
keycode 37 = k K 204 236 Control_k Control_k Meta_k Meta_k Meta_Control_k Meta_Control_k
keycode 38 = l L 196 228 Control_l Control_l Meta_l Meta_l Meta_Control_l Meta_Control_l
keycode 39 = semicolon colon 214 246 semicolon semicolon Meta_semicolon Meta_semicolon
keycode 40 = apostrophe quotedbl 220 252 Control_g Control_g Meta_apostrophe Meta_apostrophe
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 41 = grave asciitilde grave asciitilde nul nul Meta_grave Meta_grave
keycode 42 = Shift
keycode 43 = backslash bar backslash bar Control_backslash Control_backslash Meta_backslash Meta_backslash
keycode 44 = z Z 209 241 Control_z Control_z Meta_z Meta_z Meta_Control_z Meta_Control_z
keycode 45 = x X 222 254 Control_x Control_x Meta_x Meta_x Meta_Control_x Meta_Control_x
keycode 46 = c C 211 243 Control_c Control_c Meta_c Meta_c Meta_Control_c Meta_Control_c
keycode 47 = v V 205 237 Control_v Control_v Meta_v Meta_v Meta_Control_v Meta_Control_v
keycode 48 = b B 201 233 Control_b Control_b Meta_b Meta_b Meta_Control_b Meta_Control_b
keycode 49 = n N 212 244 Control_n Control_n Meta_n Meta_n Meta_Control_n Meta_Control_n
keycode 50 = m M 216 248 Control_m Control_m Meta_m Meta_m Meta_Control_m Meta_Control_m
keycode 51 = comma less 194 226 comma comma Meta_comma Meta_comma
keycode 52 = period greater 192 224 Compose Compose Meta_period Meta_period
keycode 53 = slash question slash question Delete Delete Meta_slash Meta_slash Meta_question Meta_question
# Ctrl+Shift - Cyrillic (not working???)
keycode 54 = Shift Shift Shift Shift AltGr_Lock AltGr_Lock Shift Shift Shift Shift
keycode 55 = KP_Multiply
keycode 56 = Alt
keycode 57 = space space space space nul nul Meta_space Meta_space
keycode 58 = Caps_Lock
keycode 59 = F1 F11 F1 F11 F1 F1 Console_1 Console_1 Console_1 Console_1
keycode 60 = F2 F12 F2 F12 F2 F2 Console_2 Console_2 Console_2 Console_2
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 61 = F3 F13 F3 F13 F3 F3 Console_3 Console_3 Console_3 Console_3
keycode 62 = F4 F14 F4 F14 F4 F4 Console_4 Console_4 Console_4 Console_4
keycode 63 = F5 F15 F5 F15 F5 F5 Console_5 Console_5 Console_5 Console_5
keycode 64 = F6 F16 F6 F16 F6 F6 Console_6 Console_6 Console_6 Console_6
keycode 65 = F7 F17 F7 F17 F7 F7 Console_7 Console_7 Console_7 Console_7
keycode 66 = F8 F18 F8 F18 F8 F8 Console_8 Console_8 Console_8 Console_8
keycode 67 = F9 F19 F9 F19 F9 F9 Console_9 Console_9 Console_9 Console_9
keycode 68 = F10 F20 F10 F20 F10 F10 Console_10 Console_10 Console_10 Console_10
keycode 69 = Num_Lock Bare_Num_Lock Num_Lock Bare_Num_Lock
keycode 70 = Scroll_Lock Show_Memory Scroll_Lock Show_Memory Show_State Show_State
keycode 71 = KP_7 KP_7 KP_7 KP_7 KP_7 KP_7 Ascii_7 Ascii_7
keycode 72 = KP_8 KP_8 KP_8 KP_8 KP_8 KP_8 Ascii_8 Ascii_8
keycode 73 = KP_9 KP_9 KP_9 KP_9 KP_9 KP_9 Ascii_9 Ascii_9
keycode 74 = KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract
keycode 75 = KP_4 KP_4 KP_4 KP_4 KP_4 KP_4 Ascii_4 Ascii_4
keycode 76 = KP_5 KP_5 KP_5 KP_5 KP_5 KP_5 Ascii_5 Ascii_5
keycode 77 = KP_6 KP_6 KP_6 KP_6 KP_6 KP_6 Ascii_6 Ascii_6
keycode 78 = KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add
keycode 79 = KP_1 KP_1 KP_1 KP_1 KP_1 KP_1 Ascii_1 Ascii_1
keycode 80 = KP_2 KP_2 KP_2 KP_2 KP_2 KP_2 Ascii_2 Ascii_2
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 81 = KP_3 KP_3 KP_3 KP_3 KP_3 KP_3 Ascii_3 Ascii_3
keycode 82 = KP_0 KP_0 KP_0 KP_0 KP_0 KP_0 Ascii_0 Ascii_0
keycode 83 = KP_Period KP_Period KP_Period KP_Period KP_Period KP_Period KP_Period KP_Period Boot Boot
keycode 84 = Last_Console
keycode 85 =
keycode 86 = less greater less greater less less Meta_less Meta_less
keycode 87 = F11 F11 F11 F11 F11 F11 Console_11 Console_11 Console_11 Console_11
keycode 88 = F12 F12 F12 F12 F12 F12 Console_12 Console_12 Console_12 Console_12
keycode 89 =
keycode 90 =
keycode 91 =
keycode 92 =
keycode 93 =
keycode 94 =
keycode 95 =
keycode 96 = KP_Enter
keycode 97 = Control
keycode 98 = KP_Divide
keycode 99 = Control_backslash
# Right Alt - Cyrillic
keycode 100 = AltGr_Lock
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 101 = Break
keycode 102 = Find
keycode 103 = Up
keycode 104 = Prior Scroll_Backward Prior Scroll_Backward Prior Prior Prior Prior Prior Prior
keycode 105 = Left Left Left Left Left Left Left Left Decr_Console Decr_Console
keycode 106 = Right Right Right Right Right Right Right Right Incr_Console Incr_Console
keycode 107 = Select
keycode 108 = Down
keycode 109 = Next Scroll_Forward Next Scroll_Forward Next Next Next Next Next Next
keycode 110 = Insert
keycode 111 = Remove Remove Remove Remove Remove Remove Remove Remove Boot Boot
keycode 112 = Macro
keycode 113 = F13
keycode 114 = F14
keycode 115 = Help
keycode 116 = Do
keycode 117 = F17
keycode 118 = KP_MinPlus
keycode 119 = Pause
keycode 120 =
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 121 =
keycode 122 =
keycode 123 =
keycode 124 =
keycode 125 =
keycode 126 =
keycode 127 =
string F1 = "\033[[A"
string F2 = "\033[[B"
string F3 = "\033[[C"
string F4 = "\033[[D"
string F5 = "\033[[E"
string F6 = "\033[17~"
string F7 = "\033[18~"
string F8 = "\033[19~"
string F9 = "\033[20~"
string F10 = "\033[21~"
string F11 = "\033[23~"
string F12 = "\033[24~"
string F13 = "\033[25~"
string F14 = "\033[26~"
string F15 = "\033[28~"
string F16 = "\033[29~"
string F17 = "\033[31~"
string F18 = "\033[32~"
string F19 = "\033[33~"
string F20 = "\033[34~"
string Find = "\033[1~"
string Insert = "\033[2~"
string Remove = "\033[3~"
string Select = "\033[4~"
string Prior = "\033[5~"
string Next = "\033[6~"
string Macro = "\033[M"
string Pause = "\033[P"
-6
View File
@@ -1,9 +1,5 @@
#!/bin/sh
exec >/dev/null
exec 2>&1
exec </dev/null
user=root
baud=38400
delay=3
@@ -25,6 +21,4 @@ test -x ./cfg && . ./cfg
exec \
env - "TERM=$TERM" PATH="$PATH" LOGIN_PRE_SUID_SCRIPT="$PWD/login.sh" \
softlimit \
setuidgid "$user" \
getty "$baud" "$tty" "$TERM"
@@ -0,0 +1,200 @@
keymaps 0,1, 2,3, 4,6, 8,9, 10,11, 12,14
#
# This one is for generating Unicode Curillic chars
# Cyr/Lat switches: RightAlt, Shift+Ctrl, Ctrl+Shift, Win keys
#
# plain,shift, plain,shift, ctrl,ctrl alt,shiftalt alt,shiftalt ctrlalt,ctrlalt
# lat-------- cyr-------- lat cyr lat--------- cyr--------- lat cyr
#
#Shift 1
#AltGr (cyr) 2
#Control 4
#Alt 8
#ShiftL 16
#ShiftR 32
#CtrlL 64
#CtrlR 128
# L/R Ctrl: Shift+Ctrl - Cyrillic
keycode 29 = Control AltGr_Lock Control AltGr_Lock Control Control Control Control Control Control Control Control
keycode 97 = Control AltGr_Lock Control AltGr_Lock Control Control Control Control Control Control Control Control
# L/R Shift: Ctrl+Shift - Cyrillic
keycode 42 = Shift Shift Shift Shift AltGr_Lock AltGr_Lock Shift Shift Shift Shift Shift Shift
keycode 54 = Shift Shift Shift Shift AltGr_Lock AltGr_Lock Shift Shift Shift Shift Shift Shift
# Right Alt: Cyrillic
keycode 100 = AltGr_Lock
# L/R Win: Cyrillic
keycode 125 = AltGr_Lock
keycode 126 = AltGr_Lock
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt shift ============= alt cyr =============== alt shift cur ========= ctrlalt =============== ctrlalt cyr ===========
keycode 1 = Escape Escape Escape Escape Escape Escape Meta_Escape Meta_Escape Meta_Escape Meta_Escape SAK SAK
keycode 2 = one exclam one exclam exclam exclam Meta_one Meta_one Meta_one Meta_one
keycode 3 = two at two at nul nul Meta_two Meta_two Meta_two Meta_two
keycode 4 = three numbersign three numbersign three three Meta_three Meta_three Meta_three Meta_three
keycode 5 = four dollar four dollar Control_backslash Control_backslash Meta_four Meta_four Meta_four Meta_four
keycode 6 = five percent five percent Control_bracketright Control_bracketright Meta_five Meta_five Meta_five Meta_five
keycode 7 = six asciicircum six asciicircum Control_asciicircum Control_asciicircum Meta_six Meta_six Meta_six Meta_six
keycode 8 = seven ampersand seven ampersand Control_underscore Control_underscore Meta_seven Meta_seven Meta_seven Meta_seven
keycode 9 = eight asterisk eight asterisk eight eight Meta_eight Meta_eight Meta_eight Meta_eight
keycode 10 = nine parenleft nine parenleft nine nine Meta_nine Meta_nine Meta_nine Meta_nine
keycode 11 = zero parenright zero parenright zero zero Meta_zero Meta_zero Meta_zero Meta_zero
keycode 12 = minus underscore minus underscore Control_underscore Control_underscore Meta_minus Meta_minus Meta_minus Meta_minus
keycode 13 = equal plus equal plus equal equal Meta_equal Meta_equal Meta_equal Meta_equal
keycode 14 = Delete Delete Delete Delete BackSpace BackSpace Meta_Delete Meta_Delete Meta_Delete Meta_Delete
keycode 15 = Tab Tab Tab Tab Tab Tab Meta_Tab Meta_Tab Meta_Tab Meta_Tab
keycode 16 = +q +Q +U+0439 +U+0419 Control_q Control_q Meta_q Meta_q Meta_q Meta_q Meta_Control_q Meta_Control_q
keycode 17 = +w +W +U+0446 +U+0426 Control_w Control_w Meta_w Meta_w Meta_w Meta_w Meta_Control_w Meta_Control_w
keycode 18 = +e +E +U+0443 +U+0423 Control_e Control_e Meta_e Meta_e Meta_e Meta_e Meta_Control_e Meta_Control_e
keycode 19 = +r +R +U+043a +U+041a Control_r Control_r Meta_r Meta_r Meta_r Meta_r Meta_Control_r Meta_Control_r
keycode 20 = +t +T +U+0435 +U+0415 Control_t Control_t Meta_t Meta_t Meta_t Meta_t Meta_Control_t Meta_Control_t
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt =================== alt cyr =============== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 21 = +y +Y +U+043d +U+041d Control_y Control_y Meta_y Meta_y Meta_y Meta_y Meta_Control_y Meta_Control_y
keycode 22 = +u +U +U+0433 +U+0413 Control_u Control_u Meta_u Meta_u Meta_u Meta_u Meta_Control_u Meta_Control_u
keycode 23 = +i +I +U+0448 +U+0428 Control_i Control_i Meta_i Meta_i Meta_i Meta_i Meta_Control_i Meta_Control_i
keycode 24 = +o +O +U+0449 +U+0429 Control_o Control_o Meta_o Meta_o Meta_o Meta_o Meta_Control_o Meta_Control_o
keycode 25 = +p +P +U+0437 +U+0417 Control_p Control_p Meta_p Meta_p Meta_p Meta_p Meta_Control_p Meta_Control_p
keycode 26 = bracketleft braceleft +U+0445 +U+0425 Escape Escape Meta_bracketleft Meta_bracketleft Meta_bracketleft Meta_bracketleft
keycode 27 = bracketright braceright +U+044a +U+042a Control_bracketright Control_bracketright
keycode 28 = Return
# LCtrl
#keycode 29 =
keycode 30 = +a +A +U+0444 +U+0424 Control_a Control_a Meta_a Meta_a Meta_a Meta_a Meta_Control_a Meta_Control_a
keycode 31 = +s +S +U+044b +U+042b Control_s Control_s Meta_s Meta_s Meta_s Meta_s Meta_Control_s Meta_Control_s
keycode 32 = +d +D +U+0432 +U+0412 Control_d Control_d Meta_d Meta_d Meta_d Meta_d Meta_Control_d Meta_Control_d
keycode 33 = +f +F +U+0430 +U+0410 Control_f Control_f Meta_f Meta_f Meta_f Meta_f Meta_Control_f Meta_Control_f
keycode 34 = +g +G +U+043f +U+041f Control_g Control_g Meta_g Meta_g Meta_g Meta_g Meta_Control_g Meta_Control_g
keycode 35 = +h +H +U+0440 +U+0420 Control_h Control_h Meta_h Meta_h Meta_h Meta_h Meta_Control_h Meta_Control_h
keycode 36 = +j +J +U+043e +U+041e Control_j Control_j Meta_j Meta_j Meta_j Meta_j Meta_Control_j Meta_Control_j
keycode 37 = +k +K +U+043b +U+041b Control_k Control_k Meta_k Meta_k Meta_k Meta_k Meta_Control_k Meta_Control_k
keycode 38 = +l +L +U+0434 +U+0414 Control_l Control_l Meta_l Meta_l Meta_l Meta_l Meta_Control_l Meta_Control_l
keycode 39 = semicolon colon +U+0436 +U+0416 semicolon semicolon Meta_semicolon Meta_semicolon Meta_semicolon Meta_semicolon
keycode 40 = apostrophe quotedbl +U+044d +U+042d Control_g Control_g Meta_apostrophe Meta_apostrophe Meta_apostrophe Meta_apostrophe
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt =================== alt cyr =============== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 41 = grave asciitilde grave asciitilde nul nul Meta_grave Meta_grave Meta_grave Meta_grave
# LShift
#keycode 42 =
keycode 43 = backslash bar backslash bar Control_backslash Control_backslash Meta_backslash Meta_backslash Meta_backslash Meta_backslash
keycode 44 = +z +Z +U+044f +U+042f Control_z Control_z Meta_z Meta_z Meta_z Meta_z Meta_Control_z Meta_Control_z
keycode 45 = +x +X +U+0447 +U+0427 Control_x Control_x Meta_x Meta_x Meta_x Meta_x Meta_Control_x Meta_Control_x
keycode 46 = +c +C +U+0441 +U+0421 Control_c Control_c Meta_c Meta_c Meta_c Meta_c Meta_Control_c Meta_Control_c
keycode 47 = +v +V +U+043c +U+041c Control_v Control_v Meta_v Meta_v Meta_v Meta_v Meta_Control_v Meta_Control_v
keycode 48 = +b +B +U+0438 +U+0418 Control_b Control_b Meta_b Meta_b Meta_b Meta_b Meta_Control_b Meta_Control_b
keycode 49 = +n +N +U+0442 +U+0422 Control_n Control_n Meta_n Meta_n Meta_n Meta_n Meta_Control_n Meta_Control_n
keycode 50 = +m +M +U+044c +U+042c Control_m Control_m Meta_m Meta_m Meta_m Meta_m Meta_Control_m Meta_Control_m
keycode 51 = comma less +U+0431 +U+0411 comma comma Meta_comma Meta_comma Meta_comma Meta_comma
keycode 52 = period greater +U+044e +U+042e Compose Compose Meta_period Meta_period Meta_period Meta_period
keycode 53 = slash question slash question Delete Delete Meta_slash Meta_question Meta_slash Meta_question Meta_question Meta_question
# RShift
#keycode 54 =
keycode 55 = KP_Multiply
keycode 56 = Alt
keycode 57 = space space space space nul nul Meta_space Meta_space Meta_space Meta_space
keycode 58 = Caps_Lock
keycode 59 = F1 F11 F1 F11 F1 F1 Console_1 Console_1 Console_1 Console_1 Console_1 Console_1
keycode 60 = F2 F12 F2 F12 F2 F2 Console_2 Console_2 Console_2 Console_2 Console_2 Console_2
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt =================== alt cyr =============== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 61 = F3 F13 F3 F13 F3 F3 Console_3 Console_3 Console_3 Console_3 Console_3 Console_3
keycode 62 = F4 F14 F4 F14 F4 F4 Console_4 Console_4 Console_4 Console_4 Console_4 Console_4
keycode 63 = F5 F15 F5 F15 F5 F5 Console_5 Console_5 Console_5 Console_5 Console_5 Console_5
keycode 64 = F6 F16 F6 F16 F6 F6 Console_6 Console_6 Console_6 Console_6 Console_6 Console_6
keycode 65 = F7 F17 F7 F17 F7 F7 Console_7 Console_7 Console_7 Console_7 Console_7 Console_7
keycode 66 = F8 F18 F8 F18 F8 F8 Console_8 Console_8 Console_8 Console_8 Console_8 Console_8
keycode 67 = F9 F19 F9 F19 F9 F9 Console_9 Console_9 Console_9 Console_9 Console_9 Console_9
keycode 68 = F10 F20 F10 F20 F10 F10 Console_10 Console_10 Console_10 Console_10 Console_10 Console_10
keycode 69 = Num_Lock Bare_Num_Lock Num_Lock Bare_Num_Lock
keycode 70 = Scroll_Lock Show_Memory Scroll_Lock Show_Memory Show_State Show_State
keycode 71 = KP_7 KP_7 KP_7 KP_7 KP_7 KP_7 Ascii_7 Ascii_7 Ascii_7 Ascii_7
keycode 72 = KP_8 KP_8 KP_8 KP_8 KP_8 KP_8 Ascii_8 Ascii_8 Ascii_8 Ascii_8
keycode 73 = KP_9 KP_9 KP_9 KP_9 KP_9 KP_9 Ascii_9 Ascii_9 Ascii_9 Ascii_9
keycode 74 = KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract
keycode 75 = KP_4 KP_4 KP_4 KP_4 KP_4 KP_4 Ascii_4 Ascii_4 Ascii_4 Ascii_4
keycode 76 = KP_5 KP_5 KP_5 KP_5 KP_5 KP_5 Ascii_5 Ascii_5 Ascii_5 Ascii_5
keycode 77 = KP_6 KP_6 KP_6 KP_6 KP_6 KP_6 Ascii_6 Ascii_6 Ascii_6 Ascii_6
keycode 78 = KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add
keycode 79 = KP_1 KP_1 KP_1 KP_1 KP_1 KP_1 Ascii_1 Ascii_1 Ascii_1 Ascii_1
keycode 80 = KP_2 KP_2 KP_2 KP_2 KP_2 KP_2 Ascii_2 Ascii_2 Ascii_2 Ascii_2
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt =================== alt cyr =============== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 81 = KP_3 KP_3 KP_3 KP_3 KP_3 KP_3 Ascii_3 Ascii_3 Ascii_3 Ascii_3
keycode 82 = KP_0 KP_0 KP_0 KP_0 KP_0 KP_0 Ascii_0 Ascii_0 Ascii_0 Ascii_0
keycode 83 = KP_Period KP_Period KP_Period KP_Period KP_Period KP_Period KP_Period KP_Period KP_Period KP_Period Boot Boot
keycode 84 = Last_Console
keycode 85 =
keycode 86 = less greater less greater less less Meta_less Meta_less Meta_less Meta_less
keycode 87 = F11 F11 F11 F11 F11 F11 Console_11 Console_11 Console_11 Console_11 Console_11 Console_11
keycode 88 = F12 F12 F12 F12 F12 F12 Console_12 Console_12 Console_12 Console_12 Console_12 Console_12
keycode 89 =
keycode 90 =
keycode 91 =
keycode 92 =
keycode 93 =
keycode 94 =
keycode 95 =
keycode 96 = KP_Enter
# RControl
#keycode 97 =
keycode 98 = KP_Divide
keycode 99 = Control_backslash
# RAlt
#keycode 100 =
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt shift ============= alt cyr =============== alt shift cyr ========= ctrlalt =============== ctrlalt cyr ===========
keycode 101 = Break
keycode 102 = Find
keycode 103 = Up
keycode 104 = Prior Scroll_Backward Prior Scroll_Backward Prior Prior Prior Prior Prior Prior Prior Prior
keycode 105 = Left Left Left Left Left Left Left Left Left Left Decr_Console Decr_Console
keycode 106 = Right Right Right Right Right Right Right Right Right Right Incr_Console Incr_Console
keycode 107 = Select
keycode 108 = Down
keycode 109 = Next Scroll_Forward Next Scroll_Forward Next Next Next Next Next Next Next Next
keycode 110 = Insert
keycode 111 = Remove Remove Remove Remove Remove Remove Remove Remove Remove Remove Boot Boot
keycode 112 = Macro
keycode 113 = F13
keycode 114 = F14
keycode 115 = Help
keycode 116 = Do
keycode 117 = F17
keycode 118 = KP_MinPlus
keycode 119 = Pause
keycode 120 =
#============== plain ========= shift========== plain cyr ===== shift cyr ===== ctrl ================== ctrl cyr ============== alt =================== alt =================== alt cyr =============== alt cyr =============== ctrlalt =============== ctrlalt cyr ===========
keycode 121 =
keycode 122 =
keycode 123 =
keycode 124 =
# LWin
#keycode 125 =
# RWin
#keycode 126 =
# RMenu
keycode 127 =
string F1 = "\033[[A"
string F2 = "\033[[B"
string F3 = "\033[[C"
string F4 = "\033[[D"
string F5 = "\033[[E"
string F6 = "\033[17~"
string F7 = "\033[18~"
string F8 = "\033[19~"
string F9 = "\033[20~"
string F10 = "\033[21~"
string F11 = "\033[23~"
string F12 = "\033[24~"
string F13 = "\033[25~"
string F14 = "\033[26~"
string F15 = "\033[28~"
string F16 = "\033[29~"
string F17 = "\033[31~"
string F18 = "\033[32~"
string F19 = "\033[33~"
string F20 = "\033[34~"
string Find = "\033[1~"
string Insert = "\033[2~"
string Remove = "\033[3~"
string Select = "\033[4~"
string Prior = "\033[5~"
string Next = "\033[6~"
string Macro = "\033[M"
string Pause = "\033[P"
@@ -3,13 +3,18 @@
# $1: interface
# $2: state
if test -d "/var/service/dhcp_$1"; then
if test x"$2" = x"down"; then
echo "Downing /var/service/dhcp_$1"
sv d "/var/service/dhcp_$1"
fi
if test x"$2" = x"up"; then
echo "Upping /var/service/dhcp_$1"
sv u "/var/service/dhcp_$1"
fi
if test x"$2" = x"down"; then
echo "Downing dhcp_$1"
svc -d "dhcp_$1"
echo "Downing zcip_$1"
svc -d "zcip_$1"
fi
if test x"$2" = x"up"; then
echo "Upping dhcp_$1"
svc -u "dhcp_$1"
echo "Upping zcip_$1"
svc -u "zcip_$1"
fi
# Parent ifplugd exits if we exit with nonzero.
# Do not startle it:
exit 0
+15 -8
View File
@@ -16,7 +16,7 @@ exec \
env - PATH="$PATH" \
softlimit \
setuidgid root \
ifplugd -apqns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler"
ifplugd -aqlns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler"
# We use -t3 to wake ifplugd up less often.
# If after three tests (3*3=9 > 8) link state seen to be different,
@@ -24,19 +24,26 @@ ifplugd -apqns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler"
# IOW: short link losses will be ignored, longer ones
# will trigger DHCP reconfiguration and such (see handler code).
#-a Do not up interface automatically
#-p Dont run script on daemon startup
#-q Dont run script on daemon quit
# -l makes ifplugd run either "up" or "down" script on startup.
# For example, if wired eth cable is unplugged, this stops dhcp service
# from pointlessly trying to get a lease.
# -q means that stopping monitoring does not stop dhcp/zcip/etc:
# presumably, admin decided to control them manually.
#-a Don't up interface automatically
#-p Don't run "up" script on startup
#-q Don't run "down" script on exit
#-l Always run script on startup
#-n Do not daemonize
#-s Do not log to syslog
#-t SECS Poll time in seconds
#-u SECS Delay before running script after link up
#-d SECS Delay after link down
#-i IFACE Interface
#-r PROG Script to run
#-f/-F Treat link detection error as link down/link up (otherwise exit on error)
#-M Monitor creation/destruction of interface (otherwise it must exist)
#-r PROG Script to run
#-x ARG Extra argument for script
#-I Dont exit on nonzero exit code from script
#-l Run script on startup even if no cable is detected
#-I Don't exit on nonzero exit code from script
#-f/-F Treat link detection error as link down/link up (otherwise exit on error)
#-m MODE API mode (mii, priv, ethtool, wlan, auto)
#-k Kill running daemon
+1 -1
View File
@@ -7,7 +7,7 @@ exec </dev/null
user=root # for bind to port 69
exec \
env - \
env - PATH="$PATH" \
softlimit \
setuidgid "$user" \
udpsvd -v -c 10 -l localhost \
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "Finding Utilities"
+1 -1
View File
@@ -263,7 +263,7 @@
//usage: "\n -regex PATTERN Match path to regex PATTERN"
//usage: )
//usage: IF_FEATURE_FIND_TYPE(
//usage: "\n -type X File type is X (one of: f,d,l,b,c,...)"
//usage: "\n -type X File type is X (one of: f,d,l,b,c,s,p)"
//usage: )
//usage: IF_FEATURE_FIND_PERM(
//usage: "\n -perm MASK At least one mask bit (+MASK), all bits (-MASK),"
+1 -1
View File
@@ -352,7 +352,7 @@ static int grep_file(FILE *file)
goto opt_f_not_found;
} else
if (option_mask32 & OPT_w) {
char c = (match != str) ? match[-1] : ' ';
char c = (match != line) ? match[-1] : ' ';
if (!isalnum(c) && c != '_') {
c = match[strlen(gl->pattern)];
if (!c || (!isalnum(c) && c != '_'))
+6 -6
View File
@@ -496,16 +496,16 @@ static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg
static int xargs_ask_confirmation(void)
{
FILE *tty_stream;
int c, savec;
int r;
tty_stream = xfopen_for_read(CURRENT_TTY);
fputs(" ?...", stderr);
fflush_all();
c = savec = getc(tty_stream);
while (c != EOF && c != '\n')
c = getc(tty_stream);
r = bb_ask_y_confirmation_FILE(tty_stream);
fclose(tty_stream);
return (savec == 'y' || savec == 'Y');
return r;
}
#else
# define xargs_ask_confirmation() 1
+35 -10
View File
@@ -64,6 +64,9 @@ typedef struct archive_handle_t {
/* Currently processed file's header */
file_header_t *file_header;
/* List of link placeholders */
llist_t *link_placeholders;
/* Process the header component, e.g. tar -t */
void FAST_FUNC (*action_header)(const file_header_t *);
@@ -114,20 +117,23 @@ typedef struct archive_handle_t {
const char *ar__name;
struct archive_handle_t *ar__out;
#endif
#if ENABLE_FEATURE_AR_LONG_FILENAMES
char *ar__long_names;
unsigned ar__long_name_size;
#endif
} archive_handle_t;
/* bits in ah_flags */
#define ARCHIVE_RESTORE_DATE (1 << 0)
#define ARCHIVE_CREATE_LEADING_DIRS (1 << 1)
#define ARCHIVE_UNLINK_OLD (1 << 2)
#define ARCHIVE_EXTRACT_QUIET (1 << 3)
#define ARCHIVE_EXTRACT_NEWER (1 << 4)
#define ARCHIVE_DONT_RESTORE_OWNER (1 << 5)
#define ARCHIVE_DONT_RESTORE_PERM (1 << 6)
#define ARCHIVE_NUMERIC_OWNER (1 << 7)
#define ARCHIVE_O_TRUNC (1 << 8)
#define ARCHIVE_REMEMBER_NAMES (1 << 9)
#define ARCHIVE_EXTRACT_NEWER (1 << 3)
#define ARCHIVE_DONT_RESTORE_OWNER (1 << 4)
#define ARCHIVE_DONT_RESTORE_PERM (1 << 5)
#define ARCHIVE_NUMERIC_OWNER (1 << 6)
#define ARCHIVE_O_TRUNC (1 << 7)
#define ARCHIVE_REMEMBER_NAMES (1 << 8)
#if ENABLE_RPM
#define ARCHIVE_REPLACE_VIA_RENAME (1 << 10)
#define ARCHIVE_REPLACE_VIA_RENAME (1 << 9)
#endif
@@ -197,7 +203,11 @@ void seek_by_jump(int fd, off_t amount) FAST_FUNC;
void seek_by_read(int fd, off_t amount) FAST_FUNC;
const char *strip_unsafe_prefix(const char *str) FAST_FUNC;
int unsafe_symlink_target(const char *target) FAST_FUNC;
void create_or_remember_link(llist_t **link_placeholders,
const char *target,
const char *linkname,
int hard_link) FAST_FUNC;
void create_links_from_list(llist_t *list) FAST_FUNC;
void data_align(archive_handle_t *archive_handle, unsigned boundary) FAST_FUNC;
const llist_t *find_list_entry(const llist_t *list, const char *filename) FAST_FUNC;
@@ -205,7 +215,7 @@ const llist_t *find_list_entry2(const llist_t *list, const char *filename) FAST_
/* A bit of bunzip2 internals are exposed for compressed help support: */
typedef struct bunzip_data bunzip_data;
int start_bunzip(bunzip_data **bdp, int in_fd, const void *inbuf, int len) FAST_FUNC;
int start_bunzip(void *, bunzip_data **bdp, int in_fd, const void *inbuf, int len) FAST_FUNC;
/* NB: read_bunzip returns < 0 on error, or the number of *unfilled* bytes
* in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0: */
int read_bunzip(bunzip_data *bd, char *outbuf, int len) FAST_FUNC;
@@ -250,6 +260,21 @@ int bbunpack(char **argv,
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
const char *expected_ext
) FAST_FUNC;
#define BBUNPK_OPTSTR "cfkvq"
#define BBUNPK_OPTSTRLEN 5
#define BBUNPK_OPTSTRMASK ((1 << BBUNPK_OPTSTRLEN) - 1)
enum {
BBUNPK_OPT_STDOUT = 1 << 0,
BBUNPK_OPT_FORCE = 1 << 1,
/* only some decompressors: */
BBUNPK_OPT_KEEP = 1 << 2,
BBUNPK_OPT_VERBOSE = 1 << 3,
BBUNPK_OPT_QUIET = 1 << 4,
/* not included in BBUNPK_OPTSTR: */
BBUNPK_OPT_DECOMPRESS = 1 << 5,
BBUNPK_OPT_TEST = 1 << 6,
BBUNPK_SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION,
};
void check_errors_in_children(int signo);
#if BB_MMU
+58 -34
View File
@@ -41,6 +41,7 @@
#include <poll.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
@@ -404,10 +405,11 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
/* -P = -d (mapped in cp.c) */
FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE, /* -v */
FILEUTILS_UPDATE = 1 << 13, /* -u */
FILEUTILS_NO_TARGET_DIR = 1 << 14, /* -T */
#if ENABLE_SELINUX
FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 14, /* -c */
FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 15, /* -c */
#endif
FILEUTILS_RMDEST = 1 << (15 - !ENABLE_SELINUX), /* --remove-destination */
FILEUTILS_RMDEST = 1 << (16 - !ENABLE_SELINUX), /* --remove-destination */
/*
* Hole. cp may have some bits set here,
* they should not affect remove_file()/copy_file()
@@ -417,7 +419,7 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
#endif
FILEUTILS_IGNORE_CHMOD_ERR = 1 << 31,
};
#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvu" IF_SELINUX("c")
#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvuT" IF_SELINUX("c")
extern int remove_file(const char *path, int flags) FAST_FUNC;
/* NB: without FILEUTILS_RECUR in flags, it will basically "cat"
* the source, not copy (unless "source" is a directory).
@@ -483,6 +485,7 @@ DIR *xopendir(const char *path) FAST_FUNC;
DIR *warn_opendir(const char *path) FAST_FUNC;
char *xmalloc_realpath(const char *path) FAST_FUNC RETURNS_MALLOC;
char *xmalloc_realpath_coreutils(const char *path) FAST_FUNC RETURNS_MALLOC;
char *xmalloc_readlink(const char *path) FAST_FUNC RETURNS_MALLOC;
char *xmalloc_readlink_or_warn(const char *path) FAST_FUNC RETURNS_MALLOC;
/* !RETURNS_MALLOC: it's a realloc-like function */
@@ -635,8 +638,14 @@ void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */
int setsockopt_keepalive(int fd) FAST_FUNC;
int setsockopt_broadcast(int fd) FAST_FUNC;
int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC;
int bb_getsockname(int sockfd, void *addr, socklen_t addrlen) FAST_FUNC;
/* NB: returns port in host byte order */
unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port) FAST_FUNC;
#if ENABLE_FEATURE_ETC_SERVICES
# define bb_lookup_std_port(portstr, protocol, portnum) bb_lookup_port(portstr, protocol, portnum)
#else
# define bb_lookup_std_port(portstr, protocol, portnum) (portnum)
#endif
typedef struct len_and_sockaddr {
socklen_t len;
union {
@@ -771,7 +780,8 @@ static inline tls_state_t *new_tls_state(void)
return tls;
}
void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC;
void tls_run_copy_loop(tls_state_t *tls) FAST_FUNC;
#define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0)
void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC;
void socket_want_pktinfo(int fd) FAST_FUNC;
@@ -785,6 +795,7 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
socklen_t sa_size) FAST_FUNC;
uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
int parse_pasv_epsv(char *buf) FAST_FUNC;
/* 0 if argv[0] is NULL: */
unsigned string_array_len(char **argv) FAST_FUNC;
@@ -907,7 +918,7 @@ extern void xprint_and_close_file(FILE *file) FAST_FUNC;
* end of line. If end isn't NULL, length of the chunk is stored in it.
* Returns NULL if EOF/error.
*/
extern char *bb_get_chunk_from_file(FILE *file, int *end) FAST_FUNC;
extern char *bb_get_chunk_from_file(FILE *file, size_t *end) FAST_FUNC;
/* Reads up to (and including) TERMINATING_STRING: */
extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string) FAST_FUNC RETURNS_MALLOC;
/* Same, with limited max size, and returns the length (excluding NUL): */
@@ -1273,20 +1284,21 @@ extern smallint syslog_level;
extern smallint logmode;
extern uint8_t xfunc_error_retval;
extern void (*die_func)(void);
extern void xfunc_die(void) NORETURN FAST_FUNC;
extern void bb_show_usage(void) NORETURN FAST_FUNC;
extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
extern void bb_simple_perror_msg(const char *s) FAST_FUNC;
extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
extern void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC;
extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
extern void bb_perror_nomsg(void) FAST_FUNC;
extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
extern void bb_logenv_override(void) FAST_FUNC;
void xfunc_die(void) NORETURN FAST_FUNC;
void bb_show_usage(void) NORETURN FAST_FUNC;
void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
void bb_simple_perror_msg(const char *s) FAST_FUNC;
void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC;
void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
void bb_perror_nomsg(void) FAST_FUNC;
void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
void bb_die_memory_exhausted(void) NORETURN FAST_FUNC;
void bb_logenv_override(void) FAST_FUNC;
/* We need to export XXX_main from libbusybox
* only if we build "individual" binaries
@@ -1363,7 +1375,7 @@ struct hwtype {
int FAST_FUNC (*activate)(int fd);
int suppress_null_addr;
};
extern smallint interface_opt_a;
#define IFNAME_SHOW_DOWNED_TOO ((char*)(intptr_t)1)
int display_interfaces(char *ifname) FAST_FUNC;
int in_ether(const char *bufp, struct sockaddr *sap) FAST_FUNC;
#if ENABLE_FEATURE_HWIB
@@ -1403,11 +1415,13 @@ extern int set_loop(char **devname, const char *file, unsigned long long offset,
#define BB_LO_FLAGS_READ_ONLY 1
#define BB_LO_FLAGS_AUTOCLEAR 4
/* Like bb_ask below, but asks on stdin with no timeout. */
char *bb_ask_stdin(const char * prompt) FAST_FUNC;
//TODO: pass buf pointer or return allocated buf (avoid statics)?
char *bb_ask(const int fd, int timeout, const char * prompt) FAST_FUNC;
int bb_ask_confirmation(void) FAST_FUNC;
/* Returns malloced str */
char *bb_ask_noecho(int fd, int timeout, const char *prompt) FAST_FUNC;
/* Like bb_ask_noecho, but asks on stdin with no timeout. */
char *bb_ask_noecho_stdin(const char *prompt) FAST_FUNC;
int bb_ask_y_confirmation_FILE(FILE *fp) FAST_FUNC;
int bb_ask_y_confirmation(void) FAST_FUNC;
/* Returns -1 if input is invalid. current_mode is a base for e.g. "u+rw" */
int bb_parse_mode(const char* s, unsigned cur_mode) FAST_FUNC;
@@ -1484,6 +1498,7 @@ extern void run_shell(const char *shell, int loginshell, const char **args) NORE
*/
const char *get_shell_name(void) FAST_FUNC;
#if ENABLE_FEATURE_SETPRIV_CAPABILITIES || ENABLE_RUN_INIT
unsigned cap_name_to_number(const char *cap) FAST_FUNC;
void printf_cap(const char *pfx, unsigned cap_no) FAST_FUNC;
void drop_capability(int cap_ordinal) FAST_FUNC;
@@ -1495,9 +1510,7 @@ struct caps { \
struct __user_cap_data_struct data[2]; \
}
void getcaps(void *caps) FAST_FUNC;
unsigned cap_name_to_number(const char *name) FAST_FUNC;
void printf_cap(const char *pfx, unsigned cap_no) FAST_FUNC;
#endif
#if ENABLE_SELINUX
extern void renew_current_security_context(void) FAST_FUNC;
@@ -1590,9 +1603,11 @@ int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FU
int get_terminal_width(int fd) FAST_FUNC;
int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC;
#define TERMIOS_CLEAR_ISIG (1 << 0)
#define TERMIOS_RAW_CRNL (1 << 1)
#define TERMIOS_RAW_INPUT (1 << 2)
#define TERMIOS_CLEAR_ISIG (1 << 0)
#define TERMIOS_RAW_CRNL_INPUT (1 << 1)
#define TERMIOS_RAW_CRNL_OUTPUT (1 << 2)
#define TERMIOS_RAW_CRNL (TERMIOS_RAW_CRNL_INPUT|TERMIOS_RAW_CRNL_OUTPUT)
#define TERMIOS_RAW_INPUT (1 << 3)
int get_termios_and_make_raw(int fd, struct termios *newterm, struct termios *oldterm, int flags) FAST_FUNC;
int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC;
@@ -1927,6 +1942,8 @@ typedef struct md5_ctx_t md5sha_ctx_t;
extern uint32_t *global_crc32_table;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
uint32_t *crc32_new_table_le(void) FAST_FUNC;
uint32_t *global_crc32_new_table_le(void) FAST_FUNC;
uint32_t crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC;
uint32_t crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC;
@@ -1943,6 +1960,7 @@ typedef struct bb_progress_t {
unsigned last_update_sec;
unsigned last_change_sec;
unsigned start_sec;
/*unsigned last_eta;*/
const char *curfile;
} bb_progress_t;
@@ -2005,10 +2023,16 @@ extern const char bb_path_wtmp_file[] ALIGN1;
#define bb_dev_null "/dev/null"
extern const char bb_busybox_exec_path[] ALIGN1;
/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
* but I want to save a few bytes here */
extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */
/* allow default system PATH to be extended via CFLAGS */
#ifndef BB_ADDITIONAL_PATH
#define BB_ADDITIONAL_PATH ""
#endif
#define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH
extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */
#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH"))
/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
* but I want to save a few bytes here:
*/
#define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin"))
extern const int const_int_0;
+2 -4
View File
@@ -49,12 +49,10 @@ int lzo1x_999_compress_level(const uint8_t* in, unsigned in_len,
/* decompression */
//int lzo1x_decompress(const uint8_t* src, unsigned src_len,
// uint8_t* dst, unsigned* dst_len,
// void* wrkmem /* NOT USED */);
// uint8_t* dst, unsigned* dst_len /*, void* wrkmem */);
/* safe decompression with overrun testing */
int lzo1x_decompress_safe(const uint8_t* src, unsigned src_len,
uint8_t* dst, unsigned* dst_len,
void* wrkmem /* NOT USED */);
uint8_t* dst, unsigned* dst_len /*, void* wrkmem */);
#define LZO_E_OK 0
#define LZO_E_ERROR (-1)
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "Init Utilities"
+54
View File
@@ -24,6 +24,17 @@
//config: help
//config: Stop all processes and reboot the system.
//config:
//config:config FEATURE_WAIT_FOR_INIT
//config: bool "Before signaling init, make sure it is ready for it"
//config: default y
//config: depends on HALT || POWEROFF || REBOOT
//config: help
//config: In rare cases, poweroff may be commanded by firmware to OS
//config: even before init process exists. On Linux, this spawns
//config: "/sbin/poweroff" very early. This option adds code
//config: which checks that init is ready to receive poweroff
//config: commands. Code size increase of ~80 bytes.
//config:
//config:config FEATURE_CALL_TELINIT
//config: bool "Call telinit on shutdown and reboot"
//config: default y
@@ -108,6 +119,47 @@ static void write_wtmp(void)
#define write_wtmp() ((void)0)
#endif
#if ENABLE_FEATURE_WAIT_FOR_INIT
/* In Linux, "poweroff" may be spawned even before init.
* For example, with ACPI:
* linux/drivers/acpi/bus.c:
* static void sb_notify_work(struct work_struct *dummy)
* orderly_poweroff(true);
* linux/kernel/reboot.c:
* static int run_cmd(const char *cmd)
* ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
* poweroff_cmd[] = "/sbin/poweroff";
* static int __orderly_poweroff(bool force)
* ret = run_cmd(poweroff_cmd);
*
* We want to make sure init exists and listens to signals.
*/
static int init_was_not_there(void)
{
enum { initial = 5 }; /* 5 seconds should be plenty for timeout */
int cnt = initial - 1;
/* Just existence of PID 1 does not mean it installed
* the handlers already.
*/
#if 0
while (kill(1, 0) != 0 && --cnt >= 0)
sleep(1);
#endif
/* ... so let's wait for some evidence a usual startup event,
* mounting of /proc, happened. By that time init should be ready
* for signals.
*/
while (access("/proc/meminfo", F_OK) != 0 && --cnt >= 0)
sleep(1);
/* Does it look like init wasn't there? */
return (cnt != initial - 1);
}
#else
/* Assume it's always there */
# define init_was_not_there() 0
#endif
int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int halt_main(int argc UNUSED_PARAM, char **argv)
@@ -171,6 +223,8 @@ int halt_main(int argc UNUSED_PARAM, char **argv)
if (!ENABLE_FEATURE_CALL_TELINIT) {
/* bbox init assumed */
rc = kill(1, signals[which]);
if (init_was_not_there())
rc = kill(1, signals[which]);
} else {
/* SysV style init assumed */
/* runlevels:
+24 -17
View File
@@ -128,8 +128,8 @@
#define DEBUG_SEGV_HANDLER 0
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#include <sys/resource.h>
#ifdef __linux__
# include <linux/vt.h>
# include <sys/sysinfo.h>
@@ -203,7 +203,6 @@
*/
#define RESTART 0x80
/* A linked list of init_actions, to be read from inittab */
struct init_action {
struct init_action *next;
@@ -213,11 +212,17 @@ struct init_action {
char command[1];
};
static struct init_action *init_action_list = NULL;
struct globals {
struct init_action *init_action_list;
#if !ENABLE_FEATURE_INIT_SYSLOG
static const char *log_console = VC_5;
const char *log_console;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
IF_NOT_FEATURE_INIT_SYSLOG(G.log_console = VC_5;) \
} while (0)
enum {
L_LOG = 0x1,
@@ -265,10 +270,10 @@ static void message(int where, const char *fmt, ...)
if (log_fd < 0) {
log_fd = STDERR_FILENO;
if (log_console) {
log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
if (G.log_console) {
log_fd = device_open(G.log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
if (log_fd < 0) {
bb_error_msg("can't log to %s", log_console);
bb_error_msg("can't log to %s", G.log_console);
where = L_CONSOLE;
} else {
close_on_exec_on(log_fd);
@@ -328,7 +333,7 @@ static void console_init(void)
if (!s || strcmp(s, "linux") == 0)
putenv((char*)"TERM=vt102");
# if !ENABLE_FEATURE_INIT_SYSLOG
log_console = NULL;
G.log_console = NULL;
# endif
} else
#endif
@@ -562,7 +567,7 @@ static struct init_action *mark_terminated(pid_t pid)
if (pid > 0) {
update_utmp_DEAD_PROCESS(pid);
for (a = init_action_list; a; a = a->next) {
for (a = G.init_action_list; a; a = a->next) {
if (a->pid == pid) {
a->pid = 0;
return a;
@@ -596,7 +601,7 @@ static void run_actions(int action_type)
{
struct init_action *a;
for (a = init_action_list; a; a = a->next) {
for (a = G.init_action_list; a; a = a->next) {
if (!(a->action_type & action_type))
continue;
@@ -630,7 +635,7 @@ static void new_init_action(uint8_t action_type, const char *command, const char
* To achieve that, if we find a matching entry, we move it
* to the end.
*/
nextp = &init_action_list;
nextp = &G.init_action_list;
while ((a = *nextp) != NULL) {
/* Don't enter action if it's already in the list.
* This prevents losing running RESPAWNs.
@@ -845,7 +850,7 @@ static void exec_restart_action(void)
{
struct init_action *a;
for (a = init_action_list; a; a = a->next) {
for (a = G.init_action_list; a; a = a->next) {
if (!(a->action_type & RESTART))
continue;
@@ -923,7 +928,7 @@ static void reload_inittab(void)
message(L_LOG, "reloading /etc/inittab");
/* Disable old entries */
for (a = init_action_list; a; a = a->next)
for (a = G.init_action_list; a; a = a->next)
a->action_type = 0;
/* Append new entries, or modify existing entries
@@ -936,14 +941,14 @@ static void reload_inittab(void)
#if ENABLE_FEATURE_KILL_REMOVED
/* Kill stale entries */
/* Be nice and send SIGTERM first */
for (a = init_action_list; a; a = a->next)
for (a = G.init_action_list; a; a = a->next)
if (a->action_type == 0 && a->pid != 0)
kill(a->pid, SIGTERM);
if (CONFIG_FEATURE_KILL_DELAY) {
/* NB: parent will wait in NOMMU case */
if ((BB_MMU ? fork() : vfork()) == 0) { /* child */
sleep(CONFIG_FEATURE_KILL_DELAY);
for (a = init_action_list; a; a = a->next)
for (a = G.init_action_list; a; a = a->next)
if (a->action_type == 0 && a->pid != 0)
kill(a->pid, SIGKILL);
_exit(EXIT_SUCCESS);
@@ -955,7 +960,7 @@ static void reload_inittab(void)
* We never rerun SYSINIT entries anyway,
* removing them too saves a few bytes
*/
nextp = &init_action_list;
nextp = &G.init_action_list;
while ((a = *nextp) != NULL) {
/*
* Why pid == 0 check?
@@ -1046,6 +1051,8 @@ static void sleep_much(void)
int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int init_main(int argc UNUSED_PARAM, char **argv)
{
INIT_G();
if (argv[1] && strcmp(argv[1], "-q") == 0) {
return kill(1, SIGHUP);
}
+1 -1
View File
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#
menu "klibc-utils"
Loaded 100 of 439 files, more files were not shown because too many files have changed in this diff. Show more