From a5ee090e8651692545514a81a16c6cde3a2dc577 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 10 May 2012 19:26:37 +0200 Subject: fix for spurious testsuite failure Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- testsuite/du/du-k-works | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/du/du-k-works b/testsuite/du/du-k-works index 229a948ee..36dcaa85d 100644 --- a/testsuite/du/du-k-works +++ b/testsuite/du/du-k-works @@ -3,4 +3,5 @@ cd du.testdir dd if=/dev/zero of=file1 bs=1k count=64 2>/dev/null dd if=/dev/zero of=file2 bs=1k count=16 2>/dev/null test x"`busybox du -k .`" = x"80 ." \ + -o x"`busybox du -k .`" = x"84 ." \ -o x"`busybox du -k .`" = x"88 ." -- cgit v1.2.3-55-g6feb From 02b8b9b0144d9de65e55015c0f3848a529a0738b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 14 May 2012 23:52:57 +0200 Subject: busybox: tweak help text and copyright year Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- libbb/appletlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 73f71f1d0..09e886d7a 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -627,11 +627,11 @@ static int busybox_main(char **argv) full_write2_str(bb_banner); /* reuse const string */ full_write2_str(" multi-call binary.\n"); /* reuse */ full_write2_str( - "Copyright (C) 1998-2011 Erik Andersen, Rob Landley, Denys Vlasenko\n" + "Copyright (C) 1998-2012 Erik Andersen, Rob Landley, Denys Vlasenko\n" "and others. Licensed under GPLv2.\n" "See source distribution for full notice.\n" "\n" - "Usage: busybox [function] [arguments]...\n" + "Usage: busybox [function [arguments]...]\n" " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" IF_FEATURE_INSTALLER( " or: busybox --install [-s] [DIR]\n" -- cgit v1.2.3-55-g6feb From 4a6a56c77871e8ae249c061c4478d25a8674e762 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 16 May 2012 03:03:54 +0200 Subject: examples/mdev_fat.conf: small addition I needed this to make Android's adb see my phone Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- examples/mdev_fat.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/mdev_fat.conf b/examples/mdev_fat.conf index df329b4b5..da28bc36b 100644 --- a/examples/mdev_fat.conf +++ b/examples/mdev_fat.conf @@ -108,3 +108,6 @@ usbdev[0-9].[0-9]_.* root:root 660 # zaptel devices zap(.*) root:dialout 660 =zap/%1 dahdi!(.*) root:dialout 660 =dahdi/%1 + +# If $DEVNAME exists, create device with this name +$DEVNAME=bus/usb/.* 0:0 660 ! @mkdir -p "`dirname "$DEVNAME"`"; mknod -m 0660 "$DEVNAME" c "$MAJOR" "$MINOR" -- cgit v1.2.3-55-g6feb From be1cfeea2eba1570548b3f881740ff1ecefca660 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 17 May 2012 12:25:25 +0200 Subject: find: if DESKTOP=y, support -wholename (synonym for -path) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- findutils/find.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/findutils/find.c b/findutils/find.c index fc0fc5c9f..7f50da80c 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -831,6 +831,11 @@ static action*** parse_params(char **argv) PARM_name , PARM_iname , IF_FEATURE_FIND_PATH( PARM_path ,) +#if ENABLE_DESKTOP + /* -wholename is a synonym for -path */ + /* We support it becuase Linux kernel's "make tags" uses it */ + IF_FEATURE_FIND_PATH( PARM_wholename ,) +#endif IF_FEATURE_FIND_PATH( PARM_ipath ,) IF_FEATURE_FIND_REGEX( PARM_regex ,) IF_FEATURE_FIND_TYPE( PARM_type ,) @@ -869,6 +874,9 @@ static action*** parse_params(char **argv) "-name\0" "-iname\0" IF_FEATURE_FIND_PATH( "-path\0" ) +#if ENABLE_DESKTOP + IF_FEATURE_FIND_PATH( "-wholename\0") +#endif IF_FEATURE_FIND_PATH( "-ipath\0" ) IF_FEATURE_FIND_REGEX( "-regex\0" ) IF_FEATURE_FIND_TYPE( "-type\0" ) @@ -1076,7 +1084,7 @@ static action*** parse_params(char **argv) ap->iname = (parm == PARM_iname); } #if ENABLE_FEATURE_FIND_PATH - else if (parm == PARM_path || parm == PARM_ipath) { + else if (parm == PARM_path IF_DESKTOP(|| parm == PARM_wholename) || parm == PARM_ipath) { action_path *ap; dbg("%d", __LINE__); ap = ALLOC_ACTION(path); -- cgit v1.2.3-55-g6feb From 01339217261e3ad6f0a60c90e42e6d52580141ab Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 18 May 2012 02:51:27 +0200 Subject: volume_id/ext: detect ext4 too function old new delta volume_id_probe_ext 108 132 +24 Signed-off-by: Dees Troy<dees_troy@teamw.in> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/volume_id/ext.c | 52 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/util-linux/volume_id/ext.c b/util-linux/volume_id/ext.c index b5194a7b5..aa23d1ebf 100644 --- a/util-linux/volume_id/ext.c +++ b/util-linux/volume_id/ext.c @@ -39,10 +39,50 @@ struct ext2_super_block { uint8_t volume_name[16]; } PACKED; -#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004 -#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x00000008 #define EXT_SUPERBLOCK_OFFSET 0x400 +/* for s_flags */ +#define EXT2_FLAGS_TEST_FILESYS 0x0004 + +/* for s_feature_compat */ +#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 + +/* for s_feature_ro_compat */ +#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 +#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 +#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 +#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 +#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 +#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 +#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 + +/* for s_feature_incompat */ +#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 +#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 +#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 +#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 +#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */ +#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 +#define EXT4_FEATURE_INCOMPAT_MMP 0x0100 +#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 + +#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ + EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ + EXT2_FEATURE_RO_COMPAT_BTREE_DIR) +#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ + EXT2_FEATURE_INCOMPAT_META_BG) +#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP +#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP + +#define EXT3_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ + EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ + EXT2_FEATURE_RO_COMPAT_BTREE_DIR) +#define EXT3_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ + EXT3_FEATURE_INCOMPAT_RECOVER| \ + EXT2_FEATURE_INCOMPAT_META_BG) +#define EXT3_FEATURE_INCOMPAT_UNSUPPORTED ~EXT3_FEATURE_INCOMPAT_SUPP +#define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT3_FEATURE_RO_COMPAT_SUPP + int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/) { #define off ((uint64_t)0) @@ -66,11 +106,15 @@ int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/) dbg("ext: label '%s' uuid '%s'", id->label, id->uuid); #if ENABLE_FEATURE_BLKID_TYPE - if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0) + if ((es->feature_ro_compat & cpu_to_le32(EXT4_FEATURE_RO_COMPAT_HUGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK)) + || (es->feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_64BIT)) + ) { + id->type = "ext4"; + } + else if (es->feature_compat & cpu_to_le32(EXT3_FEATURE_COMPAT_HAS_JOURNAL)) id->type = "ext3"; else id->type = "ext2"; #endif - return 0; } -- cgit v1.2.3-55-g6feb From 7c8aa2b47cf76f710959a1f4a914010aca425016 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 18 May 2012 02:53:11 +0200 Subject: typo fix in comment Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- findutils/find.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/findutils/find.c b/findutils/find.c index 7f50da80c..0ec5bdfea 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -833,7 +833,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_PATH( PARM_path ,) #if ENABLE_DESKTOP /* -wholename is a synonym for -path */ - /* We support it becuase Linux kernel's "make tags" uses it */ + /* We support it because Linux kernel's "make tags" uses it */ IF_FEATURE_FIND_PATH( PARM_wholename ,) #endif IF_FEATURE_FIND_PATH( PARM_ipath ,) -- cgit v1.2.3-55-g6feb From 516530c932bd17d87c9eb4347a490be051e495f4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 18 May 2012 04:45:35 +0200 Subject: mdev: add support for $DEVNAME and /dev/mdev.log debug aid function old new delta make_device 1843 2083 +240 mdev_main 712 804 +92 packed_usage 29236 29251 +15 keywords 288 19 -269 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 347/-269) Total: 78 bytes text data bss dec hex filename 887506 497 7584 895587 daa63 busybox_old 887982 497 7584 896063 dac3f busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- examples/mdev_fat.conf | 3 - util-linux/mdev.c | 167 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 147 insertions(+), 23 deletions(-) diff --git a/examples/mdev_fat.conf b/examples/mdev_fat.conf index da28bc36b..df329b4b5 100644 --- a/examples/mdev_fat.conf +++ b/examples/mdev_fat.conf @@ -108,6 +108,3 @@ usbdev[0-9].[0-9]_.* root:root 660 # zaptel devices zap(.*) root:dialout 660 =zap/%1 dahdi!(.*) root:dialout 660 =dahdi/%1 - -# If $DEVNAME exists, create device with this name -$DEVNAME=bus/usb/.* 0:0 660 ! @mkdir -p "`dirname "$DEVNAME"`"; mknod -m 0660 "$DEVNAME" c "$MAJOR" "$MINOR" diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 0a34122b4..70d19033d 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -93,6 +93,8 @@ //usage: "If /dev/mdev.seq file exists, mdev will wait for its value\n" //usage: "to match $SEQNUM variable. This prevents plug/unplug races.\n" //usage: "To activate this feature, create empty /dev/mdev.seq at boot." +//usage: "\n" +//usage: "If /dev/mdev.log file exists, debug log will be appended to it.\n" #include "libbb.h" #include "xregex.h" @@ -139,6 +141,98 @@ * This happens regardless of /sys/class/.../dev existence. */ +/* Kernel's hotplug environment constantly changes. + * Here are new cases I observed on 3.1.0: + * + * Case with $DEVNAME and $DEVICE, not just $DEVPATH: + * ACTION=add + * BUSNUM=001 + * DEVICE=/proc/bus/usb/001/003 + * DEVNAME=bus/usb/001/003 + * DEVNUM=003 + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5 + * DEVTYPE=usb_device + * MAJOR=189 + * MINOR=2 + * PRODUCT=18d1/4e12/227 + * SUBSYSTEM=usb + * TYPE=0/0/0 + * + * Case with $DEVICE, but no $DEVNAME - apparenty, usb iface notification? + * "Please load me a module" thing? + * ACTION=add + * DEVICE=/proc/bus/usb/001/003 + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0 + * DEVTYPE=usb_interface + * INTERFACE=8/6/80 + * MODALIAS=usb:v18D1p4E12d0227dc00dsc00dp00ic08isc06ip50 + * PRODUCT=18d1/4e12/227 + * SUBSYSTEM=usb + * TYPE=0/0/0 + * + * ACTION=add + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5 + * DEVTYPE=scsi_host + * SUBSYSTEM=scsi + * + * ACTION=add + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/scsi_host/host5 + * SUBSYSTEM=scsi_host + * + * ACTION=add + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0 + * DEVTYPE=scsi_target + * SUBSYSTEM=scsi + * + * Case with strange $MODALIAS: + * ACTION=add + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0 + * DEVTYPE=scsi_device + * MODALIAS=scsi:t-0x00 + * SUBSYSTEM=scsi + * + * ACTION=add + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/scsi_disk/5:0:0:0 + * SUBSYSTEM=scsi_disk + * + * ACTION=add + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/scsi_device/5:0:0:0 + * SUBSYSTEM=scsi_device + * + * Case with explicit $MAJOR/$MINOR (no need to read /sys/$DEVPATH/dev?): + * ACTION=add + * DEVNAME=bsg/5:0:0:0 + * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/bsg/5:0:0:0 + * MAJOR=253 + * MINOR=1 + * SUBSYSTEM=bsg + * + * ACTION=add + * DEVPATH=/devices/virtual/bdi/8:16 + * SUBSYSTEM=bdi + * + * ACTION=add + * DEVNAME=sdb + * DEVPATH=/block/sdb + * DEVTYPE=disk + * MAJOR=8 + * MINOR=16 + * SUBSYSTEM=block + * + * Case with ACTION=change: + * ACTION=change + * DEVNAME=sdb + * DEVPATH=/block/sdb + * DEVTYPE=disk + * DISK_MEDIA_CHANGE=1 + * MAJOR=8 + * MINOR=16 + * SUBSYSTEM=block + */ + +static const char keywords[] ALIGN1 = "add\0remove\0change\0"; +enum { OP_add, OP_remove }; + struct rule { bool keep_matching; bool regex_compiled; @@ -154,6 +248,7 @@ struct rule { struct globals { int root_major, root_minor; + smallint verbose; char *subsystem; #if ENABLE_FEATURE_MDEV_CONF const char *filename; @@ -366,13 +461,17 @@ static char *build_alias(char *alias, const char *device_name) * after NUL, but we promise to not mangle (IOW: to restore if needed) * path string. * NB2: "mdev -s" may call us many times, do not leak memory/fds! + * + * device_name = $DEVNAME (may be NULL) + * path = /sys/$DEVPATH */ -static void make_device(char *path, int delete) +static void make_device(char *device_name, char *path, int operation) { - char *device_name, *subsystem_slash_devname; + char *subsystem_slash_devname; int major, minor, type, len; - dbg("%s('%s', delete:%d)", __func__, path, delete); + if (G.verbose) + bb_error_msg("make_device: %s, %s, op:%d", device_name, path, operation); /* Try to read major/minor string. Note that the kernel puts \n after * the data, so we don't need to worry about null terminating the string @@ -380,7 +479,7 @@ static void make_device(char *path, int delete) * We also depend on path having writeable space after it. */ major = -1; - if (!delete) { + if (operation != OP_remove) { char *dev_maj_min = path + strlen(path); strcpy(dev_maj_min, "/dev"); @@ -398,7 +497,8 @@ static void make_device(char *path, int delete) /* else: for delete, -1 still deletes the node, but < -1 suppresses that */ /* Determine device name, type, major and minor */ - device_name = (char*) bb_basename(path); + if (!device_name) + device_name = (char*) bb_basename(path); /* http://kernel.org/doc/pending/hotplug.txt says that only * "/sys/block/..." is for block devices. "/sys/bus" etc is not. * But since 2.6.25 block devices are also in /sys/class/block. @@ -434,7 +534,7 @@ static void make_device(char *path, int delete) char *command; char *alias; char aliaslink = aliaslink; /* for compiler */ - const char *node_name; + char *node_name; const struct rule *rule; str_to_match = ""; @@ -456,6 +556,8 @@ static void make_device(char *path, int delete) if (!str_to_match) continue; } else { +//TODO: $DEVNAME can have slashes too, +// we should stop abusing '/' as a special syntax in our regex'es /* regex to match [subsystem/]device_name */ str_to_match = (rule->regex_has_slash ? path : device_name); } @@ -537,7 +639,7 @@ static void make_device(char *path, int delete) /* Are we running this command now? * Run $cmd on delete, @cmd on create, *cmd on both */ - if (s2 - s != delete) { + if (s2 - s != (operation == OP_remove) || *s2 == '*') { /* We are here if: '*', * or: '@' and delete = 0, * or: '$' and delete = 1 @@ -556,8 +658,15 @@ static void make_device(char *path, int delete) dbg("alias2:'%s'", alias); } - if (!delete && major >= 0) { - dbg("mknod('%s',%o,(%d,%d))", node_name, rule->mode | type, major, minor); + if (operation == OP_add && major >= 0) { + char *slash = strrchr(node_name, '/'); + if (slash) { + *slash = '\0'; + bb_make_directory(node_name, 0755, FILEUTILS_RECUR); + *slash = '/'; + } + if (G.verbose) + bb_error_msg("mknod: %s (%d,%d) %o", node_name, major, minor, rule->mode | type); if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST) bb_perror_msg("can't create '%s'", node_name); if (major == G.root_major && minor == G.root_minor) @@ -571,6 +680,8 @@ static void make_device(char *path, int delete) //TODO: on devtmpfs, device_name already exists and symlink() fails. //End result is that instead of symlink, we have two nodes. //What should be done? + if (G.verbose) + bb_error_msg("symlink: %s", device_name); symlink(node_name, device_name); } } @@ -582,17 +693,24 @@ static void make_device(char *path, int delete) char *s1 = xasprintf("%s=%s", "SUBSYSTEM", G.subsystem); putenv(s); putenv(s1); + if (G.verbose) + bb_error_msg("running: %s", command); if (system(command) == -1) bb_perror_msg("can't run '%s'", command); bb_unsetenv_and_free(s1); bb_unsetenv_and_free(s); } - if (delete && major >= -1) { + if (operation == OP_remove && major >= -1) { if (ENABLE_FEATURE_MDEV_RENAME && alias) { - if (aliaslink == '>') + if (aliaslink == '>') { + if (G.verbose) + bb_error_msg("unlink: %s", device_name); unlink(device_name); + } } + if (G.verbose) + bb_error_msg("unlink: %s", node_name); unlink(node_name); } @@ -624,7 +742,7 @@ static int FAST_FUNC fileAction(const char *fileName, strcpy(scratch, fileName); scratch[len] = '\0'; - make_device(scratch, /*delete:*/ 0); + make_device(/*DEVNAME:*/ NULL, scratch, OP_add); return TRUE; } @@ -762,9 +880,8 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) char *fw; char *seq; char *action; - char *env_path; - static const char keywords[] ALIGN1 = "remove\0add\0"; - enum { OP_remove = 0, OP_add }; + char *env_devname; + char *env_devpath; smalluint op; /* Hotplug: @@ -773,9 +890,10 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) * DEVPATH is like "/block/sda" or "/class/input/mice" */ action = getenv("ACTION"); - env_path = getenv("DEVPATH"); + env_devname = getenv("DEVNAME"); /* can be NULL */ + env_devpath = getenv("DEVPATH"); G.subsystem = getenv("SUBSYSTEM"); - if (!action || !env_path /*|| !G.subsystem*/) + if (!action || !env_devpath /*|| !G.subsystem*/) bb_show_usage(); fw = getenv("FIRMWARE"); op = index_in_strings(keywords, action); @@ -804,16 +922,25 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) } while (--timeout); } - snprintf(temp, PATH_MAX, "/sys%s", env_path); + { + int logfd = open("/dev/mdev.log", O_WRONLY | O_APPEND); + if (logfd >= 0) { + xmove_fd(logfd, STDERR_FILENO); + G.verbose = 1; + bb_error_msg("pid: %u seq: %s action: %s", getpid(), seq, action); + } + } + + snprintf(temp, PATH_MAX, "/sys%s", env_devpath); if (op == OP_remove) { /* Ignoring "remove firmware". It was reported * to happen and to cause erroneous deletion * of device nodes. */ if (!fw) - make_device(temp, /*delete:*/ 1); + make_device(env_devname, temp, op); } else if (op == OP_add) { - make_device(temp, /*delete:*/ 0); + make_device(env_devname, temp, op); if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) { if (fw) load_firmware(fw, temp); -- cgit v1.2.3-55-g6feb From 8d118546785bf20963fee979e85fc9393b095082 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 18 May 2012 04:47:18 +0200 Subject: tweak help text Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/mdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 70d19033d..17355bf62 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -92,9 +92,9 @@ //usage: "\n" //usage: "If /dev/mdev.seq file exists, mdev will wait for its value\n" //usage: "to match $SEQNUM variable. This prevents plug/unplug races.\n" -//usage: "To activate this feature, create empty /dev/mdev.seq at boot." +//usage: "To activate this feature, create empty /dev/mdev.seq at boot.\n" //usage: "\n" -//usage: "If /dev/mdev.log file exists, debug log will be appended to it.\n" +//usage: "If /dev/mdev.log file exists, debug log will be appended to it." #include "libbb.h" #include "xregex.h" -- cgit v1.2.3-55-g6feb From ea57f51819a358a6c1309cf028a1a2dcd90dd7a5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 18 May 2012 11:39:57 +0200 Subject: mdev: when found, print major,minor into mdev.log Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- examples/mdev.conf | 10 ++++++++-- examples/mdev_fat.conf | 8 ++++++-- util-linux/mdev.c | 20 ++++++++++++-------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/examples/mdev.conf b/examples/mdev.conf index cdbb4fcfe..51795694d 100644 --- a/examples/mdev.conf +++ b/examples/mdev.conf @@ -7,8 +7,14 @@ # instead of the default 0:0 660. # # Syntax: -# %s %d:%d %s -# devicename_regex user:group mode +# [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] +# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] +# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] +# +# [-]: do not stop on this match, continue reading mdev.conf +# =: move, >: move and create a symlink +# !: do not create device node +# @|$|*: run@cmd if $ACTION=add, $cmd if $ACTION=remove, *cmd in all cases null 0:0 666 zero 0:0 666 diff --git a/examples/mdev_fat.conf b/examples/mdev_fat.conf index df329b4b5..d67912ba1 100644 --- a/examples/mdev_fat.conf +++ b/examples/mdev_fat.conf @@ -7,10 +7,14 @@ # instead of the default 0:0 660. # # Syntax: -# [-]devicename_regex user:group mode [>|=path] [@|$|*cmd args...] +# [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] +# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] +# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] # +# [-]: do not stop on this match, continue reading mdev.conf # =: move, >: move and create a symlink -# @|$|*: run $cmd on delete, @cmd on create, *cmd on both +# !: do not create device node +# @|$|*: run cmd if $ACTION=remove, @cmd if $ACTION=add, *cmd in all cases # support module loading on hotplug $MODALIAS=.* root:root 660 @modprobe "$MODALIAS" diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 70d19033d..101acb78a 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -471,7 +471,7 @@ static void make_device(char *device_name, char *path, int operation) int major, minor, type, len; if (G.verbose) - bb_error_msg("make_device: %s, %s, op:%d", device_name, path, operation); + bb_error_msg("device: %s, %s", device_name, path); /* Try to read major/minor string. Note that the kernel puts \n after * the data, so we don't need to worry about null terminating the string @@ -479,7 +479,7 @@ static void make_device(char *device_name, char *path, int operation) * We also depend on path having writeable space after it. */ major = -1; - if (operation != OP_remove) { + if (operation == OP_add) { char *dev_maj_min = path + strlen(path); strcpy(dev_maj_min, "/dev"); @@ -490,7 +490,10 @@ static void make_device(char *device_name, char *path, int operation) return; /* no "dev" file, but we can still run scripts * based on device name */ - } else if (sscanf(++dev_maj_min, "%u:%u", &major, &minor) != 2) { + } else if (sscanf(++dev_maj_min, "%u:%u", &major, &minor) == 2) { + if (G.verbose) + bb_error_msg("maj,min: %u,%u", major, minor); + } else { major = -1; } } @@ -502,7 +505,8 @@ static void make_device(char *device_name, char *path, int operation) /* http://kernel.org/doc/pending/hotplug.txt says that only * "/sys/block/..." is for block devices. "/sys/bus" etc is not. * But since 2.6.25 block devices are also in /sys/class/block. - * We use strstr("/block/") to forestall future surprises. */ + * We use strstr("/block/") to forestall future surprises. + */ type = S_IFCHR; if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0)) type = S_IFBLK; @@ -669,12 +673,12 @@ static void make_device(char *device_name, char *path, int operation) bb_error_msg("mknod: %s (%d,%d) %o", node_name, major, minor, rule->mode | type); if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST) bb_perror_msg("can't create '%s'", node_name); - if (major == G.root_major && minor == G.root_minor) - symlink(node_name, "root"); if (ENABLE_FEATURE_MDEV_CONF) { chmod(node_name, rule->mode); chown(node_name, rule->ugid.uid, rule->ugid.gid); } + if (major == G.root_major && minor == G.root_minor) + symlink(node_name, "root"); if (ENABLE_FEATURE_MDEV_RENAME && alias) { if (aliaslink == '>') { //TODO: on devtmpfs, device_name already exists and symlink() fails. @@ -890,13 +894,13 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) * DEVPATH is like "/block/sda" or "/class/input/mice" */ action = getenv("ACTION"); + op = index_in_strings(keywords, action); env_devname = getenv("DEVNAME"); /* can be NULL */ env_devpath = getenv("DEVPATH"); G.subsystem = getenv("SUBSYSTEM"); if (!action || !env_devpath /*|| !G.subsystem*/) bb_show_usage(); fw = getenv("FIRMWARE"); - op = index_in_strings(keywords, action); /* If it exists, does /dev/mdev.seq match $SEQNUM? * If it does not match, earlier mdev is running * in parallel, and we need to wait */ @@ -927,7 +931,7 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) if (logfd >= 0) { xmove_fd(logfd, STDERR_FILENO); G.verbose = 1; - bb_error_msg("pid: %u seq: %s action: %s", getpid(), seq, action); + bb_error_msg("seq: %s action: %s", seq, action); } } -- cgit v1.2.3-55-g6feb From b6beada5a1432645090b441531b5909983cfbf10 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 18 May 2012 15:11:16 +0200 Subject: mdev: remove undocumented subsystem/devname matching hack It was colliding with matching of devnames with slashes. We need a more generic way to examine env.vars in rules anyway. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- examples/mdev_fat.conf | 1 - util-linux/mdev.c | 31 ++----------------------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/examples/mdev_fat.conf b/examples/mdev_fat.conf index d67912ba1..ceba3a797 100644 --- a/examples/mdev_fat.conf +++ b/examples/mdev_fat.conf @@ -53,7 +53,6 @@ sr[0-9]* root:cdrom 660 @ln -sf $MDEV cdrom fd[0-9]* root:floppy 660 # net devices --net/.* root:root 600 @nameif tun[0-9]* root:root 600 =net/ tap[0-9]* root:root 600 =net/ diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 101acb78a..6603a7d79 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -236,7 +236,6 @@ enum { OP_add, OP_remove }; struct rule { bool keep_matching; bool regex_compiled; - bool regex_has_slash; mode_t mode; int maj, min0, min1; struct bb_uidgid_t ugid; @@ -340,7 +339,6 @@ static void parse_next_rule(void) } xregcomp(&G.cur_rule.match, val, REG_EXTENDED); G.cur_rule.regex_compiled = 1; - G.cur_rule.regex_has_slash = (strchr(val, '/') != NULL); } /* 2nd field: uid:gid - device ownership */ @@ -467,7 +465,6 @@ static char *build_alias(char *alias, const char *device_name) */ static void make_device(char *device_name, char *path, int operation) { - char *subsystem_slash_devname; int major, minor, type, len; if (G.verbose) @@ -511,24 +508,6 @@ static void make_device(char *device_name, char *path, int operation) if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0)) type = S_IFBLK; - /* Make path point to "subsystem/device_name" */ - subsystem_slash_devname = NULL; - /* Check for coldplug invocations first */ - if (strncmp(path, "/sys/block/", 11) == 0) /* legacy case */ - path += sizeof("/sys/") - 1; - else if (strncmp(path, "/sys/class/", 11) == 0) - path += sizeof("/sys/class/") - 1; - else { - /* Example of a hotplug invocation: - * SUBSYSTEM="block" - * DEVPATH="/sys" + "/devices/virtual/mtd/mtd3/mtdblock3" - * ("/sys" is added by mdev_main) - * - path does not contain subsystem - */ - subsystem_slash_devname = concat_path_file(G.subsystem, device_name); - path = subsystem_slash_devname; - } - #if ENABLE_FEATURE_MDEV_CONF G.rule_idx = 0; /* restart from the beginning (think mdev -s) */ #endif @@ -541,7 +520,7 @@ static void make_device(char *device_name, char *path, int operation) char *node_name; const struct rule *rule; - str_to_match = ""; + str_to_match = device_name; rule = next_rule(); @@ -559,12 +538,8 @@ static void make_device(char *device_name, char *path, int operation) dbg("getenv('%s'):'%s'", rule->envvar, str_to_match); if (!str_to_match) continue; - } else { -//TODO: $DEVNAME can have slashes too, -// we should stop abusing '/' as a special syntax in our regex'es - /* regex to match [subsystem/]device_name */ - str_to_match = (rule->regex_has_slash ? path : device_name); } + /* else: str_to_match = device_name */ if (rule->regex_compiled) { int regex_match = regexec(&rule->match, str_to_match, ARRAY_SIZE(off), off, 0); @@ -727,8 +702,6 @@ static void make_device(char *device_name, char *path, int operation) if (!ENABLE_FEATURE_MDEV_CONF || !rule->keep_matching) break; } /* for (;;) */ - - free(subsystem_slash_devname); } /* File callback for /sys/ traversal */ -- cgit v1.2.3-55-g6feb From 044610413767eda4350c5adf35cf5e69a6d6df8f Mon Sep 17 00:00:00 2001 From: Natanael Copa <natanael.copa@gmail.com> Date: Tue, 24 Apr 2012 17:06:19 +0200 Subject: tar: implement --no-recursion function old new delta tar_longopts 259 274 +15 .rodata 5757 5772 +15 tar_main 1038 1052 +14 writeTarFile 362 353 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 44/-9) Total: 35 bytes text data bss dec hex filename 81457 1706 8344 91507 16573 busybox_old 81477 1706 8344 91527 16587 busybox_unstripped Signed-off-by: Natanael Copa <natanael.copa@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/tar.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/archival/tar.c b/archival/tar.c index cf972c24c..a64d6510f 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -60,8 +60,8 @@ #if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2 /* Do not pass gzip flag to writeTarFile() */ -#define writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude, gzip) \ - writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude) +#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \ + writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude) #endif @@ -598,7 +598,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip) /* gcc 4.2.1 inlines it, making code bigger */ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, - int dereferenceFlag, const llist_t *include, + int recurseFlags, const llist_t *include, const llist_t *exclude, int gzip) { int errorFlag = FALSE; @@ -621,8 +621,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, /* Read the directory/files and iterate over them one at a time */ while (include) { - if (!recursive_action(include->data, ACTION_RECURSE | - (dereferenceFlag ? ACTION_FOLLOWLINKS : 0), + if (!recursive_action(include->data, recurseFlags, writeFileToTarball, writeFileToTarball, &tbInfo, 0) ) { errorFlag = TRUE; @@ -662,7 +661,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, } #else int writeTarFile(int tar_fd, int verboseFlag, - int dereferenceFlag, const llist_t *include, + int recurseFlags, const llist_t *include, const llist_t *exclude, int gzip); #endif /* FEATURE_TAR_CREATE */ @@ -749,6 +748,7 @@ static llist_t *append_file_list_to_list(llist_t *list) // o no-same-owner // p same-permissions // k keep-old +// no-recursion // numeric-owner // no-same-permissions // overwrite @@ -768,6 +768,7 @@ enum { IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,) #if ENABLE_FEATURE_TAR_LONG_OPTIONS + OPTBIT_NORECURSION, IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,) OPTBIT_NUMERIC_OWNER, OPTBIT_NOPRESERVE_PERM, @@ -791,6 +792,7 @@ enum { OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m + OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions @@ -835,6 +837,7 @@ static const char tar_longopts[] ALIGN1 = # if ENABLE_FEATURE_TAR_NOPRESERVE_TIME "touch\0" No_argument "m" # endif + "no-recursion\0" No_argument "\xfa" # if ENABLE_FEATURE_TAR_TO_COMMAND "to-command\0" Required_argument "\xfb" # endif @@ -1050,7 +1053,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv) zipMode = 2; #endif /* NB: writeTarFile() closes tar_handle->src_fd */ - return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE, + return writeTarFile(tar_handle->src_fd, verboseFlag, + (opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0) + | (opt & OPT_NORECURSION ? 0 : ACTION_RECURSE), tar_handle->accept, tar_handle->reject, zipMode); } -- cgit v1.2.3-55-g6feb From 25cb5aae2b7b0014b6476e7db62e204a00242762 Mon Sep 17 00:00:00 2001 From: Christoph Lohmann <20h@r-36.net> Date: Sat, 19 May 2012 23:39:45 +0200 Subject: mdev: tell kernel that we didn't find the firmware function old new delta mdev_main 797 801 +4 Signed-off-by: Christoph Lohmann <20h@r-36.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/mdev.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 84e72e2e6..79871d30e 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -756,37 +756,45 @@ static int FAST_FUNC dirAction(const char *fileName UNUSED_PARAM, static void load_firmware(const char *firmware, const char *sysfs_path) { int cnt; - int firmware_fd, loading_fd, data_fd; + int firmware_fd, loading_fd; /* check for /lib/firmware/$FIRMWARE */ xchdir("/lib/firmware"); - firmware_fd = xopen(firmware, O_RDONLY); - - /* in case we goto out ... */ - data_fd = -1; + firmware_fd = open(firmware, O_RDONLY); /* can fail */ /* check for /sys/$DEVPATH/loading ... give 30 seconds to appear */ xchdir(sysfs_path); for (cnt = 0; cnt < 30; ++cnt) { loading_fd = open("loading", O_WRONLY); - if (loading_fd != -1) + if (loading_fd >= 0) goto loading; sleep(1); } goto out; loading: - /* tell kernel we're loading by "echo 1 > /sys/$DEVPATH/loading" */ - if (full_write(loading_fd, "1", 1) != 1) - goto out; - - /* load firmware into /sys/$DEVPATH/data */ - data_fd = open("data", O_WRONLY); - if (data_fd == -1) - goto out; - cnt = bb_copyfd_eof(firmware_fd, data_fd); + cnt = 0; + if (firmware_fd >= 0) { + int data_fd; + + /* tell kernel we're loading by "echo 1 > /sys/$DEVPATH/loading" */ + if (full_write(loading_fd, "1", 1) != 1) + goto out; + + /* load firmware into /sys/$DEVPATH/data */ + data_fd = open("data", O_WRONLY); + if (data_fd < 0) + goto out; + cnt = bb_copyfd_eof(firmware_fd, data_fd); + if (ENABLE_FEATURE_CLEAN_UP) + close(data_fd); + } - /* tell kernel result by "echo [0|-1] > /sys/$DEVPATH/loading" */ + /* Tell kernel result by "echo [0|-1] > /sys/$DEVPATH/loading" + * Note: we emit -1 also if firmware file wasn't found. + * There are cases when otherwise kernel would wait for minutes + * before timing out. + */ if (cnt > 0) full_write(loading_fd, "0", 1); else @@ -796,7 +804,6 @@ static void load_firmware(const char *firmware, const char *sysfs_path) if (ENABLE_FEATURE_CLEAN_UP) { close(firmware_fd); close(loading_fd); - close(data_fd); } } -- cgit v1.2.3-55-g6feb From 6e9284db78ddfe8d7dcf3775aed78665099f827f Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" <blueness@gentoo.org> Date: Sun, 20 May 2012 12:56:17 +0200 Subject: build system: fix build failure when only gunzip is selected Signed-off-by: Anthony G. Basile <blueness@gentoo.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/libarchive/Kbuild.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src index e2134be4c..58457fc22 100644 --- a/archival/libarchive/Kbuild.src +++ b/archival/libarchive/Kbuild.src @@ -45,7 +45,7 @@ lib-$(CONFIG_UNXZ) += decompress_unxz.o lib-$(CONFIG_CPIO) += get_header_cpio.o lib-$(CONFIG_DPKG) += $(DPKG_FILES) lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES) -lib-$(CONFIG_GUNZIP) += decompress_gunzip.o +lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o lib-$(CONFIG_RPM2CPIO) += decompress_gunzip.o get_header_cpio.o lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o lib-$(CONFIG_TAR) += get_header_tar.o -- cgit v1.2.3-55-g6feb From dfc2473b9ed88039697ac89ee2a4301cdaefcf84 Mon Sep 17 00:00:00 2001 From: Boris Reisig <boris@boris.ca> Date: Thu, 24 May 2012 09:01:55 +0200 Subject: tar: support -J, --xz explicit compression option function old new delta tar_main 868 881 +13 tar_longopts 285 290 +5 packed_usage 29267 29270 +3 Signed-off-by: Boris Reisig <boris@boris.ca> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/tar.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/archival/tar.c b/archival/tar.c index a64d6510f..a3565d6ae 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -693,6 +693,7 @@ static llist_t *append_file_list_to_list(llist_t *list) //usage: "-[" IF_FEATURE_TAR_CREATE("c") "xt" //usage: IF_FEATURE_SEAMLESS_Z("Z") //usage: IF_FEATURE_SEAMLESS_GZ("z") +//usage: IF_FEATURE_SEAMLESS_XZ("J") //usage: IF_FEATURE_SEAMLESS_BZ2("j") //usage: IF_FEATURE_SEAMLESS_LZMA("a") //usage: IF_FEATURE_TAR_CREATE("h") @@ -719,6 +720,9 @@ static llist_t *append_file_list_to_list(llist_t *list) //usage: IF_FEATURE_SEAMLESS_GZ( //usage: "\n z (De)compress using gzip" //usage: ) +//usage: IF_FEATURE_SEAMLESS_XZ( +//usage: "\n J (De)compress using xz" +//usage: ) //usage: IF_FEATURE_SEAMLESS_BZ2( //usage: "\n j (De)compress using bzip2" //usage: ) @@ -765,7 +769,8 @@ enum { IF_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,) IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,) IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,) - IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit + IF_FEATURE_SEAMLESS_XZ( OPTBIT_XZ ,) // 16th bit + IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,) #if ENABLE_FEATURE_TAR_LONG_OPTIONS OPTBIT_NORECURSION, @@ -790,6 +795,7 @@ enum { OPT_INCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_INCLUDE_FROM)) + 0, // T OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z + OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion @@ -798,7 +804,7 @@ enum { OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite - OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_COMPRESS), + OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS), }; #if ENABLE_FEATURE_TAR_LONG_OPTIONS static const char tar_longopts[] ALIGN1 = @@ -831,6 +837,9 @@ static const char tar_longopts[] ALIGN1 = # if ENABLE_FEATURE_SEAMLESS_GZ "gzip\0" No_argument "z" # endif +# if ENABLE_FEATURE_SEAMLESS_XZ + "xz\0" No_argument "J" +# endif # if ENABLE_FEATURE_SEAMLESS_Z "compress\0" No_argument "Z" # endif @@ -924,6 +933,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_SEAMLESS_LZMA("a" ) IF_FEATURE_TAR_FROM( "T:X:") IF_FEATURE_SEAMLESS_GZ( "z" ) + IF_FEATURE_SEAMLESS_XZ( "J" ) IF_FEATURE_SEAMLESS_Z( "Z" ) IF_FEATURE_TAR_NOPRESERVE_TIME("m") , &base_dir // -C dir @@ -1076,6 +1086,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_LZMA) USE_FOR_MMU(xformer = unpack_lzma_stream;) USE_FOR_NOMMU(xformer_prog = "unlzma";) + if (opt & OPT_XZ) + USE_FOR_MMU(xformer = unpack_xz_stream;) + USE_FOR_NOMMU(xformer_prog = "unxz";) open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog); /* Can't lseek over pipes */ -- cgit v1.2.3-55-g6feb From 02112d8ae3d0c07214fb2b132e0eacb4ff39d167 Mon Sep 17 00:00:00 2001 From: Natanael Copa <natanael.copa@gmail.com> Date: Tue, 22 May 2012 17:11:46 +0200 Subject: unzip: ignore chmod errors This makes unzip to FAT filesystems not exit with error. This is similar to how the "normal" unzip works. Signed-off-by: Natanael Copa <natanael.copa@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/unzip.c | 2 +- include/libbb.h | 1 + libbb/make_directory.c | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/archival/unzip.c b/archival/unzip.c index 3c76cdafc..c1b945a44 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -596,7 +596,7 @@ int unzip_main(int argc, char **argv) printf(" creating: %s\n", dst_fn); } unzip_create_leading_dirs(dst_fn); - if (bb_make_directory(dst_fn, dir_mode, 0)) { + if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) { xfunc_die(); } } else { diff --git a/include/libbb.h b/include/libbb.h index f12800f53..5e5c8c7e8 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -333,6 +333,7 @@ enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */ FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 9, /* -c */ FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10, #endif + FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11, }; #define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c") extern int remove_file(const char *path, int flags) FAST_FUNC; diff --git a/libbb/make_directory.c b/libbb/make_directory.c index 72303e7a3..7826b90f5 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c @@ -107,6 +107,10 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags) * an error. */ if ((mode != -1) && (chmod(path, mode) < 0)) { fail_msg = "set permissions of"; + if (flags & FILEUTILS_IGNORE_CHMOD_ERR) { + flags = 0; + goto print_err; + } break; } goto ret0; @@ -116,8 +120,9 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags) *s = c; } /* while (1) */ - bb_perror_msg("can't %s directory '%s'", fail_msg, path); flags = -1; + print_err: + bb_perror_msg("can't %s directory '%s'", fail_msg, path); goto ret; ret0: flags = 0; -- cgit v1.2.3-55-g6feb From 085b2933384290421a0a80fd6ac98dbf1c04095b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sat, 2 Jun 2012 23:53:53 +0200 Subject: udhcpc[6]: show select timeout in log Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/udhcp/d6_dhcpc.c | 2 +- networking/udhcp/dhcpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 7c9f52ae7..d9d8b9b56 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -1066,8 +1066,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) retval = 0; /* If we already timed out, fall through with retval = 0, else... */ if ((int)tv.tv_sec > 0) { + log1("Waiting on select %u seconds", (int)tv.tv_sec); timestamp_before_wait = (unsigned)monotonic_sec(); - log1("Waiting on select..."); retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); if (retval < 0) { /* EINTR? A signal was caught, don't panic */ diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index ddb328dd5..4e7bd4bbc 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1362,8 +1362,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) retval = 0; /* If we already timed out, fall through with retval = 0, else... */ if ((int)tv.tv_sec > 0) { + log1("Waiting on select %u seconds", (int)tv.tv_sec); timestamp_before_wait = (unsigned)monotonic_sec(); - log1("Waiting on select..."); retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); if (retval < 0) { /* EINTR? A signal was caught, don't panic */ -- cgit v1.2.3-55-g6feb From 21f620f6e5f72c4cbecfecaf63a901c33911c00c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 3 Jun 2012 10:26:16 +0200 Subject: ifplugd: tweak help text Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/ifplugd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/networking/ifplugd.c b/networking/ifplugd.c index d8358cdfd..88bf448fa 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c @@ -22,9 +22,9 @@ //usage: "\n -r PROG Script to run" //usage: "\n -x ARG Extra argument for script" //usage: "\n -I Don't exit on nonzero exit code from script" -//usage: "\n -p Don't run script on daemon startup" -//usage: "\n -q Don't run script on daemon quit" -//usage: "\n -l Run script on startup even if no cable is detected" +//usage: "\n -p Don't run \"up\" script on startup" +//usage: "\n -q Don't run \"down\" script on exit" +//usage: "\n -l Always run script on startup" //usage: "\n -t SECS Poll time in seconds" //usage: "\n -u SECS Delay before running script after link up" //usage: "\n -d SECS Delay after link down" -- cgit v1.2.3-55-g6feb From 21f6fbf545e7fa58f0eaa444001a9d25bc37c4eb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 4 Jun 2012 14:44:47 +0200 Subject: sed: fix zero chars match/replace function old new delta process_files 2099 2181 +82 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/sed.c | 64 +++++++++++++++++++++++++++++++++++------------------ testsuite/sed.tests | 10 +++++++-- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index a2df93165..87fc755eb 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -673,7 +673,7 @@ static void do_subst_w_backrefs(char *line, char *replace) /* go through the replacement string */ for (i = 0; replace[i]; i++) { - /* if we find a backreference (\1, \2, etc.) print the backref'ed * text */ + /* if we find a backreference (\1, \2, etc.) print the backref'ed text */ if (replace[i] == '\\') { unsigned backref = replace[++i] - '0'; if (backref <= 9) { @@ -707,8 +707,10 @@ static void do_subst_w_backrefs(char *line, char *replace) static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) { char *line = *line_p; - int altered = 0; unsigned match_count = 0; + bool altered = 0; + bool prev_match_empty = 1; + bool tried_at_eol = 0; regex_t *current_regex; current_regex = sed_cmd->sub_match; @@ -737,46 +739,64 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) do { int i; - /* Work around bug in glibc regexec, demonstrated by: - * echo " a.b" | busybox sed 's [^ .]* x g' - * The match_count check is so not to break - * echo "hi" | busybox sed 's/^/!/g' - */ - if (!G.regmatch[0].rm_so && !G.regmatch[0].rm_eo && match_count) { - pipe_putc(*line++); - goto next; - } - match_count++; /* If we aren't interested in this match, output old line to - end of match and continue */ + * end of match and continue */ if (sed_cmd->which_match && (sed_cmd->which_match != match_count) ) { for (i = 0; i < G.regmatch[0].rm_eo; i++) pipe_putc(*line++); + /* Null match? Print one more char */ + if (G.regmatch[0].rm_so == i && *line) + pipe_putc(*line++); goto next; } - /* print everything before the match */ + /* Print everything before the match */ for (i = 0; i < G.regmatch[0].rm_so; i++) pipe_putc(line[i]); - /* then print the substitution string */ - do_subst_w_backrefs(line, sed_cmd->string); + /* Then print the substitution string, + * unless we just matched empty string after non-empty one. + * Example: string "cccd", pattern "c*", repl "R": + * result is "RdR", not "RRdR": first match "ccc", + * second is "" before "d", third is "" after "d". + * Second match is NOT replaced! + */ + if (prev_match_empty || i != 0) { + dbg("inserting replacement at %d in '%s'", i, line); + do_subst_w_backrefs(line, sed_cmd->string); + } else { + dbg("NOT inserting replacement at %d in '%s'", i, line); + } + + /* If matched string is empty (f.e. "c*" pattern), + * copy verbatim one char after it before attempting more matches + */ + prev_match_empty = (G.regmatch[0].rm_eo == i); + if (prev_match_empty && line[i]) { + pipe_putc(line[i]); + G.regmatch[0].rm_eo++; + } - /* advance past the match */ + /* Advance past the match */ + dbg("line += %d", G.regmatch[0].rm_eo); line += G.regmatch[0].rm_eo; - /* flag that something has changed */ - altered++; + /* Flag that something has changed */ + altered = 1; /* if we're not doing this globally, get out now */ if (sed_cmd->which_match != 0) break; next: - if (*line == '\0') - break; + /* Exit if we are at EOL and already tried matching at it */ + if (*line == '\0') { + if (tried_at_eol) + break; + tried_at_eol = 1; + } //maybe (G.regmatch[0].rm_eo ? REG_NOTBOL : 0) instead of unconditional REG_NOTBOL? } while (regexec(current_regex, line, 10, G.regmatch, REG_NOTBOL) != REG_NOMATCH); @@ -1127,7 +1147,7 @@ static void process_files(void) case 's': if (!do_subst_command(sed_cmd, &pattern_space)) break; - dbg("do_subst_command succeeeded:'%s'", pattern_space); + dbg("do_subst_command succeeded:'%s'", pattern_space); substituted |= 1; /* handle p option */ diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 9fa8e190c..375beb518 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -52,10 +52,8 @@ testing "sed with empty match" "sed 's/z*//g'" "string\n" "" "string\n" testing "sed s//p" "sed -e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \ "" "foo\n" testing "sed -n s//p" "sed -ne s/abc/def/p" "def\n" "" "abc\n" -test x"$SKIP_KNOWN_BUGS" = x"" && { testing "sed s//g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \ "" "12345\n" -} testing "sed s arbitrary delimiter" "sed -e 's woo boing '" "boing\n" "" "woo\n" testing "sed s chains" "sed -e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n" testing "sed s chains2" "sed -e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n" @@ -296,6 +294,14 @@ testing "sed -i finishes ranges correctly" \ "sed '1,2d' -i input; echo \$?; cat input" \ "0\n3\n4\n" "1\n2\n3\n4\n" "" +testing "sed zero chars match/replace advances correctly 1" \ + "sed 's/l*/@/g'" \ + "@h@e@o@\n" "" "helllo\n" + +testing "sed zero chars match/replace advances correctly 2" \ + "sed 's [^ .]* x g'" \ + "x x.x\n" "" " a.b\n" + # testing "description" "commands" "result" "infile" "stdin" exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From c35545a100c08d26d49fd1c2ca10e56e6650c5c1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 4 Jun 2012 14:45:09 +0200 Subject: sed: code shrink function old new delta process_files 2181 2173 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/sed.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 87fc755eb..85c84665b 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -737,6 +737,8 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) /* Now loop through, substituting for matches */ do { + int start = G.regmatch[0].rm_so; + int end = G.regmatch[0].rm_eo; int i; match_count++; @@ -746,16 +748,16 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) if (sed_cmd->which_match && (sed_cmd->which_match != match_count) ) { - for (i = 0; i < G.regmatch[0].rm_eo; i++) + for (i = 0; i < end; i++) pipe_putc(*line++); /* Null match? Print one more char */ - if (G.regmatch[0].rm_so == i && *line) + if (start == end && *line) pipe_putc(*line++); goto next; } /* Print everything before the match */ - for (i = 0; i < G.regmatch[0].rm_so; i++) + for (i = 0; i < start; i++) pipe_putc(line[i]); /* Then print the substitution string, @@ -765,25 +767,25 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) * second is "" before "d", third is "" after "d". * Second match is NOT replaced! */ - if (prev_match_empty || i != 0) { - dbg("inserting replacement at %d in '%s'", i, line); + if (prev_match_empty || start != 0) { + dbg("inserting replacement at %d in '%s'", start, line); do_subst_w_backrefs(line, sed_cmd->string); } else { - dbg("NOT inserting replacement at %d in '%s'", i, line); + dbg("NOT inserting replacement at %d in '%s'", start, line); } /* If matched string is empty (f.e. "c*" pattern), * copy verbatim one char after it before attempting more matches */ - prev_match_empty = (G.regmatch[0].rm_eo == i); - if (prev_match_empty && line[i]) { - pipe_putc(line[i]); - G.regmatch[0].rm_eo++; + prev_match_empty = (start == end); + if (prev_match_empty && line[end]) { + pipe_putc(line[end]); + end++; } /* Advance past the match */ - dbg("line += %d", G.regmatch[0].rm_eo); - line += G.regmatch[0].rm_eo; + dbg("line += %d", end); + line += end; /* Flag that something has changed */ altered = 1; @@ -798,7 +800,7 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) tried_at_eol = 1; } -//maybe (G.regmatch[0].rm_eo ? REG_NOTBOL : 0) instead of unconditional REG_NOTBOL? +//maybe (end ? REG_NOTBOL : 0) instead of unconditional REG_NOTBOL? } while (regexec(current_regex, line, 10, G.regmatch, REG_NOTBOL) != REG_NOMATCH); /* Copy rest of string into output pipeline */ -- cgit v1.2.3-55-g6feb From 84406e459be31b89de5a3d822f205d61c4c5855b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 7 Jun 2012 16:34:57 +0200 Subject: sed: fix breakage added by zero length match code Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/sed.c | 2 +- testsuite/sed.tests | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/editors/sed.c b/editors/sed.c index 85c84665b..0fe82f337 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -767,7 +767,7 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) * second is "" before "d", third is "" after "d". * Second match is NOT replaced! */ - if (prev_match_empty || start != 0) { + if (prev_match_empty || start != 0 || start != end) { dbg("inserting replacement at %d in '%s'", start, line); do_subst_w_backrefs(line, sed_cmd->string); } else { diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 375beb518..12b36ae18 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -302,6 +302,10 @@ testing "sed zero chars match/replace advances correctly 2" \ "sed 's [^ .]* x g'" \ "x x.x\n" "" " a.b\n" +testing "sed zero chars match/replace logic must not falsely trigger here" \ + "sed 's/a/A/g'" \ + "_AAA1AA\n" "" "_aaa1aa\n" + # testing "description" "commands" "result" "infile" "stdin" exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From ba1d561d767a6f05da62adadc798f98118b2a3ee Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 8 Jun 2012 10:22:05 +0200 Subject: man: fix handling of gzipped manpages Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- miscutils/man.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/miscutils/man.c b/miscutils/man.c index 611466349..e380fdaba 100644 --- a/miscutils/man.c +++ b/miscutils/man.c @@ -129,27 +129,21 @@ static int show_manpage(const char *pager, char *man_filename, int man, int leve #endif #if ENABLE_FEATURE_SEAMLESS_XZ strcpy(ext, "xz"); - if (run_pipe(pager, man_filename, man, level)) + if (run_pipe(pager, filename_with_zext, man, level)) return 1; #endif #if ENABLE_FEATURE_SEAMLESS_BZ2 strcpy(ext, "bz2"); - if (run_pipe(pager, man_filename, man, level)) + if (run_pipe(pager, filename_with_zext, man, level)) return 1; #endif #if ENABLE_FEATURE_SEAMLESS_GZ strcpy(ext, "gz"); - if (run_pipe(pager, man_filename, man, level)) + if (run_pipe(pager, filename_with_zext, man, level)) return 1; #endif -#if SEAMLESS_COMPRESSION - ext[-1] = '\0'; -#endif - if (run_pipe(pager, man_filename, man, level)) - return 1; - - return 0; + return run_pipe(pager, man_filename, man, level); } int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -- cgit v1.2.3-55-g6feb From 37ca36a71114a6fc5303d33cabc311cd8b9bf19a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 8 Jun 2012 10:25:31 +0200 Subject: sed: yet another fix on top of zero length match code Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/sed.c | 15 ++++++++++----- testsuite/sed.tests | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 0fe82f337..652aaf573 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -768,8 +768,11 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) * Second match is NOT replaced! */ if (prev_match_empty || start != 0 || start != end) { + //dbg("%d %d %d", prev_match_empty, start, end); dbg("inserting replacement at %d in '%s'", start, line); do_subst_w_backrefs(line, sed_cmd->string); + /* Flag that something has changed */ + altered = 1; } else { dbg("NOT inserting replacement at %d in '%s'", start, line); } @@ -778,16 +781,18 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p) * copy verbatim one char after it before attempting more matches */ prev_match_empty = (start == end); - if (prev_match_empty && line[end]) { - pipe_putc(line[end]); - end++; + if (prev_match_empty) { + if (!line[end]) { + tried_at_eol = 1; + } else { + pipe_putc(line[end]); + end++; + } } /* Advance past the match */ dbg("line += %d", end); line += end; - /* Flag that something has changed */ - altered = 1; /* if we're not doing this globally, get out now */ if (sed_cmd->which_match != 0) diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 12b36ae18..468565f47 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -302,10 +302,14 @@ testing "sed zero chars match/replace advances correctly 2" \ "sed 's [^ .]* x g'" \ "x x.x\n" "" " a.b\n" -testing "sed zero chars match/replace logic must not falsely trigger here" \ +testing "sed zero chars match/replace logic must not falsely trigger here 1" \ "sed 's/a/A/g'" \ "_AAA1AA\n" "" "_aaa1aa\n" +testing "sed zero chars match/replace logic must not falsely trigger here 2" \ + "sed 's/ *$/_/g'" \ + "qwerty_\n" "" "qwerty\n" + # testing "description" "commands" "result" "infile" "stdin" exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From f451b2cfe042e3029b73261758b9ab7e956eaa03 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sat, 9 Jun 2012 02:06:57 +0200 Subject: ash: fix a bug in >${varexp} handling. Closes 5282 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- shell/ash.c | 23 +++++++++++++---------- shell/ash_test/ash-redir/redirA.right | 2 ++ shell/ash_test/ash-redir/redirA.tests | 11 +++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 shell/ash_test/ash-redir/redirA.right create mode 100755 shell/ash_test/ash-redir/redirA.tests diff --git a/shell/ash.c b/shell/ash.c index d197fa19a..e23b2034d 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -23,8 +23,9 @@ * define DEBUG=1 to compile in debugging ('set -o debug' to turn on) * define DEBUG=2 to compile in and turn on debugging. * - * When debugging is on, debugging info will be written to ./trace and - * a quit signal will generate a core dump. + * When debugging is on (DEBUG is 1 and "set -o debug" was executed), + * debugging info will be written to ./trace and a quit signal + * will generate a core dump. */ #define DEBUG 0 /* Tweak debug output verbosity here */ @@ -5105,15 +5106,14 @@ openredirect(union node *redir) char *fname; int f; + fname = redir->nfile.expfname; switch (redir->nfile.type) { case NFROM: - fname = redir->nfile.expfname; f = open(fname, O_RDONLY); if (f < 0) goto eopen; break; case NFROMTO: - fname = redir->nfile.expfname; f = open(fname, O_RDWR|O_CREAT, 0666); if (f < 0) goto ecreate; @@ -5124,7 +5124,6 @@ openredirect(union node *redir) #endif /* Take care of noclobber mode. */ if (Cflag) { - fname = redir->nfile.expfname; f = noclobberopen(fname); if (f < 0) goto ecreate; @@ -5132,13 +5131,11 @@ openredirect(union node *redir) } /* FALLTHROUGH */ case NCLOBBER: - fname = redir->nfile.expfname; f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666); if (f < 0) goto ecreate; break; case NAPPEND: - fname = redir->nfile.expfname; f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666); if (f < 0) goto ecreate; @@ -6138,7 +6135,9 @@ argstr(char *p, int flags, struct strlist *var_str_list) length++; goto addquote; case CTLVAR: + TRACE(("argstr: evalvar('%s')\n", p)); p = evalvar(p, flags, var_str_list); + TRACE(("argstr: evalvar:'%s'\n", (char *)stackblock())); goto start; case CTLBACKQ: c = '\0'; @@ -6846,8 +6845,7 @@ evalvar(char *p, int flags, struct strlist *var_str_list) patloc = expdest - (char *)stackblock(); if (NULL == subevalvar(p, /* varname: */ NULL, patloc, subtype, startloc, varflags, -//TODO: | EXP_REDIR too? All other such places do it too - /* quotes: */ flags & (EXP_FULL | EXP_CASE), + /* quotes: */ flags & (EXP_FULL | EXP_CASE | EXP_REDIR), var_str_list) ) { int amount = expdest - ( @@ -7249,6 +7247,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag) STARTSTACKSTR(expdest); ifsfirst.next = NULL; ifslastp = NULL; + TRACE(("expandarg: argstr('%s',flags:%x)\n", arg->narg.text, flag)); argstr(arg->narg.text, flag, /* var_str_list: */ arglist ? arglist->list : NULL); p = _STPUTC('\0', expdest); @@ -7257,6 +7256,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag) return; /* here document expanded */ } p = grabstackstr(p); + TRACE(("expandarg: p:'%s'\n", p)); exparg.lastp = &exparg.list; /* * TODO - EXP_REDIR @@ -7267,8 +7267,10 @@ expandarg(union node *arg, struct arglist *arglist, int flag) exparg.lastp = &exparg.list; expandmeta(exparg.list /*, flag*/); } else { - if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ + if (flag & EXP_REDIR) { /*XXX - for now, just remove escapes */ rmescapes(p, 0); + TRACE(("expandarg: rmescapes:'%s'\n", p)); + } sp = stzalloc(sizeof(*sp)); sp->text = p; *exparg.lastp = sp; @@ -8665,6 +8667,7 @@ expredir(union node *n) case NCLOBBER: case NAPPEND: expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR); + TRACE(("expredir expanded to '%s'\n", fn.list->text)); #if ENABLE_ASH_BASH_COMPAT store_expfname: #endif diff --git a/shell/ash_test/ash-redir/redirA.right b/shell/ash_test/ash-redir/redirA.right new file mode 100644 index 000000000..31406e336 --- /dev/null +++ b/shell/ash_test/ash-redir/redirA.right @@ -0,0 +1,2 @@ +tmp11 +tmp11 diff --git a/shell/ash_test/ash-redir/redirA.tests b/shell/ash_test/ash-redir/redirA.tests new file mode 100755 index 000000000..56833f938 --- /dev/null +++ b/shell/ash_test/ash-redir/redirA.tests @@ -0,0 +1,11 @@ +x="tmp11:tmp22" + +# Bug was incorrectly expanding variables in >redir +echo "${x%:*}" >"${x%:*}" +echo tmp1* +rm tmp1* + +# Also try unquoted +echo "${x%:*}" >${x%:*} +echo tmp1* +rm tmp1* -- cgit v1.2.3-55-g6feb From cfc212cdfff27c6a7b9d9743f87c4da70f97558c Mon Sep 17 00:00:00 2001 From: Etienne Le Sueur <elesueur@vmware.com> Date: Sat, 9 Jun 2012 08:37:05 +0200 Subject: tar: fix 256-bit encoded number decoding Signed-off-by: Etienne Le Sueur <elesueur@vmware.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/libarchive/get_header_tar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index 80a709144..b168653d8 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c @@ -84,7 +84,7 @@ static unsigned long long getOctal(char *str, int len) first >>= 1; /* now 7th bit = 6th bit */ v = first; /* sign-extend 8 bits to 64 */ while (--len != 0) - v = (v << 8) + (unsigned char) *str++; + v = (v << 8) + (uint8_t) *++str; } return v; } -- cgit v1.2.3-55-g6feb From 52de9c7141f3dc6dbb801a9d1d1429238917ee4a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 10 Jun 2012 13:47:17 +0200 Subject: lpr: don't send 0-byte print jobs (compat) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- printutils/lpr.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/printutils/lpr.c b/printutils/lpr.c index 748879542..70cda7717 100644 --- a/printutils/lpr.c +++ b/printutils/lpr.c @@ -89,6 +89,10 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[]) unsigned opts; int fd; + queue = getenv("PRINTER"); + if (!queue) + queue = "lp"; + // parse options // TODO: set opt_complementary: s,d,f are mutually exclusive opts = getopt32(argv, @@ -98,16 +102,7 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[]) ); argv += optind; - // if queue is not specified -> use $PRINTER - if (!(opts & OPT_P)) - queue = getenv("PRINTER"); - // if queue is still not specified -> - if (!queue) { - // ... queue defaults to "lp" - // server defaults to "localhost" - queue = "lp"; - // if queue is specified -> - } else { + { // queue name is to the left of '@' char *s = strchr(queue, '@'); if (s) { @@ -186,6 +181,17 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[]) dfd = xopen(*argv, O_RDONLY); } + st.st_size = 0; /* paranoia: fstat may theoretically fail */ + fstat(dfd, &st); + + /* Apparently, some servers are buggy and won't accept 0-sized jobs. + * Standard lpr works around it by refusing to send such jobs: + */ + if (st.st_size == 0) { + bb_error_msg("nothing to print"); + continue; + } + /* "The name ... should start with ASCII "cfA", * followed by a three digit job number, followed * by the host name which has constructed the file." @@ -210,7 +216,7 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[]) , (opts & LPR_m) ? user : "" , remote_filename ); - // delete possible "\nX\n" patterns + // delete possible "\nX\n" (that is, one-char) patterns c = controlfile; while ((c = strchr(c, '\n')) != NULL) { if (c[1] && c[2] == '\n') { @@ -239,8 +245,6 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[]) // send data file, with name "dfaXXX" if (opts & LPR_V) bb_error_msg("sending data file"); - st.st_size = 0; /* paranoia: fstat may theoretically fail */ - fstat(dfd, &st); fdprintf(fd, "\x3" "%"OFF_FMT"u d%s\n", st.st_size, remote_filename); get_response_or_say_and_die(fd, "sending data file"); if (bb_copyfd_size(dfd, fd, st.st_size) != st.st_size) { -- cgit v1.2.3-55-g6feb From 49b8e72012f8baa1b4d30f6b1d8f47fa88e7426f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 10 Jun 2012 14:16:16 +0200 Subject: brctl: fix build failure by s/strtotimeval/bb_strtotimeval/ (android has strtotimeval) Signed-off-by: Tias Guns <tias@ulyssis.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/brctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networking/brctl.c b/networking/brctl.c index 19f474fce..7289e641f 100644 --- a/networking/brctl.c +++ b/networking/brctl.c @@ -67,7 +67,7 @@ # include <linux/if_bridge.h> /* FIXME: These 4 funcs are not really clean and could be improved */ -static ALWAYS_INLINE void strtotimeval(struct timeval *tv, +static ALWAYS_INLINE void bb_strtotimeval(struct timeval *tv, const char *time_str) { double secs; @@ -104,7 +104,7 @@ static void jiffies_to_tv(struct timeval *tv, unsigned long jiffies) static unsigned long str_to_jiffies(const char *time_str) { struct timeval tv; - strtotimeval(&tv, time_str); + bb_strtotimeval(&tv, time_str); return tv_to_jiffies(&tv); } -- cgit v1.2.3-55-g6feb From 64f763b42a43cbf36e401690ff6767c25575e520 Mon Sep 17 00:00:00 2001 From: Tias Guns <tias@ulyssis.org> Date: Sun, 10 Jun 2012 14:19:01 +0200 Subject: inetd: fix build failure in Android Signed-off-by: Tias Guns <tias@ulyssis.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/inetd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/networking/inetd.c b/networking/inetd.c index 26b66992d..1308d74c7 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -165,6 +165,7 @@ //usage: "\n (default: 0 - disabled)" #include <syslog.h> +#include <sys/socket.h> /* un.h may need this */ #include <sys/un.h> #include "libbb.h" -- cgit v1.2.3-55-g6feb From a1ec8419139aeb83c473d1543987a69bfbe86725 Mon Sep 17 00:00:00 2001 From: Tias Guns <tias@ulyssis.org> Date: Sun, 3 Jun 2012 16:43:06 +0200 Subject: android: fix 'stat', ifdef S_TYPEIS* in coreutiles/stat.c patch modified from 'BusyBox Patch V1.0 (Vitaly Greck)' https://code.google.com/p/busybox-android/downloads/detail?name=patch_busybox Signed-off-by: Tias Guns <tias@ulyssis.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- coreutils/stat.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/coreutils/stat.c b/coreutils/stat.c index 2797719dd..3fb212f0f 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -99,9 +99,15 @@ static const char *file_type(const struct stat *st) if (S_ISFIFO(st->st_mode)) return "fifo"; if (S_ISLNK(st->st_mode)) return "symbolic link"; if (S_ISSOCK(st->st_mode)) return "socket"; +#ifdef S_TYPEISMQ if (S_TYPEISMQ(st)) return "message queue"; +#endif +#ifdef S_TYPEISSEM if (S_TYPEISSEM(st)) return "semaphore"; +#endif +#ifdef S_TYPEISSHM if (S_TYPEISSHM(st)) return "shared memory object"; +#endif #ifdef S_TYPEISTMO if (S_TYPEISTMO(st)) return "typed memory object"; #endif -- cgit v1.2.3-55-g6feb From 3645195377b73bc4265868c26c123e443aaa71c6 Mon Sep 17 00:00:00 2001 From: Tias Guns <tias@ulyssis.org> Date: Sun, 10 Jun 2012 14:26:32 +0200 Subject: platform.h: Android tweaks: ioprio defines, BB_ADDITIONAL_PATH Signed-off-by: Tias Guns <tias@ulyssis.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/platform.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/platform.h b/include/platform.h index d79cc97e5..ba534b284 100644 --- a/include/platform.h +++ b/include/platform.h @@ -334,6 +334,12 @@ typedef unsigned smalluint; # define MAXSYMLINKS SYMLOOP_MAX #endif +#if defined(ANDROID) || defined(__ANDROID__) +# define BB_ADDITIONAL_PATH ":/system/sbin:/system/bin:/system/xbin" +# define SYS_ioprio_set __NR_ioprio_set +# define SYS_ioprio_get __NR_ioprio_get +#endif + /* ---- Who misses what? ------------------------------------ */ -- cgit v1.2.3-55-g6feb From bd01f22986c03c9cb951d5c54196c28e958a6cd4 Mon Sep 17 00:00:00 2001 From: Tias Guns <tias@ulyssis.org> Date: Sun, 10 Jun 2012 14:29:15 +0200 Subject: android: some sensible defconfig changes - no /usr - no skip rootfs - use /system/lib/modules And for niceties: - show usage - have installer - long opts - verbose cp - ls --color support - bbconfig Also adds lsof (new in 1.20.0) Signed-off-by: Tias Guns <tias@ulyssis.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- configs/android_ndk_defconfig | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/configs/android_ndk_defconfig b/configs/android_ndk_defconfig index bf8827a58..332bea664 100644 --- a/configs/android_ndk_defconfig +++ b/configs/android_ndk_defconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit -# Busybox version: 1.20.0.git -# Fri Mar 2 16:53:26 2012 +# Busybox version: 1.21.0.git +# Mon May 28 21:51:18 2012 # CONFIG_HAVE_DOT_CONFIG=y @@ -20,11 +20,11 @@ CONFIG_PLATFORM_LINUX=y CONFIG_FEATURE_BUFFERS_USE_MALLOC=y # CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set # CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set -# CONFIG_SHOW_USAGE is not set -# CONFIG_FEATURE_VERBOSE_USAGE is not set -# CONFIG_FEATURE_COMPRESS_USAGE is not set -# CONFIG_FEATURE_INSTALLER is not set -# CONFIG_INSTALL_NO_USR is not set +CONFIG_SHOW_USAGE=y +CONFIG_FEATURE_VERBOSE_USAGE=y +CONFIG_FEATURE_COMPRESS_USAGE=y +CONFIG_FEATURE_INSTALLER=y +CONFIG_INSTALL_NO_USR=y # CONFIG_LOCALE_SUPPORT is not set # CONFIG_UNICODE_SUPPORT is not set # CONFIG_UNICODE_USING_LOCALE is not set @@ -36,7 +36,7 @@ CONFIG_LAST_SUPPORTED_WCHAR=0 # CONFIG_UNICODE_BIDI_SUPPORT is not set # CONFIG_UNICODE_NEUTRAL_TABLE is not set # CONFIG_UNICODE_PRESERVE_BROKEN is not set -# CONFIG_LONG_OPTS is not set +CONFIG_LONG_OPTS=y # CONFIG_FEATURE_DEVPTS is not set # CONFIG_FEATURE_CLEAN_UP is not set # CONFIG_FEATURE_UTMP is not set @@ -67,7 +67,6 @@ CONFIG_EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -march=armv7 CONFIG_EXTRA_LDFLAGS="-Xlinker -z -Xlinker muldefs -nostdlib -Bdynamic -Xlinker -dynamic-linker -Xlinker /system/bin/linker -Xlinker -z -Xlinker nocopyreloc -Xlinker --no-undefined ${SYSROOT}/usr/lib/crtbegin_dynamic.o ${SYSROOT}/usr/lib/crtend_android.o" CONFIG_EXTRA_LDLIBS="dl m c gcc" - # # Debugging Options # @@ -112,7 +111,7 @@ CONFIG_FEATURE_EDITING_HISTORY=0 # CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set # CONFIG_FEATURE_NON_POSIX_CP is not set -# CONFIG_FEATURE_VERBOSE_CP_MESSAGE is not set +CONFIG_FEATURE_VERBOSE_CP_MESSAGE=y CONFIG_FEATURE_COPYBUF_KB=4 # CONFIG_FEATURE_SKIP_ROOTFS is not set # CONFIG_MONOTONIC_SYSCALL is not set @@ -239,7 +238,7 @@ CONFIG_FEATURE_LS_RECURSIVE=y CONFIG_FEATURE_LS_SORTFILES=y CONFIG_FEATURE_LS_TIMESTAMPS=y CONFIG_FEATURE_LS_USERNAME=y -# CONFIG_FEATURE_LS_COLOR is not set +CONFIG_FEATURE_LS_COLOR=y # CONFIG_FEATURE_LS_COLOR_IS_DEFAULT is not set CONFIG_MD5SUM=y CONFIG_MKDIR=y @@ -516,7 +515,7 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y # CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set # CONFIG_FEATURE_MODUTILS_ALIAS is not set # CONFIG_FEATURE_MODUTILS_SYMBOLS is not set -CONFIG_DEFAULT_MODULES_DIR="/lib/modules" +CONFIG_DEFAULT_MODULES_DIR="/system/lib/modules" CONFIG_DEFAULT_DEPMOD_FILE="modules.dep" # @@ -647,8 +646,8 @@ CONFIG_SETSERIAL=y # CONFIG_UBIRSVOL is not set # CONFIG_UBIUPDATEVOL is not set # CONFIG_ADJTIMEX is not set -# CONFIG_BBCONFIG is not set -# CONFIG_FEATURE_COMPRESS_BBCONFIG is not set +CONFIG_BBCONFIG=y +CONFIG_FEATURE_COMPRESS_BBCONFIG=y CONFIG_BEEP=y CONFIG_FEATURE_BEEP_FREQ=4000 CONFIG_FEATURE_BEEP_LENGTH_MS=30 @@ -883,6 +882,7 @@ CONFIG_SENDMAIL=y # Process Utilities # CONFIG_IOSTAT=y +CONFIG_LSOF=y CONFIG_MPSTAT=y CONFIG_NMETER=y CONFIG_PMAP=y -- cgit v1.2.3-55-g6feb From c9677ed83c948c9afb7f1bbd9bac91c854289887 Mon Sep 17 00:00:00 2001 From: Tias Guns <tias@ulyssis.org> Date: Sun, 10 Jun 2012 14:40:30 +0200 Subject: libbb: add missing_syscalls.c: for now, only Android syscalls Signed-off-by: Tias Guns <tias@ulyssis.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- libbb/missing_syscalls.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libbb/missing_syscalls.c diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c new file mode 100644 index 000000000..dd430e3e2 --- /dev/null +++ b/libbb/missing_syscalls.c @@ -0,0 +1,42 @@ +/* + * Copyright 2012, Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ + +//kbuild:lib-y += missing_syscalls.o + +/*#include <linux/timex.h> - for struct timex, but may collide with <time.h> */ +#include <sys/syscall.h> +#include "libbb.h" + +#if defined(ANDROID) || defined(__ANDROID__) +pid_t getsid(pid_t pid) +{ + return syscall(__NR_getsid, pid); +} + +int stime(const time_t *t) +{ + struct timeval tv; + tv.tv_sec = *t; + tv.tv_usec = 0; + return settimeofday(&tv, NULL); +} + +int sethostname(const char *name, size_t len) +{ + return syscall(__NR_sethostname, name, len); +} + +struct timex; +int adjtimex(struct timex *buf) +{ + return syscall(__NR_adjtimex, buf); +} + +int pivot_root(const char *new_root, const char *put_old) +{ + return syscall(__NR_pivot_root, new_root, put_old); +} +#endif -- cgit v1.2.3-55-g6feb From 605f2641d83f4294147bede9403a590a29a6674a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 11 Jun 2012 01:53:33 +0200 Subject: vi: do not set autoindent by default Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/vi.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index b4ad12e5c..a07b68714 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -154,12 +154,12 @@ //usage:#define vi_full_usage "\n\n" //usage: "Edit FILE\n" //usage: IF_FEATURE_VI_COLON( -//usage: "\n -c Initial command to run ($EXINIT also available)" +//usage: "\n -c CMD Initial command to run ($EXINIT also available)" //usage: ) //usage: IF_FEATURE_VI_READONLY( //usage: "\n -R Read-only" //usage: ) -//usage: "\n -H Short help regarding available features" +//usage: "\n -H List available features" #include "libbb.h" /* Should be after libbb.h: on some systems regex.h needs sys/types.h: */ @@ -558,7 +558,8 @@ int vi_main(int argc, char **argv) } #endif - vi_setops = VI_AUTOINDENT | VI_SHOWMATCH | VI_IGNORECASE; + // autoindent is not default in vim 7.3 + vi_setops = /*VI_AUTOINDENT |*/ VI_SHOWMATCH | VI_IGNORECASE; // 1- process $HOME/.exrc file (not inplemented yet) // 2- process EXINIT variable from environment // 3- process command line args @@ -584,7 +585,7 @@ int vi_main(int argc, char **argv) #if ENABLE_FEATURE_VI_COLON case 'c': // cmd line vi command if (*optarg) - initial_cmds[initial_cmds[0] != 0] = xstrndup(optarg, MAX_INPUT_LEN); + initial_cmds[initial_cmds[0] != NULL] = xstrndup(optarg, MAX_INPUT_LEN); break; #endif case 'H': @@ -1191,7 +1192,7 @@ static void colon(char *buf) char *argp; #endif i = 0; // offset into args - // only blank is regarded as args delmiter. What about tab '\t' ? + // 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 @@ -2176,7 +2177,7 @@ static void show_help(void) "\n\tPattern searches with / and ?" #endif #if ENABLE_FEATURE_VI_DOT_CMD - "\n\tLast command repeat with \'.\'" + "\n\tLast command repeat with ." #endif #if ENABLE_FEATURE_VI_YANKMARK "\n\tLine marking with 'x" @@ -2187,7 +2188,7 @@ static void show_help(void) //redundant: usage text says this too: "\n\tReadonly with -R command line arg" #endif #if ENABLE_FEATURE_VI_SET - "\n\tSome colon mode commands with \':\'" + "\n\tSome colon mode commands with :" #endif #if ENABLE_FEATURE_VI_SETOPTS "\n\tSettable options with \":set\"" -- cgit v1.2.3-55-g6feb From 93c32f2dd2b9d7c06bc46be8adac704c08929da8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 11 Jun 2012 02:06:11 +0200 Subject: rdate: code shrink Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/rdate.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/util-linux/rdate.c b/util-linux/rdate.c index 1f36d8f37..2ca585fec 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c @@ -1,7 +1,7 @@ /* vi: set sw=4 ts=4: */ /* * The Rdate command will ask a time server for the RFC 868 time - * and optionally set the system time. + * and optionally set the system time. * * by Sterling Huxley <sterling@europa.com> * @@ -11,9 +11,9 @@ //usage:#define rdate_trivial_usage //usage: "[-sp] HOST" //usage:#define rdate_full_usage "\n\n" -//usage: "Get and possibly set the system date and time from a remote HOST\n" -//usage: "\n -s Set the system date and time (default)" -//usage: "\n -p Print the date and time" +//usage: "Get and possibly set the system date/time from a remote HOST\n" +//usage: "\n -s Set the system date/time (default)" +//usage: "\n -p Print the date/time" #include "libbb.h" @@ -35,15 +35,16 @@ static time_t askremotedate(const char *host) fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37)); - if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ + if (safe_read(fd, &nett, 4) != 4) /* read time from server */ bb_error_msg_and_die("%s did not send the complete time", host); - close(fd); + if (ENABLE_FEATURE_CLEAN_UP) + close(fd); - /* convert from network byte order to local byte order. + /* Convert from network byte order to local byte order. * RFC 868 time is the number of seconds * since 00:00 (midnight) 1 January 1900 GMT * the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT - * Subtract the RFC 868 time to get Linux epoch + * Subtract the RFC 868 time to get Linux epoch. */ return ntohl(nett) - RFC_868_BIAS; @@ -53,14 +54,14 @@ int rdate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int rdate_main(int argc UNUSED_PARAM, char **argv) { time_t remote_time; - unsigned long flags; + unsigned flags; opt_complementary = "-1"; flags = getopt32(argv, "sp"); remote_time = askremotedate(argv[optind]); - if ((flags & 2) == 0) { + if (!(flags & 2)) { time_t current_time; time(¤t_time); @@ -71,7 +72,7 @@ int rdate_main(int argc UNUSED_PARAM, char **argv) bb_perror_msg_and_die("can't set time of day"); } - if ((flags & 1) == 0) + if ((flags & 2) || !(flags & 1)) printf("%s", ctime(&remote_time)); return EXIT_SUCCESS; -- cgit v1.2.3-55-g6feb From 0a393cf7da9003d0d64e1868c13ef206af125451 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Mon, 11 Jun 2012 10:33:45 +0200 Subject: testsuite: some more awk tests related to conditions Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- testsuite/awk.tests | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 5a323047d..e67190757 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -16,6 +16,13 @@ testing "awk -F case 5" "awk -F '[#]' '{ print NF }'" "4\n" "" "#abc##zz\n" testing "awk -F case 6" "awk -F '[#]' '{ print NF }'" "4\n" "" "z#abc##zz\n" testing "awk -F case 7" "awk -F '[#]' '{ print NF }'" "5\n" "" "z##abc##zz\n" +# conditions and operators +testing "awk if operator == " "awk 'BEGIN{if(23==23) print \"foo\"}'" "foo\n" "" "" +testing "awk if operator != " "awk 'BEGIN{if(23!=23) print \"bar\"}'" "" "" "" +testing "awk if operator >= " "awk 'BEGIN{if(23>=23) print \"foo\"}'" "foo\n" "" "" +testing "awk if operator < " "awk 'BEGIN{if(2 < 13) print \"foo\"}'" "foo\n" "" "" +testing "awk if string == " "awk 'BEGIN{if(\"a\"==\"ab\") print \"bar\"}'" "" "" "" + # 4294967295 = 0xffffffff testing "awk bitwise op" "awk '{ print or(4294967295,1) }'" "4.29497e+09\n" "" "\n" optional DESKTOP -- cgit v1.2.3-55-g6feb From 4125a6b6306d8d12f1e22239465bce916e168d73 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 11 Jun 2012 11:41:46 +0200 Subject: ntpd: on time step, kill all outstanding replies from other peers Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/ntpd.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 603801ec6..72e9d0be2 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -220,14 +220,14 @@ typedef struct { typedef struct { len_and_sockaddr *p_lsa; char *p_dotted; - /* when to send new query (if p_fd == -1) - * or when receive times out (if p_fd >= 0): */ int p_fd; int datapoint_idx; uint32_t lastpkt_refid; uint8_t lastpkt_status; uint8_t lastpkt_stratum; uint8_t reachable_bits; + /* when to send new query (if p_fd == -1) + * or when receive times out (if p_fd >= 0): */ double next_action_time; double p_xmttime; double lastpkt_recv_time; @@ -895,6 +895,11 @@ step_time(double offset) /* Correct various fields which contain time-relative values: */ + /* Globals: */ + G.cur_time += offset; + G.last_update_recv_time += offset; + G.last_script_run += offset; + /* p->lastpkt_recv_time, p->next_action_time and such: */ for (item = G.ntp_peers; item != NULL; item = item->link) { peer_t *pp = (peer_t *) item->data; @@ -902,11 +907,16 @@ step_time(double offset) //bb_error_msg("offset:%+f pp->next_action_time:%f -> %f", // offset, pp->next_action_time, pp->next_action_time + offset); pp->next_action_time += offset; + if (pp->p_fd >= 0) { + /* We wait for reply from this peer too. + * But due to step we are doing, reply's data is no longer + * useful (in fact, it'll be bogus). Stop waiting for it. + */ + close(pp->p_fd); + pp->p_fd = -1; + set_next(pp, RETRY_INTERVAL); + } } - /* Globals: */ - G.cur_time += offset; - G.last_update_recv_time += offset; - G.last_script_run += offset; } @@ -1623,22 +1633,30 @@ recv_and_process_peer_pkt(peer_t *p) ) { //TODO: always do this? interval = retry_interval(); - goto set_next_and_close_sock; + goto set_next_and_ret; } xfunc_die(); } if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE) { bb_error_msg("malformed packet received from %s", p->p_dotted); - goto bail; + return; } if (msg.m_orgtime.int_partl != p->p_xmt_msg.m_xmttime.int_partl || msg.m_orgtime.fractionl != p->p_xmt_msg.m_xmttime.fractionl ) { - goto bail; + /* Somebody else's packet */ + return; } + /* We do not expect any more packets from this peer for now. + * Closing the socket informs kernel about it. + * We open a new socket when we send a new query. + */ + close(p->p_fd); + p->p_fd = -1; + if ((msg.m_status & LI_ALARM) == LI_ALARM || msg.m_stratum == 0 || msg.m_stratum > NTP_MAXSTRATUM @@ -1647,8 +1665,8 @@ recv_and_process_peer_pkt(peer_t *p) // "DENY", "RSTR" - peer does not like us at all // "RATE" - peer is overloaded, reduce polling freq interval = poll_interval(0); - bb_error_msg("reply from %s: not synced, next query in %us", p->p_dotted, interval); - goto set_next_and_close_sock; + bb_error_msg("reply from %s: peer is unsynced, next query in %us", p->p_dotted, interval); + goto set_next_and_ret; } // /* Verify valid root distance */ @@ -1794,16 +1812,8 @@ recv_and_process_peer_pkt(peer_t *p) /* Decide when to send new query for this peer */ interval = poll_interval(0); - set_next_and_close_sock: + set_next_and_ret: set_next(p, interval); - /* We do not expect any more packets from this peer for now. - * Closing the socket informs kernel about it. - * We open a new socket when we send a new query. - */ - close(p->p_fd); - p->p_fd = -1; - bail: - return; } #if ENABLE_FEATURE_NTPD_SERVER -- cgit v1.2.3-55-g6feb From 04b52892ed5d9d8a4cf5d887c221a8b50c71274e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 11 Jun 2012 13:51:38 +0200 Subject: vi: nuke FEATURE_VI_OPTIMIZE_CURSOR It is not Unicode safe, it is not saving much of I/O, and it's large: function old new delta vi_main 255 253 -2 go_bottom_and_clear_to_eol 28 26 -2 do_cmd 4194 4182 -12 show_status_line 388 374 -14 strncat 39 - -39 __GI_strncat 39 - -39 refresh 774 724 -50 place_cursor 276 83 -193 ------------------------------------------------------------------------------ (add/remove: 0/3 grow/shrink: 0/6 up/down: 0/-351) Total: -351 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/vi.c | 182 +++++++++++++++++++---------------------------------------- 1 file changed, 58 insertions(+), 124 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index a07b68714..459f374f7 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -136,14 +136,6 @@ //config: cursor position using "ESC [ 6 n" escape sequence, then read stdin. //config: //config: This is not clean but helps a lot on serial lines and such. -//config: -//config:config FEATURE_VI_OPTIMIZE_CURSOR -//config: bool "Optimize cursor movement" -//config: default y -//config: depends on VI -//config: help -//config: This will make the cursor movement faster, but requires more memory -//config: and it makes the applet a tiny bit larger. //applet:IF_VI(APPLET(vi, BB_DIR_BIN, BB_SUID_DROP)) @@ -202,20 +194,29 @@ enum { MAX_SCR_ROWS = CONFIG_FEATURE_VI_MAX_LEN, }; -/* vt102 typical ESC sequence */ -/* terminal standout start/normal ESC sequence */ -#define SOs "\033[7m" -#define SOn "\033[0m" -/* terminal bell sequence */ -#define bell "\007" -/* Clear-end-of-line and Clear-end-of-screen ESC sequence */ -#define Ceol "\033[K" -#define Ceos "\033[J" -/* Cursor motion arbitrary destination ESC sequence */ -#define CMrc "\033[%u;%uH" -/* Cursor motion up and down ESC sequence */ -#define CMup "\033[A" -#define CMdown "\n" +/* VT102 ESC sequences. + * See "Xterm Control Sequences" + * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html + */ +/* Inverse/Normal text */ +#define ESC_BOLD_TEXT "\033[7m" +#define ESC_NORM_TEXT "\033[0m" +/* Bell */ +#define ESC_BELL "\007" +/* Clear-to-end-of-line */ +#define ESC_CLEAR2EOL "\033[K" +/* Clear-to-end-of-screen. + * (We use default param here. + * Full sequence is "ESC [ <num> J", + * <num> is 0/1/2 = "erase below/above/all".) + */ +#define ESC_CLEAR2EOS "\033[J" +/* Cursor to given coordinate (1,1: top left) */ +#define ESC_SET_CURSOR_POS "\033[%u;%uH" +//UNUSED +///* Cursor up and down */ +//#define ESC_CURSOR_UP "\033[A" +//#define ESC_CURSOR_DOWN "\n" #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK // cmds modifying text[] @@ -303,9 +304,6 @@ struct globals { int lmc_len; // length of last_modifying_cmd char *ioq, *ioq_start; // pointer to string for get_one_char to "read" #endif -#if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR - int last_row; // where the cursor was last moved to -#endif #if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME int my_pid; #endif @@ -389,7 +387,6 @@ struct globals { #define lmc_len (G.lmc_len ) #define ioq (G.ioq ) #define ioq_start (G.ioq_start ) -#define last_row (G.last_row ) #define my_pid (G.my_pid ) #define last_search_pattern (G.last_search_pattern) @@ -470,10 +467,7 @@ static int file_size(const char *); // what is the byte size of "fn" // file_insert might reallocate text[]! static int file_insert(const char *, char *, int); static int file_write(char *, char *, char *); -#if !ENABLE_FEATURE_VI_OPTIMIZE_CURSOR -#define place_cursor(a, b, optimize) place_cursor(a, b) -#endif -static void place_cursor(int, int, int); +static void place_cursor(int, int); static void screen_erase(void); static void clear_to_eol(void); static void clear_to_eos(void); @@ -600,10 +594,10 @@ int vi_main(int argc, char **argv) // The argv array can be used by the ":next" and ":rewind" commands argv += optind; argc -= optind; - save_argc = argc; - optind = 0; //----- This is the main file handling loop -------------- + save_argc = argc; + optind = 0; while (1) { edit_file(argv[optind]); /* param might be NULL */ if (++optind >= argc) @@ -2593,107 +2587,56 @@ static int file_write(char *fn, char *first, char *last) // 23,0 ... 23,79 <- status line //----- Move the cursor to row x col (count from 0, not 1) ------- -static void place_cursor(int row, int col, int optimize) +static void place_cursor(int row, int col) { - char cm1[sizeof(CMrc) + sizeof(int)*3 * 2]; -#if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR - enum { - SZ_UP = sizeof(CMup), - SZ_DN = sizeof(CMdown), - SEQ_SIZE = SZ_UP > SZ_DN ? SZ_UP : SZ_DN, - }; - char cm2[SEQ_SIZE * 5 + 32]; // bigger than worst case size -#endif - char *cm; + char cm1[sizeof(ESC_SET_CURSOR_POS) + sizeof(int)*3 * 2]; if (row < 0) row = 0; if (row >= rows) row = rows - 1; if (col < 0) col = 0; if (col >= columns) col = columns - 1; - //----- 1. Try the standard terminal ESC sequence - sprintf(cm1, CMrc, row + 1, col + 1); - cm = cm1; - -#if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR - if (optimize && col < 16) { - char *screenp; - int Rrow = last_row; - int diff = Rrow - row; - - if (diff < -5 || diff > 5) - goto skip; - - //----- find the minimum # of chars to move cursor ------------- - //----- 2. Try moving with discreet chars (Newline, [back]space, ...) - cm2[0] = '\0'; - - // move to the correct row - while (row < Rrow) { - // the cursor has to move up - strcat(cm2, CMup); - Rrow--; - } - while (row > Rrow) { - // the cursor has to move down - strcat(cm2, CMdown); - Rrow++; - } - - // now move to the correct column - strcat(cm2, "\r"); // start at col 0 - // just send out orignal source char to get to correct place - screenp = &screen[row * columns]; // start of screen line - strncat(cm2, screenp, col); - - // pick the shortest cursor motion to send out - if (strlen(cm2) < strlen(cm)) { - cm = cm2; - } - skip: ; - } - last_row = row; -#endif /* FEATURE_VI_OPTIMIZE_CURSOR */ - write1(cm); + sprintf(cm1, ESC_SET_CURSOR_POS, row + 1, col + 1); + write1(cm1); } //----- Erase from cursor to end of line ----------------------- static void clear_to_eol(void) { - write1(Ceol); // Erase from cursor to end of line + write1(ESC_CLEAR2EOL); } static void go_bottom_and_clear_to_eol(void) { - place_cursor(rows - 1, 0, FALSE); // go to bottom of screen - clear_to_eol(); // erase to end of line + place_cursor(rows - 1, 0); + clear_to_eol(); } //----- Erase from cursor to end of screen ----------------------- static void clear_to_eos(void) { - write1(Ceos); // Erase from cursor to end of screen + write1(ESC_CLEAR2EOS); } //----- Start standout mode ------------------------------------ -static void standout_start(void) // send "start reverse video" sequence +static void standout_start(void) { - write1(SOs); // Start reverse video mode + write1(ESC_BOLD_TEXT); } //----- End standout mode -------------------------------------- -static void standout_end(void) // send "end reverse video" sequence +static void standout_end(void) { - write1(SOn); // End reverse video mode + write1(ESC_NORM_TEXT); } //----- Flash the screen -------------------------------------- static void flash(int h) { - standout_start(); // send "start reverse video" sequence + standout_start(); redraw(TRUE); mysleep(h); - standout_end(); // send "end reverse video" sequence + standout_end(); redraw(TRUE); } @@ -2704,7 +2647,7 @@ static void Indicate_Error(void) return; // generate a random command #endif if (!err_method) { - write1(bell); // send out a bell character + write1(ESC_BELL); } else { flash(10); } @@ -2750,7 +2693,7 @@ static void show_status_line(void) } have_status_msg = 0; } - place_cursor(crow, ccol, FALSE); // put cursor back in correct place + place_cursor(crow, ccol); // put cursor back in correct place } fflush_all(); } @@ -2762,12 +2705,12 @@ static void status_line_bold(const char *format, ...) va_list args; va_start(args, format); - strcpy(status_buffer, SOs); // Terminal standout mode on - vsprintf(status_buffer + sizeof(SOs)-1, format, args); - strcat(status_buffer, SOn); // Terminal standout mode off + strcpy(status_buffer, ESC_BOLD_TEXT); + vsprintf(status_buffer + sizeof(ESC_BOLD_TEXT)-1, format, args); + strcat(status_buffer, ESC_NORM_TEXT); va_end(args); - have_status_msg = 1 + sizeof(SOs) + sizeof(SOn) - 2; + have_status_msg = 1 + sizeof(ESC_BOLD_TEXT) + sizeof(ESC_NORM_TEXT) - 2; } // format status buffer @@ -2799,8 +2742,8 @@ static void print_literal(char *buf, const char *s) c = *s; c_is_no_print = (c & 0x80) && !Isprint(c); if (c_is_no_print) { - strcpy(d, SOn); - d += sizeof(SOn)-1; + strcpy(d, ESC_NORM_TEXT); + d += sizeof(ESC_NORM_TEXT)-1; c = '.'; } if (c < ' ' || c == 0x7f) { @@ -2812,8 +2755,8 @@ static void print_literal(char *buf, const char *s) *d++ = c; *d = '\0'; if (c_is_no_print) { - strcpy(d, SOs); - d += sizeof(SOs)-1; + strcpy(d, ESC_BOLD_TEXT); + d += sizeof(ESC_BOLD_TEXT)-1; } if (*s == '\n') { *d++ = '$'; @@ -2895,8 +2838,8 @@ static int format_edit_status(void) //----- Force refresh of all Lines ----------------------------- static void redraw(int full_screen) { - place_cursor(0, 0, FALSE); // put cursor in correct place - clear_to_eos(); // tell terminal to erase display + place_cursor(0, 0); + clear_to_eos(); screen_erase(); // erase the internal screen buffer last_status_cksum = 0; // force status update refresh(full_screen); // this will redraw the entire display @@ -3036,22 +2979,13 @@ static void refresh(int full_screen) if (changed) { // copy changed part of buffer to virtual screen memcpy(sp+cs, out_buf+cs, ce-cs+1); - - // move cursor to column of first change - //if (offset != old_offset) { - // // place_cursor is still too stupid - // // to handle offsets correctly - // place_cursor(li, cs, FALSE); - //} else { - place_cursor(li, cs, TRUE); - //} - + place_cursor(li, cs); // write line out to terminal fwrite(&sp[cs], ce - cs + 1, 1, stdout); } } - place_cursor(crow, ccol, TRUE); + place_cursor(crow, ccol); old_offset = offset; #undef old_offset @@ -3221,9 +3155,9 @@ static void do_cmd(int c) break; case 12: // ctrl-L force redraw whole screen case 18: // ctrl-R force redraw - place_cursor(0, 0, FALSE); // put cursor in correct place - clear_to_eos(); // tel terminal to erase display - mysleep(10); + place_cursor(0, 0); + clear_to_eos(); + //mysleep(10); // why??? screen_erase(); // erase the internal screen buffer last_status_cksum = 0; // force status update refresh(TRUE); // this will redraw the entire display @@ -4142,7 +4076,7 @@ static void crash_test() if (msg[0]) { printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s", - totalcmds, last_input_char, msg, SOs, SOn); + totalcmds, last_input_char, msg, ESC_BOLD_TEXT, ESC_NORM_TEXT); fflush_all(); while (safe_read(STDIN_FILENO, d, 1) > 0) { if (d[0] == '\n' || d[0] == '\r') -- cgit v1.2.3-55-g6feb From d3dff879f0683c2a4119f694c1b20c96ee030a26 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 11 Jun 2012 13:53:26 +0200 Subject: vi: save/restore screen upon invocation function old new delta vi_main 253 273 +20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/vi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/editors/vi.c b/editors/vi.c index 459f374f7..e09e0d9c7 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -598,11 +598,15 @@ int vi_main(int argc, char **argv) //----- This is the main file handling loop -------------- save_argc = argc; optind = 0; + // "Save cursor, use alternate screen buffer, clear screen" + write1("\033[?1049h"); while (1) { edit_file(argv[optind]); /* param might be NULL */ if (++optind >= argc) break; } + // "Use normal screen buffer, restore cursor" + write1("\033[?1049l"); //----------------------------------------------------------- return 0; -- cgit v1.2.3-55-g6feb From 0ccae4d8b379d310213a4e911670070b7030482d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 11 Jun 2012 14:40:17 +0200 Subject: Add comments in keyboard escape sequences table Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- libbb/read_key.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libbb/read_key.c b/libbb/read_key.c index 8d72d2a63..ace23defb 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c @@ -15,7 +15,10 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) const char *seq; int n; - /* Known escape sequences for cursor and function keys */ + /* Known escape sequences for cursor and function keys. + * See "Xterm Control Sequences" + * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html + */ static const char esccmds[] ALIGN1 = { 'O','A' |0x80,KEYCODE_UP , 'O','B' |0x80,KEYCODE_DOWN , @@ -44,6 +47,8 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) /* ESC [ 1 ; 4 x, where x = A/B/C/D: Alt-Shift-<arrow> */ /* ESC [ 1 ; 5 x, where x = A/B/C/D: Ctrl-<arrow> - implemented below */ /* ESC [ 1 ; 6 x, where x = A/B/C/D: Ctrl-Shift-<arrow> */ + /* ESC [ 1 ; 7 x, where x = A/B/C/D: Ctrl-Alt-<arrow> */ + /* ESC [ 1 ; 8 x, where x = A/B/C/D: Ctrl-Alt-Shift-<arrow> */ '[','H' |0x80,KEYCODE_HOME , /* xterm */ '[','F' |0x80,KEYCODE_END , /* xterm */ /* [ESC] ESC [ [2] H - [Alt-][Shift-]Home (End similarly?) */ @@ -64,10 +69,10 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) '[','7','~' |0x80,KEYCODE_HOME , /* vt100? linux vt? or what? */ '[','8','~' |0x80,KEYCODE_END , /* vt100? linux vt? or what? */ #if 0 - '[','1','1','~'|0x80,KEYCODE_FUN1 , - '[','1','2','~'|0x80,KEYCODE_FUN2 , - '[','1','3','~'|0x80,KEYCODE_FUN3 , - '[','1','4','~'|0x80,KEYCODE_FUN4 , + '[','1','1','~'|0x80,KEYCODE_FUN1 , /* old xterm, deprecated by ESC O P */ + '[','1','2','~'|0x80,KEYCODE_FUN2 , /* old xterm... */ + '[','1','3','~'|0x80,KEYCODE_FUN3 , /* old xterm... */ + '[','1','4','~'|0x80,KEYCODE_FUN4 , /* old xterm... */ '[','1','5','~'|0x80,KEYCODE_FUN5 , /* [ESC] ESC [ 1 5 [;2] ~ - [Alt-][Shift-]F5 */ '[','1','7','~'|0x80,KEYCODE_FUN6 , -- cgit v1.2.3-55-g6feb From 39f82d4309633815160a291bbf9fa83c21fb4a17 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 11 Jun 2012 14:57:29 +0200 Subject: rdate: code shrink Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/rdate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util-linux/rdate.c b/util-linux/rdate.c index 2ca585fec..6e35cd519 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c @@ -61,7 +61,7 @@ int rdate_main(int argc UNUSED_PARAM, char **argv) remote_time = askremotedate(argv[optind]); - if (!(flags & 2)) { + if (!(flags & 2)) { /* no -p (-s may be present) */ time_t current_time; time(¤t_time); @@ -72,7 +72,7 @@ int rdate_main(int argc UNUSED_PARAM, char **argv) bb_perror_msg_and_die("can't set time of day"); } - if ((flags & 2) || !(flags & 1)) + if (flags != 1) /* not lone -s */ printf("%s", ctime(&remote_time)); return EXIT_SUCCESS; -- cgit v1.2.3-55-g6feb From 588e284f53da2dc5c58f3d1b9efacd6e9061baf1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Tue, 12 Jun 2012 01:48:45 +0200 Subject: remove FEATURE_VI_OPTIMIZE_CURSOR from example config Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- configs/TEST_nommu_defconfig | 1 - configs/TEST_noprintf_defconfig | 1 - configs/TEST_rh9_defconfig | 1 - configs/android2_defconfig | 1 - configs/android_defconfig | 1 - configs/android_ndk_defconfig | 1 - configs/cygwin_defconfig | 1 - configs/freebsd_defconfig | 1 - 8 files changed, 8 deletions(-) diff --git a/configs/TEST_nommu_defconfig b/configs/TEST_nommu_defconfig index 15e12b1d2..b45afd956 100644 --- a/configs/TEST_nommu_defconfig +++ b/configs/TEST_nommu_defconfig @@ -341,7 +341,6 @@ CONFIG_FEATURE_VI_READONLY=y CONFIG_FEATURE_VI_SETOPTS=y CONFIG_FEATURE_VI_SET=y CONFIG_FEATURE_VI_WIN_RESIZE=y -CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y CONFIG_FEATURE_ALLOW_EXEC=y # diff --git a/configs/TEST_noprintf_defconfig b/configs/TEST_noprintf_defconfig index f4338df71..809b60cd8 100644 --- a/configs/TEST_noprintf_defconfig +++ b/configs/TEST_noprintf_defconfig @@ -346,7 +346,6 @@ CONFIG_FEATURE_VI_MAX_LEN=0 # CONFIG_FEATURE_VI_SET is not set # CONFIG_FEATURE_VI_WIN_RESIZE is not set # CONFIG_FEATURE_VI_ASK_TERMINAL is not set -# CONFIG_FEATURE_VI_OPTIMIZE_CURSOR is not set # CONFIG_FEATURE_ALLOW_EXEC is not set # diff --git a/configs/TEST_rh9_defconfig b/configs/TEST_rh9_defconfig index 193d8f615..565b826d0 100644 --- a/configs/TEST_rh9_defconfig +++ b/configs/TEST_rh9_defconfig @@ -358,7 +358,6 @@ CONFIG_FEATURE_VI_READONLY=y CONFIG_FEATURE_VI_SETOPTS=y CONFIG_FEATURE_VI_SET=y CONFIG_FEATURE_VI_WIN_RESIZE=y -CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y CONFIG_FEATURE_ALLOW_EXEC=y # diff --git a/configs/android2_defconfig b/configs/android2_defconfig index b5166e0fc..4dfbdb526 100644 --- a/configs/android2_defconfig +++ b/configs/android2_defconfig @@ -363,7 +363,6 @@ CONFIG_FEATURE_VI_MAX_LEN=0 # CONFIG_FEATURE_VI_SET is not set # CONFIG_FEATURE_VI_WIN_RESIZE is not set # CONFIG_FEATURE_VI_ASK_TERMINAL is not set -# CONFIG_FEATURE_VI_OPTIMIZE_CURSOR is not set # CONFIG_AWK is not set # CONFIG_FEATURE_AWK_LIBM is not set CONFIG_CMP=y diff --git a/configs/android_defconfig b/configs/android_defconfig index a9a8d5e1f..e35830e7f 100644 --- a/configs/android_defconfig +++ b/configs/android_defconfig @@ -386,7 +386,6 @@ CONFIG_FEATURE_VI_SETOPTS=y CONFIG_FEATURE_VI_SET=y CONFIG_FEATURE_VI_WIN_RESIZE=y CONFIG_FEATURE_VI_ASK_TERMINAL=y -CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y CONFIG_AWK=y CONFIG_FEATURE_AWK_LIBM=y CONFIG_CMP=y diff --git a/configs/android_ndk_defconfig b/configs/android_ndk_defconfig index 332bea664..01cc2dd15 100644 --- a/configs/android_ndk_defconfig +++ b/configs/android_ndk_defconfig @@ -371,7 +371,6 @@ CONFIG_FEATURE_VI_SETOPTS=y CONFIG_FEATURE_VI_SET=y CONFIG_FEATURE_VI_WIN_RESIZE=y CONFIG_FEATURE_VI_ASK_TERMINAL=y -CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y CONFIG_AWK=y CONFIG_FEATURE_AWK_LIBM=y CONFIG_CMP=y diff --git a/configs/cygwin_defconfig b/configs/cygwin_defconfig index bdd0d66d0..aa346e34c 100644 --- a/configs/cygwin_defconfig +++ b/configs/cygwin_defconfig @@ -363,7 +363,6 @@ CONFIG_FEATURE_VI_SETOPTS=y CONFIG_FEATURE_VI_SET=y CONFIG_FEATURE_VI_WIN_RESIZE=y CONFIG_FEATURE_VI_ASK_TERMINAL=y -CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y CONFIG_AWK=y CONFIG_FEATURE_AWK_LIBM=y CONFIG_CMP=y diff --git a/configs/freebsd_defconfig b/configs/freebsd_defconfig index dcb5d953c..ec3ed03c4 100644 --- a/configs/freebsd_defconfig +++ b/configs/freebsd_defconfig @@ -367,7 +367,6 @@ CONFIG_FEATURE_VI_SETOPTS=y CONFIG_FEATURE_VI_SET=y CONFIG_FEATURE_VI_WIN_RESIZE=y CONFIG_FEATURE_VI_ASK_TERMINAL=y -CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y CONFIG_FEATURE_ALLOW_EXEC=y # -- cgit v1.2.3-55-g6feb From 70fc8c17e2d032f34162f7abc3e65a67c0ff272a Mon Sep 17 00:00:00 2001 From: Pascal Bellard <pascal.bellard@ads-lu.com> Date: Tue, 12 Jun 2012 13:21:02 +0200 Subject: su: do not change to home dir unless -l Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/libbb.h | 1 + libbb/setup_environment.c | 8 +++++--- libbb/xfuncs_printf.c | 4 ++-- loginutils/su.c | 3 ++- networking/httpd.c | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 5e5c8c7e8..322a28cab 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1286,6 +1286,7 @@ int sd_listen_fds(void); #define SETUP_ENV_CHANGEENV (1 << 0) #define SETUP_ENV_CLEARENV (1 << 1) #define SETUP_ENV_TO_TMP (1 << 2) +#define SETUP_ENV_NO_CHDIR (1 << 4) extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; extern int correct_password(const struct passwd *pw) FAST_FUNC; /* Returns a malloced string */ diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 73229ca6c..4258656fe 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c @@ -37,9 +37,11 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass /* Change the current working directory to be the home directory * of the user */ - if (chdir(pw->pw_dir)) { - xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); - bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); + if (!(flags & SETUP_ENV_NO_CHDIR)) { + if (chdir(pw->pw_dir) != 0) { + bb_error_msg("can't change directory to '%s'", pw->pw_dir); + xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); + } } if (flags & SETUP_ENV_CLEARENV) { diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index d8a42ba0b..05aa07ce8 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -355,13 +355,13 @@ void FAST_FUNC xsetuid(uid_t uid) void FAST_FUNC xchdir(const char *path) { if (chdir(path)) - bb_perror_msg_and_die("chdir(%s)", path); + bb_perror_msg_and_die("can't change directory to '%s'", path); } void FAST_FUNC xchroot(const char *path) { if (chroot(path)) - bb_perror_msg_and_die("can't change root directory to %s", path); + bb_perror_msg_and_die("can't change root directory to '%s'", path); xchdir("/"); } diff --git a/loginutils/su.c b/loginutils/su.c index 57ea738f4..2ec05e125 100644 --- a/loginutils/su.c +++ b/loginutils/su.c @@ -131,7 +131,8 @@ int su_main(int argc UNUSED_PARAM, char **argv) change_identity(pw); setup_environment(opt_shell, ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV) - + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV), + + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV) + + (!(flags & SU_OPT_l) * SETUP_ENV_NO_CHDIR), pw); IF_SELINUX(set_current_security_context(NULL);) diff --git a/networking/httpd.c b/networking/httpd.c index 12218a0a3..a942794f5 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1414,7 +1414,7 @@ static void send_cgi_and_exit( if (script != url) { /* paranoia */ *script = '\0'; if (chdir(url + 1) != 0) { - bb_perror_msg("chdir(%s)", url + 1); + bb_perror_msg("can't change directory to '%s'", url + 1); goto error_execing_cgi; } // not needed: *script = '/'; -- cgit v1.2.3-55-g6feb From ac164dd2a7b7eefdc146ec2b0d448d029bc07ec0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Tue, 12 Jun 2012 15:00:35 +0200 Subject: volume_id/ext: use common bb_e2fs_defs.h for ext2/3/4 constants and structs Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/bb_e2fs_defs.h | 33 +++++++++++++++++---- util-linux/volume_id/ext.c | 74 +++++----------------------------------------- 2 files changed, 35 insertions(+), 72 deletions(-) diff --git a/include/bb_e2fs_defs.h b/include/bb_e2fs_defs.h index 7974497ca..071c660c5 100644 --- a/include/bb_e2fs_defs.h +++ b/include/bb_e2fs_defs.h @@ -463,6 +463,7 @@ struct ext2_super_block { #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \ ( EXT2_SB(sb)->s_feature_incompat & (mask) ) +/* for s_feature_compat */ #define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001 #define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 @@ -470,23 +471,45 @@ struct ext2_super_block { #define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010 #define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020 +/* for s_feature_ro_compat */ #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 -/* #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 not used */ +#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 /* not used */ +#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 +#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 +#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 +#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 +/* for s_feature_incompat */ #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 -#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ -#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ +#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 +#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 -#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040 +#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 +#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 +#define EXT4_FEATURE_INCOMPAT_MMP 0x0100 +#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 #define EXT2_FEATURE_COMPAT_SUPP 0 -#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE) #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ EXT2_FEATURE_RO_COMPAT_BTREE_DIR) +#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ + EXT2_FEATURE_INCOMPAT_META_BG) +#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED (~EXT2_FEATURE_INCOMPAT_SUPP) +#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED (~EXT2_FEATURE_RO_COMPAT_SUPP) + +#define EXT3_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ + EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ + EXT2_FEATURE_RO_COMPAT_BTREE_DIR) +#define EXT3_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ + EXT3_FEATURE_INCOMPAT_RECOVER| \ + EXT2_FEATURE_INCOMPAT_META_BG) +#define EXT3_FEATURE_INCOMPAT_UNSUPPORTED (~EXT3_FEATURE_INCOMPAT_SUPP) +#define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED (~EXT3_FEATURE_RO_COMPAT_SUPP) + /* * Default values for user and/or group using reserved blocks diff --git a/util-linux/volume_id/ext.c b/util-linux/volume_id/ext.c index aa23d1ebf..97451067f 100644 --- a/util-linux/volume_id/ext.c +++ b/util-linux/volume_id/ext.c @@ -19,70 +19,10 @@ */ #include "volume_id_internal.h" - -struct ext2_super_block { - uint32_t inodes_count; - uint32_t blocks_count; - uint32_t r_blocks_count; - uint32_t free_blocks_count; - uint32_t free_inodes_count; - uint32_t first_data_block; - uint32_t log_block_size; - uint32_t dummy3[7]; - uint8_t magic[2]; - uint16_t state; - uint32_t dummy5[8]; - uint32_t feature_compat; - uint32_t feature_incompat; - uint32_t feature_ro_compat; - uint8_t uuid[16]; - uint8_t volume_name[16]; -} PACKED; +#include "bb_e2fs_defs.h" #define EXT_SUPERBLOCK_OFFSET 0x400 -/* for s_flags */ -#define EXT2_FLAGS_TEST_FILESYS 0x0004 - -/* for s_feature_compat */ -#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 - -/* for s_feature_ro_compat */ -#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 -#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 -#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 -#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 -#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 -#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 -#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 - -/* for s_feature_incompat */ -#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 -#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 -#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 -#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 -#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */ -#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 -#define EXT4_FEATURE_INCOMPAT_MMP 0x0100 -#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 - -#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ - EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ - EXT2_FEATURE_RO_COMPAT_BTREE_DIR) -#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ - EXT2_FEATURE_INCOMPAT_META_BG) -#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP -#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP - -#define EXT3_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ - EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ - EXT2_FEATURE_RO_COMPAT_BTREE_DIR) -#define EXT3_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ - EXT3_FEATURE_INCOMPAT_RECOVER| \ - EXT2_FEATURE_INCOMPAT_META_BG) -#define EXT3_FEATURE_INCOMPAT_UNSUPPORTED ~EXT3_FEATURE_INCOMPAT_SUPP -#define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT3_FEATURE_RO_COMPAT_SUPP - int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/) { #define off ((uint64_t)0) @@ -94,24 +34,24 @@ int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/) if (es == NULL) return -1; - if (es->magic[0] != 0123 || es->magic[1] != 0357) { + if (es->s_magic != cpu_to_le16(EXT2_SUPER_MAGIC)) { dbg("ext: no magic found"); return -1; } // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); // volume_id_set_label_raw(id, es->volume_name, 16); - volume_id_set_label_string(id, es->volume_name, 16); - volume_id_set_uuid(id, es->uuid, UUID_DCE); + volume_id_set_label_string(id, (void*)es->s_volume_name, 16); + volume_id_set_uuid(id, es->s_uuid, UUID_DCE); dbg("ext: label '%s' uuid '%s'", id->label, id->uuid); #if ENABLE_FEATURE_BLKID_TYPE - if ((es->feature_ro_compat & cpu_to_le32(EXT4_FEATURE_RO_COMPAT_HUGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK)) - || (es->feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_64BIT)) + if ((es->s_feature_ro_compat & cpu_to_le32(EXT4_FEATURE_RO_COMPAT_HUGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK)) + || (es->s_feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_64BIT)) ) { id->type = "ext4"; } - else if (es->feature_compat & cpu_to_le32(EXT3_FEATURE_COMPAT_HAS_JOURNAL)) + else if (es->s_feature_compat & cpu_to_le32(EXT3_FEATURE_COMPAT_HAS_JOURNAL)) id->type = "ext3"; else id->type = "ext2"; -- cgit v1.2.3-55-g6feb From 772f17a8433b8572e1bf08b024fbf1f4e78395a3 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed, 30 May 2012 08:00:46 +0200 Subject: modinfo: match more standard module fields and fix version field Previously, -F version could match the srcversion= string. before : ~ # modinfo -F version tiwlan_drv version: 6.1.2012.05.29 version: 533BB7E5866E52F63B9ACCB version: 0x%x, oui=0x%x, 0x%x, 0x%x version: 0x%x ~ # modinfo tiwlan_drv filename: tiwlan_drv.ko author: Texas Instruments Inc - Retouched by CyanogenDefy license: GPL vermagic: 2.6.32.9 preempt mod_unload ARMv7 parm: g_sdio_debug_level:debug level depends: now : ~ # modinfo -F version tiwlan_drv version: 6.1.2012.05.29 ~ # modinfo tiwlan_drv filename: tiwlan_drv.ko license: GPL author: Texas Instruments Inc - Retouched by CyanogenDefy version: 6.1.2012.05.29 srcversion: 533BB7E5866E52F63B9ACCB depends: uts_release: 2.6.32.9-g306944c vermagic: 2.6.32.9 preempt mod_unload ARMv7 parm: g_sdio_debug_level:debug level This patch also add support for the old "-n" and some other helpers Change-Id: Icb4e9ca513cbce46b075a6f038799a7a19fb7e22 Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- modutils/modinfo.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/modutils/modinfo.c b/modutils/modinfo.c index c0910ffed..7c978d1da 100644 --- a/modutils/modinfo.c +++ b/modutils/modinfo.c @@ -24,9 +24,9 @@ enum { - OPT_TAGS = (1 << 8) - 1, - OPT_F = (1 << 8), /* field name */ - OPT_0 = (1 << 9), /* \0 as separator */ + OPT_TAGS = (1 << 12) - 1, /* shortcut count */ + OPT_F = (1 << 12), /* field name */ + OPT_0 = (1 << 13), /* \0 as separator */ }; struct modinfo_env { @@ -49,13 +49,17 @@ static void modinfo(const char *path, const char *version, { static const char *const shortcuts[] = { "filename", - "description", - "author", "license", + "author", + "description", + "version", + "alias", + "srcversion", + "depends", + "uts_release", "vermagic", "parm", "firmware", - "depends", }; size_t len; int j, length; @@ -97,8 +101,11 @@ static void modinfo(const char *path, const char *version, if (ptr == NULL) /* no occurance left, done */ break; if (strncmp(ptr, pattern, length) == 0 && ptr[length] == '=') { - ptr += length + 1; - ptr += display(ptr, pattern, (1<<j) != tags); + /* field prefixes are 0x80 or 0x00 */ + if ((ptr[-1] & 0x7F) == '\0') { + ptr += length + 1; + ptr += display(ptr, pattern, (1<<j) != tags); + } } ++ptr; } @@ -131,7 +138,7 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv) env.field = NULL; opt_complementary = "-1"; /* minimum one param */ - opts = getopt32(argv, "fdalvpF:0", &env.field); + opts = getopt32(argv, "nladvAsDumpF:0", &env.field); env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS; argv += optind; -- cgit v1.2.3-55-g6feb From 6979325592dd421ae4b02817ac8ac9ba5f362382 Mon Sep 17 00:00:00 2001 From: Matt Reimer <mreimer@sdgsystems.com> Date: Wed, 30 May 2012 10:31:13 -0400 Subject: nanddump: make dumping read-only partitions work Make dumping read-only partitions work by opening the device O_RDONLY; otherwise the open() will fail with -EPERM. Signed-off-by: Matt Reimer <mreimer@sdgsystems.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- miscutils/nandwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index 2ba6e3fe5..c636a5aa2 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -129,7 +129,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) xmove_fd(tmp_fd, IS_NANDDUMP ? STDOUT_FILENO : STDIN_FILENO); } - fd = xopen(argv[0], O_RDWR); + fd = xopen(argv[0], IS_NANDWRITE ? O_RDWR : O_RDONLY); xioctl(fd, MEMGETINFO, &meminfo); mtdoffset = xstrtou(opt_s, 0); -- cgit v1.2.3-55-g6feb From ac42e3de90ebf4b921035893e3670da63cad882c Mon Sep 17 00:00:00 2001 From: Michael Tokarev <mjt@tls.msk.ru> Date: Wed, 13 Jun 2012 02:51:56 +0200 Subject: ps: use separate get_uptime() and make it work on non-linux too Create get_uptime() function in procps/ps.c, and use it rather than relying on linux-specific sysinfo() inline. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- procps/ps.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/procps/ps.c b/procps/ps.c index 4727b218b..3a5af7c18 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -69,6 +69,31 @@ /* Absolute maximum on output line length */ enum { MAX_WIDTH = 2*1024 }; +#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG +static long get_uptime(void) +{ +#ifdef __linux__ + struct sysinfo info; + if (sysinfo(&info) < 0) + return 0; + return info.uptime; +#elif 1 + char buf[64]; + long uptime; + if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) + bb_perror_msg_and_die("can't read %s", "/proc/uptime"); + buf[sizeof(buf)-1] = '\0'; + sscanf(buf, "%l", &uptime); + return uptime; +#else + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) + return 0; + return ts.tv_sec; +#endif +} +#endif + #if ENABLE_DESKTOP #include <sys/times.h> /* for times() */ @@ -197,8 +222,6 @@ static inline unsigned get_HZ_by_waiting(void) static unsigned get_kernel_HZ(void) { - //char buf[64]; - struct sysinfo info; if (kernel_HZ) return kernel_HZ; @@ -208,12 +231,7 @@ static unsigned get_kernel_HZ(void) if (kernel_HZ == (unsigned)-1) kernel_HZ = get_HZ_by_waiting(); - //if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) - // bb_perror_msg_and_die("can't read %s", "/proc/uptime"); - //buf[sizeof(buf)-1] = '\0'; - ///sscanf(buf, "%llu", &seconds_since_boot); - sysinfo(&info); - seconds_since_boot = info.uptime; + seconds_since_boot = get_uptime(); return kernel_HZ; } @@ -635,7 +653,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) }; #if ENABLE_FEATURE_PS_LONG time_t now = now; - struct sysinfo info; + long uptime; #endif int opts = 0; /* If we support any options, parse argv */ @@ -695,7 +713,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD"); #if ENABLE_FEATURE_PS_LONG now = time(NULL); - sysinfo(&info); + uptime = get_uptime(); #endif } else { @@ -727,7 +745,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) char tty[2 * sizeof(int)*3 + 2]; char *endp; unsigned sut = (p->stime + p->utime) / 100; - unsigned elapsed = info.uptime - (p->start_time / 100); + unsigned elapsed = uptime - (p->start_time / 100); time_t start = now - elapsed; struct tm *tm = localtime(&start); -- cgit v1.2.3-55-g6feb From f5abc78579db1b2f0b8d8ed7353c621f4dc3d78d Mon Sep 17 00:00:00 2001 From: Vladimir Dronnikov <dronnikov@gmail.com> Date: Wed, 13 Jun 2012 17:29:41 +0200 Subject: wget: add dummy --no-cache function old new delta static.wget_longopts 155 166 +11 packed_usage 29259 29231 -28 Signed-off-by: Vladimir Dronnikov <dronnikov@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/wget.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 1991a1072..8520fe2b9 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -13,8 +13,9 @@ //usage: IF_FEATURE_WGET_LONG_OPTIONS( //usage: "[-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document FILE]\n" //usage: " [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]\n" -//usage: " [--no-check-certificate] [-U|--user-agent AGENT]" -//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." +/* Since we ignore these opts, we don't show them in --help */ +/* //usage: " [--no-check-certificate] [--no-cache]" */ +//usage: " [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." //usage: ) //usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS( //usage: "[-csq] [-O FILE] [-Y on/off] [-P DIR] [-U AGENT]" @@ -35,8 +36,11 @@ #include "libbb.h" -//#define log_io(...) bb_error_msg(__VA_ARGS__) -#define log_io(...) ((void)0) +#if 0 +# define log_io(...) bb_error_msg(__VA_ARGS__) +#else +# define log_io(...) ((void)0) +#endif struct host_info { @@ -316,8 +320,6 @@ static char *gethdr(FILE *fp) char *s, *hdrval; int c; - /* *istrunc = 0; */ - /* retrieve header line */ c = fgets_and_trim(fp); @@ -415,7 +417,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ *dfpp = open_socket(lsa); - if (G.beg_range) { + if (G.beg_range != 0) { sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range); if (ftpcmd(G.wget_buf, NULL, sfp) == 350) G.content_len -= G.beg_range; @@ -675,7 +677,7 @@ static void download_one_url(const char *url) } #endif - if (G.beg_range) + if (G.beg_range != 0) fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range); #if ENABLE_FEATURE_WGET_LONG_OPTIONS @@ -748,9 +750,11 @@ However, in real world it was observed that some web servers case 302: case 303: break; - case 206: - if (G.beg_range) + case 206: /* Partial Content */ + if (G.beg_range != 0) + /* "Range:..." worked. Good. */ break; + /* Partial Content even though we did not ask for it??? */ /* fall through */ default: bb_error_msg_and_die("server returned error: %s", sanitize_string(G.wget_buf)); @@ -878,6 +882,8 @@ int wget_main(int argc UNUSED_PARAM, char **argv) "post-data\0" Required_argument "\xfd" /* Ignored (we don't do ssl) */ "no-check-certificate\0" No_argument "\xfc" + /* Ignored (we don't support caching) */ + "no-cache\0" No_argument "\xfb" ; #endif -- cgit v1.2.3-55-g6feb From bf146b861083e3170af05016982d50d297e3ace7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 13 Jun 2012 17:31:07 +0200 Subject: wget: correctly handle failure to -c (continue) function old new delta reset_beg_range_to_zero - 52 +52 wget_main 2168 2189 +21 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/wget.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/networking/wget.c b/networking/wget.c index 8520fe2b9..013b87801 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -350,6 +350,14 @@ static char *gethdr(FILE *fp) return hdrval; } +static void reset_beg_range_to_zero(void) +{ + //bb_error_msg("restart failed"); + G.beg_range = 0; + xlseek(G.output_fd, 0, SEEK_SET); + ftruncate(G.output_fd, 0); +} + static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) { FILE *sfp; @@ -421,6 +429,8 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range); if (ftpcmd(G.wget_buf, NULL, sfp) == 350) G.content_len -= G.beg_range; + else + reset_beg_range_to_zero(); } if (ftpcmd("RETR ", target->path, sfp) > 150) @@ -744,6 +754,12 @@ However, in real world it was observed that some web servers (e.g. Boa/0.94.14rc21) simply use code 204 when file size is zero. */ case 204: + if (G.beg_range != 0) { + /* "Range:..." was not honored by the server. + * Restart download from the beginning. + */ + reset_beg_range_to_zero(); + } break; case 300: /* redirection */ case 301: -- cgit v1.2.3-55-g6feb From c5b01016e622f01dfa9c8c542c0968fe37d4a5f2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 15 Jun 2012 16:43:26 +0200 Subject: unzip: make options parsing more robust on getopt w/o gnu extensions Also, code shrank: function old new delta static.extn 15 10 -5 packed_usage 29231 29217 -14 unzip_main 2388 2291 -97 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-116) Total: -116 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/unzip.c | 137 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 70 insertions(+), 67 deletions(-) diff --git a/archival/unzip.c b/archival/unzip.c index c1b945a44..380674701 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -20,11 +20,11 @@ */ //usage:#define unzip_trivial_usage -//usage: "[-opts[modifiers]] FILE[.zip] [LIST] [-x XLIST] [-d DIR]" +//usage: "[-lnopq] FILE[.zip] [LIST] [-x XLIST] [-d DIR]" //usage:#define unzip_full_usage "\n\n" //usage: "Extract files from ZIP archives\n" //usage: "\n -l List archive contents (with -q for short form)" -//usage: "\n -n Never overwrite files (default)" +//usage: "\n -n Never overwrite files (default: ask)" //usage: "\n -o Overwrite" //usage: "\n -p Send output to stdout" //usage: "\n -q Quiet" @@ -277,6 +277,7 @@ int unzip_main(int argc, char **argv) IF_NOT_DESKTOP(const) smallint verbose = 0; smallint listing = 0; smallint overwrite = O_PROMPT; + smallint x_opt_seen; #if ENABLE_DESKTOP uint32_t cdf_offset; #endif @@ -290,7 +291,6 @@ int unzip_main(int argc, char **argv) llist_t *zreject = NULL; char *base_dir = NULL; int i, opt; - int opt_range = 0; char key_buf[80]; struct stat stat_buf; @@ -335,81 +335,81 @@ int unzip_main(int argc, char **argv) * 204372 1 file */ + x_opt_seen = 0; /* '-' makes getopt return 1 for non-options */ while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) { - switch (opt_range) { - case 0: /* Options */ - switch (opt) { - case 'l': /* List */ - listing = 1; - break; + switch (opt) { + case 'd': /* Extract to base directory */ + base_dir = optarg; + break; - case 'n': /* Never overwrite existing files */ - overwrite = O_NEVER; - break; + case 'l': /* List */ + listing = 1; + break; - case 'o': /* Always overwrite existing files */ - overwrite = O_ALWAYS; - break; + case 'n': /* Never overwrite existing files */ + overwrite = O_NEVER; + break; - case 'p': /* Extract files to stdout and fall through to set verbosity */ - dst_fd = STDOUT_FILENO; + case 'o': /* Always overwrite existing files */ + overwrite = O_ALWAYS; + break; - case 'q': /* Be quiet */ - quiet++; - break; + case 'p': /* Extract files to stdout and fall through to set verbosity */ + dst_fd = STDOUT_FILENO; - case 'v': /* Verbose list */ - IF_DESKTOP(verbose++;) - listing = 1; - break; + case 'q': /* Be quiet */ + quiet++; + break; - case 1: /* The zip file */ - /* +5: space for ".zip" and NUL */ - src_fn = xmalloc(strlen(optarg) + 5); - strcpy(src_fn, optarg); - opt_range++; - break; + case 'v': /* Verbose list */ + IF_DESKTOP(verbose++;) + listing = 1; + break; - default: - bb_show_usage(); - } + case 'x': + x_opt_seen = 1; break; - case 1: /* Include files */ - if (opt == 1) { + case 1: + if (!src_fn) { + /* The zip file */ + /* +5: space for ".zip" and NUL */ + src_fn = xmalloc(strlen(optarg) + 5); + strcpy(src_fn, optarg); + } else if (!x_opt_seen) { + /* Include files */ llist_add_to(&zaccept, optarg); - break; - } - if (opt == 'd') { - base_dir = optarg; - opt_range += 2; - break; - } - if (opt == 'x') { - opt_range++; - break; - } - bb_show_usage(); - - case 2 : /* Exclude files */ - if (opt == 1) { + } else { + /* Exclude files */ llist_add_to(&zreject, optarg); - break; } - if (opt == 'd') { /* Extract to base directory */ - base_dir = optarg; - opt_range++; - break; - } - /* fall through */ + break; default: bb_show_usage(); } } - if (src_fn == NULL) { +#ifndef __GLIBC__ + /* + * This code is needed for non-GNU getopt + * which doesn't understand "-" in option string. + * The -x option won't work properly in this case: + * "unzip a.zip q -x w e" will be interpreted as + * "unzip a.zip q w e -x" = "unzip a.zip q w e" + */ + argv += optind; + if (argv[0]) { + /* +5: space for ".zip" and NUL */ + src_fn = xmalloc(strlen(argv[0]) + 5); + strcpy(src_fn, argv[0]); + while (*++argv) + llist_add_to(&zaccept, *argv); + } +#endif + + if (!src_fn) { bb_show_usage(); } @@ -420,17 +420,20 @@ int unzip_main(int argc, char **argv) if (overwrite == O_PROMPT) overwrite = O_NEVER; } else { - static const char extn[][5] = {"", ".zip", ".ZIP"}; - int orig_src_fn_len = strlen(src_fn); - int src_fd = -1; + static const char extn[][5] = { ".zip", ".ZIP" }; + char *ext = src_fn + strlen(src_fn); + int src_fd; - for (i = 0; (i < 3) && (src_fd == -1); i++) { - strcpy(src_fn + orig_src_fn_len, extn[i]); + i = 0; + for (;;) { src_fd = open(src_fn, O_RDONLY); - } - if (src_fd == -1) { - src_fn[orig_src_fn_len] = '\0'; - bb_error_msg_and_die("can't open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn); + if (src_fd >= 0) + break; + if (++i > 2) { + *ext = '\0'; + bb_error_msg_and_die("can't open %s[.zip]", src_fn); + } + strcpy(ext, extn[i - 1]); } xmove_fd(src_fd, zip_fd); } -- cgit v1.2.3-55-g6feb From 6144124aac1d4a30ff81842ba1bb0e28373a71c8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 17 Jun 2012 19:52:25 +0200 Subject: wget: make -c _not_ truncate the file function old new delta retrieve_file_data 396 436 +40 reset_beg_range_to_zero 52 45 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/wget.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 013b87801..5d5845019 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -352,10 +352,11 @@ static char *gethdr(FILE *fp) static void reset_beg_range_to_zero(void) { - //bb_error_msg("restart failed"); + bb_error_msg("restart failed"); G.beg_range = 0; xlseek(G.output_fd, 0, SEEK_SET); - ftruncate(G.output_fd, 0); + /* Done at the end instead: */ + /* ftruncate(G.output_fd, 0); */ } static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) @@ -554,6 +555,17 @@ static void NOINLINE retrieve_file_data(FILE *dfp) G.got_clen = 1; } + /* If -c failed, we restart from the beginning, + * but we do not truncate file then, we do it only now, at the end. + * This lets user to ^C if his 99% complete 10 GB file download + * failed to restart *without* losing the almost complete file. + */ + { + off_t pos = lseek(G.output_fd, 0, SEEK_CUR); + if (pos != (off_t)-1) + ftruncate(G.output_fd, pos); + } + /* Draw full bar and free its resources */ G.chunked = 0; /* makes it show 100% even for chunked download */ G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ -- cgit v1.2.3-55-g6feb From e0a6004ce83ba519a0e6f0d277968d306c4df296 Mon Sep 17 00:00:00 2001 From: Pierre Carrier <pierre@spotify.com> Date: Sun, 17 Jun 2012 19:59:53 +0200 Subject: config: do not refer to HTTPS for wget Signed-off-by: Pierre Carrier <pierre@spotify.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/Config.src | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networking/Config.src b/networking/Config.src index fb7dca7d4..e2376d548 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -945,8 +945,8 @@ config WGET bool "wget" default y help - wget is a utility for non-interactive download of files from HTTP, - HTTPS, and FTP servers. + wget is a utility for non-interactive download of files from HTTP + and FTP servers. config FEATURE_WGET_STATUSBAR bool "Enable a nifty process meter (+2k)" -- cgit v1.2.3-55-g6feb From aacd44860129372e5d4ff1494664317f18cbb615 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 17 Jun 2012 20:21:30 +0200 Subject: wget: fix wget-supports--P testsuite failure. Closes 4940 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/wget.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 5d5845019..6d8f8a504 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -621,13 +621,11 @@ static void download_one_url(const char *url) if (G.fname_out[0] == '/' || !G.fname_out[0]) G.fname_out = (char*)"index.html"; /* -P DIR is considered only if there was no -O FILE */ + if (G.dir_prefix) + G.fname_out = fname_out_alloc = concat_path_file(G.dir_prefix, G.fname_out); else { - if (G.dir_prefix) - G.fname_out = fname_out_alloc = concat_path_file(G.dir_prefix, G.fname_out); - else { - /* redirects may free target.path later, need to make a copy */ - G.fname_out = fname_out_alloc = xstrdup(G.fname_out); - } + /* redirects may free target.path later, need to make a copy */ + G.fname_out = fname_out_alloc = xstrdup(G.fname_out); } } #if ENABLE_FEATURE_WGET_STATUSBAR -- cgit v1.2.3-55-g6feb From 9b78e14dfb891e3f53685e284bc9d5e3bf25f5a6 Mon Sep 17 00:00:00 2001 From: Bernhard Walle <bernhard@bwalle.de> Date: Mon, 18 Jun 2012 01:51:26 +0200 Subject: build system: fix build of kconfig on Darwin Of course busybox cannot be used on Darwin (Mac OS X), but it can be cross-compiled for Linux there. Cross-compilation still requires kconfig to be built as native host tool. Signed-off-by: Bernhard Walle <bernhard@bwalle.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- scripts/kconfig/mconf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index d3f69f8f5..1b0b6ab07 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -9,6 +9,8 @@ */ #define _XOPEN_SOURCE 700 +/* On Darwin, this may be needed to get SIGWINCH: */ +#define _DARWIN_C_SOURCE 1 #include <sys/ioctl.h> #include <sys/wait.h> -- cgit v1.2.3-55-g6feb From e3e0d2b81281e049db1abbdef11a2d0da079ca8f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Tue, 19 Jun 2012 12:46:59 +0200 Subject: tweak help text Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/unzip.c | 12 ++++++------ coreutils/od_bloaty.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/archival/unzip.c b/archival/unzip.c index 380674701..046027cc6 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -20,16 +20,16 @@ */ //usage:#define unzip_trivial_usage -//usage: "[-lnopq] FILE[.zip] [LIST] [-x XLIST] [-d DIR]" +//usage: "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]" //usage:#define unzip_full_usage "\n\n" -//usage: "Extract files from ZIP archives\n" -//usage: "\n -l List archive contents (with -q for short form)" +//usage: "Extract FILEs from ZIP archive\n" +//usage: "\n -l List contents (with -q for short form)" //usage: "\n -n Never overwrite files (default: ask)" //usage: "\n -o Overwrite" -//usage: "\n -p Send output to stdout" +//usage: "\n -p Print to stdout" //usage: "\n -q Quiet" -//usage: "\n -x XLST Exclude these files" -//usage: "\n -d DIR Extract files into DIR" +//usage: "\n -x FILE Exclude FILEs" +//usage: "\n -d DIR Extract into DIR" #include "libbb.h" #include "bb_archive.h" diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 347f879d7..2f6650153 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -25,7 +25,7 @@ //usage:#if ENABLE_DESKTOP //usage:#define od_trivial_usage -//usage: "[-abcdfhilovxs] [-t TYPE] [-A RADIX] [-N SIZE] [-j SKIP] [-S MINSTR] [-w WIDTH] [FILE...]" +//usage: "[-abcdfhilovxs] [-t TYPE] [-A RADIX] [-N SIZE] [-j SKIP] [-S MINSTR] [-w WIDTH] [FILE]..." // We don't support: // ... [FILE] [[+]OFFSET[.][b]] // Support is buggy for: -- cgit v1.2.3-55-g6feb From dac8e79a190fcfedb9c9054034a521e84c7bec72 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 20 Jun 2012 20:24:57 +0200 Subject: Move several applets to different install dir: Moved to [/usr]/sbin: addgroup, adduser, delgroup, deluser, arping, chat, ether-wake, fdformat, ifplugd, ip, ipaddr, iplink, iproute, iprule, iptunnel, killall5, readahead, rtcwake, tftpd, add-shell, remove-shell, powertop. Moved to /bin for /usr/bin: kbd_mode. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/applets.src.h | 40 ++++++++++++++++++++-------------------- loginutils/add-remove-shell.c | 4 ++-- procps/powertop.c | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index 252a060fb..89d258719 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -70,12 +70,12 @@ INSERT IF_TEST(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test)) IF_TEST(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test)) IF_ACPID(APPLET(acpid, BB_DIR_SBIN, BB_SUID_DROP)) -IF_ADDGROUP(APPLET(addgroup, BB_DIR_BIN, BB_SUID_DROP)) -IF_ADDUSER(APPLET(adduser, BB_DIR_BIN, BB_SUID_DROP)) +IF_ADDGROUP(APPLET(addgroup, BB_DIR_USR_SBIN, BB_SUID_DROP)) +IF_ADDUSER(APPLET(adduser, BB_DIR_SBIN, BB_SUID_DROP)) IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP)) IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_ARP(APPLET(arp, BB_DIR_SBIN, BB_SUID_DROP)) -IF_ARPING(APPLET(arping, BB_DIR_USR_BIN, BB_SUID_DROP)) +IF_ARPING(APPLET(arping, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_AWK(APPLET_NOEXEC(awk, awk, BB_DIR_USR_BIN, BB_SUID_DROP, awk)) IF_BASENAME(APPLET_NOFORK(basename, basename, BB_DIR_USR_BIN, BB_SUID_DROP, basename)) IF_BBCONFIG(APPLET(bbconfig, BB_DIR_BIN, BB_SUID_DROP)) @@ -86,7 +86,7 @@ IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CAL(APPLET(cal, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat)) IF_CATV(APPLET(catv, BB_DIR_BIN, BB_SUID_DROP)) -IF_CHAT(APPLET(chat, BB_DIR_USR_BIN, BB_SUID_DROP)) +IF_CHAT(APPLET(chat, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_CHATTR(APPLET(chattr, BB_DIR_BIN, BB_SUID_DROP)) IF_CHCON(APPLET(chcon, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp)) @@ -111,8 +111,8 @@ IF_CUT(APPLET_NOEXEC(cut, cut, BB_DIR_USR_BIN, BB_SUID_DROP, cut)) IF_DC(APPLET(dc, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_DD(APPLET_NOEXEC(dd, dd, BB_DIR_BIN, BB_SUID_DROP, dd)) IF_DEALLOCVT(APPLET(deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_DELGROUP(APPLET_ODDNAME(delgroup, deluser, BB_DIR_BIN, BB_SUID_DROP, delgroup)) -IF_DELUSER(APPLET(deluser, BB_DIR_BIN, BB_SUID_DROP)) +IF_DELGROUP(APPLET_ODDNAME(delgroup, deluser, BB_DIR_USR_SBIN, BB_SUID_DROP, delgroup)) +IF_DELUSER(APPLET(deluser, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_DEVFSD(APPLET(devfsd, BB_DIR_SBIN, BB_SUID_DROP)) IF_DEVMEM(APPLET(devmem, BB_DIR_SBIN, BB_SUID_DROP)) IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP)) @@ -136,7 +136,7 @@ IF_EJECT(APPLET(eject, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env)) IF_ENVDIR(APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir)) IF_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid)) -IF_ETHER_WAKE(APPLET_ODDNAME(ether-wake, ether_wake, BB_DIR_USR_BIN, BB_SUID_DROP, ether_wake)) +IF_ETHER_WAKE(APPLET_ODDNAME(ether-wake, ether_wake, BB_DIR_USR_SBIN, BB_SUID_DROP, ether_wake)) IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_FAKEIDENTD(APPLET(fakeidentd, BB_DIR_USR_SBIN, BB_SUID_DROP)) @@ -144,7 +144,7 @@ IF_FALSE(APPLET_NOFORK(false, false, BB_DIR_BIN, BB_SUID_DROP, false)) IF_FBSET(APPLET(fbset, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_FBSPLASH(APPLET(fbsplash, BB_DIR_SBIN, BB_SUID_DROP)) IF_FDFLUSH(APPLET_ODDNAME(fdflush, freeramdisk, BB_DIR_BIN, BB_SUID_DROP, fdflush)) -IF_FDFORMAT(APPLET(fdformat, BB_DIR_USR_BIN, BB_SUID_DROP)) +IF_FDFORMAT(APPLET(fdformat, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_FDISK(APPLET(fdisk, BB_DIR_SBIN, BB_SUID_DROP)) IF_FGCONSOLE(APPLET(fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP)) /* Benefits from suid root: better access to /dev/BLOCKDEVs: */ @@ -182,7 +182,7 @@ IF_HWCLOCK(APPLET(hwclock, BB_DIR_SBIN, BB_SUID_DROP)) IF_IFCONFIG(APPLET(ifconfig, BB_DIR_SBIN, BB_SUID_DROP)) IF_IFUPDOWN(APPLET_ODDNAME(ifdown, ifupdown, BB_DIR_SBIN, BB_SUID_DROP, ifdown)) IF_IFENSLAVE(APPLET(ifenslave, BB_DIR_SBIN, BB_SUID_DROP)) -IF_IFPLUGD(APPLET(ifplugd, BB_DIR_USR_BIN, BB_SUID_DROP)) +IF_IFPLUGD(APPLET(ifplugd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_IFUPDOWN(APPLET_ODDNAME(ifup, ifupdown, BB_DIR_SBIN, BB_SUID_DROP, ifup)) IF_INETD(APPLET(inetd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_INOTIFYD(APPLET(inotifyd, BB_DIR_SBIN, BB_SUID_DROP)) @@ -193,20 +193,20 @@ IF_IONICE(APPLET(ionice, BB_DIR_BIN, BB_SUID_DROP)) || ENABLE_FEATURE_IP_LINK \ || ENABLE_FEATURE_IP_TUNNEL \ || ENABLE_FEATURE_IP_RULE -IF_IP(APPLET(ip, BB_DIR_BIN, BB_SUID_DROP)) +IF_IP(APPLET(ip, BB_DIR_SBIN, BB_SUID_DROP)) #endif -IF_IPADDR(APPLET(ipaddr, BB_DIR_BIN, BB_SUID_DROP)) +IF_IPADDR(APPLET(ipaddr, BB_DIR_SBIN, BB_SUID_DROP)) IF_IPCALC(APPLET(ipcalc, BB_DIR_BIN, BB_SUID_DROP)) IF_IPCRM(APPLET(ipcrm, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_IPCS(APPLET(ipcs, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_IPLINK(APPLET(iplink, BB_DIR_BIN, BB_SUID_DROP)) -IF_IPROUTE(APPLET(iproute, BB_DIR_BIN, BB_SUID_DROP)) -IF_IPRULE(APPLET(iprule, BB_DIR_BIN, BB_SUID_DROP)) -IF_IPTUNNEL(APPLET(iptunnel, BB_DIR_BIN, BB_SUID_DROP)) -IF_KBD_MODE(APPLET(kbd_mode, BB_DIR_USR_BIN, BB_SUID_DROP)) +IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP)) +IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP)) +IF_IPRULE(APPLET(iprule, BB_DIR_SBIN, BB_SUID_DROP)) +IF_IPTUNNEL(APPLET(iptunnel, BB_DIR_SBIN, BB_SUID_DROP)) +IF_KBD_MODE(APPLET(kbd_mode, BB_DIR_BIN, BB_SUID_DROP)) IF_KILL(APPLET(kill, BB_DIR_BIN, BB_SUID_DROP)) IF_KILLALL(APPLET_ODDNAME(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall)) -IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall5)) +IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5)) IF_KLOGD(APPLET(klogd, BB_DIR_SBIN, BB_SUID_DROP)) IF_LAST(APPLET(last, BB_DIR_USR_BIN, BB_SUID_DROP)) //IF_LENGTH(APPLET_NOFORK(length, length, BB_DIR_USR_BIN, BB_SUID_DROP, length)) @@ -288,7 +288,7 @@ IF_PWD(APPLET_NOFORK(pwd, pwd, BB_DIR_BIN, BB_SUID_DROP, pwd)) IF_RAIDAUTORUN(APPLET(raidautorun, BB_DIR_SBIN, BB_SUID_DROP)) IF_RDATE(APPLET(rdate, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_RDEV(APPLET(rdev, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_READAHEAD(APPLET(readahead, BB_DIR_USR_BIN, BB_SUID_DROP)) +IF_READAHEAD(APPLET(readahead, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_READLINK(APPLET(readlink, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_READPROFILE(APPLET(readprofile, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_REALPATH(APPLET(realpath, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -303,7 +303,7 @@ IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir)) IF_ROUTE(APPLET(route, BB_DIR_SBIN, BB_SUID_DROP)) IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP)) IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_RTCWAKE(APPLET(rtcwake, BB_DIR_USR_BIN, BB_SUID_DROP)) +IF_RTCWAKE(APPLET(rtcwake, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts)) IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RUNLEVEL(APPLET(runlevel, BB_DIR_SBIN, BB_SUID_DROP)) @@ -365,7 +365,7 @@ IF_TELNETD(APPLET(telnetd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_TEST(APPLET_NOFORK(test, test, BB_DIR_USR_BIN, BB_SUID_DROP, test)) #if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT IF_TFTP(APPLET(tftp, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_TFTPD(APPLET(tftpd, BB_DIR_USR_BIN, BB_SUID_DROP)) +IF_TFTPD(APPLET(tftpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) #endif IF_TIME(APPLET(time, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_TIMEOUT(APPLET(timeout, BB_DIR_USR_BIN, BB_SUID_DROP)) diff --git a/loginutils/add-remove-shell.c b/loginutils/add-remove-shell.c index 9a1454430..e492b6e5a 100644 --- a/loginutils/add-remove-shell.c +++ b/loginutils/add-remove-shell.c @@ -8,8 +8,8 @@ * for details. */ -//applet:IF_ADD_SHELL( APPLET_ODDNAME(add-shell , add_remove_shell, BB_DIR_USR_BIN, BB_SUID_DROP, add_shell )) -//applet:IF_REMOVE_SHELL(APPLET_ODDNAME(remove-shell, add_remove_shell, BB_DIR_USR_BIN, BB_SUID_DROP, remove_shell)) +//applet:IF_ADD_SHELL( APPLET_ODDNAME(add-shell , add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, add_shell )) +//applet:IF_REMOVE_SHELL(APPLET_ODDNAME(remove-shell, add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, remove_shell)) //kbuild:lib-$(CONFIG_ADD_SHELL) += add-remove-shell.o //kbuild:lib-$(CONFIG_REMOVE_SHELL) += add-remove-shell.o diff --git a/procps/powertop.c b/procps/powertop.c index 008cdfca4..b4c45edbc 100644 --- a/procps/powertop.c +++ b/procps/powertop.c @@ -9,7 +9,7 @@ * Licensed under GPLv2, see file LICENSE in this source tree. */ -//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_POWERTOP) += powertop.o -- cgit v1.2.3-55-g6feb From 2bc495e4c402d9bc74c42ea01b7891356917d06e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 20 Jun 2012 20:35:58 +0200 Subject: adduser: install to /usr, not /, like all other similar tools Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/applets.src.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/applets.src.h b/include/applets.src.h index 89d258719..597b1c9a6 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -71,7 +71,7 @@ IF_TEST(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test)) IF_TEST(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test)) IF_ACPID(APPLET(acpid, BB_DIR_SBIN, BB_SUID_DROP)) IF_ADDGROUP(APPLET(addgroup, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_ADDUSER(APPLET(adduser, BB_DIR_SBIN, BB_SUID_DROP)) +IF_ADDUSER(APPLET(adduser, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP)) IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_ARP(APPLET(arp, BB_DIR_SBIN, BB_SUID_DROP)) -- cgit v1.2.3-55-g6feb From 1d7ad7a022bf894e89904832a0c84f14c8ca2d31 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 21 Jun 2012 09:45:11 +0200 Subject: tweak help texts Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- debianutils/run_parts.c | 15 +++++++-------- editors/sed.c | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 8f08f6dc6..005b30420 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c @@ -4,14 +4,13 @@ * * Copyright (C) 2007 Bernhard Reutner-Fischer * - * Based on a older version that was in busybox which was 1k big.. + * Based on a older version that was in busybox which was 1k big. * Copyright (C) 2001 by Emanuele Aina <emanuele.aina@tiscali.it> * * Based on the Debian run-parts program, version 1.15 * Copyright (C) 1996 Jeff Noxon <jeff@router.patch.net>, * Copyright (C) 1996-1999 Guy Maor <maor@debian.org> * - * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ @@ -19,7 +18,7 @@ * attempt to write a program! :-) . */ /* This piece of code is heavily based on the original version of run-parts, - * taken from debian-utils. I've only removed the long options and a the + * taken from debian-utils. I've only removed the long options and the * report mode. As the original run-parts support only long options, I've * broken compatibility because the BusyBox policy doesn't allow them. * The supported options are: @@ -31,15 +30,15 @@ */ //usage:#define run_parts_trivial_usage -//usage: "[-t] "IF_FEATURE_RUN_PARTS_FANCY("[-l] ")"[-a ARG] [-u MASK] DIRECTORY" +//usage: "[-t"IF_FEATURE_RUN_PARTS_FANCY("l")"] [-a ARG]... [-u MASK] DIRECTORY" //usage:#define run_parts_full_usage "\n\n" //usage: "Run a bunch of scripts in DIRECTORY\n" -//usage: "\n -t Print what would be run, but don't actually run anything" -//usage: "\n -a ARG Pass ARG as argument for every program" -//usage: "\n -u MASK Set the umask to MASK before running every program" +//usage: "\n -t Dry run" //usage: IF_FEATURE_RUN_PARTS_FANCY( -//usage: "\n -l Print names of all matching files even if they are not executable" +//usage: "\n -l Print names of matching files even if they are not executable" //usage: ) +//usage: "\n -a ARG Pass ARG as argument to programs" +//usage: "\n -u MASK Set umask to MASK before running programs" //usage: //usage:#define run_parts_example_usage //usage: "$ run-parts -a start /etc/init.d\n" diff --git a/editors/sed.c b/editors/sed.c index 652aaf573..42d8e17c6 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -63,7 +63,7 @@ //usage: " -e CMD Add CMD to sed commands to be executed" //usage: "\n -f FILE Add FILE contents to sed commands to be executed" //usage: "\n -i[SFX] Edit files in-place (otherwise sends to stdout)" -//usage: "\n Optionally backs files up, appending SFX" +//usage: "\n Optionally back files up, appending SFX" //usage: "\n -n Suppress automatic printing of pattern space" //usage: "\n -r Use extended regex syntax" //usage: "\n" -- cgit v1.2.3-55-g6feb From 9ee426649006c4a0db7b4784f2ebb96865d4c705 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 21 Jun 2012 12:08:56 +0200 Subject: mount: set up RO loop device if mount -o ro. Closes 4784 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/mount.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/util-linux/mount.c b/util-linux/mount.c index f1da30fac..220a4e67c 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -450,9 +450,9 @@ static void append_mount_options(char **oldopts, const char *newopts) // Use the mount_options list to parse options into flags. // Also update list of unrecognized options if unrecognized != NULL -static long parse_mount_options(char *options, char **unrecognized) +static unsigned long parse_mount_options(char *options, char **unrecognized) { - long flags = MS_SILENT; + unsigned long flags = MS_SILENT; // Loop through options for (;;) { @@ -466,7 +466,7 @@ static long parse_mount_options(char *options, char **unrecognized) // Find this option in mount_options for (i = 0; i < ARRAY_SIZE(mount_options); i++) { if (strcasecmp(option_str, options) == 0) { - long fl = mount_options[i]; + unsigned long fl = mount_options[i]; if (fl < 0) flags &= fl; else @@ -548,7 +548,7 @@ void delete_block_backed_filesystems(void); // Perform actual mount of specific filesystem at specific location. // NB: mp->xxx fields may be trashed on exit -static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts) +static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filteropts) { int rc = 0; @@ -1080,7 +1080,7 @@ static void error_msg_rpc(const char *msg) } /* NB: mp->xxx fields may be trashed on exit */ -static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts) +static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts) { CLIENT *mclient; char *hostname; @@ -1711,7 +1711,7 @@ static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts) * For older kernels, you must build busybox with ENABLE_FEATURE_MOUNT_NFS. * (However, note that then you lose any chances that NFS over IPv6 would work). */ -static int nfsmount(struct mntent *mp, long vfsflags, char *filteropts) +static int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts) { len_and_sockaddr *lsa; char *opts; @@ -1753,7 +1753,7 @@ static int nfsmount(struct mntent *mp, long vfsflags, char *filteropts) static int singlemount(struct mntent *mp, int ignore_busy) { int rc = -1; - long vfsflags; + unsigned long vfsflags; char *loopFile = NULL, *filteropts = NULL; llist_t *fl = NULL; struct stat st; @@ -1854,7 +1854,7 @@ static int singlemount(struct mntent *mp, int ignore_busy) if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { loopFile = bb_simplify_path(mp->mnt_fsname); mp->mnt_fsname = NULL; // will receive malloced loop dev name - if (set_loop(&mp->mnt_fsname, loopFile, 0, /*ro:*/ 0) < 0) { + if (set_loop(&mp->mnt_fsname, loopFile, 0, /*ro:*/ (vfsflags & MS_RDONLY)) < 0) { if (errno == EPERM || errno == EACCES) bb_error_msg(bb_msg_perm_denied_are_you_root); else @@ -1992,6 +1992,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) FILE *fstab; int i, j; int rc = EXIT_SUCCESS; + unsigned long cmdopt_flags; unsigned opt; struct mntent mtpair[2], *mtcur = mtpair; IF_NOT_DESKTOP(const int nonroot = 0;) @@ -2066,16 +2067,16 @@ int mount_main(int argc UNUSED_PARAM, char **argv) // Past this point, we are handling either "mount -a [opts]" // or "mount [opts] single_param" - i = parse_mount_options(cmdopts, NULL); // FIXME: should be "long", not "int" - if (nonroot && (i & ~MS_SILENT)) // Non-root users cannot specify flags + cmdopt_flags = parse_mount_options(cmdopts, NULL); + if (nonroot && (cmdopt_flags & ~MS_SILENT)) // Non-root users cannot specify flags bb_error_msg_and_die(bb_msg_you_must_be_root); // If we have a shared subtree flag, don't worry about fstab or mtab. if (ENABLE_FEATURE_MOUNT_FLAGS - && (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) + && (cmdopt_flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) ) { // verbose_mount(source, target, type, flags, data) - rc = verbose_mount("", argv[0], "", i, ""); + rc = verbose_mount("", argv[0], "", cmdopt_flags, ""); if (rc) bb_simple_perror_msg_and_die(argv[0]); return rc; @@ -2083,7 +2084,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) // Open either fstab or mtab fstabname = "/etc/fstab"; - if (i & MS_REMOUNT) { + if (cmdopt_flags & MS_REMOUNT) { // WARNING. I am not sure this matches util-linux's // behavior. It's possible util-linux does not // take -o opts from mtab (takes only mount source). @@ -2182,7 +2183,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) // End of fstab/mtab is reached. // Were we looking for something specific? if (argv[0]) { // yes - long l; + unsigned long l; // If we didn't find anything, complain if (!mtcur->mnt_fsname) -- cgit v1.2.3-55-g6feb From c9a13116a4497f4597ad5db6eb3cac9680fd6fc4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 21 Jun 2012 16:50:46 +0200 Subject: mount: fix the wrongly stored fs creation time This bug made our ext2 images non-mountable by ext4 driver. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/bb_e2fs_defs.h | 30 ++++++++++++++++++++++++------ testsuite/mount.tests | 27 ++++++++++++++++++++++++++- util-linux/mkfs_ext2.c | 11 ++++------- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/include/bb_e2fs_defs.h b/include/bb_e2fs_defs.h index 071c660c5..b400f8c11 100644 --- a/include/bb_e2fs_defs.h +++ b/include/bb_e2fs_defs.h @@ -406,25 +406,43 @@ struct ext2_super_block { * Performance hints. Directory preallocation should only * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on. */ - uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ - uint8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ + uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ + uint8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ uint16_t s_reserved_gdt_blocks; /* Per group table for online growth */ /* * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set. */ - uint8_t s_journal_uuid[16]; /* uuid of journal superblock */ - uint32_t s_journal_inum; /* inode number of journal file */ +/*D0*/ uint8_t s_journal_uuid[16]; /* uuid of journal superblock */ +/*E0*/ uint32_t s_journal_inum; /* inode number of journal file */ uint32_t s_journal_dev; /* device number of journal file */ uint32_t s_last_orphan; /* start of list of inodes to delete */ uint32_t s_hash_seed[4]; /* HTREE hash seed */ uint8_t s_def_hash_version; /* Default hash version to use */ uint8_t s_jnl_backup_type; /* Default type of journal backup */ uint16_t s_reserved_word_pad; - uint32_t s_default_mount_opts; +/*100*/ uint32_t s_default_mount_opts; uint32_t s_first_meta_bg; /* First metablock group */ + /* ext3 additions */ uint32_t s_mkfs_time; /* When the filesystem was created */ uint32_t s_jnl_blocks[17]; /* Backup of the journal inode */ - uint32_t s_reserved[172]; /* Padding to the end of the block */ + /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */ +/*150*/ uint32_t s_blocks_count_hi; /* Blocks count */ + uint32_t s_r_blocks_count_hi; /* Reserved blocks count */ + uint32_t s_free_blocks_count_hi; /* Free blocks count */ + uint16_t s_min_extra_isize; /* All inodes have at least # bytes */ + uint16_t s_want_extra_isize; /* New inodes should reserve # bytes */ + uint32_t s_flags; /* Miscellaneous flags */ + uint16_t s_raid_stride; /* RAID stride */ + uint16_t s_mmp_interval; /* # seconds to wait in MMP checking */ + uint64_t s_mmp_block; /* Block for multi-mount protection */ + uint32_t s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ + uint8_t s_log_groups_per_flex; /* FLEX_BG group size */ + uint8_t s_reserved_char_pad2; + uint16_t s_reserved_pad; + uint32_t s_reserved[162]; /* Padding to the end of the block */ +}; +struct BUG_ext2_super_block { + char bug[sizeof(struct ext2_super_block) == 1024 ? 1 : -1]; }; /* diff --git a/testsuite/mount.tests b/testsuite/mount.tests index c5891be83..a0bc50888 100755 --- a/testsuite/mount.tests +++ b/testsuite/mount.tests @@ -36,7 +36,8 @@ testing "mount -o remount,mand" \ "mount -o loop mount.image1m $testdir "\ "&& grep -Fc $testdir </proc/mounts "\ "&& mount -o remount,mand $testdir "\ -"&& grep -F $testdir </proc/mounts | grep -c '[, ]mand[, ]'" \ +"&& grep -F $testdir </proc/mounts | grep -c '[, ]mand[, ]'"\ +"|| grep -F $testdir </proc/mounts" \ "1\n""1\n" \ "" "" @@ -83,4 +84,28 @@ b "" "" SKIP= + +testing "mount RO loop" "\ +exec 2>&1 +umount -d mount.dir 2>/dev/null +rmdir mount.dir 2>/dev/null +mkdir -p mount.dir +( +cd mount.dir || { echo 'cd error'; exit 1; } +mkdir z1 z2 || { echo 'mkdir error'; exit 1; } +mount -t tmpfs tmpfs z1 || { echo 'mount tmpfs error'; exit 1; } +dd if=/dev/zero of=z1/e2img count=10 bs=1M 2>/dev/null || { echo 'dd error'; exit 1; } +mke2fs -F z1/e2img 2>/dev/null >&2 || { echo 'mke2fs error'; exit 1; } +mount -r -o loop -t ext2 z1/e2img z2 || { echo 'mount -r -o loop error'; exit 1; } +mount -o remount,ro z1 || { echo 'mount -o remount,ro error'; exit 1; } +) +umount -d mount.dir/z2 +##losetup -d /dev/loop* +umount -d mount.dir/z1 +rm -rf mount.dir +echo DONE +" \ +"DONE\n" "" "" + + exit $FAILCOUNT diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index 69b25c946..3258d7eee 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c @@ -53,11 +53,6 @@ #define ENABLE_FEATURE_MKFS_EXT2_RESERVED_GDT 0 #define ENABLE_FEATURE_MKFS_EXT2_DIR_INDEX 1 -// from e2fsprogs -#define s_reserved_gdt_blocks s_padding1 -#define s_mkfs_time s_reserved[0] -#define s_flags s_reserved[22] - #define EXT2_HASH_HALF_MD4 1 #define EXT2_FLAGS_SIGNED_HASH 0x0001 #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 @@ -482,8 +477,10 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) STORE_LE(sb->s_magic, EXT2_SUPER_MAGIC); STORE_LE(sb->s_inode_size, inodesize); // set "Required extra isize" and "Desired extra isize" fields to 28 - if (inodesize != sizeof(*inode)) - STORE_LE(sb->s_reserved[21], 0x001C001C); + if (inodesize != sizeof(*inode)) { + STORE_LE(sb->s_min_extra_isize, 0x001c); + STORE_LE(sb->s_want_extra_isize, 0x001c); + } STORE_LE(sb->s_first_ino, EXT2_GOOD_OLD_FIRST_INO); STORE_LE(sb->s_log_block_size, blocksize_log2 - EXT2_MIN_BLOCK_LOG_SIZE); STORE_LE(sb->s_log_frag_size, blocksize_log2 - EXT2_MIN_BLOCK_LOG_SIZE); -- cgit v1.2.3-55-g6feb From a396ade9f83f05a65b0a6df3dcbdeb8cfef0c696 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 22 Jun 2012 15:06:27 +0200 Subject: mount: undo recent breakage when mount flags were made unsigned Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/mount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util-linux/mount.c b/util-linux/mount.c index 220a4e67c..95dee18ec 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -467,7 +467,7 @@ static unsigned long parse_mount_options(char *options, char **unrecognized) for (i = 0; i < ARRAY_SIZE(mount_options); i++) { if (strcasecmp(option_str, options) == 0) { unsigned long fl = mount_options[i]; - if (fl < 0) + if ((long)fl < 0) flags &= fl; else flags |= fl; -- cgit v1.2.3-55-g6feb From 6ebb2b6b242fc4e66100f6ea64101eb75d2071e9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 22 Jun 2012 15:17:18 +0200 Subject: mount: do not pass "comment=ANYTHING" option to kernel. Closes 5240 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/mount.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/util-linux/mount.c b/util-linux/mount.c index 95dee18ec..b6c94d7ba 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -218,6 +218,7 @@ static const int32_t mount_options[] = { IF_DESKTOP(/* "user" */ MOUNT_USERS,) IF_DESKTOP(/* "users" */ MOUNT_USERS,) /* "_netdev" */ 0, + IF_DESKTOP(/* "comment" */ 0,) /* systemd uses this in fstab */ ) IF_FEATURE_MOUNT_FLAGS( @@ -275,6 +276,7 @@ static const char mount_option_str[] = IF_DESKTOP("user\0") IF_DESKTOP("users\0") "_netdev\0" + IF_DESKTOP("comment\0") /* systemd uses this in fstab */ ) IF_FEATURE_MOUNT_FLAGS( // vfs flags @@ -465,7 +467,11 @@ static unsigned long parse_mount_options(char *options, char **unrecognized) // FIXME: use hasmntopt() // Find this option in mount_options for (i = 0; i < ARRAY_SIZE(mount_options); i++) { - if (strcasecmp(option_str, options) == 0) { + /* We support "option=" match for "comment=" thingy */ + unsigned opt_len = strlen(option_str); + if (strncasecmp(option_str, options, opt_len) == 0 + && (options[opt_len] == '\0' || options[opt_len] == '=') + ) { unsigned long fl = mount_options[i]; if ((long)fl < 0) flags &= fl; @@ -473,7 +479,7 @@ static unsigned long parse_mount_options(char *options, char **unrecognized) flags |= fl; goto found; } - option_str += strlen(option_str) + 1; + option_str += opt_len + 1; } // We did not recognize this option. // If "unrecognized" is not NULL, append option there. -- cgit v1.2.3-55-g6feb From d52c9510fd3a9407044166360fe8b752fd841efc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 22 Jun 2012 15:54:05 +0200 Subject: trivial small speed optimization Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/libarchive/filter_accept_reject_list.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/archival/libarchive/filter_accept_reject_list.c b/archival/libarchive/filter_accept_reject_list.c index 39c811337..248374941 100644 --- a/archival/libarchive/filter_accept_reject_list.c +++ b/archival/libarchive/filter_accept_reject_list.c @@ -24,11 +24,13 @@ char FAST_FUNC filter_accept_reject_list(archive_handle_t *archive_handle) if (reject_entry) { return EXIT_FAILURE; } - accept_entry = find_list_entry2(archive_handle->accept, key); /* Fail if an accept list was specified and the key wasnt in there */ - if ((accept_entry == NULL) && archive_handle->accept) { - return EXIT_FAILURE; + if (archive_handle->accept) { + accept_entry = find_list_entry2(archive_handle->accept, key); + if (!accept_entry) { + return EXIT_FAILURE; + } } /* Accepted */ -- cgit v1.2.3-55-g6feb From 440a509849391f2dc8ec720a136577ede3306fa8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 22 Jun 2012 16:27:21 +0200 Subject: dpkg: fix creation of .list files (were empty since b768aeb). Closes 5324 While at it, fix filename order and free the list of names. function old new delta llist_rev - 21 +21 get_header_tar 1733 1741 +8 unpack_package 587 585 -2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 29/-2) Total: 27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- archival/dpkg.c | 13 +++++++++---- archival/libarchive/get_header_tar.c | 6 ++++-- include/bb_archive.h | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/archival/dpkg.c b/archival/dpkg.c index bf9e9992c..dae8a9747 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -1665,20 +1665,25 @@ static void unpack_package(deb_file_t *deb_file) archive_handle = init_archive_deb_ar(deb_file->filename); init_archive_deb_data(archive_handle); archive_handle->dpkg__sub_archive->accept = conffile_list; + /* Why ARCHIVE_REMEMBER_NAMES? + * We want names collected in ->passed list even if conffile_list + * is NULL (otherwise get_header_tar may optimize name saving out): + */ + archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_REMEMBER_NAMES | ARCHIVE_UNLINK_OLD; archive_handle->dpkg__sub_archive->filter = filter_rename_config; archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix; archive_handle->dpkg__sub_archive->dpkg__buffer = (char*)"/"; /* huh? */ - archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD; unpack_ar_archive(archive_handle); /* Create the list file */ list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list"); out_stream = xfopen_for_write(list_filename); + archive_handle->dpkg__sub_archive->passed = llist_rev(archive_handle->dpkg__sub_archive->passed); while (archive_handle->dpkg__sub_archive->passed) { + char *filename = llist_pop(&archive_handle->dpkg__sub_archive->passed); /* the leading . has been stripped by data_extract_all_prefix already */ - fputs(archive_handle->dpkg__sub_archive->passed->data, out_stream); - fputc('\n', out_stream); - archive_handle->dpkg__sub_archive->passed = archive_handle->dpkg__sub_archive->passed->link; + fprintf(out_stream, "%s\n", filename); + free(filename); } fclose(out_stream); diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index b168653d8..bc09756ba 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c @@ -452,9 +452,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) if (cp) *cp = '\0'; archive_handle->action_data(archive_handle); - if (archive_handle->accept || archive_handle->reject) + if (archive_handle->accept || archive_handle->reject + || (archive_handle->ah_flags & ARCHIVE_REMEMBER_NAMES) + ) { llist_add_to(&archive_handle->passed, file_header->name); - else /* Caller isn't interested in list of unpacked files */ + } else /* Caller isn't interested in list of unpacked files */ free(file_header->name); } else { data_skip(archive_handle); diff --git a/include/bb_archive.h b/include/bb_archive.h index 2043d8570..7bb5615da 100644 --- a/include/bb_archive.h +++ b/include/bb_archive.h @@ -121,6 +121,7 @@ typedef struct archive_handle_t { #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) /* POSIX tar Header Block, from POSIX 1003.1-1990 */ -- cgit v1.2.3-55-g6feb From ea664dde87d8e52df7d4003d988352a66562a945 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 22 Jun 2012 18:41:01 +0200 Subject: awk: make -F STR interpret escape sequences. Closes 5126 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/awk.c | 26 +++++++++++++++++++------- testsuite/awk.tests | 5 +++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index 71abca215..d69720d64 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -696,6 +696,10 @@ static char nextchar(char **s) pps = *s; if (c == '\\') c = bb_process_escape_sequence((const char**)s); + /* Example awk statement: + * s = "abc\"def" + * we must treat \" as " + */ if (c == '\\' && *s == pps) { /* unrecognized \z? */ c = *(*s); /* yes, fetch z */ if (c) @@ -704,6 +708,15 @@ static char nextchar(char **s) return c; } +/* TODO: merge with strcpy_and_process_escape_sequences()? + */ +static void unescape_string_in_place(char *s1) +{ + char *s = s1; + while ((*s1 = nextchar(&s)) != '\0') + s1++; +} + static ALWAYS_INLINE int isalnum_(int c) { return (isalnum(c) || c == '_'); @@ -2992,7 +3005,7 @@ static int awk_exit(int r) * otherwise return 0 */ static int is_assignment(const char *expr) { - char *exprc, *val, *s, *s1; + char *exprc, *val; if (!isalnum_(*expr) || (val = strchr(expr, '=')) == NULL) { return FALSE; @@ -3002,10 +3015,7 @@ static int is_assignment(const char *expr) val = exprc + (val - expr); *val++ = '\0'; - s = s1 = val; - while ((*s1 = nextchar(&s)) != '\0') - s1++; - + unescape_string_in_place(val); setvar_u(newvar(exprc), val); free(exprc); return TRUE; @@ -3118,8 +3128,10 @@ int awk_main(int argc, char **argv) opt = getopt32(argv, "F:v:f:W:", &opt_F, &list_v, &list_f, NULL); argv += optind; argc -= optind; - if (opt & 0x1) - setvar_s(intvar[FS], opt_F); // -F + if (opt & 0x1) { /* -F */ + unescape_string_in_place(opt_F); + setvar_s(intvar[FS], opt_F); + } while (list_v) { /* -v */ if (!is_assignment(llist_pop(&list_v))) bb_show_usage(); diff --git a/testsuite/awk.tests b/testsuite/awk.tests index e67190757..d4c390d31 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -43,6 +43,11 @@ testing "awk long field sep" "awk -F-- '{ print NF, length(\$NF), \$NF }'" \ "" \ "a--\na--b--\na--b--c--\na--b--c--d--" +testing "awk -F handles escapes" "awk -F'\\x21' '{print \$1}'" \ + "a\n" \ + "" \ + "a!b\n" + # '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'), # but gawk 3.1.5 does not bail out on it. testing "awk gsub falls back to non-extended-regex" \ -- cgit v1.2.3-55-g6feb From 9ad8979ff15e1b894ee1f4bb6a2535a1a2c20d65 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Tue, 26 Jun 2012 16:09:00 +0200 Subject: mount: support strictatime option. Closes 5240 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- 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 b6c94d7ba..525fdcce9 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -113,6 +113,12 @@ #ifndef MS_RELATIME # define MS_RELATIME (1 << 21) #endif +#ifndef MS_STRICTATIME +# define MS_STRICTATIME (1 << 24) +#endif + +/* Any ~MS_FOO value has this bit set: */ +#define BB_MS_INVERTED_VALUE (1u << 31) #include "libbb.h" #if ENABLE_FEATURE_MOUNT_LABEL @@ -240,6 +246,7 @@ static const int32_t mount_options[] = { /* "nomand" */ ~MS_MANDLOCK, /* "relatime" */ MS_RELATIME, /* "norelatime" */ ~MS_RELATIME, + /* "strictatime" */ MS_STRICTATIME, /* "loud" */ ~MS_SILENT, /* "rbind" */ MS_BIND|MS_RECURSIVE, @@ -297,6 +304,7 @@ static const char mount_option_str[] = "nomand\0" "relatime\0" "norelatime\0" + "strictatime\0" "loud\0" "rbind\0" @@ -473,7 +481,7 @@ static unsigned long parse_mount_options(char *options, char **unrecognized) && (options[opt_len] == '\0' || options[opt_len] == '=') ) { unsigned long fl = mount_options[i]; - if ((long)fl < 0) + if (fl & BB_MS_INVERTED_VALUE) flags &= fl; else flags |= fl; -- cgit v1.2.3-55-g6feb From c5fe9f7b723f949457263ef8e22ab807d5b549ce Mon Sep 17 00:00:00 2001 From: Mike Frysinger <vapier@gentoo.org> Date: Thu, 5 Jul 2012 23:19:09 -0400 Subject: include sys/resource.h where needed We use functions from sys/resource.h in misc applets, but don't include the header. This breaks building with newer glibc versions, so add the include where needed. Signed-off-by: Mike Frysinger <vapier@gentoo.org> --- loginutils/passwd.c | 1 + miscutils/time.c | 1 + networking/inetd.c | 1 + networking/ntpd.c | 1 + networking/ntpd_simple.c | 1 + runit/chpst.c | 1 + shell/shell_common.c | 1 + 7 files changed, 7 insertions(+) diff --git a/loginutils/passwd.c b/loginutils/passwd.c index b83db0083..a7006f054 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -15,6 +15,7 @@ #include "libbb.h" #include <syslog.h> +#include <sys/resource.h> /* setrlimit */ static void nuke_str(char *str) { diff --git a/miscutils/time.c b/miscutils/time.c index 945f15f0d..ffed38632 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -16,6 +16,7 @@ //usage: "\n -v Verbose" #include "libbb.h" +#include <sys/resource.h> /* getrusage */ /* Information on the resources used by a child process. */ typedef struct { diff --git a/networking/inetd.c b/networking/inetd.c index 1308d74c7..00baf6971 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -165,6 +165,7 @@ //usage: "\n (default: 0 - disabled)" #include <syslog.h> +#include <sys/resource.h> /* setrlimit */ #include <sys/socket.h> /* un.h may need this */ #include <sys/un.h> diff --git a/networking/ntpd.c b/networking/ntpd.c index 72e9d0be2..5b92db6f6 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -46,6 +46,7 @@ #include "libbb.h" #include <math.h> #include <netinet/ip.h> /* For IPTOS_LOWDELAY definition */ +#include <sys/resource.h> /* setpriority */ #include <sys/timex.h> #ifndef IPTOS_LOWDELAY # define IPTOS_LOWDELAY 0x10 diff --git a/networking/ntpd_simple.c b/networking/ntpd_simple.c index 4ad44e4f3..1b7c66b84 100644 --- a/networking/ntpd_simple.c +++ b/networking/ntpd_simple.c @@ -7,6 +7,7 @@ */ #include "libbb.h" #include <netinet/ip.h> /* For IPTOS_LOWDELAY definition */ +#include <sys/resource.h> /* setpriority */ #ifndef IPTOS_LOWDELAY # define IPTOS_LOWDELAY 0x10 #endif diff --git a/runit/chpst.c b/runit/chpst.c index ac296babf..ed72c8b8c 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -91,6 +91,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //usage: "\n a SIGXCPU after N seconds" #include "libbb.h" +#include <sys/resource.h> /* getrlimit */ /* Five applets here: chpst, envdir, envuidgid, setuidgid, softlimit. diff --git a/shell/shell_common.c b/shell/shell_common.c index 51c92d60e..780e27ebd 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -18,6 +18,7 @@ */ #include "libbb.h" #include "shell_common.h" +#include <sys/resource.h> /* getrlimit */ const char defifsvar[] ALIGN1 = "IFS= \t\n"; -- cgit v1.2.3-55-g6feb From 5345b8db8b30326d9ab0db9ac11fde9e7b9d3686 Mon Sep 17 00:00:00 2001 From: Eric Martin <eric.martin@gmx.net> Date: Sat, 7 Jul 2012 19:06:50 +0200 Subject: acpid: add missing lid switch definition This patch adds a missing LID0 switch definition. Without it, closing the notebook lid is not detected by acpid. Signed-off-by: Eric Martin <eric.martin@gmx.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/acpid.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util-linux/acpid.c b/util-linux/acpid.c index 1b22f3a01..5d2792948 100644 --- a/util-linux/acpid.c +++ b/util-linux/acpid.c @@ -75,6 +75,7 @@ struct acpi_event { static const struct acpi_event f_evt_tab[] = { { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRF 00000080" }, { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRB 00000080" }, + { "EV_SW", 0x05, "SW_LID", 0x00, 1, "button/lid LID0 00000080" }, }; struct acpi_action { -- cgit v1.2.3-55-g6feb From b5c7220e7b2b6611fe5beca494c67bfe51fcfafb Mon Sep 17 00:00:00 2001 From: Linus Walleij <triad@df.lth.se> Date: Sun, 1 Jul 2012 22:34:42 +0200 Subject: fbset: respect rgba configuration lines in fb.modes The fbset utility would not respect "rgba" config entries in the fb.modes file such as this (for the ARM Integrator/CP): mode "640x480-60-clcd" # D: 25.175 MHz, H: 31.469 kHz, V: 59.94 Hz geometry 640 480 640 480 16 timings 39722 48 16 33 10 96 2 rgba 5/10,5/5,5/0,1/15 endmode This is important especially for this ARGB5551 device which is hopeless to configure otherwise. I noticed this lacking feature after the TI "fbtest" program managed to set up the the colormode correctly. Signed-off-by: Linus Walleij <triad@df.lth.se> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/fbset.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/util-linux/fbset.c b/util-linux/fbset.c index 196c2aa24..e9aacce4f 100644 --- a/util-linux/fbset.c +++ b/util-linux/fbset.c @@ -271,7 +271,7 @@ static int read_mode_db(struct fb_var_screeninfo *base, const char *fn, } p = token[1]; i = index_in_strings( - "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0", + "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0rgba\0", token[0]); switch (i) { case 0: @@ -342,6 +342,30 @@ static int read_mode_db(struct fb_var_screeninfo *base, const char *fn, ss(&base->sync, FB_SYNC_EXT, p, "false"); //bb_info_msg("EXTSYNC[%s]", p); break; + case 8: { + int red_offset, red_length; + int green_offset, green_length; + int blue_offset, blue_length; + int transp_offset, transp_length; + + sscanf(p, "%d/%d,%d/%d,%d/%d,%d/%d", + &red_offset, &red_length, + &green_offset, &green_length, + &blue_offset, &blue_length, + &transp_offset, &transp_length); + base->red.offset = red_offset; + base->red.length = red_length; + base->red.msb_right = 0; + base->green.offset = green_offset; + base->green.length = green_length; + base->green.msb_right = 0; + base->blue.offset = blue_offset; + base->blue.length = blue_length; + base->blue.msb_right = 0; + base->transp.offset = transp_offset; + base->transp.length = transp_length; + base->transp.msb_right = 0; + } } } return 0; -- cgit v1.2.3-55-g6feb From 566a313a7f531d7df28f8ae01d19a4b28134b2e3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sat, 7 Jul 2012 21:40:35 +0200 Subject: ash: add a comment about VEXPORT Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- shell/ash.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/ash.c b/shell/ash.c index e23b2034d..b20c32b89 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -1900,6 +1900,10 @@ static const struct { const char *var_text; void (*var_func)(const char *) FAST_FUNC; } varinit_data[] = { + /* + * Note: VEXPORT would not work correctly here for NOFORK applets: + * some environment strings may be constant. + */ { VSTRFIXED|VTEXTFIXED , defifsvar , NULL }, #if ENABLE_ASH_MAIL { VSTRFIXED|VTEXTFIXED|VUNSET, "MAIL" , changemail }, -- cgit v1.2.3-55-g6feb From 3bb858765e0524efdf2a05c8669ddbfde522d634 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 11 Jul 2012 00:16:08 +0200 Subject: ftpd: fix MDTM's month value. Closes 5336 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/ftpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/ftpd.c b/networking/ftpd.c index 1c97df564..4ba96cfc2 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c @@ -821,7 +821,7 @@ handle_size_or_mdtm(int need_size) gmtime_r(&statbuf.st_mtime, &broken_out); sprintf(buf, STR(FTP_STATFILE_OK)" %04u%02u%02u%02u%02u%02u\r\n", broken_out.tm_year + 1900, - broken_out.tm_mon, + broken_out.tm_mon + 1, broken_out.tm_mday, broken_out.tm_hour, broken_out.tm_min, -- cgit v1.2.3-55-g6feb From e1db338a5187c008819932a4166f3aa27958c48e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 11 Jul 2012 00:26:24 +0200 Subject: ftpd: free allocated string on error path Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/ftpd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/networking/ftpd.c b/networking/ftpd.c index 4ba96cfc2..33db964fa 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c @@ -927,6 +927,7 @@ handle_upload_common(int is_append, int is_unique) || fstat(local_file_fd, &statbuf) != 0 || !S_ISREG(statbuf.st_mode) ) { + free(tempname); WRITE_ERR(FTP_UPLOADFAIL); if (local_file_fd >= 0) goto close_local_and_bail; -- cgit v1.2.3-55-g6feb From df8066a78ccd9b899244145f6be0171957a41a1e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 11 Jul 2012 01:27:15 +0200 Subject: awk: fix FS assignment behavior. Closes 5108 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/awk.c | 12 ++++++++++++ testsuite/awk.tests | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/editors/awk.c b/editors/awk.c index d69720d64..42f6ef866 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -1812,6 +1812,18 @@ static void handle_special(var *v) is_f0_split = FALSE; } else if (v == intvar[FS]) { + /* + * The POSIX-2008 standard says that changing FS should have no effect on the + * current input line, but only on the next one. The language is: + * + * > Before the first reference to a field in the record is evaluated, the record + * > shall be split into fields, according to the rules in Regular Expressions, + * > using the value of FS that was current at the time the record was read. + * + * So, split up current line before assignment to FS: + */ + split_f0(); + mk_splitter(getvar_s(v), &fsplitter); } else if (v == intvar[RS]) { diff --git a/testsuite/awk.tests b/testsuite/awk.tests index d4c390d31..f9c3b6b4d 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -217,4 +217,11 @@ end d testing "awk handles empty ()" \ "awk 'BEGIN {print()}' 2>&1" "awk: cmd. line:1: Empty sequence\n" "" "" +testing "awk FS assignment" "awk '{FS=\":\"; print \$1}'" \ + "a:b\ne\n" \ + "" \ + "a:b c:d\ne:f g:h" + +# testing "description" "command" "result" "infile" "stdin" + exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From dbed6c4b46f3c8dc74d50e4cf35b1cb8b8c4ff2d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 18 Jul 2012 17:32:32 +0200 Subject: tftpd: fix -u USER to work with chroot. Closes 5348 function old new delta tftpd_main 546 568 +22 tftp_protocol 1844 1839 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/tftp.c | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/networking/tftp.c b/networking/tftp.c index ce48a1edd..630fdaf9a 100644 --- a/networking/tftp.c +++ b/networking/tftp.c @@ -116,7 +116,7 @@ enum { struct globals { /* u16 TFTP_ERROR; u16 reason; both network-endian, then error text: */ uint8_t error_pkt[4 + 32]; - char *user_opt; + struct passwd *pw; /* used in tftpd_main(), a bit big for stack: */ char block_buf[TFTP_BLKSIZE_DEFAULT]; #if ENABLE_FEATURE_TFTP_PROGRESS_BAR @@ -130,13 +130,10 @@ struct globals { struct BUG_G_too_big { char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; }; -#define block_buf (G.block_buf ) -#define user_opt (G.user_opt ) -#define error_pkt (G.error_pkt ) #define INIT_G() do { } while (0) -#define error_pkt_reason (error_pkt[3]) -#define error_pkt_str (error_pkt + 4) +#define G_error_pkt_reason (G.error_pkt[3]) +#define G_error_pkt_str ((char*)(G.error_pkt + 4)) #if ENABLE_FEATURE_TFTP_PROGRESS_BAR static void tftp_progress_update(void) @@ -272,12 +269,11 @@ static int tftp_protocol( xconnect(socket_fd, &peer_lsa->u.sa, peer_lsa->len); /* Is there an error already? Send pkt and bail out */ - if (error_pkt_reason || error_pkt_str[0]) + if (G_error_pkt_reason || G_error_pkt_str[0]) goto send_err_pkt; - if (user_opt) { - struct passwd *pw = xgetpwnam(user_opt); - change_identity(pw); /* initgroups, setgid, setuid */ + if (G.pw) { + change_identity(G.pw); /* initgroups, setgid, setuid */ } } @@ -329,8 +325,8 @@ static int tftp_protocol( /* Open file (must be after changing user) */ local_fd = open(local_file, open_mode, 0666); if (local_fd < 0) { - error_pkt_reason = ERR_NOFILE; - strcpy((char*)error_pkt_str, "can't open file"); + G_error_pkt_reason = ERR_NOFILE; + strcpy(G_error_pkt_str, "can't open file"); goto send_err_pkt; } /* gcc 4.3.1 would NOT optimize it out as it should! */ @@ -575,7 +571,7 @@ static int tftp_protocol( if (res) { blksize = tftp_blksize_check(res, blksize); if (blksize < 0) { - error_pkt_reason = ERR_BAD_OPT; + G_error_pkt_reason = ERR_BAD_OPT; goto send_err_pkt; } io_bufsize = blksize + 4; @@ -614,8 +610,8 @@ static int tftp_protocol( if (recv_blk == block_nr) { int sz = full_write(local_fd, &rbuf[4], len - 4); if (sz != len - 4) { - strcpy((char*)error_pkt_str, bb_msg_write_error); - error_pkt_reason = ERR_WRITE; + strcpy(G_error_pkt_str, bb_msg_write_error); + G_error_pkt_reason = ERR_WRITE; goto send_err_pkt; } if (sz != blksize) { @@ -664,12 +660,12 @@ static int tftp_protocol( return finished == 0; /* returns 1 on failure */ send_read_err_pkt: - strcpy((char*)error_pkt_str, bb_msg_read_error); + strcpy(G_error_pkt_str, bb_msg_read_error); send_err_pkt: - if (error_pkt_str[0]) - bb_error_msg("%s", (char*)error_pkt_str); - error_pkt[1] = TFTP_ERROR; - xsendto(socket_fd, error_pkt, 4 + 1 + strlen((char*)error_pkt_str), + if (G_error_pkt_str[0]) + bb_error_msg("%s", G_error_pkt_str); + G.error_pkt[1] = TFTP_ERROR; + xsendto(socket_fd, G.error_pkt, 4 + 1 + strlen(G_error_pkt_str), &peer_lsa->u.sa, peer_lsa->len); return EXIT_FAILURE; #undef remote_file @@ -761,7 +757,7 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) { len_and_sockaddr *our_lsa; len_and_sockaddr *peer_lsa; - char *local_file, *mode; + char *local_file, *mode, *user_opt; const char *error_msg; int opt, result, opcode; IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;) @@ -789,18 +785,22 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) openlog(applet_name, LOG_PID, LOG_DAEMON); logmode = LOGMODE_SYSLOG; } + if (opt & TFTPD_OPT_u) { + /* Must be before xchroot */ + G.pw = xgetpwnam(user_opt); + } if (argv[0]) { xchroot(argv[0]); } - result = recv_from_to(STDIN_FILENO, block_buf, sizeof(block_buf), + result = recv_from_to(STDIN_FILENO, G.block_buf, sizeof(G.block_buf), 0 /* flags */, &peer_lsa->u.sa, &our_lsa->u.sa, our_lsa->len); error_msg = "malformed packet"; - opcode = ntohs(*(uint16_t*)block_buf); - if (result < 4 || result >= sizeof(block_buf) - || block_buf[result-1] != '\0' + opcode = ntohs(*(uint16_t*)G.block_buf); + if (result < 4 || result >= sizeof(G.block_buf) + || G.block_buf[result-1] != '\0' || (IF_FEATURE_TFTP_PUT(opcode != TFTP_RRQ) /* not download */ IF_GETPUT(&&) IF_FEATURE_TFTP_GET(opcode != TFTP_WRQ) /* not upload */ @@ -808,27 +808,27 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) ) { goto err; } - local_file = block_buf + 2; + local_file = G.block_buf + 2; if (local_file[0] == '.' || strstr(local_file, "/.")) { error_msg = "dot in file name"; goto err; } mode = local_file + strlen(local_file) + 1; /* RFC 1350 says mode string is case independent */ - if (mode >= block_buf + result || strcasecmp(mode, "octet") != 0) { + if (mode >= G.block_buf + result || strcasecmp(mode, "octet") != 0) { goto err; } # if ENABLE_FEATURE_TFTP_BLOCKSIZE { char *res; char *opt_str = mode + sizeof("octet"); - int opt_len = block_buf + result - opt_str; + int opt_len = G.block_buf + result - opt_str; if (opt_len > 0) { res = tftp_get_option("blksize", opt_str, opt_len); if (res) { blksize = tftp_blksize_check(res, 65564); if (blksize < 0) { - error_pkt_reason = ERR_BAD_OPT; + G_error_pkt_reason = ERR_BAD_OPT; /* will just send error pkt */ goto do_proto; } @@ -846,7 +846,7 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) if (!ENABLE_FEATURE_TFTP_PUT || opcode == TFTP_WRQ) { if (opt & TFTPD_OPT_r) { /* This would mean "disk full" - not true */ - /*error_pkt_reason = ERR_WRITE;*/ + /*G_error_pkt_reason = ERR_WRITE;*/ error_msg = bb_msg_write_error; goto err; } @@ -855,7 +855,7 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) IF_GETPUT(option_mask32 |= TFTP_OPT_PUT;) /* will send file's data */ } - /* NB: if error_pkt_str or error_pkt_reason is set up, + /* NB: if G_error_pkt_str or G_error_pkt_reason is set up, * tftp_protocol() just sends one error pkt and returns */ do_proto: @@ -870,7 +870,7 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) return result; err: - strcpy((char*)error_pkt_str, error_msg); + strcpy(G_error_pkt_str, error_msg); goto do_proto; } -- cgit v1.2.3-55-g6feb From 37a79c092edcc8691686a4d4b609d2c034ccd840 Mon Sep 17 00:00:00 2001 From: Mimi Li <felloak@gmail.com> Date: Tue, 24 Jul 2012 13:20:12 +0200 Subject: sed: allow 'w' cmd to use two address form function old new delta add_cmd 1101 1094 -7 Signed-off-by: Mimi Li <felloak@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- editors/sed.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 42d8e17c6..070af611a 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -53,7 +53,9 @@ * Todo: * - Create a wrapper around regex to make libc's regex conform with sed * - * Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html + * Reference + * http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html + * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html */ //usage:#define sed_trivial_usage @@ -492,8 +494,10 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) } /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */ else if (idx <= IDX_c) { /* a,i,c */ - if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c') - bb_error_msg_and_die("only a beginning address can be specified for edit commands"); + if (idx < IDX_c) { /* a,i */ + if (sed_cmd->end_line || sed_cmd->end_match) + bb_error_msg_and_die("command '%c' uses only one address", sed_cmd->cmd); + } for (;;) { if (*cmdstr == '\n' || *cmdstr == '\\') { cmdstr++; @@ -510,8 +514,10 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) } /* handle file cmds: (r)ead */ else if (idx <= IDX_w) { /* r,w */ - if (sed_cmd->end_line || sed_cmd->end_match) - bb_error_msg_and_die("command only uses one address"); + if (idx < IDX_w) { /* r */ + if (sed_cmd->end_line || sed_cmd->end_match) + bb_error_msg_and_die("command '%c' uses only one address", sed_cmd->cmd); + } cmdstr += parse_file_cmd(/*sed_cmd,*/ cmdstr, &sed_cmd->string); if (sed_cmd->cmd == 'w') { sed_cmd->sw_file = xfopen_for_write(sed_cmd->string); -- cgit v1.2.3-55-g6feb From e565383fd53b999ce868081d077316e7ebbd1118 Mon Sep 17 00:00:00 2001 From: Yao Zhao <yao.zhao@windriver.com> Date: Tue, 24 Jul 2012 13:58:12 +0200 Subject: testsuite: make mkfs.minix test not fail spuriously on big endian Signed-off-by: Yao Zhao <yao.zhao@windriver.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- testsuite/mkfs.minix.tests | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/testsuite/mkfs.minix.tests b/testsuite/mkfs.minix.tests index 8a33c1681..7eecaf230 100755 --- a/testsuite/mkfs.minix.tests +++ b/testsuite/mkfs.minix.tests @@ -8,6 +8,14 @@ # testing "test name" "options" "expected result" "file input" "stdin" +# '\n' produces 10 on little endian, but not on big endian +cr=`echo | od -i | sed 's/.* //g;2d'` +if [ x"$cr" = x"10" ]; then + hash=4f35f7afeba07d56055bed1f29ae20b7 +else + hash=5adbc1b3ccd20ca5d0ab5bc1e13ac3fc +fi + testing "mkfs.minix" \ "dd if=/dev/zero of=input bs=1k count=1024 2>/dev/null; mkfs.minix input; md5sum <input" \ "352 inodes\n"\ @@ -15,7 +23,7 @@ testing "mkfs.minix" \ "Firstdatazone=15 (15)\n"\ "Zonesize=1024\n"\ "Maxsize=268966912\n"\ -"4f35f7afeba07d56055bed1f29ae20b7 -\n" \ +"$hash -\n" \ "" \ "" -- cgit v1.2.3-55-g6feb From 32f774cd344cf12336c22b0947f102274a99ee31 Mon Sep 17 00:00:00 2001 From: Michael Tokarev <mjt@tls.msk.ru> Date: Tue, 24 Jul 2012 15:56:37 +0200 Subject: *: declare strings with ALIGN1, as appropriate Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/busybox.h | 4 ++-- networking/udhcp/common.h | 4 ++-- shell/shell_common.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/busybox.h b/include/busybox.h index 315ef8f26..b1e31e5ee 100644 --- a/include/busybox.h +++ b/include/busybox.h @@ -13,10 +13,10 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN /* Defined in appletlib.c (by including generated applet_tables.h) */ /* Keep in sync with applets/applet_tables.c! */ -extern const char applet_names[]; +extern const char applet_names[] ALIGN1; extern int (*const applet_main[])(int argc, char **argv); extern const uint16_t applet_nameofs[]; -extern const uint8_t applet_install_loc[]; +extern const uint8_t applet_install_loc[] ALIGN1; #if ENABLE_FEATURE_SUID || ENABLE_FEATURE_PREFER_APPLETS # define APPLET_NAME(i) (applet_names + (applet_nameofs[i] & 0x0fff)) diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index cfd58679a..4fa0471de 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -187,8 +187,8 @@ struct option_set { }; extern const struct dhcp_optflag dhcp_optflags[]; -extern const char dhcp_option_strings[]; -extern const uint8_t dhcp_option_lengths[]; +extern const char dhcp_option_strings[] ALIGN1; +extern const uint8_t dhcp_option_lengths[] ALIGN1; unsigned FAST_FUNC udhcp_option_idx(const char *name); diff --git a/shell/shell_common.h b/shell/shell_common.h index f06bc4120..993ed5951 100644 --- a/shell/shell_common.h +++ b/shell/shell_common.h @@ -21,7 +21,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN -extern const char defifsvar[]; /* "IFS= \t\n" */ +extern const char defifsvar[] ALIGN1; /* "IFS= \t\n" */ #define defifs (defifsvar + 4) int FAST_FUNC is_well_formed_var_name(const char *s, char terminator); -- cgit v1.2.3-55-g6feb From d3a42391b12b5428a246166e76175edbafbba069 Mon Sep 17 00:00:00 2001 From: Aurelien Jarno <aurelien@aurel32.net> Date: Tue, 24 Jul 2012 16:28:34 +0200 Subject: *: declare strings with ALIGN1, as appropriate Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/libbb.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 322a28cab..f22e58e27 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1612,8 +1612,8 @@ unsigned get_cpu_count(void) FAST_FUNC; char *percent_decode_in_place(char *str, int strict) FAST_FUNC; -extern const char bb_uuenc_tbl_base64[]; -extern const char bb_uuenc_tbl_std[]; +extern const char bb_uuenc_tbl_base64[] ALIGN1; +extern const char bb_uuenc_tbl_std[] ALIGN1; void bb_uuencode(char *store, const void *s, int length, const char *tbl) FAST_FUNC; enum { BASE64_FLAG_UU_STOP = 0x100, @@ -1694,24 +1694,24 @@ extern const char *applet_name; * Therefore now we use #defines. */ /* "BusyBox vN.N.N (timestamp or extra_version)" */ -extern const char bb_banner[]; -extern const char bb_msg_memory_exhausted[]; -extern const char bb_msg_invalid_date[]; +extern const char bb_banner[] ALIGN1; +extern const char bb_msg_memory_exhausted[] ALIGN1; +extern const char bb_msg_invalid_date[] ALIGN1; #define bb_msg_read_error "read error" #define bb_msg_write_error "write error" -extern const char bb_msg_unknown[]; -extern const char bb_msg_can_not_create_raw_socket[]; -extern const char bb_msg_perm_denied_are_you_root[]; -extern const char bb_msg_you_must_be_root[]; -extern const char bb_msg_requires_arg[]; -extern const char bb_msg_invalid_arg[]; -extern const char bb_msg_standard_input[]; -extern const char bb_msg_standard_output[]; +extern const char bb_msg_unknown[] ALIGN1; +extern const char bb_msg_can_not_create_raw_socket[] ALIGN1; +extern const char bb_msg_perm_denied_are_you_root[] ALIGN1; +extern const char bb_msg_you_must_be_root[] ALIGN1; +extern const char bb_msg_requires_arg[] ALIGN1; +extern const char bb_msg_invalid_arg[] ALIGN1; +extern const char bb_msg_standard_input[] ALIGN1; +extern const char bb_msg_standard_output[] ALIGN1; /* NB: (bb_hexdigits_upcase[i] | 0x20) -> lowercase hex digit */ -extern const char bb_hexdigits_upcase[]; +extern const char bb_hexdigits_upcase[] ALIGN1; -extern const char bb_path_wtmp_file[]; +extern const char bb_path_wtmp_file[] ALIGN1; /* Busybox mount uses either /proc/mounts or /etc/mtab to * get the list of currently mounted filesystems */ @@ -1725,10 +1725,10 @@ extern const char bb_path_wtmp_file[]; #define bb_path_motd_file "/etc/motd" #define bb_dev_null "/dev/null" -extern const char bb_busybox_exec_path[]; +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[]; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */ +extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */ #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) #define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin")) @@ -1758,7 +1758,7 @@ extern struct globals *const ptr_to_globals; * If you change LIBBB_DEFAULT_LOGIN_SHELL, * don't forget to change increment constant. */ #define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh" -extern const char bb_default_login_shell[]; +extern const char bb_default_login_shell[] ALIGN1; /* "/bin/sh" */ #define DEFAULT_SHELL (bb_default_login_shell+1) /* "sh" */ -- cgit v1.2.3-55-g6feb From 71045cc819cc2a3c7e20bf7aba5cfeb8acfd9dad Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Tue, 24 Jul 2012 17:21:26 +0200 Subject: dhcpd: write lease file on exit function old new delta udhcpd_main 1431 1403 -28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/udhcp/dhcpd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index dd55e70f4..9ad95954d 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -377,6 +377,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) /* Setup the signal pipe */ udhcp_sp_setup(); + continue_with_autotime: timeout_end = monotonic_sec() + server_config.auto_time; while (1) { /* loop until universe collapses */ fd_set rfds; @@ -406,8 +407,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) } if (retval == 0) { write_leases(); - timeout_end = monotonic_sec() + server_config.auto_time; - continue; + goto continue_with_autotime; } if (retval < 0 && errno != EINTR) { log1("Error on select"); @@ -419,10 +419,10 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) bb_info_msg("Received SIGUSR1"); write_leases(); /* why not just reset the timeout, eh */ - timeout_end = monotonic_sec() + server_config.auto_time; - continue; + goto continue_with_autotime; case SIGTERM: bb_info_msg("Received SIGTERM"); + write_leases(); goto ret0; case 0: /* no signal: read a packet */ break; -- cgit v1.2.3-55-g6feb From 5cfb8181816aec29fb293d4c42f32ed8b942bce6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 26 Jul 2012 12:58:41 +0200 Subject: Add yet another missing ALIGN2 on a global declaration. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/udhcp/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 4fa0471de..0e8e45fd2 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -14,7 +14,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN -extern const uint8_t MAC_BCAST_ADDR[6]; /* six all-ones */ +extern const uint8_t MAC_BCAST_ADDR[6] ALIGN2; /* six all-ones */ /*** DHCP packet ***/ -- cgit v1.2.3-55-g6feb From 0e941d542736dc5eb69add1d3377a4601536eb97 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" <bkuhn@ebb.org> Date: Fri, 13 Jul 2012 11:38:38 -0400 Subject: Simplify copyright/license notice that appears in the binary. Existing copyright notice for binary would need to be longer to achieve optimal accuracy. This compromise punts to the source for full notices, but does note the years of the copyrights and that there are many authors, all licensing under GPLv2. Signed-off-by: Bradley M. Kuhn <bkuhn@ebb.org> Signed-off-by: Tony Sebro <tony@sfconservancy.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- libbb/appletlib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 09e886d7a..da13bf36c 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -627,9 +627,9 @@ static int busybox_main(char **argv) full_write2_str(bb_banner); /* reuse const string */ full_write2_str(" multi-call binary.\n"); /* reuse */ full_write2_str( - "Copyright (C) 1998-2012 Erik Andersen, Rob Landley, Denys Vlasenko\n" - "and others. Licensed under GPLv2.\n" - "See source distribution for full notice.\n" + "BusyBox is copyrighted by many authors between 1998-2012.\n" + "Licensed under GPLv2. See source distribution for detailed\n" + "copyright notices.\n" "\n" "Usage: busybox [function [arguments]...]\n" " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" -- cgit v1.2.3-55-g6feb From 293c94564ccee60c8e954bb6347fd36034cb7590 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 27 Jul 2012 13:25:07 +0200 Subject: udhcpc: make -O <numeric_opt> work. Closes 5402 function old new delta udhcpc_main 2642 2685 +43 udhcp_recv_raw_packet 414 415 +1 d6_recv_raw_packet 248 249 +1 udhcpc6_main 2430 2413 -17 add_client_options 239 213 -26 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/2 up/down: 45/-43) Total: 2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/udhcp/d6_dhcpc.c | 12 ++++++++++-- networking/udhcp/dhcpc.c | 21 +++++++++++---------- networking/udhcp/dhcpc.h | 1 - 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index d9d8b9b56..dda4a9112 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -965,8 +965,6 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) SERVER_PORT = CLIENT_PORT - 1; } #endif - if (opt & OPT_o) - client_config.no_default_options = 1; while (list_O) { char *optstr = llist_pop(&list_O); unsigned n = bb_strtou(optstr, NULL, 0); @@ -976,6 +974,16 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) } client_config.opt_mask[n >> 3] |= 1 << (n & 7); } + if (!(opt & OPT_o)) { + /* + unsigned i, n; + for (i = 0; (n = dhcp_optflags[i].code) != 0; i++) { + if (dhcp_optflags[i].flags & OPTION_REQ) { + client_config.opt_mask[n >> 3] |= 1 << (n & 7); + } + } + */ + } while (list_x) { char *optstr = llist_pop(&list_x); char *colon = strchr(optstr, ':'); diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 4e7bd4bbc..bc1db7087 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -589,7 +589,6 @@ static void init_packet(struct dhcp_packet *packet, char type) static void add_client_options(struct dhcp_packet *packet) { - uint8_t c; int i, end, len; udhcp_add_simple_option(packet, DHCP_MAX_SIZE, htons(IP_UDP_DHCP_SIZE)); @@ -599,13 +598,9 @@ static void add_client_options(struct dhcp_packet *packet) * No bounds checking because it goes towards the head of the packet. */ end = udhcp_end_option(packet->options); len = 0; - for (i = 0; (c = dhcp_optflags[i].code) != 0; i++) { - if (( (dhcp_optflags[i].flags & OPTION_REQ) - && !client_config.no_default_options - ) - || (client_config.opt_mask[c >> 3] & (1 << (c & 7))) - ) { - packet->options[end + OPT_DATA + len] = c; + for (i = 1; i < DHCP_END; i++) { + if (client_config.opt_mask[i >> 3] & (1 << (i & 7))) { + packet->options[end + OPT_DATA + len] = i; len++; } } @@ -1257,8 +1252,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) SERVER_PORT = CLIENT_PORT - 1; } #endif - if (opt & OPT_o) - client_config.no_default_options = 1; while (list_O) { char *optstr = llist_pop(&list_O); unsigned n = bb_strtou(optstr, NULL, 0); @@ -1268,6 +1261,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) } client_config.opt_mask[n >> 3] |= 1 << (n & 7); } + if (!(opt & OPT_o)) { + unsigned i, n; + for (i = 0; (n = dhcp_optflags[i].code) != 0; i++) { + if (dhcp_optflags[i].flags & OPTION_REQ) { + client_config.opt_mask[n >> 3] |= 1 << (n & 7); + } + } + } while (list_x) { char *optstr = llist_pop(&list_x); char *colon = strchr(optstr, ':'); diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 2b3599120..2859a0772 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h @@ -9,7 +9,6 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN struct client_config_t { uint8_t client_mac[6]; /* Our mac address */ - char no_default_options; /* Do not include default options in request */ IF_FEATURE_UDHCP_PORT(uint16_t port;) int ifindex; /* Index number of the interface to use */ uint8_t opt_mask[256 / 8]; /* Bitmask of options to send (-O option) */ -- cgit v1.2.3-55-g6feb From ca81a937225714f75157eb596d90255243ae2e29 Mon Sep 17 00:00:00 2001 From: Mike Frysinger <vapier@gentoo.org> Date: Sat, 4 Aug 2012 16:14:24 -0400 Subject: disable format security warnings We pass strings to printf directly a lot. Some distros enable some flags in their gcc by default like -Wformat-security. With these two things, we end up with a lot of build warnings like so: loginutils/chpasswd.c:42:3: warning: format not a string literal and no format arguments [-Wformat-security] But we don't care. Our focus is first and foremost on size, so adding a lot of dummy calls like: - printf(some_constant_string); + printf("%s", some_constant_string); is pointless bloat. Disable this warning flag if the compiler supports it. Signed-off-by: Mike Frysinger <vapier@gentoo.org> --- Makefile.flags | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.flags b/Makefile.flags index c43c8dca8..f5f446598 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -25,6 +25,7 @@ CFLAGS += $(call cc-option,-Wstrict-prototypes,) CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,) CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,) CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,) +CFLAGS += $(call cc-option,-Wno-format-security,) # warn about C99 declaration after statement CFLAGS += $(call cc-option,-Wdeclaration-after-statement,) # If you want to add more -Wsomething above, make sure that it is -- cgit v1.2.3-55-g6feb From 2ffd710656d83c4bcc66cef10e1fe7deb1c47605 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 6 Aug 2012 17:17:15 +0200 Subject: platform.h: disable ALIGNn macros for s390[x] Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- include/platform.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/platform.h b/include/platform.h index ba534b284..4025561c6 100644 --- a/include/platform.h +++ b/include/platform.h @@ -284,7 +284,8 @@ typedef unsigned smalluint; #define fdprintf dprintf /* Useful for defeating gcc's alignment of "char message[]"-like data */ -#if 1 /* if needed: !defined(arch1) && !defined(arch2) */ +#if !defined(__s390__) + /* on s390[x], non-word-aligned data accesses require larger code */ # define ALIGN1 __attribute__((aligned(1))) # define ALIGN2 __attribute__((aligned(2))) # define ALIGN4 __attribute__((aligned(4))) -- cgit v1.2.3-55-g6feb From 4919565c152f2ecee760b5419c947764e991ab3e Mon Sep 17 00:00:00 2001 From: Cliff Frey <cliff@meraki.com> Date: Tue, 7 Aug 2012 17:59:40 +0200 Subject: lineedit: fix Alt-D when cursor==0 Signed-off-by: Cliff Frey <cliff@meraki.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- libbb/lineedit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index b89748a1c..92bea856e 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2527,9 +2527,9 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman /* Delete word forward */ int nc, sc = cursor; ctrl_right(); - nc = cursor; - input_backward(cursor - sc); - while (--nc >= cursor) + nc = cursor - sc; + input_backward(nc); + while (--nc >= 0) input_delete(1); break; } -- cgit v1.2.3-55-g6feb From 6567edd10b0ebd3333f4283decd90e1d57a42885 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Fri, 10 Aug 2012 00:27:22 +0200 Subject: udhcp[cd]: fix binding to network aliases. Closes 5432, 5438 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/udhcp/socket.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index a5220ba74..a42106960 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c @@ -80,6 +80,7 @@ int FAST_FUNC udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) { int fd; struct sockaddr_in addr; + char *colon; log1("Opening listen socket on *:%d %s", port, inf); fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); @@ -88,10 +89,17 @@ int FAST_FUNC udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) if (setsockopt_broadcast(fd) == -1) bb_perror_msg_and_die("SO_BROADCAST"); - /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */ + /* SO_BINDTODEVICE doesn't work on ethernet aliases (ethN:M) */ + colon = strrchr(inf, ':'); + if (colon) + *colon = '\0'; + if (setsockopt_bindtodevice(fd, inf)) xfunc_die(); /* warning is already printed */ + if (colon) + *colon = ':'; + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); -- cgit v1.2.3-55-g6feb From dba7094d62d699d1bd16c76c287d1e6d944970ca Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 15 Aug 2012 17:06:37 +0200 Subject: login: increase login name size limit from 32 to 64 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- loginutils/login.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loginutils/login.c b/loginutils/login.c index bf43f3aba..6ec8dc42e 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -37,7 +37,8 @@ static const struct pam_conv conv = { enum { TIMEOUT = 60, EMPTY_USERNAME_COUNT = 10, - USERNAME_SIZE = 32, + /* Some users found 32 chars limit to be too low: */ + USERNAME_SIZE = 64, TTYNAME_SIZE = 32, }; -- cgit v1.2.3-55-g6feb From 45c35e9de01010c6bb12f2b86fd5b8b31afe4617 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 16 Aug 2012 13:29:25 +0200 Subject: getty: add commented-out extended error diagnostic Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- loginutils/getty.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/loginutils/getty.c b/loginutils/getty.c index bbb5a96b4..f9b8bac44 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -549,7 +549,15 @@ int getty_main(int argc UNUSED_PARAM, char **argv) */ pid = getpid(); if (getsid(0) != pid) + { + //for debugging: + //bb_perror_msg_and_die("setsid failed:" + // " pid %d ppid %d" + // " sid %d pgid %d", + // pid, getppid(), + // getsid(0), getpgid(0)); bb_perror_msg_and_die("setsid"); + } /* Looks like we are already a session leader. * In this case (setsid failed) we may still have ctty, * and it may be different from tty we need to control! -- cgit v1.2.3-55-g6feb From 9c55143bbf4ce24bef093301e46aab15b4a71d69 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 16 Aug 2012 16:52:27 +0200 Subject: wget: try reading after poll timeout - stdio may have buffered data. Closes 5426 function old new delta retrieve_file_data 436 451 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/wget.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 6d8f8a504..3416636ae 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -448,6 +448,9 @@ static void NOINLINE retrieve_file_data(FILE *dfp) # endif struct pollfd polldata; +# if ENABLE_FEATURE_WGET_TIMEOUT + second_cnt = G.timeout_seconds; +# endif polldata.fd = fileno(dfp); polldata.events = POLLIN | POLLPRI; #endif @@ -483,12 +486,7 @@ static void NOINLINE retrieve_file_data(FILE *dfp) } #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT -# if ENABLE_FEATURE_WGET_TIMEOUT - second_cnt = G.timeout_seconds; -# endif - while (1) { - if (safe_poll(&polldata, 1, 1000) != 0) - break; /* error, EOF, or data is available */ + if (safe_poll(&polldata, 1, 1000) == 0) { # if ENABLE_FEATURE_WGET_TIMEOUT if (second_cnt != 0 && --second_cnt == 0) { progress_meter(PROGRESS_END); @@ -497,6 +495,13 @@ static void NOINLINE retrieve_file_data(FILE *dfp) # endif /* Needed for "stalled" indicator */ progress_meter(PROGRESS_BUMP); + /* + * We used to loop back to poll here, + * but in chunked case, we can be here after + * fgets and it could buffer some data in dfp... + * which poll knows nothing about! + * Therefore let's try fread'ing anyway. + */ } /* fread internally uses read loop, which in our case @@ -527,7 +532,9 @@ static void NOINLINE retrieve_file_data(FILE *dfp) } xwrite(G.output_fd, G.wget_buf, n); - +#if ENABLE_FEATURE_WGET_TIMEOUT + second_cnt = G.timeout_seconds; +#endif #if ENABLE_FEATURE_WGET_STATUSBAR G.transferred += n; progress_meter(PROGRESS_BUMP); -- cgit v1.2.3-55-g6feb From 41f7885f06612edcd525782f7ce3e75bd9a0d787 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 2 Sep 2012 13:57:49 +0200 Subject: getty: tweak style, no code changes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- loginutils/getty.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/loginutils/getty.c b/loginutils/getty.c index f9b8bac44..e5d13bed6 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -548,8 +548,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv) * a session leader - which is quite possible for getty! */ pid = getpid(); - if (getsid(0) != pid) - { + if (getsid(0) != pid) { //for debugging: //bb_perror_msg_and_die("setsid failed:" // " pid %d ppid %d" -- cgit v1.2.3-55-g6feb From a0fd4a789c4f9bfa0a9c257aa6a96c3588be6ce5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 2 Sep 2012 14:29:14 +0200 Subject: style fixes, no code changes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- applets/individual.c | 2 +- networking/ifupdown.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applets/individual.c b/applets/individual.c index 1e74e4ce5..4c468df06 100644 --- a/applets/individual.c +++ b/applets/individual.c @@ -14,7 +14,7 @@ const char *applet_name; int main(int argc, char **argv) { applet_name = argv[0]; - return APPLET_main(argc,argv); + return APPLET_main(argc, argv); } void bb_show_usage(void) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 9b3498696..ad0a9971b 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -1058,7 +1058,7 @@ static int iface_up(struct interface_defn_t *iface) static int iface_down(struct interface_defn_t *iface) { - if (!iface->method->down(iface,check)) return -1; + if (!iface->method->down(iface, check)) return -1; set_environ(iface, "stop", "pre-down"); if (!execute_all(iface, "down")) return 0; if (!iface->method->down(iface, doit)) return 0; -- cgit v1.2.3-55-g6feb From 405dafffbbbbaf2d036aca79856866f0031edd9f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 2 Sep 2012 14:29:45 +0200 Subject: ll_proto.c: code shrink text data bss dec hex filename 762 0 0 762 2fa ll_proto.o.old 526 0 0 526 20e ll_proto.o Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/libiproute/ll_proto.c | 108 ++++++++++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 23 deletions(-) diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c index 7aac8364d..60add2f0c 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c @@ -14,19 +14,78 @@ #include <netinet/if_ether.h> -#if !ENABLE_WERROR -#warning de-bloat +/* Please conditionalize exotic protocols on CONFIG_something */ + +static const uint16_t llproto_ids[] = +#define __PF(f,n) ETH_P_##f, +__PF(LOOP,loop) +__PF(PUP,pup) +#ifdef ETH_P_PUPAT +__PF(PUPAT,pupat) #endif -/* Before re-enabling this, please (1) conditionalize exotic protocols - * on CONFIG_something, and (2) decouple strings and numbers - * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;) - */ +__PF(IP,ip) +__PF(X25,x25) +__PF(ARP,arp) +__PF(BPQ,bpq) +#ifdef ETH_P_IEEEPUP +__PF(IEEEPUP,ieeepup) +#endif +#ifdef ETH_P_IEEEPUPAT +__PF(IEEEPUPAT,ieeepupat) +#endif +__PF(DEC,dec) +__PF(DNA_DL,dna_dl) +__PF(DNA_RC,dna_rc) +__PF(DNA_RT,dna_rt) +__PF(LAT,lat) +__PF(DIAG,diag) +__PF(CUST,cust) +__PF(SCA,sca) +__PF(RARP,rarp) +__PF(ATALK,atalk) +__PF(AARP,aarp) +__PF(IPX,ipx) +__PF(IPV6,ipv6) +#ifdef ETH_P_PPP_DISC +__PF(PPP_DISC,ppp_disc) +#endif +#ifdef ETH_P_PPP_SES +__PF(PPP_SES,ppp_ses) +#endif +#ifdef ETH_P_ATMMPOA +__PF(ATMMPOA,atmmpoa) +#endif +#ifdef ETH_P_ATMFATE +__PF(ATMFATE,atmfate) +#endif + +__PF(802_3,802_3) +__PF(AX25,ax25) +__PF(ALL,all) +__PF(802_2,802_2) +__PF(SNAP,snap) +__PF(DDCMP,ddcmp) +__PF(WAN_PPP,wan_ppp) +__PF(PPP_MP,ppp_mp) +__PF(LOCALTALK,localtalk) +__PF(PPPTALK,ppptalk) +__PF(TR_802_2,tr_802_2) +__PF(MOBITEX,mobitex) +__PF(CONTROL,control) +__PF(IRDA,irda) +#ifdef ETH_P_ECONET +__PF(ECONET,econet) +#endif + +0x8100, +ETH_P_IP +; +#undef __PF + +/* Keep declarations above and below in sync! */ -#define __PF(f,n) { ETH_P_##f, #n }, -static struct { - int id; - const char *name; -} llproto_names[] = { +static const char llproto_names[] = +#define __PF(f,n) #n "\0" __PF(LOOP,loop) __PF(PUP,pup) #ifdef ETH_P_PUPAT @@ -86,9 +145,9 @@ __PF(IRDA,irda) __PF(ECONET,econet) #endif -{ 0x8100, "802.1Q" }, -{ ETH_P_IP, "ipv4" }, -}; +"802.1Q" "\0" +"ipv4" "\0" +; #undef __PF @@ -96,23 +155,26 @@ const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len) { unsigned i; id = ntohs(id); - for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { - if (llproto_names[i].id == id) - return llproto_names[i].name; + for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) { + if (llproto_ids[i] == id) + return nth_string(llproto_names, i); } - snprintf(buf, len, "[%d]", id); + snprintf(buf, len, "[%u]", id); return buf; } int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf) { unsigned i; - for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { - if (strcasecmp(llproto_names[i].name, buf) == 0) { - i = llproto_names[i].id; - goto good; - } + const char *name = llproto_names; + for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) { + if (strcasecmp(name, buf) == 0) { + i = llproto_ids[i]; + goto good; + } + name += strlen(name) + 1; } + errno = 0; i = bb_strtou(buf, NULL, 0); if (errno || i > 0xffff) return -1; -- cgit v1.2.3-55-g6feb From 11f2c0d4f87ab7b1bb08632bfb67b1eb2df5f0e4 Mon Sep 17 00:00:00 2001 From: Sven-Göran Bergh <svengbergh-busybox@yahoo.com> Date: Sun, 2 Sep 2012 14:56:25 +0200 Subject: blkid: add type display for btrfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sven-Göran Bergh <svengbergh-busybox@yahoo.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/volume_id/btrfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util-linux/volume_id/btrfs.c b/util-linux/volume_id/btrfs.c index 777b80923..ee71d2e00 100644 --- a/util-linux/volume_id/btrfs.c +++ b/util-linux/volume_id/btrfs.c @@ -102,6 +102,7 @@ int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/) // N.B.: btrfs natively supports 256 (>VOLUME_ID_LABEL_SIZE) size labels volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE); volume_id_set_uuid(id, sb->fsid, UUID_DCE); + IF_FEATURE_BLKID_TYPE(id->type = "btrfs";) return 0; } -- cgit v1.2.3-55-g6feb From 8019b3a7aea51343f79922928c91ef833344b743 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Sun, 2 Sep 2012 15:33:47 +0200 Subject: volume_id: code shrink function old new delta volume_id_set_unicode16 200 173 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/volume_id/util.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c index dd75c7ba1..69e43dda8 100644 --- a/util-linux/volume_id/util.c +++ b/util-linux/volume_id/util.c @@ -31,25 +31,29 @@ void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum end c = (buf[i+1] << 8) | buf[i]; else c = (buf[i] << 8) | buf[i+1]; - if (c == 0) { - str[j] = '\0'; + if (c == 0) break; - } else if (c < 0x80) { - if (j+1 >= len) - break; - str[j++] = (uint8_t) c; - } else if (c < 0x800) { - if (j+2 >= len) - break; - str[j++] = (uint8_t) (0xc0 | (c >> 6)); - str[j++] = (uint8_t) (0x80 | (c & 0x3f)); + if (j+1 >= len) + break; + if (c < 0x80) { + /* 0xxxxxxx */ } else { - if (j+3 >= len) + uint8_t topbits = 0xc0; + if (j+2 >= len) break; - str[j++] = (uint8_t) (0xe0 | (c >> 12)); - str[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f)); - str[j++] = (uint8_t) (0x80 | (c & 0x3f)); + if (c < 0x800) { + /* 110yyyxx 10xxxxxx */ + } else { + if (j+3 >= len) + break; + /* 1110yyyy 10yyyyxx 10xxxxxx */ + str[j++] = (uint8_t) (0xe0 | (c >> 12)); + topbits = 0x80; + } + str[j++] = (uint8_t) (topbits | ((c >> 6) & 0x3f)); + c = 0x80 | (c & 0x3f); } + str[j++] = (uint8_t) c; } str[j] = '\0'; } -- cgit v1.2.3-55-g6feb From c5a9fa2d2ac0165eda4b862e99cfcb91a9380416 Mon Sep 17 00:00:00 2001 From: Sven-Göran Bergh <svengbergh-busybox@yahoo.com> Date: Sun, 2 Sep 2012 15:34:39 +0200 Subject: blkid: add support for nilfs2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit function old new delta volume_id_probe_nilfs - 99 +99 fs2 52 56 +4 Signed-off-by: Sven-Göran Bergh <svengbergh-busybox@yahoo.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- util-linux/Config.src | 7 +++ util-linux/volume_id/Kbuild.src | 1 + util-linux/volume_id/nilfs.c | 96 +++++++++++++++++++++++++++++++ util-linux/volume_id/volume_id.c | 3 + util-linux/volume_id/volume_id_internal.h | 2 + 5 files changed, 109 insertions(+) create mode 100644 util-linux/volume_id/nilfs.c diff --git a/util-linux/Config.src b/util-linux/Config.src index 57a52cefb..3355e9729 100644 --- a/util-linux/Config.src +++ b/util-linux/Config.src @@ -762,6 +762,13 @@ config FEATURE_VOLUMEID_XFS help TODO +config FEATURE_VOLUMEID_NILFS + bool "nilfs filesystem" + default y + depends on VOLUMEID + help + TODO + config FEATURE_VOLUMEID_NTFS bool "ntfs filesystem" default y diff --git a/util-linux/volume_id/Kbuild.src b/util-linux/volume_id/Kbuild.src index 70da65482..39a2d8cf4 100644 --- a/util-linux/volume_id/Kbuild.src +++ b/util-linux/volume_id/Kbuild.src @@ -31,6 +31,7 @@ lib-$(CONFIG_FEATURE_VOLUMEID_LINUXSWAP) += linux_swap.o ### lib-$(CONFIG_FEATURE_VOLUMEID_LVM) += lvm.o ### lib-$(CONFIG_FEATURE_VOLUMEID_MAC) += mac.o ### lib-$(CONFIG_FEATURE_VOLUMEID_MSDOS) += msdos.o +lib-$(CONFIG_FEATURE_VOLUMEID_NILFS) += nilfs.o lib-$(CONFIG_FEATURE_VOLUMEID_NTFS) += ntfs.o lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS) += reiserfs.o lib-$(CONFIG_FEATURE_VOLUMEID_UDF) += udf.o diff --git a/util-linux/volume_id/nilfs.c b/util-linux/volume_id/nilfs.c new file mode 100644 index 000000000..ffa86d43c --- /dev/null +++ b/util-linux/volume_id/nilfs.c @@ -0,0 +1,96 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> + * Copyright (C) 2012 S-G Bergh <sgb@systemasis.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "volume_id_internal.h" + +#define NILFS_UUID_SIZE 16 +#define NILFS_LABEL_SIZE 80 +#define NILFS_SB1_OFFSET 0x400 +#define NILFS_SB2_OFFSET 0x1000 +#define NILFS_MAGIC 0x3434 + +struct nilfs2_super_block { +/* 0x00 */ uint32_t s_rev_level; // Major revision level. +/* 0x04 */ uint16_t s_minor_rev_level; // Minor revision level. +/* 0x06 */ uint16_t s_magic; // Magic signature. +/* 0x08 */ uint16_t s_bytes; +/* 0x0A */ uint16_t s_flags; +/* 0x0C */ uint32_t s_crc_seed; +/* 0x10 */ uint32_t s_sum; +/* 0x14 */ uint32_t s_log_block_size; +/* 0x18 */ uint64_t s_nsegments; +/* 0x20 */ uint64_t s_dev_size; // Block device size in bytes. +/* 0x28 */ uint64_t s_first_data_block; +/* 0x30 */ uint32_t s_blocks_per_segment; +/* 0x34 */ uint32_t s_r_segments_percentage; +/* 0x38 */ uint64_t s_last_cno; +/* 0x40 */ uint64_t s_last_pseg; +/* 0x48 */ uint64_t s_last_seq; +/* 0x50 */ uint64_t s_free_blocks_count; +/* 0x58 */ uint64_t s_ctime; +/* 0x60 */ uint64_t s_mtime; +/* 0x68 */ uint64_t s_wtime; +/* 0x70 */ uint16_t s_mnt_count; +/* 0x72 */ uint16_t s_max_mnt_count; +/* 0x74 */ uint16_t s_state; +/* 0x76 */ uint16_t s_errors; +/* 0x78 */ uint64_t s_lastcheck; +/* 0x80 */ uint32_t s_checkinterval; +/* 0x84 */ uint32_t s_creator_os; +/* 0x88 */ uint16_t s_def_resuid; +/* 0x8A */ uint16_t s_def_resgid; +/* 0x8C */ uint32_t s_first_ino; +/* 0x90 */ uint16_t s_inode_size; +/* 0x92 */ uint16_t s_dat_entry_size; +/* 0x94 */ uint16_t s_checkpoint_size; +/* 0x96 */ uint16_t s_segment_usage_size; +/* 0x98 */ uint8_t s_uuid[NILFS_UUID_SIZE]; // 128-bit UUID for volume. +/* 0xA8 */ uint8_t s_volume_name[NILFS_LABEL_SIZE]; // Volume label. +/* 0xF8 */ // ... +} PACKED; + +int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/) +{ + struct nilfs2_super_block *sb; + + // Primary super block + dbg("nilfs: probing at offset 0x%x", NILFS_SB1_OFFSET); + + sb = volume_id_get_buffer(id, NILFS_SB1_OFFSET, sizeof(*sb)); + + if (sb == NULL) + return -1; + + if (sb->s_magic != NILFS_MAGIC) + return -1; + + // The secondary superblock is not always used, so ignore it for now. + // When used it is at 4K from the end of the partition (sb->s_dev_size - NILFS_SB2_OFFSET). + + volume_id_set_label_string(id, sb->s_volume_name, NILFS_LABEL_SIZE < VOLUME_ID_LABEL_SIZE ? + NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE); + volume_id_set_uuid(id, sb->s_uuid, UUID_DCE); + + if (sb->s_rev_level == 2) + IF_FEATURE_BLKID_TYPE(id->type = "nilfs2"); + + return 0; +} diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c index f41d4e0d9..c1d615283 100644 --- a/util-linux/volume_id/volume_id.c +++ b/util-linux/volume_id/volume_id.c @@ -130,6 +130,9 @@ static const probe_fptr fs2[] = { #if ENABLE_FEATURE_VOLUMEID_UFS volume_id_probe_ufs, #endif +#if ENABLE_FEATURE_VOLUMEID_NILFS + volume_id_probe_nilfs, +#endif #if ENABLE_FEATURE_VOLUMEID_NTFS volume_id_probe_ntfs, #endif diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h index 1c64046e5..1c2e0ffa6 100644 --- a/util-linux/volume_id/volume_id_internal.h +++ b/util-linux/volume_id/volume_id_internal.h @@ -212,6 +212,8 @@ int FAST_FUNC volume_id_probe_luks(struct volume_id *id /*,uint64_t off*/); //int FAST_FUNC volume_id_probe_msdos_part_table(struct volume_id *id /*,uint64_t off*/); +int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/); + int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/); int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id /*,uint64_t off*/); -- cgit v1.2.3-55-g6feb From 5f10fdf1dd43cf8db74cd2f84eb1c6ede48e3328 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 3 Sep 2012 11:41:30 +0200 Subject: Fix compile failure in ll_proto.c Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/libiproute/ll_proto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c index 60add2f0c..da2b53cbf 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c @@ -16,7 +16,7 @@ /* Please conditionalize exotic protocols on CONFIG_something */ -static const uint16_t llproto_ids[] = +static const uint16_t llproto_ids[] = { #define __PF(f,n) ETH_P_##f, __PF(LOOP,loop) __PF(PUP,pup) @@ -79,7 +79,7 @@ __PF(ECONET,econet) 0x8100, ETH_P_IP -; +}; #undef __PF /* Keep declarations above and below in sync! */ -- cgit v1.2.3-55-g6feb From 168f87c531d04be06e16f04144c61ba289e0c0ec Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 3 Sep 2012 12:20:10 +0200 Subject: httpd_indexcgi.c: fix compile failure Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/httpd_indexcgi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/networking/httpd_indexcgi.c b/networking/httpd_indexcgi.c index d732cd4f8..562cd7fbe 100644 --- a/networking/httpd_indexcgi.c +++ b/networking/httpd_indexcgi.c @@ -35,6 +35,7 @@ httpd_indexcgi.c -o index.cgi * 2576 4 2048 4628 1214 index.cgi.o */ +#define _GNU_SOURCE 1 /* for strchrnul */ #include <sys/types.h> #include <sys/stat.h> #include <errno.h> -- cgit v1.2.3-55-g6feb From b7812ce0f7ee230330e18de3ac447b700311ab84 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon, 3 Sep 2012 12:49:30 +0200 Subject: wget: reorder fread and poll: poll only if fread returns EAGAIN. Closes 5426 function old new delta retrieve_file_data 451 427 -24 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- networking/wget.c | 114 +++++++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 3416636ae..4eafebe40 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -444,13 +444,10 @@ static void NOINLINE retrieve_file_data(FILE *dfp) { #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT # if ENABLE_FEATURE_WGET_TIMEOUT - unsigned second_cnt; + unsigned second_cnt = G.timeout_seconds; # endif struct pollfd polldata; -# if ENABLE_FEATURE_WGET_TIMEOUT - second_cnt = G.timeout_seconds; -# endif polldata.fd = fileno(dfp); polldata.events = POLLIN | POLLPRI; #endif @@ -468,7 +465,7 @@ static void NOINLINE retrieve_file_data(FILE *dfp) * which messes up progress bar and/or timeout logic. * Because of nonblocking I/O, we need to dance * very carefully around EAGAIN. See explanation at - * clearerr() call. + * clearerr() calls. */ ndelay_on(polldata.fd); #endif @@ -476,34 +473,7 @@ static void NOINLINE retrieve_file_data(FILE *dfp) int n; unsigned rdsz; - rdsz = sizeof(G.wget_buf); - if (G.got_clen) { - if (G.content_len < (off_t)sizeof(G.wget_buf)) { - if ((int)G.content_len <= 0) - break; - rdsz = (unsigned)G.content_len; - } - } - #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT - if (safe_poll(&polldata, 1, 1000) == 0) { -# if ENABLE_FEATURE_WGET_TIMEOUT - if (second_cnt != 0 && --second_cnt == 0) { - progress_meter(PROGRESS_END); - bb_error_msg_and_die("download timed out"); - } -# endif - /* Needed for "stalled" indicator */ - progress_meter(PROGRESS_BUMP); - /* - * We used to loop back to poll here, - * but in chunked case, we can be here after - * fgets and it could buffer some data in dfp... - * which poll knows nothing about! - * Therefore let's try fread'ing anyway. - */ - } - /* fread internally uses read loop, which in our case * is usually exited when we get EAGAIN. * In this case, libc sets error marker on the stream. @@ -513,38 +483,71 @@ static void NOINLINE retrieve_file_data(FILE *dfp) * into if (n <= 0) ... */ clearerr(dfp); - errno = 0; #endif + errno = 0; + rdsz = sizeof(G.wget_buf); + if (G.got_clen) { + if (G.content_len < (off_t)sizeof(G.wget_buf)) { + if ((int)G.content_len <= 0) + break; + rdsz = (unsigned)G.content_len; + } + } n = fread(G.wget_buf, 1, rdsz, dfp); - /* man fread: + + if (n > 0) { + xwrite(G.output_fd, G.wget_buf, n); +#if ENABLE_FEATURE_WGET_STATUSBAR + G.transferred += n; +#endif + if (G.got_clen) { + G.content_len -= n; + if (G.content_len == 0) + break; + } +#if ENABLE_FEATURE_WGET_TIMEOUT + second_cnt = G.timeout_seconds; +#endif + continue; + } + + /* n <= 0. + * man fread: * If error occurs, or EOF is reached, the return value * is a short item count (or zero). * fread does not distinguish between EOF and error. */ - if (n <= 0) { -#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT - if (errno == EAGAIN) /* poll lied, there is no data? */ - continue; /* yes */ -#endif - if (ferror(dfp)) + if (errno != EAGAIN) { + if (ferror(dfp)) { + progress_meter(PROGRESS_END); bb_perror_msg_and_die(bb_msg_read_error); + } break; /* EOF, not error */ } - xwrite(G.output_fd, G.wget_buf, n); -#if ENABLE_FEATURE_WGET_TIMEOUT - second_cnt = G.timeout_seconds; -#endif -#if ENABLE_FEATURE_WGET_STATUSBAR - G.transferred += n; +#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT + /* It was EAGAIN. There is no data. Wait up to one second + * then abort if timed out, or update the bar and try reading again. + */ + if (safe_poll(&polldata, 1, 1000) == 0) { +# if ENABLE_FEATURE_WGET_TIMEOUT + if (second_cnt != 0 && --second_cnt == 0) { + progress_meter(PROGRESS_END); + bb_error_msg_and_die("download timed out"); + } +# endif + /* We used to loop back to poll here, + * but there is no great harm in letting fread + * to try reading anyway. + */ + } + /* Need to do it _every_ second for "stalled" indicator + * to be shown properly. + */ progress_meter(PROGRESS_BUMP); #endif - if (G.got_clen) { - G.content_len -= n; - if (G.content_len == 0) - break; - } - } + } /* while (reading data) */ + #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT clearerr(dfp); ndelay_off(polldata.fd); /* else fgets can get very unhappy */ @@ -560,6 +563,13 @@ static void NOINLINE retrieve_file_data(FILE *dfp) if (G.content_len == 0) break; /* all done! */ G.got_clen = 1; + /* + * Note that fgets may result in some data being buffered in dfp. + * We loop back to fread, which will retrieve this data. + * Also note that code has to be arranged so that fread + * is done _before_ one-second poll wait - poll doesn't know + * about stdio buffering and can result in spurious one second waits! + */ } /* If -c failed, we restart from the beginning, -- cgit v1.2.3-55-g6feb From 9b80b903c7fd2120a72de287fe6b0920e6d3c8ff Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Tue, 4 Sep 2012 11:46:44 +0200 Subject: build system: stop .eh_frame generation From Rich Felker: By default, modern GCC generates DWARF2 debug/unwind tables in the .eh_frame section of the object files/binaries. This adds significant bloat (as much as 15%) to the size of the busybox binary, including the portion mapped/loaded into memory at runtime (possibly a big issue for NOMMU targets), and the section is not strippable with the strip command due to being part of the loaded program text. I've since done some further checking - both testing and asking the GCC developers about it - and it seems the solution is to add to the CFLAGS -fno-unwind-tables and -fno-asynchronous-unwind-tables. If debugging is disabled, this will prevent GCC from outputting DWARF2 tables entirely. But since busybox builds with -g by default, the interesting case is what happens then. I originally thought these options would break debugging, but they don't; instead, they tell GCC to output the DWARF2 tables in the .debug_frame section instead of the newish .eh_frame section (used for exception handling). With these options added, busybox_unstripped is still fully debuggable, and the final busybox binary loses the 15% bloat factor from the DWARF2 tables. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- Makefile.flags | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile.flags b/Makefile.flags index f5f446598..e77c0e527 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -53,6 +53,9 @@ CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-poi CFLAGS += $(call cc-option,-fno-guess-branch-probability,) CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,) CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,) +# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary): +CFLAGS += $(call cc-option,-fno-unwind-tables,) +CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,) # FIXME: These warnings are at least partially to be concerned about and should # be fixed.. -- cgit v1.2.3-55-g6feb From d1d794fd4878834324602ae12ad7af73064683a9 Mon Sep 17 00:00:00 2001 From: walter harms <wharms@bfs.de> Date: Tue, 4 Sep 2012 12:26:20 +0200 Subject: refactor correct_password.c to avoid one if Signed-off-by: walter harms <wharms@bfs.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- libbb/correct_password.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libbb/correct_password.c b/libbb/correct_password.c index 6301589e6..7cabd33d0 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c @@ -41,12 +41,6 @@ int FAST_FUNC correct_password(const struct passwd *pw) char *unencrypted, *encrypted; const char *correct; int r; -#if ENABLE_FEATURE_SHADOWPASSWDS - /* Using _r function to avoid pulling in static buffers */ - struct spwd spw; - char buffer[256]; -#endif - /* fake salt. crypt() can choke otherwise. */ correct = "aa"; if (!pw) { @@ -55,7 +49,10 @@ int FAST_FUNC correct_password(const struct passwd *pw) } correct = pw->pw_passwd; #if ENABLE_FEATURE_SHADOWPASSWDS + /* Using _r function to avoid pulling in static buffers */ if ((correct[0] == 'x' || correct[0] == '*') && !correct[1]) { + struct spwd spw; + char buffer[256]; /* getspnam_r may return 0 yet set result to NULL. * At least glibc 2.4 does this. Be extra paranoid here. */ struct spwd *result = NULL; -- cgit v1.2.3-55-g6feb From c4398514385f806e1725685d0fee62dc0eb69b9f Mon Sep 17 00:00:00 2001 From: Joshua Kahlenberg <jbkberg@gmail.com> Date: Wed, 5 Sep 2012 18:15:12 +0200 Subject: sysctl: implement -q function old new delta packed_usage 29208 29223 +15 sysctl_act_recursive 605 598 -7 sysctl_main 233 222 -11 Signed-off-by: Joshua Kahlenberg <jbkberg@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- procps/sysctl.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/procps/sysctl.c b/procps/sysctl.c index 5296d0f58..878656862 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c @@ -12,21 +12,23 @@ */ //usage:#define sysctl_trivial_usage -//usage: "[OPTIONS] [VALUE]..." +//usage: "[OPTIONS] [KEY[=VALUE]]..." //usage:#define sysctl_full_usage "\n\n" -//usage: "Configure kernel parameters at runtime\n" -//usage: "\n -n Don't print key names" +//usage: "Show/set kernel parameters\n" //usage: "\n -e Don't warn about unknown keys" -//usage: "\n -w Change sysctl setting" -//usage: "\n -p FILE Load sysctl settings from FILE (default /etc/sysctl.conf)" -//usage: "\n -a Display all values" -//usage: "\n -A Display all values in table form" +//usage: "\n -n Don't show key names" +//usage: "\n -a Show all values" +/* Same as -a, no need to show it */ +/* //usage: "\n -A Show all values in table form" */ +//usage: "\n -w Set values" +//usage: "\n -p FILE Set values from FILE (default /etc/sysctl.conf)" +//usage: "\n -q Set values silently" //usage: //usage:#define sysctl_example_usage //usage: "sysctl [-n] [-e] variable...\n" -//usage: "sysctl [-n] [-e] -w variable=value...\n" +//usage: "sysctl [-n] [-e] [-q] -w variable=value...\n" //usage: "sysctl [-n] [-e] -a\n" -//usage: "sysctl [-n] [-e] -p file (default /etc/sysctl.conf)\n" +//usage: "sysctl [-n] [-e] [-q] -p file (default /etc/sysctl.conf)\n" //usage: "sysctl [-n] [-e] -A\n" #include "libbb.h" @@ -37,9 +39,11 @@ enum { FLAG_TABLE_FORMAT = 1 << 2, /* not implemented */ FLAG_SHOW_ALL = 1 << 3, FLAG_PRELOAD_FILE = 1 << 4, +/* TODO: procps 3.2.8 seems to not require -w for KEY=VAL to work: */ FLAG_WRITE = 1 << 5, + FLAG_QUIET = 1 << 6, }; -#define OPTION_STR "neAapw" +#define OPTION_STR "neAapwq" static void sysctl_dots_to_slashes(char *name) { @@ -144,9 +148,11 @@ static int sysctl_act_on_setting(char *setting) //TODO: procps 3.2.7 writes "value\n", note trailing "\n" xwrite_str(fd, value); close(fd); - if (option_mask32 & FLAG_SHOW_KEYS) - printf("%s = ", outname); - puts(value); + if (!(option_mask32 & FLAG_QUIET)) { + if (option_mask32 & FLAG_SHOW_KEYS) + printf("%s = ", outname); + puts(value); + } } else { char c; -- cgit v1.2.3-55-g6feb From 50157f3decce78d3172314a5f97363faedba565a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 6 Sep 2012 12:43:22 +0200 Subject: top: fix "last CPU" parsing Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- libbb/procps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbb/procps.c b/libbb/procps.c index 40587db82..295048c46 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -425,7 +425,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) if (n < 11) continue; /* bogus data, get next /proc/XXX */ # if ENABLE_FEATURE_TOP_SMP_PROCESS - if (n < 11+15) + if (n == 11) sp->last_seen_on_cpu = 0; # endif -- cgit v1.2.3-55-g6feb From 9e71e3cea59c06d40234d8f3363c3f05112e8d5a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 6 Sep 2012 13:28:10 +0200 Subject: ash: fix "read -s" + ^C. Closes 5504 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- shell/ash.c | 5 +++++ shell/shell_common.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index b20c32b89..153bcc057 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12803,6 +12803,10 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) } } + /* "read -s" needs to save/restore termios, can't allow ^C + * to jump out of it. + */ + INT_OFF; r = shell_builtin_read(setvar2, argptr, bltinlookup("IFS"), /* can be NULL */ @@ -12812,6 +12816,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) opt_t, opt_u ); + INT_ON; if ((uintptr_t)r > 1) ash_msg_and_raise_error(r); diff --git a/shell/shell_common.c b/shell/shell_common.c index 780e27ebd..0051f21d9 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -170,7 +170,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val), int timeout; if ((bufpos & 0xff) == 0) - buffer = xrealloc(buffer, bufpos + 0x100); + buffer = xrealloc(buffer, bufpos + 0x101); timeout = -1; if (end_ms) { -- cgit v1.2.3-55-g6feb From 2dc1a9727288dd732af47e2618a791be9214dfe4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 6 Sep 2012 15:24:11 +0200 Subject: find: make -mindepth N -xdev correctly stop on mountpoints function old new delta fileAction 153 193 +40 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- findutils/find.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/findutils/find.c b/findutils/find.c index 0ec5bdfea..b521e5b08 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -728,10 +728,27 @@ static int FAST_FUNC fileAction(const char *fileName, int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM)) { int r; + int same_fs = 1; + +#if ENABLE_FEATURE_FIND_XDEV + if (S_ISDIR(statbuf->st_mode) && G.xdev_count) { + int i; + for (i = 0; i < G.xdev_count; i++) { + if (G.xdev_dev[i] == statbuf->st_dev) + goto found; + } + //bb_error_msg("'%s': not same fs", fileName); + same_fs = 0; + found: ; + } +#endif #if ENABLE_FEATURE_FIND_MAXDEPTH - if (depth < G.minmaxdepth[0]) - return TRUE; /* skip this, continue recursing */ + if (depth < G.minmaxdepth[0]) { + if (same_fs) + return TRUE; /* skip this, continue recursing */ + return SKIP; /* stop recursing */ + } if (depth > G.minmaxdepth[1]) return SKIP; /* stop recursing */ #endif @@ -747,21 +764,11 @@ static int FAST_FUNC fileAction(const char *fileName, return SKIP; } #endif -#if ENABLE_FEATURE_FIND_XDEV /* -xdev stops on mountpoints, but AFTER mountpoit itself * is processed as usual */ - if (S_ISDIR(statbuf->st_mode)) { - if (G.xdev_count) { - int i; - for (i = 0; i < G.xdev_count; i++) { - if (G.xdev_dev[i] == statbuf->st_dev) - goto found; - } - return SKIP; - found: ; - } + if (!same_fs) { + return SKIP; } -#endif /* Cannot return 0: our caller, recursive_action(), * will perror() and skip dirs (if called on dir) */ -- cgit v1.2.3-55-g6feb From 6d463de46b418e6c4c8d1397033608f78b33ab21 Mon Sep 17 00:00:00 2001 From: Linus Walleij <triad@df.lth.se> Date: Thu, 6 Sep 2012 16:52:31 +0200 Subject: fbsplash: support non-RGB565 pixels in 16-bit mode function old new delta fbsplash_main 953 989 +36 fb_pixel_value 80 110 +30 Signed-off-by: Linus Walleij <triad@df.lth.se> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- miscutils/fbsplash.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 988439b25..37ca66559 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c @@ -50,6 +50,10 @@ struct globals { struct fb_var_screeninfo scr_var; struct fb_fix_screeninfo scr_fix; unsigned bytes_per_pixel; + // cached (8 - scr_var.COLOR.length): + unsigned red_shift; + unsigned green_shift; + unsigned blue_shift; }; #define G (*ptr_to_globals) #define INIT_G() do { \ @@ -139,6 +143,9 @@ static void fb_open(const char *strfb_device) break; } + G.red_shift = 8 - G.scr_var.red.length; + G.green_shift = 8 - G.scr_var.green.length; + G.blue_shift = 8 - G.scr_var.blue.length; G.bytes_per_pixel = (G.scr_var.bits_per_pixel + 7) >> 3; // map the device in memory @@ -155,10 +162,13 @@ static void fb_open(const char *strfb_device) /** - * Return pixel value of the passed RGB color + * Return pixel value of the passed RGB color. + * This is performance critical fn. */ static unsigned fb_pixel_value(unsigned r, unsigned g, unsigned b) { + /* We assume that the r,g,b values are <= 255 */ + if (G.bytes_per_pixel == 1) { r = r & 0xe0; // 3-bit red g = (g >> 3) & 0x1c; // 3-bit green @@ -166,10 +176,17 @@ static unsigned fb_pixel_value(unsigned r, unsigned g, unsigned b) return r + g + b; } if (G.bytes_per_pixel == 2) { - r = (r & 0xf8) << 8; // 5-bit red - g = (g & 0xfc) << 3; // 6-bit green - b = b >> 3; // 5-bit blue - return r + g + b; + // ARM PL110 on Integrator/CP has RGBA5551 bit arrangement. + // We want to support bit locations like that. + // + // First shift out unused bits + r = r >> G.red_shift; + g = g >> G.green_shift; + b = b >> G.blue_shift; + // Then shift the remaining bits to their offset + return (r << G.scr_var.red.offset) + + (g << G.scr_var.green.offset) + + (b << G.scr_var.blue.offset); } // RGB 888 return b + (g << 8) + (r << 16); -- cgit v1.2.3-55-g6feb