From 77e2bde6a50f0f6b9b3c9983c86e661a9872b5f6 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 1 Dec 2015 11:25:10 -0500 Subject: trylink: include LDFLAGS when checking linkage The user might be including options in their LDFLAGS (like -fuse-ld=gold) that change the behavior of the linker and thus change the results of the flag tests. Make sure we include the user's LDFLAGS when running these tests so we filter out flags that will fail when used later on. URL: https://bugs.gentoo.org/499712 Signed-off-by: Mike Frysinger --- scripts/trylink | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/trylink b/scripts/trylink index 6e1187ed0..3c431edc3 100755 --- a/scripts/trylink +++ b/scripts/trylink @@ -54,7 +54,7 @@ check_cc() { # "eval" may be needed if CFLAGS can contain # '... -D"BB_VER=KBUILD_STR(1.N.M)" ...' # and we need shell to process quotes! - $CC $CFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1 + $CC $CFLAGS $LDFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1 r=$? rm -f "$tempname" "$tempname".c "$tempname".o return $r -- cgit v1.2.3-55-g6feb From 5f11ec3f6a7e4fe6cc2626ccb7cda4ecb5c3938a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 16 Dec 2015 12:59:08 -0500 Subject: swapon/swapoff: refine the -e (ifexists) option The -e option should only apply to swapon, and it should swallow all errors/warnings when the device does not exist. So delete the flag from the swapoff patch and unify the check in the swapoff path. Signed-off-by: Mike Frysinger --- util-linux/swaponoff.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 5cd1fbe70..7e548a464 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -22,11 +22,10 @@ //usage: ) //usage: //usage:#define swapoff_trivial_usage -//usage: "[-a] [-e] [DEVICE]" +//usage: "[-a] [DEVICE]" //usage:#define swapoff_full_usage "\n\n" //usage: "Stop swapping on DEVICE\n" //usage: "\n -a Stop swapping on all swap devices" -//usage: "\n -e Silently skip devices that do not exist" #include "libbb.h" #include @@ -93,15 +92,12 @@ enum { #define OPT_IFEXISTS (option_mask32 & OPT_e) #define OPT_PRIO (option_mask32 & OPT_p) -static int swap_enable_disable(char *device) +static int swap_enable_disable(const char *device) { int err = 0; int quiet = 0; - struct stat st; resolve_mount_spec(&device); - if (!OPT_IFEXISTS) - xstat(device, &st); if (do_swapoff) { err = swapoff(device); @@ -109,6 +105,7 @@ static int swap_enable_disable(char *device) quiet = (OPT_ALL && (errno == EINVAL || errno == ENOENT)); } else { /* swapon */ + struct stat st; err = stat(device, &st); if (!err) { if (ENABLE_DESKTOP && S_ISREG(st.st_mode)) { @@ -119,9 +116,11 @@ static int swap_enable_disable(char *device) } err = swapon(device, g_flags); /* Don't complain on swapon -a if device is already in use */ - /* Don't complain if file does not exist with -e option */ - quiet = (OPT_ALL && errno == EBUSY) || (OPT_IFEXISTS && errno == ENOENT); + quiet = (OPT_ALL && errno == EBUSY); } + /* Don't complain if file does not exist with -e option */ + if (err && OPT_IFEXISTS && errno == ENOENT) + err = 0; } if (err && !quiet) { -- cgit v1.2.3-55-g6feb From e0942acb9e186cbfc16afe704e10a8af9cd1cc58 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 16 Dec 2015 14:42:25 -0500 Subject: blkid: add bcache support URL: https://bugs.gentoo.org/508596 Signed-off-by: Mike Frysinger --- util-linux/volume_id/bcache.c | 110 ++++++++++++++++++++++++++++++ util-linux/volume_id/volume_id.c | 3 + util-linux/volume_id/volume_id_internal.h | 2 + 3 files changed, 115 insertions(+) create mode 100644 util-linux/volume_id/bcache.c diff --git a/util-linux/volume_id/bcache.c b/util-linux/volume_id/bcache.c new file mode 100644 index 000000000..648e44de5 --- /dev/null +++ b/util-linux/volume_id/bcache.c @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2013 Rolf Fokkens + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + * + * Based on code fragments from bcache-tools by Kent Overstreet: + * http://evilpiepirate.org/git/bcache-tools.git + */ + +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BCACHE) += bcache.o + +//config: +//config:config FEATURE_VOLUMEID_BCACHE +//config: bool "bcache filesystem" +//config: default y +//config: depends on VOLUMEID +//config: help +//config: TODO +//config: + +#include "volume_id_internal.h" + +#define SB_LABEL_SIZE 32 +#define SB_JOURNAL_BUCKETS 256U + +static const char bcache_magic[] = { + 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca, + 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 +}; + +struct bcache_super_block { + uint64_t csum; + uint64_t offset; /* sector where this sb was written */ + uint64_t version; + + uint8_t magic[16]; + + uint8_t uuid[16]; + union { + uint8_t set_uuid[16]; + uint64_t set_magic; + }; + uint8_t label[SB_LABEL_SIZE]; + + uint64_t flags; + uint64_t seq; + uint64_t pad[8]; + + union { + struct { + /* Cache devices */ + uint64_t nbuckets; /* device size */ + + uint16_t block_size; /* sectors */ + uint16_t bucket_size; /* sectors */ + + uint16_t nr_in_set; + uint16_t nr_this_dev; + }; + struct { + /* Backing devices */ + uint64_t data_offset; + + /* + * block_size from the cache device section is still used by + * backing devices, so don't add anything here until we fix + * things to not need it for backing devices anymore + */ + }; + }; + + uint32_t last_mount; /* time_t */ + + uint16_t first_bucket; + union { + uint16_t njournal_buckets; + uint16_t keys; + }; + uint64_t d[SB_JOURNAL_BUCKETS]; /* journal buckets */ +}; + +/* magic string */ +#define BCACHE_SB_MAGIC bcache_magic +/* magic string len */ +#define BCACHE_SB_MAGIC_LEN sizeof (bcache_magic) +/* super block offset */ +#define BCACHE_SB_OFF 0x1000 +/* supper block offset in kB */ +#define BCACHE_SB_KBOFF (BCACHE_SB_OFF >> 10) +/* magic string offset within super block */ +#define BCACHE_SB_MAGIC_OFF offsetof (struct bcache_super_block, magic) + +int FAST_FUNC volume_id_probe_bcache(struct volume_id *id /*,uint64_t off*/) +{ + struct bcache_super_block *sb; + + sb = volume_id_get_buffer(id, BCACHE_SB_OFF, sizeof(*sb)); + if (sb == NULL) + return -1; + + if (memcmp(sb->magic, BCACHE_SB_MAGIC, BCACHE_SB_MAGIC_LEN) != 0) + return -1; + + volume_id_set_label_string(id, sb->label, SB_LABEL_SIZE); + volume_id_set_uuid(id, sb->uuid, UUID_DCE); + IF_FEATURE_BLKID_TYPE(id->type = "bcache";) + + return 0; +} diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c index 5c459a0e2..3f71e0084 100644 --- a/util-linux/volume_id/volume_id.c +++ b/util-linux/volume_id/volume_id.c @@ -107,6 +107,9 @@ static const probe_fptr fs1[] = { #if ENABLE_FEATURE_VOLUMEID_XFS volume_id_probe_xfs, #endif +#if ENABLE_FEATURE_VOLUMEID_BCACHE + volume_id_probe_bcache, +#endif }; /* fill buffer with maximum */ diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h index 6e2dbd7bb..3061ac4d5 100644 --- a/util-linux/volume_id/volume_id_internal.h +++ b/util-linux/volume_id/volume_id_internal.h @@ -169,6 +169,8 @@ int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/, /* FS */ +int FAST_FUNC volume_id_probe_bcache(struct volume_id *id /*,uint64_t off*/); + int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/); int FAST_FUNC volume_id_probe_cramfs(struct volume_id *id /*,uint64_t off*/); -- cgit v1.2.3-55-g6feb From 6df961257d584714c5690b1f4197c677e4f832ec Mon Sep 17 00:00:00 2001 From: Chris Renshaw Date: Thu, 17 Dec 2015 16:42:01 +0100 Subject: Resolve linker issues with Android API 21 (dprintf, tcdrain) Signed-off-by: Chris Renshaw Signed-off-by: Denys Vlasenko --- include/platform.h | 7 ++++++- libbb/missing_syscalls.c | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/platform.h b/include/platform.h index 1706b1847..026ebbe17 100644 --- a/include/platform.h +++ b/include/platform.h @@ -481,9 +481,14 @@ typedef unsigned smalluint; #if defined(ANDROID) || defined(__ANDROID__) # if __ANDROID_API__ < 8 + /* ANDROID < 8 has no [f]dprintf at all */ # undef HAVE_DPRINTF -# else +# elif __ANDROID_API__ < 21 + /* ANDROID < 21 has fdprintf */ # define dprintf fdprintf +# else + /* ANDROID >= 21 has standard dprintf */ +# endif # endif # if __ANDROID_API__ < 21 # undef HAVE_TTYNAME_R diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c index e3c1e924b..093412811 100644 --- a/libbb/missing_syscalls.c +++ b/libbb/missing_syscalls.c @@ -40,8 +40,10 @@ int pivot_root(const char *new_root, const char *put_old) return syscall(__NR_pivot_root, new_root, put_old); } +# if __ANDROID_API__ < 21 int tcdrain(int fd) { return ioctl(fd, TCSBRK, 1); } +# endif #endif -- cgit v1.2.3-55-g6feb From b50525124228b566ccfd5c6df0647988bb2d2d3a Mon Sep 17 00:00:00 2001 From: Ari Sundholm Date: Thu, 17 Dec 2015 20:43:12 +0200 Subject: include/platform.h: Remove extra #endif introduced in 6df9612. It causes the compilation to fail. Signed-off-by: Ari Sundholm Signed-off-by: Mike Frysinger --- include/platform.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/platform.h b/include/platform.h index 026ebbe17..c987d418c 100644 --- a/include/platform.h +++ b/include/platform.h @@ -489,7 +489,6 @@ typedef unsigned smalluint; # else /* ANDROID >= 21 has standard dprintf */ # endif -# endif # if __ANDROID_API__ < 21 # undef HAVE_TTYNAME_R # undef HAVE_GETLINE -- cgit v1.2.3-55-g6feb From 2c0d3f5fd08ccc6963c402030efcbe8a2c028f2d Mon Sep 17 00:00:00 2001 From: Pascal Bach Date: Fri, 18 Dec 2015 19:01:14 +0100 Subject: chpasswd: support -c argument and respect DEFAULT_PASSWD_ALGO Signed-off-by: Pascal Bach Signed-off-by: Denys Vlasenko --- libbb/pw_encrypt.c | 10 +++++++--- loginutils/chpasswd.c | 31 ++++++++++++++++--------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c index bfc7030a8..dbc15e5fc 100644 --- a/libbb/pw_encrypt.c +++ b/libbb/pw_encrypt.c @@ -52,14 +52,18 @@ char* FAST_FUNC crypt_make_pw_salt(char salt[MAX_PW_SALT_LEN], const char *algo) { int len = 2/2; char *salt_ptr = salt; - if (algo[0] != 'd') { /* not des */ + + /* Standard chpasswd uses uppercase algos ("MD5", not "md5"). + * Need to be case-insensitive in the code below. + */ + if ((algo[0]|0x20) != 'd') { /* not des */ len = 8/2; /* so far assuming md5 */ *salt_ptr++ = '$'; *salt_ptr++ = '1'; *salt_ptr++ = '$'; #if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA - if (algo[0] == 's') { /* sha */ - salt[1] = '5' + (strcmp(algo, "sha512") == 0); + if ((algo[0]|0x20) == 's') { /* sha */ + salt[1] = '5' + (strcasecmp(algo, "sha512") == 0); len = 16/2; } #endif diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index 6c41d17be..a022a42d6 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c @@ -24,26 +24,27 @@ //kbuild:lib-$(CONFIG_CHPASSWD) += chpasswd.o //usage:#define chpasswd_trivial_usage -//usage: IF_LONG_OPTS("[--md5|--encrypted]") IF_NOT_LONG_OPTS("[-m|-e]") +//usage: IF_LONG_OPTS("[--md5|--encrypted|--crypt-method]") IF_NOT_LONG_OPTS("[-m|-e|-c]") //usage:#define chpasswd_full_usage "\n\n" //usage: "Read user:password from stdin and update /etc/passwd\n" //usage: IF_LONG_OPTS( -//usage: "\n -e,--encrypted Supplied passwords are in encrypted form" -//usage: "\n -m,--md5 Use MD5 encryption instead of DES" +//usage: "\n -e,--encrypted Supplied passwords are in encrypted form" +//usage: "\n -m,--md5 Use MD5 encryption instead of DES" +//usage: "\n -c,--crypt-method Use the specified method to encrypt the passwords" //usage: ) //usage: IF_NOT_LONG_OPTS( //usage: "\n -e Supplied passwords are in encrypted form" //usage: "\n -m Use MD5 encryption instead of DES" +//usage: "\n -c Use the specified method to encrypt the passwords" //usage: ) -//TODO: implement -c ALGO - #include "libbb.h" #if ENABLE_LONG_OPTS static const char chpasswd_longopts[] ALIGN1 = - "encrypted\0" No_argument "e" - "md5\0" No_argument "m" + "encrypted\0" No_argument "e" + "md5\0" No_argument "m" + "crypt-method\0" Required_argument "c" ; #endif @@ -54,14 +55,15 @@ int chpasswd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int chpasswd_main(int argc UNUSED_PARAM, char **argv) { char *name; + const char *algo = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; int opt; if (getuid() != 0) bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); - opt_complementary = "m--e:e--m"; + opt_complementary = "m--ec:e--mc:c--em"; IF_LONG_OPTS(applet_long_options = chpasswd_longopts;) - opt = getopt32(argv, "em"); + opt = getopt32(argv, "emc:", &algo); while ((name = xmalloc_fgetline(stdin)) != NULL) { char *free_me; @@ -77,15 +79,14 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) free_me = NULL; if (!(opt & OPT_ENC)) { - char salt[sizeof("$N$XXXXXXXX")]; + char salt[MAX_PW_SALT_LEN]; - crypt_make_salt(salt, 1); if (opt & OPT_MD5) { - salt[0] = '$'; - salt[1] = '1'; - salt[2] = '$'; - crypt_make_salt(salt + 3, 4); + /* Force MD5 if the -m flag is set */ + algo = "md5"; } + + crypt_make_pw_salt(salt, algo); free_me = pass = pw_encrypt(pass, salt, 0); } -- cgit v1.2.3-55-g6feb From 6c634f7968032ab2b8b7daf528990ac15809f7eb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 18 Dec 2015 19:02:31 +0100 Subject: swaponoff: fix compile-time warning CC util-linux/swaponoff.o cc1: warnings being treated as errors util-linux/swaponoff.c: In function 'swap_enable_disable': util-linux/swaponoff.c:100: warning: passing argument 1 of 'resolve_mount_spec' from incompatible pointer type make[1]: *** [util-linux/swaponoff.o] Error 1 Signed-off-by: Denys Vlasenko --- util-linux/swaponoff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 7e548a464..c29dd3071 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -92,7 +92,7 @@ enum { #define OPT_IFEXISTS (option_mask32 & OPT_e) #define OPT_PRIO (option_mask32 & OPT_p) -static int swap_enable_disable(const char *device) +static int swap_enable_disable(char *device) { int err = 0; int quiet = 0; -- cgit v1.2.3-55-g6feb From ce4bc1ed048233e89ee4cb95830bf6f01d523d1e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Dec 2015 17:32:51 +0100 Subject: iproute: support "scope". Closes 8561 function old new delta iproute_modify 1051 1120 +69 Signed-off-by: Denys Vlasenko --- networking/libiproute/iproute.c | 52 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index d232ee6fd..82827488f 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -313,12 +313,13 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, static int iproute_modify(int cmd, unsigned flags, char **argv) { static const char keywords[] ALIGN1 = - "src\0""via\0""mtu\0""lock\0""protocol\0"IF_FEATURE_IP_RULE("table\0") + "src\0""via\0""mtu\0""lock\0""scope\0""protocol\0"IF_FEATURE_IP_RULE("table\0") "dev\0""oif\0""to\0""metric\0""onlink\0"; enum { ARG_src, ARG_via, ARG_mtu, PARM_lock, + ARG_scope, ARG_protocol, IF_FEATURE_IP_RULE(ARG_table,) ARG_dev, @@ -344,6 +345,7 @@ IF_FEATURE_IP_RULE(ARG_table,) unsigned mxlock = 0; char *d = NULL; smalluint ok = 0; + smalluint scope_ok = 0; int arg; memset(&req, 0, sizeof(req)); @@ -352,15 +354,18 @@ IF_FEATURE_IP_RULE(ARG_table,) req.n.nlmsg_flags = NLM_F_REQUEST | flags; req.n.nlmsg_type = cmd; req.r.rtm_family = preferred_family; - if (RT_TABLE_MAIN) /* if it is zero, memset already did it */ + if (RT_TABLE_MAIN != 0) /* if it is zero, memset already did it */ req.r.rtm_table = RT_TABLE_MAIN; - if (RT_SCOPE_NOWHERE) + if (RT_SCOPE_NOWHERE != 0) req.r.rtm_scope = RT_SCOPE_NOWHERE; if (cmd != RTM_DELROUTE) { - req.r.rtm_protocol = RTPROT_BOOT; - req.r.rtm_scope = RT_SCOPE_UNIVERSE; - req.r.rtm_type = RTN_UNICAST; + if (RTPROT_BOOT != 0) + req.r.rtm_protocol = RTPROT_BOOT; + if (RT_SCOPE_UNIVERSE != 0) + req.r.rtm_scope = RT_SCOPE_UNIVERSE; + if (RTN_UNICAST != 0) + req.r.rtm_type = RTN_UNICAST; } mxrta->rta_type = RTA_METRICS; @@ -393,6 +398,13 @@ IF_FEATURE_IP_RULE(ARG_table,) } mtu = get_unsigned(*argv, "mtu"); rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu); + } else if (arg == ARG_scope) { + uint32_t scope; + NEXT_ARG(); + if (rtnl_rtscope_a2n(&scope, *argv)) + invarg_1_to_2(*argv, "scope"); + req.r.rtm_scope = scope; + scope_ok = 1; } else if (arg == ARG_protocol) { uint32_t prot; NEXT_ARG(); @@ -469,20 +481,22 @@ IF_FEATURE_IP_RULE(ARG_table,) addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta)); } - if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT) - req.r.rtm_scope = RT_SCOPE_HOST; - else - if (req.r.rtm_type == RTN_BROADCAST - || req.r.rtm_type == RTN_MULTICAST - || req.r.rtm_type == RTN_ANYCAST - ) { - req.r.rtm_scope = RT_SCOPE_LINK; - } - else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) { - if (cmd == RTM_DELROUTE) - req.r.rtm_scope = RT_SCOPE_NOWHERE; - else if (!(ok & gw_ok)) + if (!scope_ok) { + if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT) + req.r.rtm_scope = RT_SCOPE_HOST; + else + if (req.r.rtm_type == RTN_BROADCAST + || req.r.rtm_type == RTN_MULTICAST + || req.r.rtm_type == RTN_ANYCAST + ) { req.r.rtm_scope = RT_SCOPE_LINK; + } + else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) { + if (cmd == RTM_DELROUTE) + req.r.rtm_scope = RT_SCOPE_NOWHERE; + else if (!(ok & gw_ok)) + req.r.rtm_scope = RT_SCOPE_LINK; + } } if (req.r.rtm_family == AF_UNSPEC) { -- cgit v1.2.3-55-g6feb From 911d265faf34c90158f5ba0ef81d1d558ec595e6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Dec 2015 20:11:34 +0100 Subject: mount: support "nofail" option. Closes 8551 function old new delta singlemount 1045 1060 +15 mount_option_str 338 345 +7 mount_it_now 355 361 +6 mount_options 172 176 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 32/0) Total: 32 bytes Signed-off-by: Denys Vlasenko --- util-linux/mount.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util-linux/mount.c b/util-linux/mount.c index cb40c802d..c428f5827 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -259,9 +259,11 @@ static struct mntent *getmntent_r(FILE* stream, struct mntent* result, // Not real flags, but we want to be able to check for this. enum { - MOUNT_USERS = (1 << 28) * ENABLE_DESKTOP, + MOUNT_USERS = (1 << 27) * ENABLE_DESKTOP, + MOUNT_NOFAIL = (1 << 28) * ENABLE_DESKTOP, MOUNT_NOAUTO = (1 << 29), MOUNT_SWAP = (1 << 30), + MOUNT_FAKEFLAGS = MOUNT_USERS | MOUNT_NOFAIL | MOUNT_NOAUTO | MOUNT_SWAP }; @@ -326,6 +328,7 @@ static const int32_t mount_options[] = { /* "swap" */ MOUNT_SWAP, IF_DESKTOP(/* "user" */ MOUNT_USERS,) IF_DESKTOP(/* "users" */ MOUNT_USERS,) + IF_DESKTOP(/* "nofail" */ MOUNT_NOFAIL,) /* "_netdev" */ 0, IF_DESKTOP(/* "comment=" */ 0,) /* systemd uses this in fstab */ ) @@ -385,6 +388,7 @@ static const char mount_option_str[] = "swap\0" IF_DESKTOP("user\0") IF_DESKTOP("users\0") + IF_DESKTOP("nofail\0") "_netdev\0" IF_DESKTOP("comment=\0") /* systemd uses this in fstab */ ) @@ -672,6 +676,8 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero { int rc = 0; + vfsflags &= ~(unsigned long)MOUNT_FAKEFLAGS; + if (FAKE_IT) { if (verbose >= 2) bb_error_msg("would do mount('%s','%s','%s',0x%08lx,'%s')", @@ -2061,6 +2067,8 @@ static int singlemount(struct mntent *mp, int ignore_busy) if (errno == EBUSY && ignore_busy) return 0; + if (errno == ENOENT && (vfsflags & MOUNT_NOFAIL)) + return 0; if (rc != 0) bb_perror_msg("mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); return rc; -- cgit v1.2.3-55-g6feb From c2a2625bcbd0d883ca74afb5275e6fd9806936d2 Mon Sep 17 00:00:00 2001 From: Cristian Ionescu-Idbohrn Date: Sat, 2 Jan 2016 00:52:29 +0100 Subject: ash: suppress a compilation warning Reported by gcc (Debian 5.3.1-4) 5.3.1 20151219 shell/ash.c: In function 'evaltree': shell/ash.c:8432:19: warning: logical not is only applied to the left hand side of comparison Signed-off-by: Cristian Ionescu-Idbohrn Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index e7a867f52..daec975c5 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -8429,7 +8429,7 @@ evaltree(union node *n, int flags) n->nbinary.ch1, (flags | ((is_or >> 1) - 1)) & EV_TESTED ); - if (!exitstatus == is_or) + if ((!exitstatus) == is_or) break; if (!evalskip) { n = n->nbinary.ch2; -- cgit v1.2.3-55-g6feb From dbf5a6da6a4295ce26edd1ce34fde567d19afa02 Mon Sep 17 00:00:00 2001 From: Ari Sundholm Date: Sat, 2 Jan 2016 01:18:32 +0100 Subject: blkdiscard: new applet function old new delta blkdiscard_main - 264 +264 Signed-off-by: Ari Sundholm Signed-off-by: Denys Vlasenko --- util-linux/blkdiscard.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 util-linux/blkdiscard.c diff --git a/util-linux/blkdiscard.c b/util-linux/blkdiscard.c new file mode 100644 index 000000000..ace88a1f0 --- /dev/null +++ b/util-linux/blkdiscard.c @@ -0,0 +1,83 @@ +/* + * Mini blkdiscard implementation for busybox + * + * Copyright (C) 2015 by Ari Sundholm and Tuxera Inc. + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ + +//config:config BLKDISCARD +//config: bool "blkdiscard" +//config: default y +//config: help +//config: blkdiscard discards sectors on a given device. + +//kbuild:lib-$(CONFIG_BLKDISCARD) += blkdiscard.o +//applet:IF_BLKDISCARD(APPLET(blkdiscard, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//usage:#define blkdiscard_trivial_usage +//usage: "[-o OFS] [-l LEN] [-s] DEVICE" +//usage:#define blkdiscard_full_usage "\n\n" +//usage: "Discard sectors on DEVICE\n" +//usage: "\n -o OFS Byte offset into device" +//usage: "\n -l LEN Number of bytes to discard" +//usage: "\n -s Perform a secure discard" +//usage: +//usage:#define blkdiscard_example_usage +//usage: "$ blkdiscard -o 0 -l 1G /dev/sdb" + +#include "libbb.h" +#include + +int blkdiscard_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int blkdiscard_main(int argc UNUSED_PARAM, char **argv) +{ + unsigned opts; + const char *offset_str = "0"; + const char *length_str; + uint64_t offset; /* Leaving these two variables out does not */ + uint64_t length; /* shrink code size and hampers readability. */ + uint64_t range[2]; +// struct stat st; + int fd; + + enum { + OPT_OFFSET = (1 << 0), + OPT_LENGTH = (1 << 1), + OPT_SECURE = (1 << 2), + }; + + opt_complementary = "=1"; + opts = getopt32(argv, "o:l:s", &offset_str, &length_str); + argv += optind; + + fd = xopen(argv[0], O_RDWR|O_EXCL); +//Why bother, BLK[SEC]DISCARD will fail on non-blockdevs anyway? +// xfstat(fd, &st); +// if (!S_ISBLK(st.st_mode)) +// bb_error_msg_and_die("%s: not a block device", argv[0]); + + offset = xatoull_sfx(offset_str, kMG_suffixes); + + if (opts & OPT_LENGTH) + length = xatoull_sfx(length_str, kMG_suffixes); + else { + xioctl(fd, BLKGETSIZE64, &length); + length -= offset; + } + + range[0] = offset; + range[1] = length; + ioctl_or_perror_and_die(fd, + (opts & OPT_SECURE) ? BLKSECDISCARD : BLKDISCARD, + &range, + "%s: %s failed", + argv[0], + (opts & OPT_SECURE) ? "BLKSECDISCARD" : "BLKDISCARD" + ); + + if (ENABLE_FEATURE_CLEAN_UP) + close(fd); + + return EXIT_SUCCESS; +} -- cgit v1.2.3-55-g6feb From 76915bf738c4532c7ca57fc673b5a0ebd4b91af8 Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Sat, 19 Dec 2015 22:34:44 +0200 Subject: nandwrite: implement -n (read/write without ecc) Implement -n (read/write without ecc). Signed-off-by: Aaro Koskinen Signed-off-by: Denys Vlasenko --- miscutils/nandwrite.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index 247fc72f4..c95cbb21e 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -29,16 +29,18 @@ //kbuild:lib-$(CONFIG_NANDDUMP) += nandwrite.o //usage:#define nandwrite_trivial_usage -//usage: "[-p] [-s ADDR] MTD_DEVICE [FILE]" +//usage: "[-np] [-s ADDR] MTD_DEVICE [FILE]" //usage:#define nandwrite_full_usage "\n\n" //usage: "Write to MTD_DEVICE\n" +//usage: "\n -n Write without ecc" //usage: "\n -p Pad to page size" //usage: "\n -s ADDR Start address" //usage:#define nanddump_trivial_usage -//usage: "[-o]" IF_LONG_OPTS(" [--bb=padbad|skipbad]") " [-s ADDR] [-l LEN] [-f FILE] MTD_DEVICE" +//usage: "[-no]" IF_LONG_OPTS(" [--bb=padbad|skipbad]") " [-s ADDR] [-l LEN] [-f FILE] MTD_DEVICE" //usage:#define nanddump_full_usage "\n\n" //usage: "Dump MTD_DEVICE\n" +//usage: "\n -n Read without ecc" //usage: "\n -o Dump oob data" //usage: "\n -s ADDR Start address" //usage: "\n -l LEN Length" @@ -57,10 +59,11 @@ #define OPT_p (1 << 0) /* nandwrite only */ #define OPT_o (1 << 0) /* nanddump only */ -#define OPT_s (1 << 1) -#define OPT_f (1 << 2) -#define OPT_l (1 << 3) -#define OPT_bb (1 << 4) /* must be the last one in the list */ +#define OPT_n (1 << 1) +#define OPT_s (1 << 2) +#define OPT_f (1 << 3) +#define OPT_l (1 << 4) +#define OPT_bb (1 << 5) /* must be the last one in the list */ #define BB_PADBAD (1 << 0) #define BB_SKIPBAD (1 << 1) @@ -125,10 +128,10 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) applet_long_options = "bb\0" Required_argument "\xff"; /* no short equivalent */ #endif - opts = getopt32(argv, "os:f:l:", &opt_s, &opt_f, &opt_l, &opt_bb); + opts = getopt32(argv, "ons:f:l:", &opt_s, &opt_f, &opt_l, &opt_bb); } else { /* nandwrite */ opt_complementary = "-1:?2"; - opts = getopt32(argv, "ps:", &opt_s); + opts = getopt32(argv, "pns:", &opt_s); } argv += optind; @@ -144,6 +147,9 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) fd = xopen(argv[0], IS_NANDWRITE ? O_RDWR : O_RDONLY); xioctl(fd, MEMGETINFO, &meminfo); + if (opts & OPT_n) + xioctl(fd, MTDFILEMODE, (void *)MTD_FILE_MODE_RAW); + mtdoffset = xstrtou(opt_s, 0); if (IS_NANDDUMP && (opts & OPT_l)) { unsigned length = xstrtou(opt_l, 0); -- cgit v1.2.3-55-g6feb From bae8f986336383f688f0cf913e6315d430217095 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Jan 2016 22:43:40 +0100 Subject: login: add commented-out PAM double password avoidance from BZ 4003 Signed-off-by: Denys Vlasenko --- loginutils/login.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/loginutils/login.c b/loginutils/login.c index 67fe82e86..4ebc18502 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -78,6 +78,49 @@ * Apparently they like to confuse people. */ # include # include + +# if 0 +/* This supposedly can be used to avoid double password prompt, + * if used instead of standard misc_conv(): + * + * "When we want to authenticate first with local method and then with tacacs for example, + * the password is asked for local method and if not good is asked a second time for tacacs. + * So if we want to authenticate a user with tacacs, and the user exists localy, the password is + * asked two times before authentication is accepted." + * + * However, code looks shaky. For example, why misc_conv() return value is ignored? + * Are msg[i] and resp[i] indexes handled correctly? + */ +static char *passwd = NULL; +static int my_conv(int num_msg, const struct pam_message **msg, + struct pam_response **resp, void *data) +{ + int i; + for (i = 0; i < num_msg; i++) { + switch (msg[i]->msg_style) { + case PAM_PROMPT_ECHO_OFF: + if (passwd == NULL) { + misc_conv(num_msg, msg, resp, data); + passwd = xstrdup(resp[i]->resp); + return PAM_SUCCESS; + } + + resp[0] = xzalloc(sizeof(struct pam_response)); + resp[0]->resp = passwd; + passwd = NULL; + resp[0]->resp_retcode = PAM_SUCCESS; + resp[1] = NULL; + return PAM_SUCCESS; + + default: + break; + } + } + + return PAM_SUCCESS; +} +# endif + static const struct pam_conv conv = { misc_conv, NULL -- cgit v1.2.3-55-g6feb From e111a1640494fe87fc913f94fae3bb805de0fc99 Mon Sep 17 00:00:00 2001 From: Ari Sundholm Date: Mon, 4 Jan 2016 15:40:37 +0200 Subject: truncate: always set mode when opening file to avoid fortify errors Busybox crashes due to no mode being given when opening: $ ./busybox truncate -s 1M foo *** invalid open64 call: O_CREAT without mode ***: ./busybox terminated ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7f66d921338f] /lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f66d92aac9c] /lib/x86_64-linux-gnu/libc.so.6(+0xeb6aa)[0x7f66d928b6aa] ./busybox[0x4899f9] ======= Memory map: ======== 00400000-004d0000 r-xp 00000000 00:1a 137559 /home/ari/busybox/busybox 006cf000-006d0000 r--p 000cf000 00:1a 137559 /home/ari/busybox/busybox 006d0000-006d1000 rw-p 000d0000 00:1a 137559 /home/ari/busybox/busybox 006d1000-006d4000 rw-p 00000000 00:00 0 014e7000-01508000 rw-p 00000000 00:00 0 [heap] 7f66d8f8a000-7f66d8fa0000 r-xp 00000000 08:07 1579008 /lib/x86_64-linux-gnu/libgcc_s.so.1 7f66d8fa0000-7f66d919f000 ---p 00016000 08:07 1579008 /lib/x86_64-linux-gnu/libgcc_s.so.1 7f66d919f000-7f66d91a0000 rw-p 00015000 08:07 1579008 /lib/x86_64-linux-gnu/libgcc_s.so.1 7f66d91a0000-7f66d935b000 r-xp 00000000 08:07 1578994 /lib/x86_64-linux-gnu/libc-2.19.so 7f66d935b000-7f66d955a000 ---p 001bb000 08:07 1578994 /lib/x86_64-linux-gnu/libc-2.19.so 7f66d955a000-7f66d955e000 r--p 001ba000 08:07 1578994 /lib/x86_64-linux-gnu/libc-2.19.so 7f66d955e000-7f66d9560000 rw-p 001be000 08:07 1578994 /lib/x86_64-linux-gnu/libc-2.19.so 7f66d9560000-7f66d9565000 rw-p 00000000 00:00 0 7f66d9565000-7f66d966a000 r-xp 00000000 08:07 1579020 /lib/x86_64-linux-gnu/libm-2.19.so 7f66d966a000-7f66d9869000 ---p 00105000 08:07 1579020 /lib/x86_64-linux-gnu/libm-2.19.so 7f66d9869000-7f66d986a000 r--p 00104000 08:07 1579020 /lib/x86_64-linux-gnu/libm-2.19.so 7f66d986a000-7f66d986b000 rw-p 00105000 08:07 1579020 /lib/x86_64-linux-gnu/libm-2.19.so 7f66d986b000-7f66d988e000 r-xp 00000000 08:07 1578981 /lib/x86_64-linux-gnu/ld-2.19.so 7f66d9a64000-7f66d9a67000 rw-p 00000000 00:00 0 7f66d9a8a000-7f66d9a8d000 rw-p 00000000 00:00 0 7f66d9a8d000-7f66d9a8e000 r--p 00022000 08:07 1578981 /lib/x86_64-linux-gnu/ld-2.19.so 7f66d9a8e000-7f66d9a8f000 rw-p 00023000 08:07 1578981 /lib/x86_64-linux-gnu/ld-2.19.so 7f66d9a8f000-7f66d9a90000 rw-p 00000000 00:00 0 7ffc47761000-7ffc47782000 rw-p 00000000 00:00 0 [stack] 7ffc477ab000-7ffc477ad000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] Aborted (core dumped) $ Fix this by simply always setting the mode, as it doesn't hurt even when O_CREAT is not specified. This bug is a regression introduced in fc3e40e, as xopen(), which was originally used, would automatically set the mode. Signed-off-by: Ari Sundholm Signed-off-by: Mike Frysinger --- coreutils/truncate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/truncate.c b/coreutils/truncate.c index e5fa656c8..4c997bf7a 100644 --- a/coreutils/truncate.c +++ b/coreutils/truncate.c @@ -64,7 +64,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv) argv += optind; while (*argv) { - int fd = open(*argv, flags); + int fd = open(*argv, flags, 0666); if (fd < 0) { if (errno != ENOENT || !(opts & OPT_NOCREATE)) { bb_perror_msg("%s: open", *argv); -- cgit v1.2.3-55-g6feb From 6a70db85cfc2aba89fc23edf426a47630f497eb8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 13 Jan 2016 13:30:20 -0500 Subject: truncate: use O_WRONLY|O_NONBLOCK This matches coreutils behavior. We don't read the fd, and truncation does not need blocking. Signed-off-by: Mike Frysinger --- coreutils/truncate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/truncate.c b/coreutils/truncate.c index 4c997bf7a..8d845f218 100644 --- a/coreutils/truncate.c +++ b/coreutils/truncate.c @@ -40,7 +40,7 @@ int truncate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int truncate_main(int argc UNUSED_PARAM, char **argv) { unsigned opts; - int flags = O_RDWR; + int flags = O_WRONLY | O_NONBLOCK; int ret = EXIT_SUCCESS; char *size_str; off_t size; -- cgit v1.2.3-55-g6feb From ccf7f0e4d3aed3bd9f46a239d9033cd773e67ab8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 17 Jan 2016 01:09:36 +0100 Subject: setsid: implement -c function old new delta setsid_main 53 96 +43 packed_usage 30846 30833 -13 Signed-off-by: Denys Vlasenko --- miscutils/setsid.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/miscutils/setsid.c b/miscutils/setsid.c index 637081b6c..1b27377b2 100644 --- a/miscutils/setsid.c +++ b/miscutils/setsid.c @@ -15,19 +15,22 @@ */ //usage:#define setsid_trivial_usage -//usage: "PROG ARGS" +//usage: "[-c] PROG ARGS" //usage:#define setsid_full_usage "\n\n" //usage: "Run PROG in a new session. PROG will have no controlling terminal\n" -//usage: "and will not be affected by keyboard signals (Ctrl-C etc).\n" -//usage: "See setsid(2) for details." +//usage: "and will not be affected by keyboard signals (^C etc).\n" +//usage: "\n -c Set controlling terminal to stdin" #include "libbb.h" int setsid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int setsid_main(int argc UNUSED_PARAM, char **argv) { - if (!argv[1]) - bb_show_usage(); + unsigned opt; + + opt_complementary = "-1"; /* at least one arg */ + opt = getopt32(argv, "c"); + argv += optind; /* setsid() is allowed only when we are not a process group leader. * Otherwise our PID serves as PGID of some existing process group @@ -61,6 +64,10 @@ int setsid_main(int argc UNUSED_PARAM, char **argv) setsid(); } - argv++; + if (opt) { + /* -c: set (with stealing) controlling tty */ + ioctl(0, TIOCSCTTY, 1); + } + BB_EXECVP_or_die(argv); } -- cgit v1.2.3-55-g6feb From c7e47cf6273830a59f5d3f822e4a6855a80312c6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 17 Jan 2016 03:50:36 +0100 Subject: dos2unix: try to preserve ownership. closes 8311 function old new delta dos2unix_main 426 441 +15 Signed-off-by: Denys Vlasenko --- coreutils/dos2unix.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index 07398bdfa..ccb74a113 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c @@ -41,7 +41,7 @@ enum { static void convert(char *fn, int conv_type) { FILE *in, *out; - int i; + int ch; char *temp_fn = temp_fn; /* for compiler */ char *resolved_fn = resolved_fn; @@ -49,28 +49,30 @@ static void convert(char *fn, int conv_type) out = stdout; if (fn != NULL) { struct stat st; + int fd; resolved_fn = xmalloc_follow_symlinks(fn); if (resolved_fn == NULL) bb_simple_perror_msg_and_die(fn); in = xfopen_for_read(resolved_fn); - fstat(fileno(in), &st); + xfstat(fileno(in), &st, resolved_fn); temp_fn = xasprintf("%sXXXXXX", resolved_fn); - i = xmkstemp(temp_fn); - if (fchmod(i, st.st_mode) == -1) + fd = xmkstemp(temp_fn); + if (fchmod(fd, st.st_mode) == -1) bb_simple_perror_msg_and_die(temp_fn); + fchown(fd, st.st_uid, st.st_gid); - out = xfdopen_for_write(i); + out = xfdopen_for_write(fd); } - while ((i = fgetc(in)) != EOF) { - if (i == '\r') + while ((ch = fgetc(in)) != EOF) { + if (ch == '\r') continue; - if (i == '\n') + if (ch == '\n') if (conv_type == CT_UNIX2DOS) fputc('\r', out); - fputc(i, out); + fputc(ch, out); } if (fn != NULL) { -- cgit v1.2.3-55-g6feb From eb5091070f6876993d868d2b2bb49b4b4d3ed002 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 23 Jan 2016 05:13:15 +0100 Subject: patch: correctly handle "patch FILE_TO_PATCH" form. Closes 7736 Signed-off-by: Denys Vlasenko --- editors/patch.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/editors/patch.c b/editors/patch.c index cb25e4140..988021d77 100644 --- a/editors/patch.c +++ b/editors/patch.c @@ -372,10 +372,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv) xmove_fd(xopen_stdin(argv[1]), STDIN_FILENO); } } - if (argv[0]) { - oldname = xstrdup(argv[0]); - newname = xstrdup(argv[0]); - } // Loop through the lines in the patch for(;;) { @@ -486,10 +482,10 @@ int patch_main(int argc UNUSED_PARAM, char **argv) // or if new hunk is empty (zero context) after patching if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) { name = reverse ? newname : oldname; - empty++; + empty = 1; } - // handle -p path truncation. + // Handle -p path truncation. for (i = 0, s = name; *s;) { if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i) break; @@ -500,6 +496,9 @@ int patch_main(int argc UNUSED_PARAM, char **argv) i++; name = s; } + // If "patch FILE_TO_PATCH", completely ignore name from patch + if (argv[0]) + name = argv[0]; if (empty) { // File is empty after the patches have been applied -- cgit v1.2.3-55-g6feb From 2a4bba3ce2e00e55e6690fa8ba2607679277eed4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 24 Jan 2016 15:52:16 +0100 Subject: sed: make 's///w FILE' actually write to FILE. Closes 8251 function old new delta add_cmd 1167 1210 +43 Signed-off-by: Denys Vlasenko --- editors/sed.c | 11 +++++++---- testsuite/sed.tests | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index a8c35388b..4c7f75521 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -113,7 +113,7 @@ typedef struct sed_cmd_s { int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($). -2-N = +N */ int end_line_orig; - FILE *sw_file; /* File (sw) command writes to, -1 for none. */ + FILE *sw_file; /* File (sw) command writes to, NULL for none. */ char *string; /* Data string for (saicytb) commands. */ unsigned which_match; /* (s) Which match to replace (0 for all) */ @@ -179,7 +179,7 @@ static void sed_free_and_close_stuff(void) sed_cmd_t *sed_cmd_next = sed_cmd->next; if (sed_cmd->sw_file) - xprint_and_close_file(sed_cmd->sw_file); + fclose(sed_cmd->sw_file); if (sed_cmd->beg_match) { regfree(sed_cmd->beg_match); @@ -426,8 +426,11 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) /* Write to file */ case 'w': { - char *temp; - idx += parse_file_cmd(/*sed_cmd,*/ substr+idx, &temp); + char *fname; + idx += parse_file_cmd(/*sed_cmd,*/ substr+idx+1, &fname); + sed_cmd->sw_file = xfopen_for_write(fname); + sed_cmd->sw_last_char = '\n'; + free(fname); break; } /* Ignore case (gnu exension) */ diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 34479e55f..5d2356b64 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -365,6 +365,12 @@ testing "sed /regex/,+0 -i works" \ "1\n2\n3\n4\n5\n6\n7\n8\n" \ "1\n2\n4\n5\n6\n7\n8\n" \ +testing "sed 's///w FILE'" \ + "sed 's/qwe/ZZZ/wz'; cat z; rm z" \ + "123\nZZZ\nasd\n""ZZZ\n" \ + "" \ + "123\nqwe\nasd\n" + # testing "description" "commands" "result" "infile" "stdin" exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From 4a79224cfcde1c941f581d0c61edaf293e743af5 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 31 Jan 2016 22:22:25 +0100 Subject: printf: short-circuit output when argument to %b includes \c printf wasn't correctly handling \c in an argument to the %b format specifier. printf %bXX OK\\c returned 'OK\cXX' rather than the expected 'OK'. function old new delta printf_main 886 899 +13 Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/coreutils/printf.c b/coreutils/printf.c index 3dd43a978..9ee7350d0 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -131,8 +131,8 @@ static double my_xstrtod(const char *arg) return result; } -/* Handles %b */ -static void print_esc_string(const char *str) +/* Handles %b; return 1 if output is to be short-circuited by \c */ +static int print_esc_string(const char *str) { char c; while ((c = *str) != '\0') { @@ -145,6 +145,9 @@ static void print_esc_string(const char *str) str++; } } + else if (*str == 'c') { + return 1; + } { /* optimization: don't force arg to be on-stack, * use another variable for that. */ @@ -155,6 +158,8 @@ static void print_esc_string(const char *str) } putchar(c); } + + return 0; } static void print_direc(char *format, unsigned fmt_length, @@ -280,7 +285,8 @@ static char **print_formatted(char *f, char **argv, int *conv_err) } if (*f == 'b') { if (*argv) { - print_esc_string(*argv); + if (print_esc_string(*argv)) + return saved_argv; /* causes main() to exit */ ++argv; } break; -- cgit v1.2.3-55-g6feb From 40eea690c7eabbf4d12e1e0c30c31f40125ca996 Mon Sep 17 00:00:00 2001 From: Kylie McClain Date: Mon, 1 Feb 2016 01:36:05 +0100 Subject: Fix compiling with musl's utmp stubs This patch fixes compiling busybox with FEATURE_UTMP and _WTMP enabled. musl, while not really support utmp/wtmp, provides stub functions, as well as variables such as _PATH_UTMP, so that programs using utmp or wtmp can still compile fine. My reasoning for this patch is that on Exherbo, I'm currently trying to get us to be able to use the same busybox config file for both glibc and musl systems, using utmp/wtmp on systems that support it, and using the stubs on musl without needing two different configs. As of latest musl git, it provides all utmp functions needed; 1.1.12 doesn't, but I sent a patch to Rich to add the utmp{,x}name functions expected to exist, which was merged into musl upstream. Signed-off-by: Kylie McClain Signed-off-by: Denys Vlasenko --- include/libbb.h | 5 +++++ init/init.c | 1 - shell/ash.c | 1 - sysklogd/klogd.c | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 82484f911..d05ac2976 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -20,6 +20,7 @@ #include #include #include +#include #if defined __UCLIBC__ /* TODO: and glibc? */ /* use inlined versions of these: */ # define sigfillset(s) __sigfillset(s) @@ -106,7 +107,11 @@ # define updwtmpx updwtmp # define _PATH_UTMPX _PATH_UTMP # else +# include # include +# if defined _PATH_UTMP && !defined _PATH_UTMPX +# define _PATH_UTMPX _PATH_UTMP +# endif # endif #endif #if ENABLE_LOCALE_SUPPORT diff --git a/init/init.c b/init/init.c index 80c5d0f74..2040a59e8 100644 --- a/init/init.c +++ b/init/init.c @@ -112,7 +112,6 @@ #include "libbb.h" #include -#include #include #ifdef __linux__ # include diff --git a/shell/ash.c b/shell/ash.c index daec975c5..b5a2d961d 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -37,7 +37,6 @@ #define JOBS ENABLE_ASH_JOB_CONTROL -#include #include #include #include diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index ca8b848bd..03d65b37f 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -98,7 +98,6 @@ static void klogd_close(void) #else -# include # ifndef _PATH_KLOG # ifdef __GNU__ # define _PATH_KLOG "/dev/klog" -- cgit v1.2.3-55-g6feb From c30a5b13731919367ec2d781a107706fd00f21bc Mon Sep 17 00:00:00 2001 From: Rafał Miłecki Date: Mon, 1 Feb 2016 02:17:28 +0100 Subject: dd: support iflag=skip_bytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It allows specifying amount of bytes directly (not only amount of blocks) is also supported by GNU's Coreutils. function old new delta parse_comma_flags - 93 +93 static.iflag_words - 12 +12 dd_main 1569 1580 +11 packed_usage 30591 30600 +9 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 2/0 up/down: 125/0) Total: 125 bytes Signed-off-by: Rafał Miłecki Signed-off-by: Denys Vlasenko --- coreutils/dd.c | 78 ++++++++++++++++++++++++++++++---------------- docs/posix_conformance.txt | 1 + 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/coreutils/dd.c b/coreutils/dd.c index 6a5288da1..0c0ea07b9 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c @@ -55,7 +55,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]") +//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes]") //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" @@ -76,6 +76,7 @@ //usage: "\n conv=sync Pad blocks with zeros" //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: ) //usage: IF_FEATURE_DD_STATUS( //usage: "\n status=noxfer Suppress rate output" @@ -122,11 +123,15 @@ enum { FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS, FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS, /* end of conv flags */ - FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, - FLAG_COUNT = 1 << 6, - FLAG_STATUS = 1 << 7, - FLAG_STATUS_NONE = 1 << 7, - FLAG_STATUS_NOXFER = 1 << 8, + /* start of input flags */ + FLAG_IFLAG_SHIFT = 5, + FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, + /* end of input flags */ + FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, + FLAG_COUNT = 1 << 7, + FLAG_STATUS = 1 << 8, + FLAG_STATUS_NONE = 1 << 9, + FLAG_STATUS_NOXFER = 1 << 10, }; static void dd_output_status(int UNUSED_PARAM cur_signal) @@ -203,18 +208,47 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs, # define XATOU_SFX xatoul_sfx #endif +#if ENABLE_FEATURE_DD_IBS_OBS +static int parse_comma_flags(char *val, const char *words, const char *error_in) +{ + int flags = 0; + while (1) { + int n; + char *arg; + /* find ',', replace them with NUL so we can use val for + * index_in_strings() without copying. + * We rely on val being non-null, else strchr would fault. + */ + arg = strchr(val, ','); + if (arg) + *arg = '\0'; + n = index_in_strings(words, val); + if (n < 0) + bb_error_msg_and_die(bb_msg_invalid_arg_to, val, error_in); + flags |= (1 << n); + if (!arg) /* no ',' left, so this was the last specifier */ + break; + *arg = ','; /* to preserve ps listing */ + val = arg + 1; /* skip this keyword and ',' */ + } + return flags; +} +#endif + int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int dd_main(int argc UNUSED_PARAM, char **argv) { static const char keywords[] ALIGN1 = "bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0") #if ENABLE_FEATURE_DD_IBS_OBS - "ibs\0""obs\0""conv\0" + "ibs\0""obs\0""conv\0""iflag\0" #endif ; #if ENABLE_FEATURE_DD_IBS_OBS 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"; #endif #if ENABLE_FEATURE_DD_STATUS static const char status_words[] ALIGN1 = @@ -232,6 +266,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) OP_ibs, OP_obs, OP_conv, + OP_iflag, /* Must be in the same order as FLAG_XXX! */ OP_conv_notrunc = 0, OP_conv_sync, @@ -251,6 +286,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) //ibm from ASCII to alternate EBCDIC /* Partially implemented: */ //swab swap every pair of input bytes: will abort on non-even reads + OP_iflag_skip_bytes, #endif }; smallint exitcode = EXIT_FAILURE; @@ -315,24 +351,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv) /*continue;*/ } if (what == OP_conv) { - while (1) { - int n; - /* find ',', replace them with NUL so we can use val for - * index_in_strings() without copying. - * We rely on val being non-null, else strchr would fault. - */ - arg = strchr(val, ','); - if (arg) - *arg = '\0'; - n = index_in_strings(conv_words, val); - if (n < 0) - bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "conv"); - G.flags |= (1 << n); - if (!arg) /* no ',' left, so this was the last specifier */ - break; - /* *arg = ','; - to preserve ps listing? */ - val = arg + 1; /* skip this keyword and ',' */ - } + G.flags |= parse_comma_flags(val, conv_words, "conv"); + /*continue;*/ + } + if (what == OP_iflag) { + G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT; /*continue;*/ } #endif @@ -421,9 +444,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv) outfile = bb_msg_standard_output; } if (skip) { - if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) { + 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, ibs); + ssize_t n = safe_read(ifd, ibuf, blocksz); if (n < 0) goto die_infile; if (n == 0) diff --git a/docs/posix_conformance.txt b/docs/posix_conformance.txt index 5b616d701..c0582dc23 100644 --- a/docs/posix_conformance.txt +++ b/docs/posix_conformance.txt @@ -178,6 +178,7 @@ dd POSIX options: conv=noerror | yes | | conv=notrunc | yes | | conv=sync | yes | | + iflag=skip_bytes| yes | | dd Busybox specific options: conv=fsync -- cgit v1.2.3-55-g6feb From f2c043acfcf9dad9fd3d65821b81f89986bbe54e Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 18 Jan 2016 12:07:35 +0100 Subject: busybox: fix uninitialized memory when displaying IPv6 addresses After commit 8e74adab0107658e3dc04ed342206272a284f43e ("libbb: make INET[6]_rresolve use sockaddr2{host,dotted}_noport") INET_sprint6 uses more than just sin6_addr, it also tries to display the scope id, which is uninitialized when called from ife_print6. Signed-off-by: Felix Fietkau Signed-off-by: Denys Vlasenko --- networking/interface.c | 1 + 1 file changed, 1 insertion(+) diff --git a/networking/interface.c b/networking/interface.c index 24bd13c57..e5723b428 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -881,6 +881,7 @@ static void ife_print6(struct interface *ptr) sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s", addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7]); + memset(&sap, 0, sizeof(sap)); inet_pton(AF_INET6, addr6, (struct sockaddr *) &sap.sin6_addr); sap.sin6_family = AF_INET6; -- cgit v1.2.3-55-g6feb From fc47fcefb6401605b142c30025c597dc4d110087 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 10 Feb 2016 06:55:07 +0100 Subject: ntpd: step when |offset| > 1 sec, not 0.125 sec update_local_clock 769 820 +51 recv_and_process_peer_pkt 838 862 +24 reset_peer_stats 137 133 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 75/-4) Total: 71 bytes Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 9732c9b1a..32590a185 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -112,7 +112,7 @@ * * Made some changes to speed up re-syncing after our clock goes bad * (tested with suspending my laptop): - * - if largish offset (>= STEP_THRESHOLD * 8 == 1 sec) is seen + * - if largish offset (>= STEP_THRESHOLD == 1 sec) is seen * from a peer, schedule next query for this peer soon * without drastically lowering poll interval for everybody. * This makes us collect enough data for step much faster: @@ -131,11 +131,14 @@ #define RESPONSE_INTERVAL 16 /* wait for reply up to N secs */ /* Step threshold (sec). std ntpd uses 0.128. + */ +#define STEP_THRESHOLD 1 +/* Slew threshold (sec): adjtimex() won't accept offsets larger than this. * Using exact power of 2 (1/8) results in smaller code */ -#define STEP_THRESHOLD 0.125 +#define SLEW_THRESHOLD 0.125 /* Stepout threshold (sec). std ntpd uses 900 (11 mins (!)) */ -#define WATCH_THRESHOLD 128 +#define WATCH_THRESHOLD 128 /* NB: set WATCH_THRESHOLD to ~60 when debugging to save time) */ //UNUSED: #define PANIC_THRESHOLD 1000 /* panic threshold (sec) */ @@ -143,7 +146,7 @@ * If we got |offset| > BIGOFF from a peer, cap next query interval * for this peer by this many seconds: */ -#define BIGOFF (STEP_THRESHOLD * 8) +#define BIGOFF STEP_THRESHOLD #define BIGOFF_INTERVAL (1 << 7) /* 128 s */ #define FREQ_TOLERANCE 0.000015 /* frequency tolerance (15 PPM) */ @@ -157,10 +160,10 @@ #define MAXPOLL 12 /* maximum poll interval (12: 1.1h, 17: 36.4h). std ntpd uses 17 */ /* * Actively lower poll when we see such big offsets. - * With STEP_THRESHOLD = 0.125, it means we try to sync more aggressively + * With SLEW_THRESHOLD = 0.125, it means we try to sync more aggressively * if offset increases over ~0.04 sec */ -//#define POLLDOWN_OFFSET (STEP_THRESHOLD / 3) +//#define POLLDOWN_OFFSET (SLEW_THRESHOLD / 3) #define MINDISP 0.01 /* minimum dispersion (sec) */ #define MAXDISP 16 /* maximum dispersion (sec) */ #define MAXSTRAT 16 /* maximum stratum (infinity metric) */ @@ -720,7 +723,7 @@ static void reset_peer_stats(peer_t *p, double offset) { int i; - bool small_ofs = fabs(offset) < 16 * STEP_THRESHOLD; + bool small_ofs = fabs(offset) < STEP_THRESHOLD; /* Used to set p->filter_datapoint[i].d_dispersion = MAXDISP * and clear reachable bits, but this proved to be too agressive: @@ -771,7 +774,7 @@ add_peers(const char *s) p->p_fd = -1; p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); p->next_action_time = G.cur_time; /* = set_next(p, 0); */ - reset_peer_stats(p, 16 * STEP_THRESHOLD); + reset_peer_stats(p, STEP_THRESHOLD); llist_add_to(&G.ntp_peers, p); G.peer_cnt++; @@ -1638,14 +1641,7 @@ update_local_clock(peer_t *p) tmx.freq = G.discipline_freq_drift * 65536e6; #endif tmx.modes = ADJ_OFFSET | ADJ_STATUS | ADJ_TIMECONST;// | ADJ_MAXERROR | ADJ_ESTERROR; - tmx.offset = (offset * 1000000); /* usec */ - tmx.status = STA_PLL; - if (G.ntp_status & LI_PLUSSEC) - tmx.status |= STA_INS; - if (G.ntp_status & LI_MINUSSEC) - tmx.status |= STA_DEL; - - tmx.constant = (int)G.poll_exp - 4 > 0 ? (int)G.poll_exp - 4 : 0; + tmx.constant = (int)G.poll_exp - 4; /* EXPERIMENTAL. * The below if statement should be unnecessary, but... * It looks like Linux kernel's PLL is far too gentle in changing @@ -1656,8 +1652,27 @@ update_local_clock(peer_t *p) * To be on a safe side, let's do it only if offset is significantly * larger than jitter. */ - if (tmx.constant > 0 && G.offset_to_jitter_ratio >= TIMECONST_HACK_GATE) + if (G.offset_to_jitter_ratio >= TIMECONST_HACK_GATE) tmx.constant--; + tmx.offset = (long)(offset * 1000000); /* usec */ + if (SLEW_THRESHOLD < STEP_THRESHOLD) { + if (tmx.offset > (long)(SLEW_THRESHOLD * 1000000)) { + tmx.offset = (long)(SLEW_THRESHOLD * 1000000); + tmx.constant--; + } + if (tmx.offset < -(long)(SLEW_THRESHOLD * 1000000)) { + tmx.offset = -(long)(SLEW_THRESHOLD * 1000000); + tmx.constant--; + } + } + if (tmx.constant < 0) + tmx.constant = 0; + + tmx.status = STA_PLL; + if (G.ntp_status & LI_PLUSSEC) + tmx.status |= STA_INS; + if (G.ntp_status & LI_MINUSSEC) + tmx.status |= STA_DEL; //tmx.esterror = (uint32_t)(clock_jitter * 1e6); //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6); @@ -1931,6 +1946,9 @@ recv_and_process_peer_pkt(peer_t *p) increase_interval: adjust_poll(MINPOLL); } else { + VERB3 if (rc > 0) + bb_error_msg("want smaller poll interval: offset/jitter ratio > %u", + POLLADJ_GATE); adjust_poll(-G.poll_exp * 2); } } @@ -1939,7 +1957,7 @@ recv_and_process_peer_pkt(peer_t *p) pick_normal_interval: interval = poll_interval(INT_MAX); if (fabs(offset) >= BIGOFF && interval > BIGOFF_INTERVAL) { - /* If we are synced, offsets are less than STEP_THRESHOLD, + /* If we are synced, offsets are less than SLEW_THRESHOLD, * or at the very least not much larger than it. * Now we see a largish one. * Either this peer is feeling bad, or packet got corrupted, -- cgit v1.2.3-55-g6feb From 383201e7258c3c1646f6d5cab4e813b5c3b3ecd0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 10 Feb 2016 07:06:31 +0100 Subject: ntpd: shorter message Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 32590a185..1651670d9 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1947,7 +1947,7 @@ recv_and_process_peer_pkt(peer_t *p) adjust_poll(MINPOLL); } else { VERB3 if (rc > 0) - bb_error_msg("want smaller poll interval: offset/jitter ratio > %u", + bb_error_msg("want smaller poll interval: offset/jitter > %u", POLLADJ_GATE); adjust_poll(-G.poll_exp * 2); } -- cgit v1.2.3-55-g6feb From 29eae728e959a382841bd0a32cc1a8d1bcdc9150 Mon Sep 17 00:00:00 2001 From: Nicolas Carrier Date: Thu, 4 Feb 2016 12:18:01 +0100 Subject: init: make the command-line rewrite optional When launched as PID 1 and after parsing its arguments, init wipes all all of them except argv[0] and rewrites argv[0] to contain only "init", so that its command-line appears solely as "init" in tools such as ps. This patch adds the FEATURE_INIT_MODIFY_CMDLINE which, if set to n, will make init preserve all its arguments including argv[0], be they parsed or ignored. The original command-line used to launch init can then be retrieved in /proc/1/cmdline on Linux, for example. Signed-off-by: Nicolas Carrier Signed-off-by: Denys Vlasenko --- init/init.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/init/init.c b/init/init.c index 2040a59e8..25bfaec8c 100644 --- a/init/init.c +++ b/init/init.c @@ -102,6 +102,21 @@ //config: //config: Note that on Linux, init attempts to detect serial terminal and //config: sets TERM to "vt102" if one is found. +//config: +//config:config FEATURE_INIT_MODIFY_CMDLINE +//config: bool "Modify the command-line to \"init\"" +//config: default y +//config: depends on INIT +//config: help +//config: When launched as PID 1 and after parsing its arguments, init +//config: wipes all the arguments but argv[0] and rewrites argv[0] to +//config: contain only "init", so that its command-line appears solely as +//config: "init" in tools such as ps. +//config: If this option is set to Y, init will keep its original behavior, +//config: otherwise, all the arguments including argv[0] will be preserved, +//config: be they parsed or ignored by init. +//config: The original command-line used to launch init can then be +//config: retrieved in /proc/1/cmdline on Linux, for example. //applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP)) //applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) @@ -1138,11 +1153,13 @@ int init_main(int argc UNUSED_PARAM, char **argv) } #endif - /* Make the command line just say "init" - thats all, nothing else */ - strncpy(argv[0], "init", strlen(argv[0])); - /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ - while (*++argv) - nuke_str(*argv); + if (ENABLE_FEATURE_INIT_MODIFY_CMDLINE) { + /* Make the command line just say "init" - that's all, nothing else */ + strncpy(argv[0], "init", strlen(argv[0])); + /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ + while (*++argv) + nuke_str(*argv); + } /* Set up signal handlers */ if (!DEBUG_INIT) { -- cgit v1.2.3-55-g6feb From 8efcc9589bd61171ec1fe4f71c33e9df62b6005b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 11 Feb 2016 17:44:44 +0100 Subject: networking: allow dot at the end of the domain name in dhcp response Patch based on Balaji Punnuru work. Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 915f65935..48097bc24 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -201,6 +201,8 @@ static int good_hostname(const char *name) //Do we want this? //return ((name - start) < 1025); /* NS_MAXDNAME */ name++; + if (*name == '\0') + return 1; // We allow trailing dot too } } #else -- cgit v1.2.3-55-g6feb From 43e56639c6739953d5a6686823bcd0d256512ea5 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 12 Feb 2016 22:12:47 -0500 Subject: build: add a sanitizer debug option Building & running with ASAN is super helpful, so add a dedicated config knob for it. This way people don't have to guess at the right compiler settings in order to get a good build. We can just tell people to enable this one option. Signed-off-by: Mike Frysinger --- Config.in | 10 ++++++++++ Makefile.flags | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/Config.in b/Config.in index 07b4bf36b..0a0b5d7cb 100644 --- a/Config.in +++ b/Config.in @@ -688,6 +688,16 @@ config DEBUG_PESSIMIZE in a much bigger executable that more closely matches the source code. +config DEBUG_SANITIZE + bool "Enable runtime sanitizers (ASAN/LSAN/USAN/etc...)" + default n + help + Say Y here if you want to enable runtime sanitizers. These help + catch bad memory accesses (e.g. buffer overflows), but will make + the executable larger and slow down runtime a bit. + + If you aren't developing/testing busybox, say N here. + config UNIT_TEST bool "Build unit tests" default n diff --git a/Makefile.flags b/Makefile.flags index 9f77674ba..65021de25 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -75,6 +75,11 @@ else CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,)) endif endif +ifeq ($(CONFIG_DEBUG_SANITIZE),y) +CFLAGS += $(call cc-option,-fsanitize=address,) +CFLAGS += $(call cc-option,-fsanitize=leak,) +CFLAGS += $(call cc-option,-fsanitize=undefined,) +endif # If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)... ARCH_FPIC ?= -fpic -- cgit v1.2.3-55-g6feb From 3a5cc989025eefe03fda0552b253a4a8f015a761 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 12 Feb 2016 23:26:51 -0500 Subject: modprobe: only parse files that end in .conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matches behavior with kmod which has been the standard for a long time at this point. URL: https://bugs.busybox.net/8021 Reported-by: Jö Signed-off-by: Mike Frysinger --- modutils/modprobe.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modutils/modprobe.c b/modutils/modprobe.c index ec490b74d..997ee3c67 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c @@ -220,8 +220,16 @@ static int FAST_FUNC config_file_action(const char *filename, parser_t *p; struct module_entry *m; int rc = TRUE; + const char *base, *ext; - if (bb_basename(filename)[0] == '.') + /* Skip files that begin with a ".". */ + base = bb_basename(filename); + if (base[0] == '.') + goto error; + + /* Skip files that do not end with a ".conf". */ + ext = strrchr(base, '.'); + if (ext == NULL || strcmp(ext + 1, "conf")) goto error; p = config_open2(filename, fopen_for_read); -- cgit v1.2.3-55-g6feb