From e3b1a1fd28558f7a1b3c0ec33313bedb675be8a1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 26 Feb 2011 22:24:08 +0100 Subject: Replace "depends on PLATFORM_LINUX" with "select PLATFORM_LINUX" Signed-off-by: Denys Vlasenko --- Config.in | 2 +- console-tools/Config.src | 26 ++++++++++----------- coreutils/Config.src | 2 +- coreutils/date.c | 3 ++- e2fsprogs/Config.src | 2 +- libbb/Config.src | 2 +- miscutils/Config.src | 27 +++++++++++----------- miscutils/conspy.c | 2 +- miscutils/nandwrite.c | 4 ++-- miscutils/ubi_attach_detach.c | 10 ++++---- modutils/Config.src | 20 +++++++++++++++- networking/Config.src | 37 ++++++++++++++--------------- networking/ping.c | 2 +- networking/udhcp/Config.src | 4 ++-- procps/Config.src | 7 +++--- sysklogd/Config.src | 3 ++- util-linux/Config.src | 54 +++++++++++++++++++++---------------------- 17 files changed, 115 insertions(+), 92 deletions(-) diff --git a/Config.in b/Config.in index 3361e7381..94414db04 100644 --- a/Config.in +++ b/Config.in @@ -385,7 +385,7 @@ config FEATURE_SUID_CONFIG_QUIET config SELINUX bool "Support NSA Security Enhanced Linux" default n - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Enable support for SELinux in applets ls, ps, and id. Also provide the option of compiling in SELinux applets. diff --git a/console-tools/Config.src b/console-tools/Config.src index cdb26800e..c65704478 100644 --- a/console-tools/Config.src +++ b/console-tools/Config.src @@ -10,7 +10,7 @@ INSERT config CHVT bool "chvt" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program is used to change to another terminal. Example: chvt 4 (change to terminal /dev/tty4) @@ -18,7 +18,7 @@ config CHVT config FGCONSOLE bool "fgconsole" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program prints active (foreground) console number. @@ -31,14 +31,14 @@ config CLEAR config DEALLOCVT bool "deallocvt" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program deallocates unused virtual consoles. config DUMPKMAP bool "dumpkmap" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program dumps the kernel's keyboard translation table to stdout, in binary format. You can then use loadkmap to load it. @@ -46,21 +46,21 @@ config DUMPKMAP config KBD_MODE bool "kbd_mode" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program reports and sets keyboard mode. config LOADFONT bool "loadfont" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program loads a console font from standard input. config LOADKMAP bool "loadkmap" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program loads a keyboard translation table from standard input. @@ -68,7 +68,7 @@ config LOADKMAP config OPENVT bool "openvt" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program is used to start a command on an unused virtual terminal. @@ -100,7 +100,7 @@ config FEATURE_RESIZE_PRINT config SETCONSOLE bool "setconsole" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program redirects the system console to another device, like the current tty while logged in via telnet. @@ -115,7 +115,7 @@ config FEATURE_SETCONSOLE_LONG_OPTIONS config SETFONT bool "setfont" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Allows to load console screen map. Useful for i18n. @@ -137,7 +137,7 @@ config DEFAULT_SETFONT_DIR config SETKEYCODES bool "setkeycodes" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program loads entries into the kernel's scancode-to-keycode map, allowing unusual keyboards to generate usable keycodes. @@ -145,14 +145,14 @@ config SETKEYCODES config SETLOGCONS bool "setlogcons" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This program redirects the output console of kernel messages. config SHOWKEY bool "showkey" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Shows keys pressed. diff --git a/coreutils/Config.src b/coreutils/Config.src index 1a044f96c..1843e8b0e 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src @@ -591,7 +591,7 @@ config FEATURE_SPLIT_FANCY config STAT bool "stat" default y - depends on PLATFORM_LINUX # statfs() + select PLATFORM_LINUX # statfs() help display file or filesystem status. diff --git a/coreutils/date.c b/coreutils/date.c index 05b4f6eed..db1b693aa 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -42,7 +42,8 @@ //config:config FEATURE_DATE_NANO //config: bool "Support %[num]N nanosecond format specifier" //config: default n -//config: depends on DATE && PLATFORM_LINUX # syscall(__NR_clock_gettime) +//config: depends on DATE # syscall(__NR_clock_gettime) +//config: select PLATFORM_LINUX //config: help //config: Support %[num]N format specifier. Adds ~250 bytes of code. //config: diff --git a/e2fsprogs/Config.src b/e2fsprogs/Config.src index 6043e9b57..743e1e11f 100644 --- a/e2fsprogs/Config.src +++ b/e2fsprogs/Config.src @@ -33,7 +33,7 @@ config FSCK config LSATTR bool "lsattr" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help lsattr lists the file attributes on a second extended file system. diff --git a/libbb/Config.src b/libbb/Config.src index 18bdc5151..a25af23b4 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -183,7 +183,7 @@ config FEATURE_SKIP_ROOTFS config MONOTONIC_SYSCALL bool "Use clock_gettime(CLOCK_MONOTONIC) syscall" default n - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring time intervals (time, ping, traceroute etc need this). diff --git a/miscutils/Config.src b/miscutils/Config.src index b5866bbd7..61529141d 100644 --- a/miscutils/Config.src +++ b/miscutils/Config.src @@ -10,7 +10,7 @@ INSERT config ADJTIMEX bool "adjtimex" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Adjtimex reads and optionally sets adjustment parameters for the Linux clock adjustment algorithm. @@ -39,7 +39,7 @@ config FEATURE_COMPRESS_BBCONFIG config BEEP bool "beep" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The beep applets beeps in a given freq/Hz. @@ -194,7 +194,7 @@ config FEATURE_DC_LIBM config DEVFSD bool "devfsd (obsolete)" default n - depends on PLATFORM_LINUX + select PLATFORM_LINUX select FEATURE_SYSLOG help This is deprecated and should NOT be used anymore. @@ -238,7 +238,7 @@ config DEVFSD_VERBOSE config FEATURE_DEVFS bool "Use devfs names for all devices (obsolete)" default n - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This is obsolete and should NOT be used anymore. Use linux >= 2.6 (optionally with hotplug) and mdev instead! @@ -258,7 +258,7 @@ config DEVMEM config EJECT bool "eject" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Used to eject cdroms. (defaults to /dev/cdrom) @@ -273,7 +273,7 @@ config FEATURE_EJECT_SCSI config FBSPLASH bool "fbsplash" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Shows splash image and progress bar on framebuffer device. Can be used during boot phase of an embedded device. ~2kb. @@ -323,7 +323,7 @@ config FLASH_ERASEALL config IONICE bool "ionice" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Set/set program io scheduling class and priority Requires kernel >= 2.6.13 @@ -429,7 +429,7 @@ config FEATURE_LESS_LINENUMS config HDPARM bool "hdparm" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Get/Set hard drive parameters. Primarily intended for ATA drives. Adds about 13k (or around 30k if you enable the @@ -546,7 +546,7 @@ config MT config RAIDAUTORUN bool "raidautorun" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help raidautorun tells the kernel md driver to search and start RAID arrays. @@ -554,7 +554,8 @@ config RAIDAUTORUN config READAHEAD bool "readahead" default y - depends on LFS && PLATFORM_LINUX + depends on LFS + select PLATFORM_LINUX help Preload the files listed on the command line into RAM cache so that subsequent reads on these files will not block on disk I/O. @@ -571,7 +572,7 @@ config READAHEAD config RFKILL bool "rfkill" default n # doesn't build on Ubuntu 9.04 - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Enable/disable wireless devices. @@ -593,7 +594,7 @@ config RUNLEVEL config RX bool "rx" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Receive files using the Xmodem protocol. @@ -666,7 +667,7 @@ config WALL config WATCHDOG bool "watchdog" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The watchdog utility is used with hardware or software watchdog device drivers. It opens the specified watchdog device special file diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 721eb6d59..1fdb2fb38 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c @@ -17,7 +17,7 @@ //config:config CONSPY //config: bool "conspy" //config: default n -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: A text-mode VNC like program for Linux virtual terminals. //config: example: conspy NUM shared access to console num diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index c5e2fb841..c7fbe7d9c 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -17,14 +17,14 @@ //config:config NANDWRITE //config: bool "nandwrite" //config: default n -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: Write to the specified MTD device, with bad blocks awareness //config: //config:config NANDDUMP //config: bool "nanddump" //config: default n -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: Dump the content of raw NAND chip diff --git a/miscutils/ubi_attach_detach.c b/miscutils/ubi_attach_detach.c index fef9250ee..9007f8c3f 100644 --- a/miscutils/ubi_attach_detach.c +++ b/miscutils/ubi_attach_detach.c @@ -6,35 +6,35 @@ //config:config UBIATTACH //config: bool "ubiattach" //config: default y -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: Attach MTD device to an UBI device. //config: //config:config UBIDETACH //config: bool "ubidetach" //config: default y -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: Detach MTD device from an UBI device. //config: //config:config UBIMKVOL //config: bool "ubimkvol" //config: default y -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: Create a UBI volume. //config: //config:config UBIRMVOL //config: bool "ubirmvol" //config: default y -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: Delete a UBI volume. //config: //config:config UBIRSVOL //config: bool "ubirsvol" //config: default y -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: Resize a UBI volume. diff --git a/modutils/Config.src b/modutils/Config.src index 4191d29f2..449ac65af 100644 --- a/modutils/Config.src +++ b/modutils/Config.src @@ -4,13 +4,13 @@ # menu "Linux Module Utilities" -depends on PLATFORM_LINUX INSERT config MODPROBE_SMALL bool "Simplified modutils" default y + select PLATFORM_LINUX help Simplified modutils. @@ -45,6 +45,7 @@ config FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE bool "Accept module options on modprobe command line" default y depends on MODPROBE_SMALL + select PLATFORM_LINUX help Allow insmod and modprobe take module options from command line. @@ -59,6 +60,7 @@ config INSMOD bool "insmod" default n depends on !MODPROBE_SMALL + select PLATFORM_LINUX help insmod is used to load specified modules in the running kernel. @@ -66,6 +68,7 @@ config RMMOD bool "rmmod" default n depends on !MODPROBE_SMALL + select PLATFORM_LINUX help rmmod is used to unload specified modules from the kernel. @@ -73,6 +76,7 @@ config LSMOD bool "lsmod" default n depends on !MODPROBE_SMALL + select PLATFORM_LINUX help lsmod is used to display a list of loaded modules. @@ -80,6 +84,7 @@ config FEATURE_LSMOD_PRETTY_2_6_OUTPUT bool "Pretty output" default n depends on LSMOD + select PLATFORM_LINUX help This option makes output format of lsmod adjusted to the format of module-init-tools for Linux kernel 2.6. @@ -89,6 +94,7 @@ config MODPROBE bool "modprobe" default n depends on !MODPROBE_SMALL + select PLATFORM_LINUX help Handle the loading of modules, and their dependencies on a high level. @@ -97,6 +103,7 @@ config FEATURE_MODPROBE_BLACKLIST bool "Blacklist support" default n depends on MODPROBE + select PLATFORM_LINUX help Say 'y' here to enable support for the 'blacklist' command in modprobe.conf. This prevents the alias resolver to resolve @@ -108,6 +115,7 @@ config DEPMOD bool "depmod" default n depends on !MODPROBE_SMALL + select PLATFORM_LINUX help depmod generates modules.dep (and potentially modules.alias and modules.symbols) that contain dependency information @@ -119,6 +127,7 @@ config FEATURE_2_4_MODULES bool "Support version 2.2/2.4 Linux kernels" default n depends on INSMOD || RMMOD || LSMOD + select PLATFORM_LINUX help Support module loading for 2.2.x and 2.4.x Linux kernels. This increases size considerably. Say N unless you plan @@ -128,6 +137,7 @@ config FEATURE_INSMOD_TRY_MMAP bool "Try to load module from a mmap'ed area" default n depends on INSMOD || MODPROBE_SMALL + select PLATFORM_LINUX help This option causes module loading code to try to mmap module first. If it does not work (for example, @@ -144,6 +154,7 @@ config FEATURE_INSMOD_VERSION_CHECKING bool "Enable module version checking" default n depends on FEATURE_2_4_MODULES && (INSMOD || MODPROBE) + select PLATFORM_LINUX help Support checking of versions for modules. This is used to ensure that the kernel and module are made for each other. @@ -152,6 +163,7 @@ config FEATURE_INSMOD_KSYMOOPS_SYMBOLS bool "Add module symbols to kernel symbol table" default n depends on FEATURE_2_4_MODULES && (INSMOD || MODPROBE) + select PLATFORM_LINUX help By adding module symbols to the kernel symbol table, Oops messages occuring within kernel modules can be properly debugged. By enabling @@ -163,6 +175,7 @@ config FEATURE_INSMOD_LOADINKMEM bool "In kernel memory optimization (uClinux only)" default n depends on FEATURE_2_4_MODULES && (INSMOD || MODPROBE) + select PLATFORM_LINUX help This is a special uClinux only memory optimization that lets insmod load the specified kernel module directly into kernel space, reducing @@ -173,6 +186,7 @@ config FEATURE_INSMOD_LOAD_MAP bool "Enable insmod load map (-m) option" default n depends on FEATURE_2_4_MODULES && INSMOD + select PLATFORM_LINUX help Enabling this, one would be able to get a load map output on stdout. This makes kernel module debugging @@ -184,6 +198,7 @@ config FEATURE_INSMOD_LOAD_MAP_FULL bool "Symbols in load map" default y depends on FEATURE_INSMOD_LOAD_MAP && !MODPROBE_SMALL + select PLATFORM_LINUX help Without this option, -m will only output section load map. With this option, -m will also output @@ -193,6 +208,7 @@ config FEATURE_CHECK_TAINTED_MODULE bool "Support tainted module checking with new kernels" default y depends on (LSMOD || FEATURE_2_4_MODULES) && !MODPROBE_SMALL + select PLATFORM_LINUX help Support checking for tainted modules. These are usually binary only modules that will make the linux-kernel list ignore your @@ -203,6 +219,7 @@ config FEATURE_MODUTILS_ALIAS bool "Support for module.aliases file" default y depends on DEPMOD || MODPROBE + select PLATFORM_LINUX help Generate and parse modules.alias containing aliases for bus identifiers: @@ -219,6 +236,7 @@ config FEATURE_MODUTILS_SYMBOLS bool "Support for module.symbols file" default y depends on DEPMOD || MODPROBE + select PLATFORM_LINUX help Generate and parse modules.symbols containing aliases for symbol_request() kernel calls, such as: diff --git a/networking/Config.src b/networking/Config.src index 274fcae3a..06930f4a6 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -51,21 +51,21 @@ config VERBOSE_RESOLUTION_ERRORS config ARP bool "arp" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Manipulate the system ARP cache. config ARPING bool "arping" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Ping hosts by ARP packets. config BRCTL bool "brctl" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Manage ethernet bridges. Supports addbr/delbr and addif/delif. @@ -98,7 +98,7 @@ config DNSD config ETHER_WAKE bool "ether-wake" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Send a magic packet to wake up sleeping machines. @@ -281,7 +281,7 @@ config FEATURE_HTTPD_GZIP config IFCONFIG bool "ifconfig" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Ifconfig is used to configure the kernel-resident network interfaces. @@ -329,7 +329,7 @@ config FEATURE_IFCONFIG_BROADCAST_PLUS config IFENSLAVE bool "ifenslave" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Userspace application to bind several interfaces to a logical interface (use with kernel bonding driver). @@ -337,7 +337,7 @@ config IFENSLAVE config IFPLUGD bool "ifplugd" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Network interface plug detection daemon. @@ -379,7 +379,8 @@ config FEATURE_IFUPDOWN_IP config FEATURE_IFUPDOWN_IP_BUILTIN bool "Use busybox ip applet" default y - depends on FEATURE_IFUPDOWN_IP && PLATFORM_LINUX + depends on FEATURE_IFUPDOWN_IP + select PLATFORM_LINUX select IP select FEATURE_IP_ADDRESS select FEATURE_IP_LINK @@ -498,7 +499,7 @@ config FEATURE_INETD_RPC config IP bool "ip" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The "ip" applet is a TCP/IP interface configuration and routing utility. You generally don't need "ip" to use busybox with @@ -614,7 +615,7 @@ config FEATURE_IPCALC_LONG_OPTIONS config NAMEIF bool "nameif" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX select FEATURE_SYSLOG help nameif is used to rename network interface by its MAC address. @@ -643,7 +644,7 @@ config FEATURE_NAMEIF_EXTENDED config NETSTAT bool "netstat" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help netstat prints information about the Linux networking subsystem. @@ -672,7 +673,7 @@ config NSLOOKUP config NTPD bool "ntpd" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The NTP client/server daemon. @@ -693,14 +694,14 @@ config PSCAN config ROUTE bool "route" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Route displays or manipulates the kernel's IP routing tables. config SLATTACH bool "slattach" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help slattach is a small utility to attach network interfaces to serial lines. @@ -887,7 +888,7 @@ config TFTP_DEBUG config TRACEROUTE bool "traceroute" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Utility to trace the route of IP packets. @@ -924,7 +925,7 @@ config FEATURE_TRACEROUTE_USE_ICMP config TUNCTL bool "tunctl" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help tunctl creates or deletes tun devices. @@ -957,7 +958,7 @@ config UDPSVD config VCONFIG bool "vconfig" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Creates, removes, and configures VLAN interfaces @@ -1004,7 +1005,7 @@ config FEATURE_WGET_TIMEOUT config ZCIP bool "zcip" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX select FEATURE_SYSLOG help ZCIP provides ZeroConf IPv4 address selection, according to RFC 3927. diff --git a/networking/ping.c b/networking/ping.c index c2ff42e2c..7a9c2d1f0 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -32,7 +32,7 @@ //config:config PING //config: bool "ping" //config: default y -//config: depends on PLATFORM_LINUX +//config: select PLATFORM_LINUX //config: help //config: ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to //config: elicit an ICMP ECHO_RESPONSE from a host or gateway. diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src index 750a53a32..9cd8cbbae 100644 --- a/networking/udhcp/Config.src +++ b/networking/udhcp/Config.src @@ -8,7 +8,7 @@ INSERT config UDHCPD bool "udhcp server (udhcpd)" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help udhcpd is a DHCP server geared primarily toward embedded systems, while striving to be fully functional and RFC compliant. @@ -66,7 +66,7 @@ config DHCPD_LEASES_FILE config UDHCPC bool "udhcp client (udhcpc)" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help udhcpc is a DHCP client geared primarily toward embedded systems, while striving to be fully functional and RFC compliant. diff --git a/procps/Config.src b/procps/Config.src index cf664eeb2..3e7df0b81 100644 --- a/procps/Config.src +++ b/procps/Config.src @@ -10,7 +10,7 @@ INSERT config FREE bool "free" default y - depends on PLATFORM_LINUX #sysinfo() + select PLATFORM_LINUX #sysinfo() help free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. @@ -99,7 +99,8 @@ config FEATURE_PS_WIDE config FEATURE_PS_TIME bool "Enable time and elapsed time output" default y - depends on PS && DESKTOP && PLATFORM_LINUX #sysinfo() + depends on PS && DESKTOP + select PLATFORM_LINUX help Support -o time and -o etime output specifiers. @@ -196,7 +197,7 @@ config FEATURE_SHOW_THREADS config UPTIME bool "uptime" default y - depends on PLATFORM_LINUX #sysinfo() + select PLATFORM_LINUX #sysinfo() help uptime gives a one line display of the current time, how long the system has been running, how many users are currently logged diff --git a/sysklogd/Config.src b/sysklogd/Config.src index 1e5987275..d62dc5f5c 100644 --- a/sysklogd/Config.src +++ b/sysklogd/Config.src @@ -119,7 +119,8 @@ config KLOGD config FEATURE_KLOGD_KLOGCTL bool "Use the klogctl() interface" default y - depends on KLOGD && PLATFORM_LINUX + depends on KLOGD + select PLATFORM_LINUX help The klogd applet supports two interfaces for reading kernel messages. Linux provides the klogctl() interface diff --git a/util-linux/Config.src b/util-linux/Config.src index 941a47f90..90606bcae 100644 --- a/util-linux/Config.src +++ b/util-linux/Config.src @@ -10,7 +10,7 @@ INSERT config ACPID bool "acpid" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help acpid listens to ACPI events coming either in textual form from /proc/acpi/event (though it is marked deprecated it is still widely @@ -33,7 +33,7 @@ config FEATURE_ACPID_COMPAT config BLKID bool "blkid" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX select VOLUMEID help Lists labels and UUIDs of all filesystems. @@ -50,7 +50,7 @@ config FEATURE_BLKID_TYPE config DMESG bool "dmesg" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help dmesg is used to examine or control the kernel ring buffer. When the Linux kernel prints messages to the system log, they are stored in @@ -84,7 +84,7 @@ config FEATURE_DMESG_PRETTY config FBSET bool "fbset" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help fbset is used to show or change the settings of a Linux frame buffer device. The frame buffer device provides a simple and unique @@ -113,7 +113,7 @@ config FEATURE_FBSET_READMODE config FDFLUSH bool "fdflush" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help fdflush is only needed when changing media on slightly-broken removable media drives. It is used to make Linux believe that a @@ -126,14 +126,14 @@ config FDFLUSH config FDFORMAT bool "fdformat" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help fdformat is used to low-level format a floppy disk. config FDISK bool "fdisk" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The fdisk utility is used to divide hard disks into one or more logical disks, which are generally called partitions. This utility @@ -209,7 +209,7 @@ config FEATURE_FDISK_ADVANCED config FINDFS bool "findfs" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX select VOLUMEID help Prints the name of a filesystem with given label or UUID. @@ -225,7 +225,7 @@ config FLOCK config FREERAMDISK bool "freeramdisk" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Linux allows you to create ramdisks. This utility allows you to delete them and completely free all memory that was used for the @@ -248,14 +248,14 @@ config FSCK_MINIX config MKFS_EXT2 bool "mkfs_ext2" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Utility to create EXT2 filesystems. config MKFS_MINIX bool "mkfs_minix" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The minix filesystem is a nice, small, compact, read-write filesystem with little overhead. If you wish to be able to create minix @@ -273,7 +273,7 @@ config FEATURE_MINIX2 config MKFS_REISER bool "mkfs_reiser" default n - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Utility to create ReiserFS filesystems. Note: this applet needs a lot of testing and polishing. @@ -281,7 +281,7 @@ config MKFS_REISER config MKFS_VFAT bool "mkfs_vfat" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Utility to create FAT32 filesystems. @@ -330,7 +330,7 @@ config HD config HWCLOCK bool "hwclock" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The hwclock utility is used to read and set the hardware clock on a system. This is primarily used to set the current time on @@ -369,7 +369,7 @@ config IPCRM config IPCS bool "ipcs" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The ipcs utility is used to provide information on the currently allocated System V interprocess (IPC) objects in the system. @@ -377,7 +377,7 @@ config IPCS config LOSETUP bool "losetup" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help losetup is used to associate or detach a loop device with a regular file or block device, and to query the status of a loop device. This @@ -386,7 +386,7 @@ config LOSETUP config LSPCI bool "lspci" default y - #depends on PLATFORM_LINUX + #select PLATFORM_LINUX help lspci is a utility for displaying information about PCI buses in the system and devices connected to them. @@ -396,7 +396,7 @@ config LSPCI config LSUSB bool "lsusb" default y - #depends on PLATFORM_LINUX + #select PLATFORM_LINUX help lsusb is a utility for displaying information about USB buses in the system and devices connected to them. @@ -406,7 +406,7 @@ config LSUSB config MDEV bool "mdev" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help mdev is a mini-udev implementation for dynamically creating device nodes in the /dev directory. @@ -494,7 +494,7 @@ config MORE config MOUNT bool "mount" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help All files and filesystems in Unix are arranged into one big directory tree. The 'mount' utility is used to graft a filesystem onto a @@ -577,7 +577,7 @@ config FEATURE_MOUNT_FSTAB config PIVOT_ROOT bool "pivot_root" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The pivot_root utility swaps the mount points for the root filesystem with some other mounted filesystem. This allows you to do all sorts @@ -605,14 +605,14 @@ config RDEV config READPROFILE bool "readprofile" default y - #depends on PLATFORM_LINUX + #select PLATFORM_LINUX help This allows you to parse /proc/profile for basic profiling. config RTCWAKE bool "rtcwake" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help Enter a system sleep state until specified wakeup time. @@ -632,7 +632,7 @@ config SCRIPTREPLAY config SETARCH bool "setarch" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The linux32 utility is used to create a 32bit environment for the specified program (usually a shell). It only makes sense to have @@ -642,7 +642,7 @@ config SETARCH config SWAPONOFF bool "swaponoff" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help This option enables both the 'swapon' and the 'swapoff' utilities. Once you have created some swap space using 'mkswap', you also need @@ -661,7 +661,7 @@ config FEATURE_SWAPON_PRI config SWITCH_ROOT bool "switch_root" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help The switch_root utility is used from initramfs to select a new root device. Under initramfs, you have to use this instead of @@ -681,7 +681,7 @@ config SWITCH_ROOT config UMOUNT bool "umount" default y - depends on PLATFORM_LINUX + select PLATFORM_LINUX help When you want to remove a mounted filesystem from its current mount point, for example when you are shutting down the system, the -- cgit v1.2.3-55-g6feb From 143c5baf6c2471c7f695e5e20da865f9e799ffbd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 27 Feb 2011 04:03:27 +0100 Subject: adduser: use better argv passing to addgroup function old new delta adduser_main 855 882 +27 Signed-off-by: Denys Vlasenko --- loginutils/adduser.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/loginutils/adduser.c b/loginutils/adduser.c index d938b80f3..9d3d9cb4c 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c @@ -67,15 +67,24 @@ static void passwd_study(struct passwd *p) static void addgroup_wrapper(struct passwd *p, const char *group_name) { - char *cmd; - - if (group_name) /* Add user to existing group */ - cmd = xasprintf("addgroup '%s' '%s'", p->pw_name, group_name); - else /* Add user to his own group with the first free gid found in passwd_study */ - cmd = xasprintf("addgroup -g %u '%s'", (unsigned)p->pw_gid, p->pw_name); - /* Warning: to be compatible with external addgroup programs we should use --gid instead */ - system(cmd); - free(cmd); + char *argv[5]; + + argv[0] = (char*)"addgroup"; + if (group_name) { + /* Add user to existing group */ + argv[1] = p->pw_name; + argv[2] = (char*)group_name; + argv[3] = NULL; + } else { + /* Add user to his own group with the first free gid found in passwd_study */ +//TODO: to be compatible with external addgroup programs we should use --gid instead... + argv[1] = (char*)"-g"; + argv[2] = utoa(p->pw_gid); + argv[3] = p->pw_name; + argv[4] = NULL; + } + + spawn_and_wait(argv); } static void passwd_wrapper(const char *login_name) NORETURN; -- cgit v1.2.3-55-g6feb From cd387f2554c62c7716970e90af54b8bde6c86c86 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 27 Feb 2011 04:10:00 +0100 Subject: ls: fix one-bit-off which caused -H to behave as -h Signed-off-by: Denys Vlasenko --- coreutils/ls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/ls.c b/coreutils/ls.c index 2be3afadf..2242fbaac 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -234,7 +234,7 @@ enum { OPTBIT_Z, /* 25 */ OPTBIT_L = OPTBIT_K + 2 * ENABLE_SELINUX, OPTBIT_H, /* 27 */ - OPTBIT_h = OPTBIT_L + 1 * ENABLE_FEATURE_LS_FOLLOWLINKS, + OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS, OPTBIT_T = OPTBIT_h + 2 * ENABLE_FEATURE_HUMAN_READABLE, OPTBIT_w, /* 30 */ OPTBIT_color = OPTBIT_T + 2 * ENABLE_FEATURE_AUTOWIDTH, -- cgit v1.2.3-55-g6feb From 9beb68e3e2dc1c6f457acfb307cfed73cce65cd9 Mon Sep 17 00:00:00 2001 From: Harald Becker Date: Sun, 27 Feb 2011 07:16:44 +0100 Subject: showkey: make showkey -a work on any stdin function old new delta showkey_main 496 513 +17 Signed-off-by: Harald Becker Signed-off-by: Denys Vlasenko --- console-tools/showkey.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/console-tools/showkey.c b/console-tools/showkey.c index e7834f702..06df68bfd 100644 --- a/console-tools/showkey.c +++ b/console-tools/showkey.c @@ -56,37 +56,45 @@ int showkey_main(int argc UNUSED_PARAM, char **argv) // FIXME: aks are all mutually exclusive getopt32(argv, "aks"); - // get keyboard settings - xioctl(STDIN_FILENO, KDGKBMODE, &kbmode); - printf("kb mode was %s\n\nPress any keys. Program terminates %s\n\n", - kbmode == K_RAW ? "RAW" : - (kbmode == K_XLATE ? "XLATE" : - (kbmode == K_MEDIUMRAW ? "MEDIUMRAW" : - (kbmode == K_UNICODE ? "UNICODE" : "UNKNOWN"))) - , (option_mask32 & OPT_a) ? "on EOF (ctrl-D)" : "10s after last keypress" - ); - // prepare for raw mode xget1(&tio, &tio0); // put stdin in raw mode xset1(&tio); +#define press_keys "Press any keys, program terminates %s:\r\n\n" + if (option_mask32 & OPT_a) { + // just read stdin char by char unsigned char c; - // just read stdin char by char + printf(press_keys, "on EOF (ctrl-D)"); + + // read and show byte values while (1 == read(STDIN_FILENO, &c, 1)) { printf("%3u 0%03o 0x%02x\r\n", c, c, c); if (04 /*CTRL-D*/ == c) break; } + } else { + // we assume a PC keyboard + xioctl(STDIN_FILENO, KDGKBMODE, &kbmode); + printf("Keyboard mode was %s.\r\n\n", + kbmode == K_RAW ? "RAW" : + (kbmode == K_XLATE ? "XLATE" : + (kbmode == K_MEDIUMRAW ? "MEDIUMRAW" : + (kbmode == K_UNICODE ? "UNICODE" : "UNKNOWN"))) + ); + // set raw keyboard mode xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)((option_mask32 & OPT_k) ? K_MEDIUMRAW : K_RAW)); // we should exit on any signal; signals should interrupt read bb_signals_recursive_norestart(BB_FATAL_SIGS, record_signo); + // inform user that program ends after time of inactivity + printf(press_keys, "10s after last keypress"); + // read and show scancodes while (!bb_got_signal) { char buf[18]; @@ -94,6 +102,7 @@ int showkey_main(int argc UNUSED_PARAM, char **argv) // setup 10s watchdog alarm(10); + // read scancodes n = read(STDIN_FILENO, buf, sizeof(buf)); i = 0; @@ -121,11 +130,13 @@ int showkey_main(int argc UNUSED_PARAM, char **argv) } puts("\r"); } + + // restore keyboard mode + xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode); } - // restore keyboard and console settings + // restore console settings xset1(&tio0); - xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode); return EXIT_SUCCESS; } -- cgit v1.2.3-55-g6feb From 251962f20737c5138c7d33e90c68dfca856361e1 Mon Sep 17 00:00:00 2001 From: Pere Orga Date: Sun, 27 Feb 2011 23:38:52 +0100 Subject: whois: new applet function old new delta whois_main - 118 +118 pipe_out - 80 +80 packed_usage 28084 28095 +11 applet_names 2385 2391 +6 applet_main 1388 1392 +4 applet_nameofs 694 696 +2 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 4/0 up/down: 221/0) Total: 221 bytes Signed-off-by: Pere Orga Signed-off-by: Denys Vlasenko --- networking/whois.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 networking/whois.c diff --git a/networking/whois.c b/networking/whois.c new file mode 100644 index 000000000..4eab9e5fe --- /dev/null +++ b/networking/whois.c @@ -0,0 +1,66 @@ +/* vi: set sw=4 ts=4: */ +/* + * whois - tiny client for the whois directory service + * + * Copyright (c) 2011 Pere Orga + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ +/* TODO + * Add ipv6 support + * Add proxy support + */ + +//config:config WHOIS +//config: bool "whois" +//config: default y +//config: help +//config: whois is a client for the whois directory service + +//applet:IF_WHOIS(APPLET(whois, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_WHOIS) += whois.o + +//usage:#define whois_trivial_usage +//usage: "[-h SERVER] [-p PORT] NAME..." +//usage:#define whois_full_usage "\n\n" +//usage: "Query WHOIS info about NAME\n" +//usage: "\nOptions:" +//usage: "\n -h,-p Server to query" + +#include "libbb.h" + +static void pipe_out(int fd) +{ + FILE *fp; + char buf[1024]; + + fp = xfdopen_for_read(fd); + while (fgets(buf, sizeof(buf), fp)) { + char *p = strpbrk(buf, "\r\n"); + if (p) + *p = '\0'; + puts(buf); + } + + fclose(fp); /* closes fd too */ +} + +int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int whois_main(int argc UNUSED_PARAM, char **argv) +{ + int port = 43; + const char *host = "whois-servers.net"; + + opt_complementary = "-1:p+"; + getopt32(argv, "h:p:", &host, &port); + + argv += optind; + do { + int fd = create_and_connect_stream_or_die(host, port); + fdprintf(fd, "%s\r\n", *argv); + pipe_out(fd); + } + while (*++argv); + + return EXIT_SUCCESS; +} -- cgit v1.2.3-55-g6feb From c8dc01dc8030a697cd3ee47da6381066d3142265 Mon Sep 17 00:00:00 2001 From: Roman Borisov Date: Mon, 28 Feb 2011 05:06:01 +0100 Subject: mount: update /etc/mtab properly on mount --move Signed-off-by: Roman Borisov Signed-off-by: Denys Vlasenko --- util-linux/mount.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/util-linux/mount.c b/util-linux/mount.c index 0baa74c7c..0127f1958 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -279,6 +279,61 @@ enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_b #define fslist (G.fslist ) #define getmntent_buf (G.getmntent_buf ) +#if ENABLE_FEATURE_MTAB_SUPPORT +/* + * update_mtab_entry_on_move() is used to update entry in case of mount --move. + * we are looking for existing entries mnt_dir which is equal to mnt_fsname of + * input mntent and replace it by new one. + */ +static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp) +{ + struct mntent *entries, *m; + int i, count; + FILE *mountTable; + + mountTable = setmntent(bb_path_mtab_file, "r"); + if (!mountTable) { + bb_perror_msg(bb_path_mtab_file); + return; + } + + entries = NULL; + count = 0; + while ((m = getmntent(mountTable)) != NULL) { + entries = xrealloc_vector(entries, 3, count); + entries[count].mnt_fsname = xstrdup(m->mnt_fsname); + entries[count].mnt_dir = xstrdup(m->mnt_dir); + entries[count].mnt_type = xstrdup(m->mnt_type); + entries[count].mnt_opts = xstrdup(m->mnt_opts); + entries[count].mnt_freq = m->mnt_freq; + entries[count].mnt_passno = m->mnt_passno; + count++; + } + endmntent(mountTable); + + mountTable = setmntent(bb_path_mtab_file, "w"); + if (mountTable) { + for (i = 0; i < count; i++) { + if (strcmp(entries[i].mnt_dir, mp->mnt_fsname) != 0) + addmntent(mountTable, &entries[i]); + else + addmntent(mountTable, mp); + } + endmntent(mountTable); + } else if (errno != EROFS) + bb_perror_msg(bb_path_mtab_file); + + if (ENABLE_FEATURE_CLEAN_UP) { + for (i = 0; i < count; i++) { + free(entries[i].mnt_fsname); + free(entries[i].mnt_dir); + free(entries[i].mnt_type); + free(entries[i].mnt_opts); + } + free(entries); + } +} +#endif #if ENABLE_FEATURE_MOUNT_VERBOSE static int verbose_mount(const char *source, const char *target, @@ -496,12 +551,11 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts) int i; if (!mountTable) { - bb_error_msg("no %s", bb_path_mtab_file); + bb_perror_msg(bb_path_mtab_file); goto ret; } // Add vfs string flags - for (i = 0; mount_options[i] != MS_REMOUNT; i++) { if (mount_options[i] > 0 && (mount_options[i] & vfsflags)) append_mount_options(&(mp->mnt_opts), option_str); @@ -509,24 +563,28 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts) } // Remove trailing / (if any) from directory we mounted on - i = strlen(mp->mnt_dir) - 1; - if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = '\0'; + while (i > 0 && mp->mnt_dir[i] == '/') + mp->mnt_dir[i] = '\0'; // Convert to canonical pathnames as needed - mp->mnt_dir = bb_simplify_path(mp->mnt_dir); - fsname = 0; + fsname = NULL; if (!mp->mnt_type || !*mp->mnt_type) { // bind mount mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname); mp->mnt_type = (char*)"bind"; } mp->mnt_freq = mp->mnt_passno = 0; - // Write and close. - - addmntent(mountTable, mp); + // Write and close +#if ENABLE_FEATURE_MTAB_SUPPORT + if (vfsflags & MS_MOVE) + update_mtab_entry_on_move(mp); + else +#endif + addmntent(mountTable, mp); endmntent(mountTable); + if (ENABLE_FEATURE_CLEAN_UP) { free(mp->mnt_dir); free(fsname); -- cgit v1.2.3-55-g6feb From c6450c974f4ff8520113d727d58fa74f474cd913 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Feb 2011 11:09:49 +0100 Subject: mount: strip multiple trailing slashes, not just one Signed-off-by: Denys Vlasenko --- 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 0127f1958..989e5d1a8 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -565,7 +565,7 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts) // Remove trailing / (if any) from directory we mounted on i = strlen(mp->mnt_dir) - 1; while (i > 0 && mp->mnt_dir[i] == '/') - mp->mnt_dir[i] = '\0'; + mp->mnt_dir[i--] = '\0'; // Convert to canonical pathnames as needed mp->mnt_dir = bb_simplify_path(mp->mnt_dir); -- cgit v1.2.3-55-g6feb From 9f368e38fbd165144a7398d3e6d8ae68ea97a3e6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Feb 2011 12:16:10 +0100 Subject: ls: fix bits for -T, -w and --color; make -n imply -l; fix comments Signed-off-by: Denys Vlasenko --- coreutils/ls.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/coreutils/ls.c b/coreutils/ls.c index 2242fbaac..8d25b5d5f 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -159,7 +159,7 @@ STYLE_MASK = STYLE_SINGLE, /* which of the three times will be used */ TIME_CHANGE = (1 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS, -TIME_ACCESS = (1 << 22) * ENABLE_FEATURE_LS_TIMESTAMPS, +TIME_ACCESS = (2 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS, TIME_MASK = (3 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS, /* how will the files be sorted (CONFIG_FEATURE_LS_SORTFILES) */ @@ -189,10 +189,9 @@ LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \ /* Not fully compatible - we show not only '/' but other chars too */ /* -SXvhTw GNU options, busybox optionally supports */ /* -T TABWIDTH is ignored (we don't use tabs on output) */ -/* -K SELinux mandated options, busybox optionally supports */ +/* -KZ SELinux mandated options, busybox optionally supports */ +/* (coreutils 8.4 has no -K, remove it?) */ /* -e I think we made this one up (looks similar to GNU --full-time) */ -/* Std opts we do not support: */ -/* -H Follow the links on command line only */ static const char ls_options[] ALIGN1 = "Cadil1gnsxQAk" /* 13 opts, total 13 */ IF_FEATURE_LS_TIMESTAMPS("cetu") /* 4, 17 */ @@ -235,7 +234,7 @@ enum { OPTBIT_L = OPTBIT_K + 2 * ENABLE_SELINUX, OPTBIT_H, /* 27 */ OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS, - OPTBIT_T = OPTBIT_h + 2 * ENABLE_FEATURE_HUMAN_READABLE, + OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE, OPTBIT_w, /* 30 */ OPTBIT_color = OPTBIT_T + 2 * ENABLE_FEATURE_AUTOWIDTH, @@ -269,12 +268,12 @@ static const uint32_t opt_flags[] = { LIST_LONG | STYLE_LONG, /* l */ STYLE_SINGLE, /* 1 */ 0, /* g (don't show owner) - handled via OPT_g */ - LIST_ID_NUMERIC, /* n */ + LIST_ID_NUMERIC | LIST_LONG | STYLE_LONG, /* n (assumes l) */ LIST_BLOCKS, /* s */ DISP_ROWS | STYLE_COLUMNAR, /* x */ 0, /* Q (quote filename) - handled via OPT_Q */ DISP_HIDDEN, /* A */ - ENABLE_SELINUX * LIST_CONTEXT, /* k (ignored if !SELINUX) */ + ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */ #if ENABLE_FEATURE_LS_TIMESTAMPS TIME_CHANGE | (ENABLE_FEATURE_LS_SORTFILES * SORT_CTIME), /* c */ LIST_FULLTIME, /* e */ @@ -295,8 +294,8 @@ static const uint32_t opt_flags[] = { DISP_RECURSIVE, /* R */ #endif #if ENABLE_SELINUX - LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */ - LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT, /* Z */ + LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME|STYLE_SINGLE, /* K */ + LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT|STYLE_SINGLE, /* Z */ #endif (1U << 31) /* options after Z are not processed through opt_flags */ @@ -688,8 +687,16 @@ static NOINLINE unsigned list_single(const struct dnode *dn) column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode)); if (all_fmt & LIST_NLINKS) column += printf("%4lu ", (long) dn->dstat.st_nlink); + if (all_fmt & LIST_ID_NUMERIC) { + if (option_mask32 & OPT_g) + column += printf("%-8u ", (int) dn->dstat.st_gid); + else + column += printf("%-8u %-8u ", + (int) dn->dstat.st_uid, + (int) dn->dstat.st_gid); + } #if ENABLE_FEATURE_LS_USERNAME - if (all_fmt & LIST_ID_NAME) { + else if (all_fmt & LIST_ID_NAME) { if (option_mask32 & OPT_g) { column += printf("%-8.8s ", get_cached_groupname(dn->dstat.st_gid)); @@ -700,14 +707,6 @@ static NOINLINE unsigned list_single(const struct dnode *dn) } } #endif - if (all_fmt & LIST_ID_NUMERIC) { - if (option_mask32 & OPT_g) - column += printf("%-8u ", (int) dn->dstat.st_gid); - else - column += printf("%-8u %-8u ", - (int) dn->dstat.st_uid, - (int) dn->dstat.st_gid); - } if (all_fmt & LIST_SIZE) { if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { column += printf("%4u, %3u ", @@ -1040,7 +1039,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv) init_unicode(); - all_fmt = ENABLE_FEATURE_LS_SORTFILES * SORT_NAME; + if (ENABLE_FEATURE_LS_SORTFILES) + all_fmt = SORT_NAME; #if ENABLE_FEATURE_AUTOWIDTH /* obtain the terminal width */ @@ -1081,8 +1081,6 @@ int ls_main(int argc UNUSED_PARAM, char **argv) if (flags & TIME_MASK) all_fmt &= ~TIME_MASK; - if (flags & LIST_CONTEXT) - all_fmt |= STYLE_SINGLE; all_fmt |= flags; } } @@ -1121,11 +1119,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv) if (all_fmt & TIME_ACCESS) all_fmt = (all_fmt & ~SORT_MASK) | SORT_ATIME; } - if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* only for long list */ + if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* not -l? */ all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME|LIST_FULLTIME); - if (ENABLE_FEATURE_LS_USERNAME) - if ((all_fmt & STYLE_MASK) == STYLE_LONG && (all_fmt & LIST_ID_NUMERIC)) - all_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */ /* choose a display format if one was not already specified by an option */ if (!(all_fmt & STYLE_MASK)) -- cgit v1.2.3-55-g6feb From 26d11b8133b3ba71e6e94ff525e45984ddeaef72 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Feb 2011 12:38:08 +0100 Subject: ls: -g implies -l Signed-off-by: Denys Vlasenko --- coreutils/ls.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/coreutils/ls.c b/coreutils/ls.c index 8d25b5d5f..da370c74b 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -192,6 +192,8 @@ LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \ /* -KZ SELinux mandated options, busybox optionally supports */ /* (coreutils 8.4 has no -K, remove it?) */ /* -e I think we made this one up (looks similar to GNU --full-time) */ +/* We already used up all 32 bits, if we need to add more, candidates for removal: */ +/* -K, -T, -e (add --full-time instead) */ static const char ls_options[] ALIGN1 = "Cadil1gnsxQAk" /* 13 opts, total 13 */ IF_FEATURE_LS_TIMESTAMPS("cetu") /* 4, 17 */ @@ -202,7 +204,7 @@ static const char ls_options[] ALIGN1 = IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 28 */ IF_FEATURE_HUMAN_READABLE("h") /* 1, 29 */ IF_FEATURE_AUTOWIDTH("T:w:") /* 2, 31 */ - ; + /* with --color, we use all 32 bits */; enum { //OPT_C = (1 << 0), //OPT_a = (1 << 1), @@ -267,7 +269,7 @@ static const uint32_t opt_flags[] = { LIST_INO, /* i */ LIST_LONG | STYLE_LONG, /* l */ STYLE_SINGLE, /* 1 */ - 0, /* g (don't show owner) - handled via OPT_g */ + LIST_LONG | STYLE_LONG, /* g (don't show owner) - handled via OPT_g. assumes l */ LIST_ID_NUMERIC | LIST_LONG | STYLE_LONG, /* n (assumes l) */ LIST_BLOCKS, /* s */ DISP_ROWS | STYLE_COLUMNAR, /* x */ @@ -733,9 +735,12 @@ static NOINLINE unsigned list_single(const struct dnode *dn) ttime = dn->dstat.st_ctime; filetime = ctime(&ttime); /* filetime's format: "Wed Jun 30 21:49:08 1993\n" */ - if (all_fmt & LIST_FULLTIME) + if (all_fmt & LIST_FULLTIME) { /* -e */ + /* Note: coreutils 8.4 ls --full-time prints: + * 2009-07-13 17:49:27.000000000 +0200 + */ column += printf("%.24s ", filetime); - else { /* LIST_DATE_TIME */ + } else { /* LIST_DATE_TIME */ /* current_time_t ~== time(NULL) */ time_t age = current_time_t - ttime; printf("%.6s ", filetime + 4); /* "Jun 30" */ @@ -1086,7 +1091,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) } #if ENABLE_FEATURE_LS_COLOR - /* find color bit value - last position for short getopt */ + /* set show_color = 1/0 */ if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && isatty(STDOUT_FILENO)) { char *p = getenv("LS_COLORS"); /* LS_COLORS is unset, or (not empty && not "none") ? */ -- cgit v1.2.3-55-g6feb From 3b28dae17dc93584f0e38388d0dbdbd6761d705e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 1 Mar 2011 05:37:41 +0100 Subject: ls: widen -s (1k blocks) column from 4 to 6 Signed-off-by: Denys Vlasenko --- coreutils/ls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coreutils/ls.c b/coreutils/ls.c index da370c74b..19c868ca4 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -683,8 +683,9 @@ static NOINLINE unsigned list_single(const struct dnode *dn) if (all_fmt & LIST_INO) column += printf("%7llu ", (long long) dn->dstat.st_ino); +//TODO: -h should affect -s too: if (all_fmt & LIST_BLOCKS) - column += printf("%4"OFF_FMT"u ", (off_t) (dn->dstat.st_blocks >> 1)); + column += printf("%6"OFF_FMT"u ", (off_t) (dn->dstat.st_blocks >> 1)); if (all_fmt & LIST_MODEBITS) column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode)); if (all_fmt & LIST_NLINKS) -- cgit v1.2.3-55-g6feb From 7d65abea092e917bc2320cbf1d5a2dccb2a8288f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 1 Mar 2011 16:27:13 +0100 Subject: libbb: make user/group name cache strings longer (~27 chars) Signed-off-by: Denys Vlasenko --- include/libbb.h | 6 +++--- libbb/bb_pwd.c | 4 ++-- libbb/procps.c | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 65c319402..c26012c5d 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -839,14 +839,14 @@ char* xuid2uname(uid_t uid) FAST_FUNC; char* xgid2group(gid_t gid) FAST_FUNC; char* uid2uname(uid_t uid) FAST_FUNC; char* gid2group(gid_t gid) FAST_FUNC; -char* uid2uname_utoa(long uid) FAST_FUNC; -char* gid2group_utoa(long gid) FAST_FUNC; +char* uid2uname_utoa(uid_t uid) FAST_FUNC; +char* gid2group_utoa(gid_t gid) FAST_FUNC; /* versions which cache results (useful for ps, ls etc) */ const char* get_cached_username(uid_t uid) FAST_FUNC; const char* get_cached_groupname(gid_t gid) FAST_FUNC; void clear_username_cache(void) FAST_FUNC; /* internally usernames are saved in fixed-sized char[] buffers */ -enum { USERNAME_MAX_SIZE = 16 - sizeof(int) }; +enum { USERNAME_MAX_SIZE = 32 - sizeof(uid_t) }; #if ENABLE_FEATURE_CHECK_NAMES void die_if_bad_username(const char* name) FAST_FUNC; #else diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c index 32406cb58..4829b723a 100644 --- a/libbb/bb_pwd.c +++ b/libbb/bb_pwd.c @@ -72,13 +72,13 @@ char* FAST_FUNC gid2group(gid_t gid) return (gr) ? gr->gr_name : NULL; } -char* FAST_FUNC uid2uname_utoa(long uid) +char* FAST_FUNC uid2uname_utoa(uid_t uid) { char *name = uid2uname(uid); return (name) ? name : utoa(uid); } -char* FAST_FUNC gid2group_utoa(long gid) +char* FAST_FUNC gid2group_utoa(gid_t gid) { char *name = gid2group(gid); return (name) ? name : utoa(gid); diff --git a/libbb/procps.c b/libbb/procps.c index fb4c32001..5833a1f0d 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -12,13 +12,13 @@ #include "libbb.h" -typedef struct unsigned_to_name_map_t { - long id; +typedef struct id_to_name_map_t { + uid_t id; char name[USERNAME_MAX_SIZE]; -} unsigned_to_name_map_t; +} id_to_name_map_t; typedef struct cache_t { - unsigned_to_name_map_t *cache; + id_to_name_map_t *cache; int size; } cache_t; @@ -39,7 +39,7 @@ void FAST_FUNC clear_username_cache(void) #if 0 /* more generic, but we don't need that yet */ /* Returns -N-1 if not found. */ /* cp->cache[N] is allocated and must be filled in this case */ -static int get_cached(cache_t *cp, unsigned id) +static int get_cached(cache_t *cp, uid_t id) { int i; for (i = 0; i < cp->size; i++) @@ -52,8 +52,8 @@ static int get_cached(cache_t *cp, unsigned id) } #endif -static char* get_cached(cache_t *cp, long id, - char* FAST_FUNC x2x_utoa(long id)) +static char* get_cached(cache_t *cp, uid_t id, + char* FAST_FUNC x2x_utoa(uid_t id)) { int i; for (i = 0; i < cp->size; i++) -- cgit v1.2.3-55-g6feb From 5e29e263888284b2451debd9e5cb138b48fd293a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 1 Mar 2011 17:21:07 +0100 Subject: tar: on extract, everything up to and including last ".." is stripped function old new delta get_header_tar 1493 1545 +52 Signed-off-by: Denys Vlasenko --- archival/libarchive/get_header_tar.c | 27 ++++++++++++++++++++++----- include/archive.h | 2 ++ testsuite/tar.tests | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index 2e0332792..6a1532c86 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c @@ -422,11 +422,28 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) p_linkname = NULL; } #endif - if (strncmp(file_header->name, "/../"+1, 3) == 0 - || strstr(file_header->name, "/../") - ) { - bb_error_msg_and_die("name with '..' encountered: '%s'", - file_header->name); + + /* Everything up to and including last ".." component is stripped */ + cp = file_header->name; + while (1) { + char *cp2; + if (strncmp(cp, "/../"+1, 3) == 0) { + cp += 3; + continue; + } + cp2 = strstr(cp, "/../"); + if (cp2) { + cp = cp2 + 4; + continue; + } + break; + } + if (cp != file_header->name) { + if (!(archive_handle->ah_flags & ARCHIVE_TAR__TRUNC_WARNED)) { + archive_handle->ah_flags |= ARCHIVE_TAR__TRUNC_WARNED; + bb_error_msg("removing leading '%.*s'", (int)(cp - file_header->name), file_header->name); + } + overlapping_strcpy(file_header->name, cp); } /* Strip trailing '/' in directories */ diff --git a/include/archive.h b/include/archive.h index 49c478728..9fc77e542 100644 --- a/include/archive.h +++ b/include/archive.h @@ -118,6 +118,8 @@ typedef struct archive_handle_t { #define ARCHIVE_DONT_RESTORE_PERM (1 << 6) #define ARCHIVE_NUMERIC_OWNER (1 << 7) #define ARCHIVE_O_TRUNC (1 << 8) +/* Archiver specific. */ +#define ARCHIVE_TAR__TRUNC_WARNED (1 << 9) /* POSIX tar Header Block, from POSIX 1003.1-1990 */ diff --git a/testsuite/tar.tests b/testsuite/tar.tests index 472064f7f..d41d10d57 100755 --- a/testsuite/tar.tests +++ b/testsuite/tar.tests @@ -168,6 +168,23 @@ Ok " \ "" "" +# On extract, everything up to and including last ".." component is stripped +testing "tar strips /../ on extract" "\ +rm -rf input_* test.tar 2>/dev/null +mkdir input_dir +echo Ok >input_dir/file +tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1 +rm -rf input_* 2>/dev/null +tar -vxf test.tar 2>&1 +cat input_dir/file 2>&1 +" "\ +tar: removing leading './../tar.tempdir/input_dir/../' +input_dir/ +input_dir/file +Ok +" \ +"" "" + cd .. && rm -rf tar.tempdir || exit 1 -- cgit v1.2.3-55-g6feb From ea6116ee59af0945f4a6ac9ede984930a0ede429 Mon Sep 17 00:00:00 2001 From: Alexey Fomenko Date: Tue, 1 Mar 2011 19:25:49 +0100 Subject: libbb: remove dead code in getopt32. -7 bytes Signed-off-by: Alexey Fomenko Signed-off-by: Denys Vlasenko --- libbb/getopt32.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libbb/getopt32.c b/libbb/getopt32.c index f3f1cfcba..18f33c704 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -542,8 +542,6 @@ getopt32(char **argv, const char *applet_opts, ...) #endif /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */ - pargv = NULL; - /* Note: just "getopt() <= 0" will not work well for * "fake" short options, like this one: * wget $'-\203' "Test: test" http://kernel.org/ @@ -574,19 +572,16 @@ getopt32(char **argv, const char *applet_opts, ...) flags ^= trigger; if (on_off->counter) (*(on_off->counter))++; - if (on_off->param_type == PARAM_LIST) { - if (optarg) + if (optarg) { + if (on_off->param_type == PARAM_LIST) { llist_add_to_end((llist_t **)(on_off->optarg), optarg); - } else if (on_off->param_type == PARAM_INT) { - if (optarg) + } else if (on_off->param_type == PARAM_INT) { //TODO: xatoi_positive indirectly pulls in printf machinery *(unsigned*)(on_off->optarg) = xatoi_positive(optarg); - } else if (on_off->optarg) { - if (optarg) + } else if (on_off->optarg) { *(char **)(on_off->optarg) = optarg; + } } - if (pargv != NULL) - break; } /* check depending requires for given options */ -- cgit v1.2.3-55-g6feb From b80acf58f16339078da5cbee88a322f2450aa2ad Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 2 Mar 2011 01:21:02 +0100 Subject: tar: skip leading / and handle names like abc/..////def -> def (not ///def) function old new delta strip_unsafe_prefix - 105 +105 writeFileToTarball 557 520 -37 get_header_tar 1545 1462 -83 Signed-off-by: Denys Vlasenko --- archival/libarchive/get_header_tar.c | 51 ++++++++++++++++++++--------------- archival/tar.c | 13 ++------- include/archive.h | 52 ++++++++++++++++++------------------ testsuite/tar.tests | 2 +- 4 files changed, 59 insertions(+), 59 deletions(-) diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index 6a1532c86..f73cd338e 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c @@ -18,6 +18,35 @@ typedef uint32_t aliased_uint32_t FIX_ALIASING; typedef off_t aliased_off_t FIX_ALIASING; +const char* FAST_FUNC strip_unsafe_prefix(const char *str) +{ + const char *cp = str; + while (1) { + char *cp2; + if (*cp == '/') { + cp++; + continue; + } + if (strncmp(cp, "/../"+1, 3) == 0) { + cp += 3; + continue; + } + cp2 = strstr(cp, "/../"); + if (!cp2) + break; + cp = cp2 + 4; + } + if (cp != str) { + static smallint warned = 0; + if (!warned) { + warned = 1; + bb_error_msg("removing leading '%.*s' from member names", + (int)(cp - str), str); + } + } + return cp; +} + /* NB: _DESTROYS_ str[len] character! */ static unsigned long long getOctal(char *str, int len) { @@ -424,27 +453,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) #endif /* Everything up to and including last ".." component is stripped */ - cp = file_header->name; - while (1) { - char *cp2; - if (strncmp(cp, "/../"+1, 3) == 0) { - cp += 3; - continue; - } - cp2 = strstr(cp, "/../"); - if (cp2) { - cp = cp2 + 4; - continue; - } - break; - } - if (cp != file_header->name) { - if (!(archive_handle->ah_flags & ARCHIVE_TAR__TRUNC_WARNED)) { - archive_handle->ah_flags |= ARCHIVE_TAR__TRUNC_WARNED; - bb_error_msg("removing leading '%.*s'", (int)(cp - file_header->name), file_header->name); - } - overlapping_strcpy(file_header->name, cp); - } + overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name)); /* Strip trailing '/' in directories */ /* Must be done after mode is set as '/' is used to check if it's a directory */ diff --git a/archival/tar.c b/archival/tar.c index 1e3cecf44..d43c8dee3 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -397,17 +397,8 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb DBG("writeFileToTarball('%s')", fileName); - /* Strip leading '/' (must be before memorizing hardlink's name) */ - header_name = fileName; - while (header_name[0] == '/') { - static smallint warned; - - if (!warned) { - bb_error_msg("removing leading '/' from member names"); - warned = 1; - } - header_name++; - } + /* Strip leading '/' and such (must be before memorizing hardlink's name) */ + header_name = strip_unsafe_prefix(fileName); if (header_name[0] == '\0') return TRUE; diff --git a/include/archive.h b/include/archive.h index 9fc77e542..181c187f7 100644 --- a/include/archive.h +++ b/include/archive.h @@ -118,8 +118,6 @@ typedef struct archive_handle_t { #define ARCHIVE_DONT_RESTORE_PERM (1 << 6) #define ARCHIVE_NUMERIC_OWNER (1 << 7) #define ARCHIVE_O_TRUNC (1 << 8) -/* Archiver specific. */ -#define ARCHIVE_TAR__TRUNC_WARNED (1 << 9) /* POSIX tar Header Block, from POSIX 1003.1-1990 */ @@ -161,37 +159,39 @@ typedef struct unpack_info_t { time_t mtime; } unpack_info_t; -extern archive_handle_t *init_handle(void) FAST_FUNC; +archive_handle_t *init_handle(void) FAST_FUNC; -extern char filter_accept_all(archive_handle_t *archive_handle) FAST_FUNC; -extern char filter_accept_list(archive_handle_t *archive_handle) FAST_FUNC; -extern char filter_accept_list_reassign(archive_handle_t *archive_handle) FAST_FUNC; -extern char filter_accept_reject_list(archive_handle_t *archive_handle) FAST_FUNC; +char filter_accept_all(archive_handle_t *archive_handle) FAST_FUNC; +char filter_accept_list(archive_handle_t *archive_handle) FAST_FUNC; +char filter_accept_list_reassign(archive_handle_t *archive_handle) FAST_FUNC; +char filter_accept_reject_list(archive_handle_t *archive_handle) FAST_FUNC; -extern void unpack_ar_archive(archive_handle_t *ar_archive) FAST_FUNC; +void unpack_ar_archive(archive_handle_t *ar_archive) FAST_FUNC; -extern void data_skip(archive_handle_t *archive_handle) FAST_FUNC; -extern void data_extract_all(archive_handle_t *archive_handle) FAST_FUNC; -extern void data_extract_to_stdout(archive_handle_t *archive_handle) FAST_FUNC; -extern void data_extract_to_command(archive_handle_t *archive_handle) FAST_FUNC; +void data_skip(archive_handle_t *archive_handle) FAST_FUNC; +void data_extract_all(archive_handle_t *archive_handle) FAST_FUNC; +void data_extract_to_stdout(archive_handle_t *archive_handle) FAST_FUNC; +void data_extract_to_command(archive_handle_t *archive_handle) FAST_FUNC; -extern void header_skip(const file_header_t *file_header) FAST_FUNC; -extern void header_list(const file_header_t *file_header) FAST_FUNC; -extern void header_verbose_list(const file_header_t *file_header) FAST_FUNC; +void header_skip(const file_header_t *file_header) FAST_FUNC; +void header_list(const file_header_t *file_header) FAST_FUNC; +void header_verbose_list(const file_header_t *file_header) FAST_FUNC; -extern char get_header_ar(archive_handle_t *archive_handle) FAST_FUNC; -extern char get_header_cpio(archive_handle_t *archive_handle) FAST_FUNC; -extern char get_header_tar(archive_handle_t *archive_handle) FAST_FUNC; -extern char get_header_tar_gz(archive_handle_t *archive_handle) FAST_FUNC; -extern char get_header_tar_bz2(archive_handle_t *archive_handle) FAST_FUNC; -extern char get_header_tar_lzma(archive_handle_t *archive_handle) FAST_FUNC; +char get_header_ar(archive_handle_t *archive_handle) FAST_FUNC; +char get_header_cpio(archive_handle_t *archive_handle) FAST_FUNC; +char get_header_tar(archive_handle_t *archive_handle) FAST_FUNC; +char get_header_tar_gz(archive_handle_t *archive_handle) FAST_FUNC; +char get_header_tar_bz2(archive_handle_t *archive_handle) FAST_FUNC; +char get_header_tar_lzma(archive_handle_t *archive_handle) FAST_FUNC; -extern void seek_by_jump(int fd, off_t amount) FAST_FUNC; -extern void seek_by_read(int fd, off_t amount) FAST_FUNC; +void seek_by_jump(int fd, off_t amount) FAST_FUNC; +void seek_by_read(int fd, off_t amount) FAST_FUNC; -extern void data_align(archive_handle_t *archive_handle, unsigned boundary) FAST_FUNC; -extern const llist_t *find_list_entry(const llist_t *list, const char *filename) FAST_FUNC; -extern const llist_t *find_list_entry2(const llist_t *list, const char *filename) FAST_FUNC; +const char *strip_unsafe_prefix(const char *str) FAST_FUNC; + +void data_align(archive_handle_t *archive_handle, unsigned boundary) FAST_FUNC; +const llist_t *find_list_entry(const llist_t *list, const char *filename) FAST_FUNC; +const llist_t *find_list_entry2(const llist_t *list, const char *filename) FAST_FUNC; /* A bit of bunzip2 internals are exposed for compressed help support: */ typedef struct bunzip_data bunzip_data; diff --git a/testsuite/tar.tests b/testsuite/tar.tests index d41d10d57..534135df8 100755 --- a/testsuite/tar.tests +++ b/testsuite/tar.tests @@ -178,7 +178,7 @@ rm -rf input_* 2>/dev/null tar -vxf test.tar 2>&1 cat input_dir/file 2>&1 " "\ -tar: removing leading './../tar.tempdir/input_dir/../' +tar: removing leading './../tar.tempdir/input_dir/../' from member names input_dir/ input_dir/file Ok -- cgit v1.2.3-55-g6feb From 708dd4c98662670f3104b71c2fc5eef82bb726a8 Mon Sep 17 00:00:00 2001 From: Alexey Fomenko Date: Wed, 2 Mar 2011 04:01:24 +0100 Subject: add missing fclose's Signed-off-by: Alexey Fomenko Signed-off-by: Denys Vlasenko --- networking/route.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/networking/route.c b/networking/route.c index b7d08dd63..ac4fbb472 100644 --- a/networking/route.c +++ b/networking/route.c @@ -537,6 +537,7 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) printf("%-6d %-2d %7d %s\n", metric, ref, use, devname); } } + fclose(fp); } #if ENABLE_FEATURE_IPV6 @@ -625,6 +626,7 @@ static void INET6_displayroutes(void) } } while (1); } + fclose(fp); } #endif -- cgit v1.2.3-55-g6feb From 940c7206c2a4acb386ab47199a6c313c04387f3b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 2 Mar 2011 04:07:14 +0100 Subject: convert "do {...} while (1);" -> "while (1) {...}" Signed-off-by: Denys Vlasenko --- coreutils/split.c | 4 ++-- loginutils/vlock.c | 9 +++++---- networking/route.c | 4 ++-- shell/ash.c | 16 ++++++++-------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/coreutils/split.c b/coreutils/split.c index db5a1727a..79316ed74 100644 --- a/coreutils/split.c +++ b/coreutils/split.c @@ -32,7 +32,7 @@ static char *next_file(char *old, unsigned suffix_len) unsigned i = 1; char *curr; - do { + while (1) { curr = old + end - i; if (*curr < 'z') { *curr += 1; @@ -43,7 +43,7 @@ static char *next_file(char *old, unsigned suffix_len) return NULL; } *curr = 'a'; - } while (1); + } return old; } diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 216b317f1..0d0f3bca2 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c @@ -93,16 +93,17 @@ int vlock_main(int argc UNUSED_PARAM, char **argv) term.c_lflag &= ~(ECHO | ECHOCTL); tcsetattr_stdin_TCSANOW(&term); - do { + while (1) { printf("Virtual console%s locked by %s.\n", - option_mask32 /*o_lock_all*/ ? "s" : "", - pw->pw_name); + /* "s" if -a, else "": */ "s" + !option_mask32, + pw->pw_name + ); if (correct_password(pw)) { break; } bb_do_delay(FAIL_DELAY); puts("Password incorrect"); - } while (1); + } #ifdef __linux__ ioctl(STDIN_FILENO, VT_SETMODE, &ovtm); diff --git a/networking/route.c b/networking/route.c index ac4fbb472..98a03ded7 100644 --- a/networking/route.c +++ b/networking/route.c @@ -605,7 +605,7 @@ static void INET6_displayroutes(void) set_flags(flags, (iflags & IPV6_MASK)); r = 0; - do { + while (1) { inet_pton(AF_INET6, addr6x + r, (struct sockaddr *) &snaddr6.sin6_addr); snaddr6.sin6_family = AF_INET6; @@ -624,7 +624,7 @@ static void INET6_displayroutes(void) free(naddr6); break; } - } while (1); + } } fclose(fp); } diff --git a/shell/ash.c b/shell/ash.c index 98d2c7c29..c3c953656 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -3539,12 +3539,12 @@ set_curjob(struct job *jp, unsigned mode) /* first remove from list */ jpp = curp = &curjob; - do { + while (1) { jp1 = *jpp; if (jp1 == jp) break; jpp = &jp1->prev_job; - } while (1); + } *jpp = jp1->prev_job; /* Then re-insert in correct position */ @@ -3560,14 +3560,14 @@ set_curjob(struct job *jp, unsigned mode) case CUR_RUNNING: /* newly created job or backgrounded job, put after all stopped jobs. */ - do { + while (1) { jp1 = *jpp; #if JOBS if (!jp1 || jp1->state != JOBSTOPPED) #endif break; jpp = &jp1->prev_job; - } while (1); + } /* FALLTHROUGH */ #if JOBS case CUR_STOPPED: @@ -3740,7 +3740,7 @@ setjobctl(int on) goto out; /* fd is a tty at this point */ close_on_exec_on(fd); - do { /* while we are in the background */ + while (1) { /* while we are in the background */ pgrp = tcgetpgrp(fd); if (pgrp < 0) { out: @@ -3751,7 +3751,7 @@ setjobctl(int on) if (pgrp == getpgrp()) break; killpg(0, SIGTTIN); - } while (1); + } initialpgrp = pgrp; setsignal(SIGTSTP); @@ -5970,7 +5970,7 @@ expari(int quotes) p = expdest - 1; *p = '\0'; p--; - do { + while (1) { int esc; while ((unsigned char)*p != CTLARI) { @@ -5988,7 +5988,7 @@ expari(int quotes) } p -= esc + 1; - } while (1); + } begoff = p - start; -- cgit v1.2.3-55-g6feb From 1df0af76700c7f75ea43006ad6d450cdeeb6244f Mon Sep 17 00:00:00 2001 From: Alexey Fomenko Date: Wed, 2 Mar 2011 04:13:21 +0100 Subject: don't leak malloced variables in the loop; remove double alloc Signed-off-by: Alexey Fomenko Signed-off-by: Denys Vlasenko --- networking/ifupdown.c | 7 +++++-- networking/nameif.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 59df4e80f..c7b560bf8 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -1220,13 +1220,13 @@ int ifupdown_main(int argc UNUSED_PARAM, char **argv) /* ifup */ if (iface_state) { bb_error_msg("interface %s already configured", iface); - continue; + goto next; } } else { /* ifdown */ if (!iface_state) { bb_error_msg("interface %s not configured", iface); - continue; + goto next; } } llist_free(state_list, free); @@ -1316,6 +1316,9 @@ int ifupdown_main(int argc UNUSED_PARAM, char **argv) fclose(state_fp); llist_free(state_list, free); } + next: + free(iface); + free(liface); } return any_failures; diff --git a/networking/nameif.c b/networking/nameif.c index d02c2c11b..6cf1c50c2 100644 --- a/networking/nameif.c +++ b/networking/nameif.c @@ -156,7 +156,7 @@ int nameif_main(int argc, char **argv) if (argc) { while (*argv) { - char *ifname = xstrdup(*argv++); + char *ifname = *argv++; prepend_new_eth_table(&clist, ifname, *argv++); } } else { -- cgit v1.2.3-55-g6feb From 7cfe6ea99e78f82b068216faac4739eaaebaaa8b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 3 Mar 2011 09:51:57 +0100 Subject: xargs: support --no-run-if-empty (synonym to -r) Signed-off-by: Denys Vlasenko --- findutils/xargs.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/findutils/xargs.c b/findutils/xargs.c index 0ec80f809..967737133 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -15,10 +15,6 @@ * http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html */ -//applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, BB_DIR_USR_BIN, BB_SUID_DROP, xargs)) - -//kbuild:lib-$(CONFIG_XARGS) += xargs.o - //config:config XARGS //config: bool "xargs" //config: default y @@ -58,6 +54,10 @@ //config: instead of whitespace, and the quotes and backslash //config: are not special. +//applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, BB_DIR_USR_BIN, BB_SUID_DROP, xargs)) + +//kbuild:lib-$(CONFIG_XARGS) += xargs.o + #include "libbb.h" /* This is a NOEXEC applet. Be very careful! */ @@ -89,7 +89,9 @@ struct globals { int idx; } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { \ + G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \ +} while (0) /* @@ -412,7 +414,12 @@ int xargs_main(int argc, char **argv) INIT_G(); - G.eof_str = NULL; +#if ENABLE_DESKTOP && ENABLE_LONG_OPTS + /* For example, Fedora's build system uses --no-run-if-empty */ + applet_long_options = + "no-run-if-empty\0" No_argument "r" + ; +#endif opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &G.eof_str, &G.eof_str); /* -E ""? You may wonder why not just omit -E? -- cgit v1.2.3-55-g6feb From 4a2a86d5e7e7bf284a31af604a738dfa1f1a2240 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Mar 2011 06:02:31 +0100 Subject: improve --install operation in chroot jails Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index fc3e962d5..69cac2e9a 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -713,12 +713,23 @@ static int busybox_main(char **argv) if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { int use_symbolic_links; const char *busybox; + busybox = xmalloc_readlink(bb_busybox_exec_path); - if (!busybox) - busybox = bb_busybox_exec_path; - /* busybox --install [-s] [DIR]: */ - /* -s: make symlinks */ - /* DIR: directory to install links to */ + if (!busybox) { + /* bb_busybox_exec_path is usually "/proc/self/exe". + * In chroot, readlink("/proc/self/exe") usually fails. + * In such case, better use argv[0] as symlink target + * if it is a full path name. + */ + if (argv[0][0] == '/') + busybox = argv[0]; + else + busybox = bb_busybox_exec_path; + } + /* busybox --install [-s] [DIR]: + * -s: make symlinks + * DIR: directory to install links to + */ use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && argv++); install_links(busybox, use_symbolic_links, argv[2]); return 0; -- cgit v1.2.3-55-g6feb From 41478ade4f28cbacd954c9663d851c374d33f6b9 Mon Sep 17 00:00:00 2001 From: Alexey Soloviev Date: Sun, 6 Mar 2011 18:21:07 +0100 Subject: tr: free allocated memory in tr if CLEANUP enabled Signed-off-by: Alexey Soloviev Signed-off-by: Denys Vlasenko --- coreutils/tr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/coreutils/tr.c b/coreutils/tr.c index 21d77ef95..5b2b9a9a4 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -324,5 +324,11 @@ int tr_main(int argc UNUSED_PARAM, char **argv) str2[out_index++] = last = coded; } + if (ENABLE_FEATURE_CLEAN_UP) { + free(vector); + free(str2); + free(str1); + } + return EXIT_SUCCESS; } -- cgit v1.2.3-55-g6feb From bd74e3d8beb0fedc4c1fdd9469a9de3f1f04c7b5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Mar 2011 18:49:40 +0100 Subject: libbb/login/su: do not sanitize shell name twice function old new delta setup_environment 191 205 +14 login_main 1002 987 -15 su_main 474 458 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 14/-31) Total: -17 bytes Signed-off-by: Denys Vlasenko --- libbb/setup_environment.c | 3 +++ loginutils/login.c | 8 ++------ loginutils/su.c | 10 ++-------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index a95fbc5bf..73229ca6c 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c @@ -32,6 +32,9 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) { + if (!shell || !shell[0]) + shell = DEFAULT_SHELL; + /* Change the current working directory to be the home directory * of the user */ if (chdir(pw->pw_dir)) { diff --git a/loginutils/login.c b/loginutils/login.c index 952b3aadd..028a099b6 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -198,7 +198,6 @@ int login_main(int argc UNUSED_PARAM, char **argv) }; char *fromhost; char username[USERNAME_SIZE]; - const char *shell; int run_by_root; unsigned opt; int count = 0; @@ -391,10 +390,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) run_login_script(pw, full_tty); change_identity(pw); - shell = pw->pw_shell; - if (!shell || !shell[0]) - shell = DEFAULT_SHELL; - setup_environment(shell, + setup_environment(pw->pw_shell, (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + SETUP_ENV_CHANGEENV, pw); @@ -442,7 +438,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) signal(SIGINT, SIG_DFL); /* Exec login shell with no additional parameters */ - run_shell(shell, 1, NULL, NULL); + run_shell(pw->pw_shell, 1, NULL, NULL); /* return EXIT_FAILURE; - not reached */ } diff --git a/loginutils/su.c b/loginutils/su.c index db303af6d..72dd0f06f 100644 --- a/loginutils/su.c +++ b/loginutils/su.c @@ -114,20 +114,14 @@ int su_main(int argc UNUSED_PARAM, char **argv) opt_shell = getenv("SHELL"); } - /* Make sure pw->pw_shell is non-NULL. It may be NULL when NEW_USER - * is a username that is retrieved via NIS (YP), that doesn't have - * a default shell listed. */ - if (!pw->pw_shell || !pw->pw_shell[0]) - pw->pw_shell = (char *)DEFAULT_SHELL; - #if ENABLE_FEATURE_SU_CHECKS_SHELLS - if (opt_shell && cur_uid != 0 && restricted_shell(pw->pw_shell)) { + if (opt_shell && cur_uid != 0 && pw->pw_shell && restricted_shell(pw->pw_shell)) { /* The user being su'd to has a nonstandard shell, and so is * probably a uucp account or has restricted access. Don't * compromise the account by allowing access with a standard * shell. */ bb_error_msg("using restricted shell"); - opt_shell = NULL; + opt_shell = NULL; /* ignore -s PROG */ } /* else: user can run whatever he wants via "su -s PROG USER". * This is safe since PROG is run under user's uid/gid. */ -- cgit v1.2.3-55-g6feb From 2adc0e6d8b146991063309238569a703af6bda8f Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sun, 6 Mar 2011 19:15:30 +0100 Subject: nameif: fix parsing of /proc/net/dev; small code shrink function old new delta nameif_main 628 618 -10 Signed-off-by: Phil Sutter Signed-off-by: Denys Vlasenko --- networking/nameif.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/networking/nameif.c b/networking/nameif.c index 6cf1c50c2..e9bff8b11 100644 --- a/networking/nameif.c +++ b/networking/nameif.c @@ -133,7 +133,7 @@ void delete_eth_table(ethtable_t *ch); #endif int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int nameif_main(int argc, char **argv) +int nameif_main(int argc UNUSED_PARAM, char **argv) { ethtable_t *clist = NULL; const char *fname = "/etc/mactab"; @@ -148,17 +148,15 @@ int nameif_main(int argc, char **argv) * can't hurt. 2>/dev/null if you don't like it: */ logmode |= LOGMODE_SYSLOG; } - argc -= optind; argv += optind; - if (argc & 1) - bb_show_usage(); - - if (argc) { - while (*argv) { - char *ifname = *argv++; - prepend_new_eth_table(&clist, ifname, *argv++); - } + if (argv[0]) { + do { + if (!argv[1]) + bb_show_usage(); + prepend_new_eth_table(&clist, argv[0], argv[1]); + argv += 2; + } while (*argv); } else { parser = config_open(fname); while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) @@ -174,7 +172,7 @@ int nameif_main(int argc, char **argv) #if ENABLE_FEATURE_NAMEIF_EXTENDED struct ethtool_drvinfo drvinfo; #endif - if (parser->lineno < 2) + if (parser->lineno <= 2) continue; /* Skip the first two lines */ /* Find the current interface name and copy it to ifr.ifr_name */ -- cgit v1.2.3-55-g6feb From 293a8f250d35157aced813695e1975078a521d19 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sun, 6 Mar 2011 19:42:51 +0100 Subject: nameif: add matching by phy_address=NUM; extend help text function old new delta nameif_main 618 686 +68 packed_usage 28095 28149 +54 prepend_new_eth_table 295 338 +43 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 165/0) Total: 165 bytes Signed-off-by: Phil Sutter Signed-off-by: Denys Vlasenko --- include/usage.src.h | 14 -------- networking/Config.src | 29 ---------------- networking/nameif.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 94 insertions(+), 44 deletions(-) diff --git a/include/usage.src.h b/include/usage.src.h index c2575b561..df770c454 100644 --- a/include/usage.src.h +++ b/include/usage.src.h @@ -2546,20 +2546,6 @@ INSERT "ras3 reset retension rewind rewoffline seek setblk setdensity\n" \ "setpart tell unload unlock weof wset" \ -#define nameif_trivial_usage \ - "[-s] [-c FILE] [{IFNAME MACADDR}]" -#define nameif_full_usage "\n\n" \ - "Rename network interface while it in the down state\n" \ - "\nOptions:" \ - "\n -c FILE Use configuration file (default: /etc/mactab)" \ - "\n -s Use syslog (LOCAL0 facility)" \ - "\n IFNAME MACADDR new_interface_name interface_mac_address" \ - -#define nameif_example_usage \ - "$ nameif -s dmz0 00:A0:C9:8C:F6:3F\n" \ - " or\n" \ - "$ nameif -c /etc/my_mactab_file\n" \ - #define nohup_trivial_usage \ "PROG ARGS" #define nohup_full_usage "\n\n" \ diff --git a/networking/Config.src b/networking/Config.src index 06930f4a6..8aeba0ef9 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -612,35 +612,6 @@ config FEATURE_IPCALC_LONG_OPTIONS help Support long options for the ipcalc applet. -config NAMEIF - bool "nameif" - default y - select PLATFORM_LINUX - select FEATURE_SYSLOG - help - nameif is used to rename network interface by its MAC address. - Renamed interfaces MUST be in the down state. - It is possible to use a file (default: /etc/mactab) - with list of new interface names and MACs. - Maximum interface name length: IFNAMSIZ = 16 - File fields are separated by space or tab. - File format: - # Comment - new_interface_name XX:XX:XX:XX:XX:XX - -config FEATURE_NAMEIF_EXTENDED - bool "Extended nameif" - default y - depends on NAMEIF - help - This extends the nameif syntax to support the bus_info and driver - checks. The syntax is compatible to the normal nameif. - File format: - new_interface_name driver=asix bus=usb-0000:00:08.2-3 - new_interface_name bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5 - new_interface_name mac=00:80:C8:38:91:B5 - new_interface_name 00:80:C8:38:91:B5 - config NETSTAT bool "netstat" default y diff --git a/networking/nameif.c b/networking/nameif.c index e9bff8b11..78719edac 100644 --- a/networking/nameif.c +++ b/networking/nameif.c @@ -10,6 +10,66 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config NAMEIF +//config: bool "nameif" +//config: default y +//config: select PLATFORM_LINUX +//config: select FEATURE_SYSLOG +//config: help +//config: nameif is used to rename network interface by its MAC address. +//config: Renamed interfaces MUST be in the down state. +//config: It is possible to use a file (default: /etc/mactab) +//config: with list of new interface names and MACs. +//config: Maximum interface name length: IFNAMSIZ = 16 +//config: File fields are separated by space or tab. +//config: File format: +//config: # Comment +//config: new_interface_name XX:XX:XX:XX:XX:XX +//config: +//config:config FEATURE_NAMEIF_EXTENDED +//config: bool "Extended nameif" +//config: default y +//config: depends on NAMEIF +//config: help +//config: This extends the nameif syntax to support the bus_info, driver, +//config: phyaddr selectors. The syntax is compatible to the normal nameif. +//config: File format: +//config: new_interface_name driver=asix bus=usb-0000:00:08.2-3 +//config: new_interface_name bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5 +//config: new_interface_name phy_address=2 00:80:C8:38:91:B5 +//config: new_interface_name mac=00:80:C8:38:91:B5 +//config: new_interface_name 00:80:C8:38:91:B5 + +//usage:#define nameif_trivial_usage +//usage: IF_NOT_FEATURE_NAMEIF_EXTENDED( +//usage: "[-s] [-c FILE] [IFNAME HWADDR]..." +//usage: ) +//usage: IF_FEATURE_NAMEIF_EXTENDED( +//usage: "[-s] [-c FILE] [IFNAME SELECTOR]..." +//usage: ) +//usage:#define nameif_full_usage "\n\n" +//usage: "Rename network interface while it in the down state." +//usage: IF_NOT_FEATURE_NAMEIF_EXTENDED( +//usage: "\nThe device with address HWADDR is renamed to IFACE." +//usage: ) +//usage: IF_FEATURE_NAMEIF_EXTENDED( +//usage: "\nThe device matched by SELECTOR is renamed to IFACE." +//usage: "\nSELECTOR can be a combination of:" +//usage: "\n driver=STRING" +//usage: "\n bus=STRING" +//usage: "\n phy_address=NUM" +//usage: "\n [mac=]XX:XX:XX:XX:XX:XX" +//usage: ) +//usage: "\n" +//usage: "\nOptions:" +//usage: "\n -c FILE Configuration file (default: /etc/mactab)" +//usage: "\n -s Log to syslog" +//usage: +//usage:#define nameif_example_usage +//usage: "$ nameif -s dmz0 00:A0:C9:8C:F6:3F\n" +//usage: " or\n" +//usage: "$ nameif -c /etc/my_mactab_file\n" + #include "libbb.h" #include #include @@ -38,6 +98,7 @@ typedef struct ethtable_s { #if ENABLE_FEATURE_NAMEIF_EXTENDED char *bus_info; char *driver; + int32_t phy_address; #endif } ethtable_t; @@ -59,6 +120,25 @@ struct ethtool_drvinfo { uint32_t eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */ uint32_t regdump_len; /* Size of data from ETHTOOL_GREGS (bytes) */ }; + +struct ethtool_cmd { + __u32 cmd; + __u32 supported; /* Features this interface supports */ + __u32 advertising; /* Features this interface advertises */ + __u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */ + __u8 duplex; /* Duplex, half or full */ + __u8 port; /* Which connector port */ + __u8 phy_address; + __u8 transceiver; /* Which transceiver to use */ + __u8 autoneg; /* Enable or disable autonegotiation */ + __u32 maxtxpkt; /* Tx pkts before generating tx int */ + __u32 maxrxpkt; /* Rx pkts before generating rx int */ + __u16 speed_hi; + __u16 reserved2; + __u32 reserved[3]; +}; + +#define ETHTOOL_GSET 0x00000001 /* Get settings. */ #define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */ #endif @@ -74,6 +154,7 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector) #endif selector = skip_whitespace(selector); #if ENABLE_FEATURE_NAMEIF_EXTENDED + ch->phy_address = -1; if (*selector == '\0') break; /* Search for the end .... */ @@ -87,6 +168,9 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector) } else if (strncmp(selector, "driver=", 7) == 0) { ch->driver = xstrdup(selector + 7); found_selector++; + } else if (strncmp(selector, "phyaddr=", 8) == 0) { + ch->phy_address = xatoi_positive(selector + 8); + found_selector++; } else { #endif lmac = xmalloc(ETH_ALEN); @@ -171,6 +255,7 @@ int nameif_main(int argc UNUSED_PARAM, char **argv) struct ifreq ifr; #if ENABLE_FEATURE_NAMEIF_EXTENDED struct ethtool_drvinfo drvinfo; + struct ethtool_cmd eth_settings; #endif if (parser->lineno <= 2) continue; /* Skip the first two lines */ @@ -180,8 +265,14 @@ int nameif_main(int argc UNUSED_PARAM, char **argv) strncpy_IFNAMSIZ(ifr.ifr_name, token[0]); #if ENABLE_FEATURE_NAMEIF_EXTENDED + /* Check for phy address */ + memset(ð_settings, 0, sizeof(eth_settings)); + eth_settings.cmd = ETHTOOL_GSET; + ifr.ifr_data = (caddr_t) ð_settings; + ioctl(ctl_sk, SIOCETHTOOL, &ifr); + /* Check for driver etc. */ - memset(&drvinfo, 0, sizeof(struct ethtool_drvinfo)); + memset(&drvinfo, 0, sizeof(drvinfo)); drvinfo.cmd = ETHTOOL_GDRVINFO; ifr.ifr_data = (caddr_t) &drvinfo; /* Get driver and businfo first, so we have it in drvinfo */ @@ -196,6 +287,8 @@ int nameif_main(int argc UNUSED_PARAM, char **argv) continue; if (ch->driver && strcmp(ch->driver, drvinfo.driver) != 0) continue; + if (ch->phy_address != -1 && ch->phy_address != eth_settings.phy_address) + continue; #endif if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0) continue; -- cgit v1.2.3-55-g6feb From 102b8bde3b86e5d2eb9e8a60d220e55e00beccf1 Mon Sep 17 00:00:00 2001 From: Bjørn Forsman Date: Thu, 3 Mar 2011 09:55:19 +0100 Subject: .gitignore: add missing ignores MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore output files created by "make defconfig; make". Signed-off-by: Bjørn Forsman Signed-off-by: Denys Vlasenko --- applets/.gitignore | 1 + docs/.gitignore | 1 + include/.gitignore | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/applets/.gitignore b/applets/.gitignore index cc932fcc0..459938d67 100644 --- a/applets/.gitignore +++ b/applets/.gitignore @@ -1,2 +1,3 @@ /applet_tables /usage +/usage_pod diff --git a/docs/.gitignore b/docs/.gitignore index 11d616360..3d1c5bd8a 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,4 +1,5 @@ /busybox.1 /BusyBox.html +/busybox.net /BusyBox.txt /busybox.pod diff --git a/include/.gitignore b/include/.gitignore index f0ce546cf..9d9b6c499 100644 --- a/include/.gitignore +++ b/include/.gitignore @@ -1,6 +1,10 @@ /config +/applets.h /applet_tables.h /autoconf.h +/bbconfigopts_bz2.h /bbconfigopts.h +/NUM_APPLETS.h /usage_compressed.h +/usage.h -- cgit v1.2.3-55-g6feb From 726ebbaa9f1cae426b5f2a4bddbe0a88c81d754e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Mar 2011 23:09:42 +0100 Subject: fix bit rot in scripts/Makefile.IMA Signed-off-by: Denys Vlasenko --- loginutils/getty.c | 4 ++-- scripts/Makefile.IMA | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/loginutils/getty.c b/loginutils/getty.c index 3f20c8e81..dfa15b3da 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -87,7 +87,7 @@ struct globals { const char *login; /* login program */ const char *fakehost; const char *tty; /* name of tty */ - const char *initstring; /* modem init string */ + char *initstring; /* modem init string */ const char *issue; /* alternative issue file */ int numspeed; /* number of baud rates to try */ int speeds[MAX_SPEED]; /* baud rates to be tried */ @@ -176,7 +176,7 @@ static void parse_args(char **argv) if (flags & F_INITSTRING) { G.initstring = xstrdup(G.initstring); /* decode \ddd octal codes into chars */ - strcpy_and_process_escape_sequences((char*)G.initstring, G.initstring); + strcpy_and_process_escape_sequences(G.initstring, G.initstring); } argv += optind; debug("after getopt\n"); diff --git a/scripts/Makefile.IMA b/scripts/Makefile.IMA index a62618ae0..fcb8e5049 100644 --- a/scripts/Makefile.IMA +++ b/scripts/Makefile.IMA @@ -9,7 +9,10 @@ objtree := $(CURDIR) src := $(srctree) obj := $(objtree) -# Look for make include files relative to root of kernel src +# Make generated files +DUMMY := $(shell $(Q)$(srctree)/scripts/gen_build_files.sh $(srctree) $(objtree) >&2) + +# Look for make include files relative to root of src MAKEFLAGS += --include-dir=$(srctree) default: busybox @@ -121,6 +124,9 @@ lib-y:= include miscutils/Kbuild lib-all-y += $(patsubst %,miscutils/%,$(sort $(lib-y))) lib-y:= +include mailutils/Kbuild +lib-all-y += $(patsubst %,mailutils/%,$(sort $(lib-y))) +lib-y:= include coreutils/libcoreutils/Kbuild lib-all-y += $(patsubst %,coreutils/libcoreutils/%,$(sort $(lib-y))) lib-y:= -- cgit v1.2.3-55-g6feb From bff5f3f2b4c568aa516ee3ec9201c887c0f1eca4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Mar 2011 23:48:24 +0100 Subject: fix bit rot in scripts/Makefile.IMA #2 Signed-off-by: Denys Vlasenko --- applets/Kbuild.src | 3 +++ scripts/Makefile.IMA | 13 ++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/applets/Kbuild.src b/applets/Kbuild.src index 9b9808f25..b61239948 100644 --- a/applets/Kbuild.src +++ b/applets/Kbuild.src @@ -42,3 +42,6 @@ quiet_cmd_gen_applet_tables = GEN include/applet_tables.h include/applet_tables.h: applets/applet_tables $(call cmd,gen_applet_tables) + +include/NUM_APPLETS.h: applets/applet_tables + $(call cmd,gen_applet_tables) diff --git a/scripts/Makefile.IMA b/scripts/Makefile.IMA index fcb8e5049..0eced2982 100644 --- a/scripts/Makefile.IMA +++ b/scripts/Makefile.IMA @@ -174,7 +174,7 @@ lib-all-y += $(patsubst %,libbb/%,$(sort $(lib-y))) lib-y:= comma:=, -busybox_unstripped.o: $(usage_stuff) include/applet_tables.h include/autoconf.h +busybox_unstripped.o: $(usage_stuff) include/applet_tables.h include/NUM_APPLETS.h include/autoconf.h $(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) \ $(patsubst %,-Wl$(comma)%,$(LDFLAGS) $(EXTRA_LDFLAGS)) \ -DGCC_COMBINE=1 \ @@ -200,14 +200,9 @@ busybox: busybox_unstripped.o include/autoconf.h: .config $(MAKE) -f $(srctree)/Makefile silentoldconfig +# Override rules for host compile applets/usage: include/autoconf.h - $(HOSTCC) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -I$(srctree)/include -o applets/usage applets/usage.c + $(HOSTCC) -Wall -O2 -I$(srctree)/include -o applets/usage applets/usage.c applets/applet_tables: include/autoconf.h - $(HOSTCC) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -I$(srctree)/include -o applets/applet_tables applets/applet_tables.c - -include/usage_compressed.h: include/usage.h applets/usage - $(srctree)/applets/usage_compressed include/usage_compressed.h applets - -include/applet_tables.h: include/applets.h - applets/applet_tables include/applet_tables.h + $(HOSTCC) -Wall -O2 -I$(srctree)/include -o applets/applet_tables applets/applet_tables.c -- cgit v1.2.3-55-g6feb From 82e785cf8cc6e78dd84adc1aee298dfa827a019c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Mar 2011 02:01:52 +0100 Subject: more: fix tabs handling function old new delta more_main 837 829 -8 Signed-off-by: Denys Vlasenko --- util-linux/more.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util-linux/more.c b/util-linux/more.c index c424a0e4b..7160b8b00 100644 --- a/util-linux/more.c +++ b/util-linux/more.c @@ -113,9 +113,12 @@ int more_main(int argc UNUSED_PARAM, char **argv) loop_top: if (input != 'r' && please_display_more_prompt) { len = printf("--More-- "); - if (st.st_size > 0) { + if (st.st_size != 0) { + uoff_t d = (uoff_t)st.st_size / 100; + if (d == 0) + d = 1; len += printf("(%u%% of %"OFF_FMT"u bytes)", - (int) (ftello(file)*100 / st.st_size), + (int) ((uoff_t)ftello(file) / d), st.st_size); } fflush_all(); @@ -159,7 +162,7 @@ int more_main(int argc UNUSED_PARAM, char **argv) /* Crudely convert tabs into spaces, which are * a bajillion times easier to deal with. */ if (c == '\t') { - spaces = CONVERTED_TAB_SIZE - 1; + spaces = ((unsigned)~len) % CONVERTED_TAB_SIZE; c = ' '; } -- cgit v1.2.3-55-g6feb From e6bb8d339fc6897c85c63a5a62d7c4402f7b1a54 Mon Sep 17 00:00:00 2001 From: Keith Young Date: Mon, 7 Mar 2011 03:18:46 +0100 Subject: udhcpc: add -B option function old new delta udhcpc_longopts - 262 +262 add_client_options 218 239 +21 packed_usage 28149 28163 +14 static.udhcpc_longopts 250 - -250 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 2/0 up/down: 297/-250) Total: 47 bytes Signed-off-by: Keith Young Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 128 +++++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 59 deletions(-) diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index d97a404fa..e9a841204 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -38,6 +38,67 @@ /* struct client_config_t client_config is in bb_common_bufsiz1 */ +#if ENABLE_LONG_OPTS +static const char udhcpc_longopts[] ALIGN1 = + "clientid-none\0" No_argument "C" + "vendorclass\0" Required_argument "V" + "hostname\0" Required_argument "H" + "fqdn\0" Required_argument "F" + "interface\0" Required_argument "i" + "now\0" No_argument "n" + "pidfile\0" Required_argument "p" + "quit\0" No_argument "q" + "release\0" No_argument "R" + "request\0" Required_argument "r" + "script\0" Required_argument "s" + "timeout\0" Required_argument "T" + "version\0" No_argument "v" + "retries\0" Required_argument "t" + "tryagain\0" Required_argument "A" + "syslog\0" No_argument "S" + "request-option\0" Required_argument "O" + "no-default-options\0" No_argument "o" + "foreground\0" No_argument "f" + "background\0" No_argument "b" + "broadcast\0" No_argument "B" + IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a") + IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") + ; +#endif +/* Must match getopt32 option string order */ +enum { + OPT_C = 1 << 0, + OPT_V = 1 << 1, + OPT_H = 1 << 2, + OPT_h = 1 << 3, + OPT_F = 1 << 4, + OPT_i = 1 << 5, + OPT_n = 1 << 6, + OPT_p = 1 << 7, + OPT_q = 1 << 8, + OPT_R = 1 << 9, + OPT_r = 1 << 10, + OPT_s = 1 << 11, + OPT_T = 1 << 12, + OPT_t = 1 << 13, + OPT_S = 1 << 14, + OPT_A = 1 << 15, + OPT_O = 1 << 16, + OPT_o = 1 << 17, + OPT_x = 1 << 18, + OPT_f = 1 << 19, + OPT_B = 1 << 20, +/* The rest has variable bit positions, need to be clever */ + OPTBIT_B = 20, + USE_FOR_MMU( OPTBIT_b,) + IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) + IF_FEATURE_UDHCP_PORT( OPTBIT_P,) + USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) + IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) + IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) +}; + + /*** Script execution code ***/ /* get a rough idea of how long an option will be (rounding up...) */ @@ -391,6 +452,10 @@ static void add_client_options(struct dhcp_packet *packet) if (client_config.fqdn) udhcp_add_binary_option(packet, client_config.fqdn); + /* Request broadcast replies if we have no IP addr */ + if ((option_mask32 & OPT_B) && packet->ciaddr == 0) + packet->flags |= htons(BROADCAST_FLAG); + /* Add -x options if any */ { struct option_set *curr = client_config.options; @@ -853,13 +918,14 @@ static void client_background(void) //usage:# define IF_UDHCP_VERBOSE(...) //usage:#endif //usage:#define udhcpc_trivial_usage -//usage: "[-fbnq"IF_UDHCP_VERBOSE("v")"oCR] [-i IFACE] [-r IP] [-s PROG] [-p PIDFILE]\n" +//usage: "[-fbnq"IF_UDHCP_VERBOSE("v")"oCRB] [-i IFACE] [-r IP] [-s PROG] [-p PIDFILE]\n" //usage: " [-H HOSTNAME] [-V VENDOR] [-x OPT:VAL]... [-O OPT]..." IF_FEATURE_UDHCP_PORT(" [-P N]") //usage:#define udhcpc_full_usage "\n" //usage: IF_LONG_OPTS( //usage: "\n -i,--interface IFACE Interface to use (default eth0)" //usage: "\n -p,--pidfile FILE Create pidfile" //usage: "\n -s,--script PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" +//usage: "\n -B,--broadcast Request broadcast replies" //usage: "\n -t,--retries N Send up to N discover packets" //usage: "\n -T,--timeout N Pause between packets (default 3 seconds)" //usage: "\n -A,--tryagain N Wait N seconds after failure (default 20)" @@ -897,6 +963,7 @@ static void client_background(void) //usage: "\n -i IFACE Interface to use (default eth0)" //usage: "\n -p FILE Create pidfile" //usage: "\n -s PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" +//usage: "\n -B Request broadcast replies" //usage: "\n -t N Send up to N discover packets" //usage: "\n -T N Pause between packets (default 3 seconds)" //usage: "\n -A N Wait N seconds (default 20) after failure" @@ -961,63 +1028,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) struct dhcp_packet packet; fd_set rfds; -#if ENABLE_LONG_OPTS - static const char udhcpc_longopts[] ALIGN1 = - "clientid-none\0" No_argument "C" - "vendorclass\0" Required_argument "V" - "hostname\0" Required_argument "H" - "fqdn\0" Required_argument "F" - "interface\0" Required_argument "i" - "now\0" No_argument "n" - "pidfile\0" Required_argument "p" - "quit\0" No_argument "q" - "release\0" No_argument "R" - "request\0" Required_argument "r" - "script\0" Required_argument "s" - "timeout\0" Required_argument "T" - "version\0" No_argument "v" - "retries\0" Required_argument "t" - "tryagain\0" Required_argument "A" - "syslog\0" No_argument "S" - "request-option\0" Required_argument "O" - "no-default-options\0" No_argument "o" - "foreground\0" No_argument "f" - "background\0" No_argument "b" - IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a") - IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") - ; -#endif - enum { - OPT_C = 1 << 0, - OPT_V = 1 << 1, - OPT_H = 1 << 2, - OPT_h = 1 << 3, - OPT_F = 1 << 4, - OPT_i = 1 << 5, - OPT_n = 1 << 6, - OPT_p = 1 << 7, - OPT_q = 1 << 8, - OPT_R = 1 << 9, - OPT_r = 1 << 10, - OPT_s = 1 << 11, - OPT_T = 1 << 12, - OPT_t = 1 << 13, - OPT_S = 1 << 14, - OPT_A = 1 << 15, - OPT_O = 1 << 16, - OPT_o = 1 << 17, - OPT_x = 1 << 18, - OPT_f = 1 << 19, -/* The rest has variable bit positions, need to be clever */ - OPTBIT_f = 19, - USE_FOR_MMU( OPTBIT_b,) - IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) - IF_FEATURE_UDHCP_PORT( OPTBIT_P,) - USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) - IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) - IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) - }; - /* Default options */ IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) @@ -1033,7 +1043,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) #endif ; IF_LONG_OPTS(applet_long_options = udhcpc_longopts;) - opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:f" + opt = getopt32(argv, "CV:H:h:F:i:np:qRr:s:T:t:SA:O:ox:fB" USE_FOR_MMU("b") IF_FEATURE_UDHCPC_ARPING("a") IF_FEATURE_UDHCP_PORT("P:") -- cgit v1.2.3-55-g6feb From 8b6b472f4edd701ac3b25d4a0c89ab506e09e0bb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Mar 2011 10:57:26 +0100 Subject: klogd: fix the problem of delayed handling of ^C and SIGTERM Signed-off-by: Denys Vlasenko --- sysklogd/klogd.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 0d4c2578d..db32065fb 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -150,12 +150,41 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) */ klogd_open(); openlog("kernel", 0, LOG_KERN); + /* + * glibc problem: for some reason, glibc changes LOG_KERN to LOG_USER + * above. The logic behind this is that standard + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/syslog.html + * says the following about openlog and syslog: + * "LOG_USER + * Messages generated by arbitrary processes. + * This is the default facility identifier if none is specified." + * + * I believe glibc misinterpreted this text as "if openlog's + * third parameter is 0 (=LOG_KERN), treat it as LOG_USER". + * Whereas it was meant to say "if *syslog* is called with facility + * 0 in its 1st parameter without prior call to openlog, then perform + * implicit openlog(LOG_USER)". + * + * As a result of this, eh, feature, standard klogd was forced + * to open-code its own openlog and syslog implementation (!). + * + * Note that prohibiting openlog(LOG_KERN) on libc level does not + * add any security: any process can open a socket to "/dev/log" + * and write a string "<0>Voila, a LOG_KERN + LOG_EMERG message" + * + * Google code search tells me there is no widespread use of + * openlog("foo", 0, 0), thus fixing glibc won't break userspace. + * + * The bug against glibc was filed: + * bugzilla.redhat.com/show_bug.cgi?id=547000 + */ if (i) klogd_setloglevel(i); - bb_signals(BB_FATAL_SIGS, record_signo); signal(SIGHUP, SIG_IGN); + /* We want klogd_read to not be restarted, thus _norestart: */ + bb_signals_recursive_norestart(BB_FATAL_SIGS, record_signo); syslog(LOG_NOTICE, "klogd started: %s", bb_banner); -- cgit v1.2.3-55-g6feb From aefe1c260ec5aa691e8b6f773c7fa393bfad0f7b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Mar 2011 12:02:40 +0100 Subject: ash: fix execution of shell scripts without shebang We were assuming #!/bin/sh, whereas we had to simply re-enter ash. Signed-off-by: Denys Vlasenko --- shell/ash.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index c3c953656..09db046fe 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -7396,8 +7396,6 @@ static int builtinloc = -1; /* index in path of %builtin, or -1 */ static void tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **envp) { - int repeated = 0; - #if ENABLE_FEATURE_SH_STANDALONE if (applet_no >= 0) { if (APPLET_IS_NOEXEC(applet_no)) { @@ -7421,25 +7419,36 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char ** #else execve(cmd, argv, envp); #endif - if (repeated) { + if (cmd == (char*) bb_busybox_exec_path) { + /* We already visited ENOEXEC branch below, don't do it again */ +//TODO: try execve(initial_argv0_of_shell, argv, envp) before giving up? free(argv); return; } if (errno == ENOEXEC) { + /* Run "cmd" as a shell script: + * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html + * "If the execve() function fails with ENOEXEC, the shell + * shall execute a command equivalent to having a shell invoked + * with the command name as its first operand, + * with any remaining arguments passed to the new shell" + * + * That is, do not use $SHELL, user's shell, or /bin/sh; + * just call ourselves. + */ char **ap; char **new; for (ap = argv; *ap; ap++) continue; - ap = new = ckmalloc((ap - argv + 2) * sizeof(ap[0])); - ap[1] = cmd; - ap[0] = cmd = (char *)DEFAULT_SHELL; - ap += 2; - argv++; - while ((*ap++ = *argv++) != NULL) + new = ckmalloc((ap - argv + 2) * sizeof(new[0])); + new[0] = (char*) "ash"; + new[1] = cmd; + ap = new + 2; + while ((*ap++ = *++argv) != NULL) continue; + cmd = (char*) bb_busybox_exec_path; argv = new; - repeated++; goto repeat; } } -- cgit v1.2.3-55-g6feb From b0b834342ffece7f3debd8c7199a07ce8a6d942c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Mar 2011 12:34:59 +0100 Subject: ash/hush: provide help text $ ./busybox ash --help BusyBox v1.19.0.git (2011-03-07 11:25:29 CET) multi-call binary. Usage: ash [-/+OPTCHARS] [-/+o OPTNAME]... [-c 'SCRIPT' [ARG0 [ARGS]] / SCRIPT_FILE [ARGS]] Unix shell interpreter $ ./busybox hush --help BusyBox v1.19.0.git (2011-03-07 11:25:29 CET) multi-call binary. Usage: hush [-nx] [-c 'SCRIPT' [ARG0 [ARGS]] / SCRIPT_FILE [ARGS]] Unix shell interpreter function old new delta packed_usage 28163 28212 +49 setcmd 85 78 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 49/-7) Total: 42 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 40 ++++++++++++++++++++++++++-------------- shell/hush.c | 21 ++++++++++++++------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 09db046fe..bfbd60d78 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -190,13 +190,6 @@ //config: variable each time it is displayed. //config: -//usage:#define ash_trivial_usage NOUSAGE_STR -//usage:#define ash_full_usage "" -//usage:#define sh_trivial_usage NOUSAGE_STR -//usage:#define sh_full_usage "" -//usage:#define bash_trivial_usage NOUSAGE_STR -//usage:#define bash_full_usage "" - /* ============ Hash table sizes. Configurable. */ @@ -10155,6 +10148,7 @@ setoption(int flag, int val) /* NOTREACHED */ } static int + options(int cmdline) { char *p; @@ -10180,7 +10174,7 @@ options(int cmdline) else if (*argptr == NULL) setparam(argptr); } - break; /* "-" or "--" terminates options */ + break; /* "-" or "--" terminates options */ } } /* first char was + or - */ @@ -10282,10 +10276,10 @@ setcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) if (!argv[1]) return showvars(nullstr, 0, VUNSET); + INT_OFF; - retval = 1; - if (!options(0)) { /* if no parse error... */ - retval = 0; + retval = options(/*cmdline:*/ 0); + if (retval == 0) { /* if no parse error... */ optschanged(); if (*argptr != NULL) { setparam(argptr); @@ -12938,14 +12932,32 @@ init(void) setvar("PPID", utoa(getppid()), 0); p = lookupvar("PWD"); - if (p) + if (p) { if (*p != '/' || stat(p, &st1) || stat(".", &st2) - || st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) + || st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino + ) { p = '\0'; + } + } setpwd(p, 0); } } + +//usage:#define ash_trivial_usage +//usage: "[-/+OPTCHARS] [-/+o OPTNAME]... [-c 'SCRIPT' [ARG0 [ARGS]] / SCRIPT_FILE [ARGS]]" +//usage:#define ash_full_usage "\n\n" +//usage: "Unix shell interpreter" + +//usage:#if ENABLE_FEATURE_SH_IS_ASH +//usage:# define sh_trivial_usage ash_trivial_usage +//usage:# define sh_full_usage ash_full_usage +//usage:#endif +//usage:#if ENABLE_FEATURE_BASH_IS_ASH +//usage:# define bash_trivial_usage ash_trivial_usage +//usage:# define bash_full_usage ash_full_usage +//usage:#endif + /* * Process the shell command line arguments. */ @@ -12963,7 +12975,7 @@ procargs(char **argv) for (i = 0; i < NOPTS; i++) optlist[i] = 2; argptr = xargv; - if (options(1)) { + if (options(/*cmdline:*/ 1)) { /* it already printed err message */ raise_exception(EXERROR); } diff --git a/shell/hush.c b/shell/hush.c index 4d9e5f8c7..6b3dc46d4 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -255,14 +255,21 @@ * therefore we don't show them either. */ //usage:#define hush_trivial_usage -//usage: "[-nx] [-c SCRIPT]" -//usage:#define hush_full_usage "" +//usage: "[-nx] [-c 'SCRIPT' [ARG0 [ARGS]] / SCRIPT_FILE [ARGS]]" +//usage:#define hush_full_usage "\n\n" +//usage: "Unix shell interpreter" + //usage:#define msh_trivial_usage hush_trivial_usage -//usage:#define msh_full_usage "" -//usage:#define sh_trivial_usage NOUSAGE_STR -//usage:#define sh_full_usage "" -//usage:#define bash_trivial_usage NOUSAGE_STR -//usage:#define bash_full_usage "" +//usage:#define msh_full_usage hush_full_usage + +//usage:#if ENABLE_FEATURE_SH_IS_HUSH +//usage:# define sh_trivial_usage hush_trivial_usage +//usage:# define sh_full_usage hush_full_usage +//usage:#endif +//usage:#if ENABLE_FEATURE_BASH_IS_HUSH +//usage:# define bash_trivial_usage hush_trivial_usage +//usage:# define bash_full_usage hush_full_usage +//usage:#endif /* Build knobs */ -- cgit v1.2.3-55-g6feb From 976ec23da5a335572be9a6130fb4efcc08d62d0e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Mar 2011 13:12:01 +0100 Subject: remove stray empty line Signed-off-by: Denys Vlasenko --- shell/ash.c | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index bfbd60d78..dc50bc102 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10148,7 +10148,6 @@ setoption(int flag, int val) /* NOTREACHED */ } static int - options(int cmdline) { char *p; -- cgit v1.2.3-55-g6feb From 9283d7c5c24cb5875f1115117fde2c69ff7735dc Mon Sep 17 00:00:00 2001 From: Pere Orga Date: Mon, 7 Mar 2011 16:22:17 +0100 Subject: kill: fix infinite loop when passed PIDs are not valid numbers Signed-off-by: Pere Orga Signed-off-by: Denys Vlasenko --- procps/kill.c | 1 + 1 file changed, 1 insertion(+) diff --git a/procps/kill.c b/procps/kill.c index 39538016e..695d266c5 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -219,6 +219,7 @@ int kill_main(int argc, char **argv) pid = bb_strtoi(arg, &end, 10); if (errno && (errno != EINVAL || *end != ' ')) { bb_error_msg("invalid number '%s'", arg); + *end = '\0'; errors++; } else if (kill(pid, signo) != 0) { bb_perror_msg("can't kill pid %d", (int)pid); -- cgit v1.2.3-55-g6feb From 115c35d68efa61f168c471df4627e4316952a69b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Mar 2011 03:01:10 +0100 Subject: ftpd: better usage text Signed-off-by: Denys Vlasenko --- include/usage.src.h | 17 ----------------- networking/ftpd.c | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/usage.src.h b/include/usage.src.h index df770c454..5a725e305 100644 --- a/include/usage.src.h +++ b/include/usage.src.h @@ -1273,23 +1273,6 @@ INSERT "\n -m Show \"mode not cleared\" warnings" \ "\n -f Force file system check" \ -#define ftpd_trivial_usage \ - "[-wvS] [-t N] [-T N] [DIR]" -#define ftpd_full_usage "\n\n" \ - "Anonymous FTP server\n" \ - "\n" \ - "ftpd should be used as an inetd service.\n" \ - "ftpd's line for inetd.conf:\n" \ - " 21 stream tcp nowait root ftpd ftpd /files/to/serve\n" \ - "It also can be ran from tcpsvd:\n" \ - " tcpsvd -vE 0.0.0.0 21 ftpd /files/to/serve\n" \ - "\nOptions:" \ - "\n -w Allow upload" \ - "\n -v Log to stderr" \ - "\n -S Log to syslog" \ - "\n -t,-T Idle and absolute timeouts" \ - "\n DIR Change root to this directory" \ - #define ftpget_trivial_usage \ "[OPTIONS] HOST [LOCAL_FILE] REMOTE_FILE" #define ftpget_full_usage "\n\n" \ diff --git a/networking/ftpd.c b/networking/ftpd.c index 64068e467..b59135667 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c @@ -12,6 +12,23 @@ * You have to run this daemon via inetd. */ +//usage:#define ftpd_trivial_usage +//usage: "[-wvS] [-t N] [-T N] [DIR]" +//usage:#define ftpd_full_usage "\n\n" +//usage: "Anonymous FTP server\n" +//usage: "\n" +//usage: "ftpd should be used as an inetd service.\n" +//usage: "ftpd's line for inetd.conf:\n" +//usage: " 21 stream tcp nowait root ftpd ftpd /files/to/serve\n" +//usage: "It also can be ran from tcpsvd:\n" +//usage: " tcpsvd -vE 0.0.0.0 21 ftpd /files/to/serve\n" +//usage: "\nOptions:" +//usage: "\n -w Allow upload" +//usage: "\n -v Log errors to stderr. -vv: verbose log" +//usage: "\n -S Log errors to syslog. -SS: verbose log" +//usage: "\n -t,-T Idle and absolute timeouts" +//usage: "\n DIR Change root to this directory" + #include "libbb.h" #include #include @@ -206,7 +223,7 @@ cmdio_write_error(unsigned status) { *(uint32_t *) G.msg_err = status; xwrite(STDOUT_FILENO, G.msg_err, sizeof("NNN " MSG_ERR) - 1); - if (G.verbose > 1) + if (G.verbose > 0) verbose_log(G.msg_err); } #define WRITE_ERR(a) cmdio_write_error(STRNUM32sp(a)) -- cgit v1.2.3-55-g6feb From 6b6af53426d98ab513972bd710f250e246e7fc98 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Mar 2011 10:24:17 +0100 Subject: ash/hush: shrink help text Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- shell/hush.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index dc50bc102..0baf7c8e5 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12944,7 +12944,7 @@ init(void) //usage:#define ash_trivial_usage -//usage: "[-/+OPTCHARS] [-/+o OPTNAME]... [-c 'SCRIPT' [ARG0 [ARGS]] / SCRIPT_FILE [ARGS]]" +//usage: "[-/+OPTIONS] [-/+o OPT]... [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS]]" //usage:#define ash_full_usage "\n\n" //usage: "Unix shell interpreter" diff --git a/shell/hush.c b/shell/hush.c index 6b3dc46d4..64d5e8587 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -255,7 +255,7 @@ * therefore we don't show them either. */ //usage:#define hush_trivial_usage -//usage: "[-nx] [-c 'SCRIPT' [ARG0 [ARGS]] / SCRIPT_FILE [ARGS]]" +//usage: "[-nx] [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS]]" //usage:#define hush_full_usage "\n\n" //usage: "Unix shell interpreter" -- cgit v1.2.3-55-g6feb From 86cf0364bd58e07646a23a1128e4a9ea79189579 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Mar 2011 12:44:02 +0100 Subject: printenv: fix environ == NULL segfault Signed-off-by: Denys Vlasenko --- coreutils/printenv.c | 11 ++++++++--- coreutils/test.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/coreutils/printenv.c b/coreutils/printenv.c index 33be5c096..d0fb71636 100644 --- a/coreutils/printenv.c +++ b/coreutils/printenv.c @@ -19,9 +19,14 @@ int printenv_main(int argc UNUSED_PARAM, char **argv) /* no variables specified, show whole env */ if (!argv[1]) { - int e = 0; - while (environ[e]) - puts(environ[e++]); + char **e = environ; + + /* environ can be NULL! (for example, after clearenv()) + * Check for that: + */ + if (e) + while (*e) + puts(*e++); } else { /* search for specified variables and print them out if found */ char *arg, *env; diff --git a/coreutils/test.c b/coreutils/test.c index 8248a1ef5..2d245be6c 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -45,7 +45,7 @@ /* This is a NOFORK applet. Be very careful! */ /* test_main() is called from shells, and we need to be extra careful here. - * This is true regardless of PREFER_APPLETS and STANDALONE_SHELL + * This is true regardless of PREFER_APPLETS and SH_STANDALONE * state. */ /* test(1) accepts the following grammar: -- cgit v1.2.3-55-g6feb From 681efe20d327e9e6774b174a617d66bbb9d21f48 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Mar 2011 21:00:36 +0100 Subject: use user's shell instead of hardwired "/bin/sh" (android needs this) Signed-off-by: Denys Vlasenko --- archival/libarchive/data_extract_to_command.c | 8 ++++++-- archival/tar.c | 1 + console-tools/openvt.c | 4 +--- coreutils/chroot.c | 8 +++----- include/archive.h | 1 + include/libbb.h | 9 ++++++++- loginutils/adduser.c | 3 ++- miscutils/conspy.c | 4 +--- miscutils/crontab.c | 7 ++++--- networking/ifupdown.c | 9 +++++---- runit/svlogd.c | 7 +++++-- util-linux/script.c | 5 +---- 12 files changed, 38 insertions(+), 28 deletions(-) diff --git a/archival/libarchive/data_extract_to_command.c b/archival/libarchive/data_extract_to_command.c index 2bbab7641..0e977049d 100644 --- a/archival/libarchive/data_extract_to_command.c +++ b/archival/libarchive/data_extract_to_command.c @@ -99,8 +99,12 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle) close(p[1]); xdup2(p[0], STDIN_FILENO); signal(SIGPIPE, SIG_DFL); - execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c", archive_handle->tar__to_command, NULL); - bb_perror_msg_and_die("can't execute '%s'", DEFAULT_SHELL); + execl(archive_handle->tar__to_command_shell, + archive_handle->tar__to_command_shell, + "-c", + archive_handle->tar__to_command, + NULL); + bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell); } close(p[0]); /* Our caller is expected to do signal(SIGPIPE, SIG_IGN) diff --git a/archival/tar.c b/archival/tar.c index d43c8dee3..01b83d5e2 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -970,6 +970,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv) putenv((char*)"TAR_FILETYPE=f"); signal(SIGPIPE, SIG_IGN); tar_handle->action_data = data_extract_to_command; + IF_FEATURE_TAR_TO_COMMAND(tar_handle->tar__to_command_shell = xstrdup(get_shell_name());) } if (opt & OPT_KEEP_OLD) diff --git a/console-tools/openvt.c b/console-tools/openvt.c index 6e0b589a0..56f50c6cd 100644 --- a/console-tools/openvt.c +++ b/console-tools/openvt.c @@ -144,9 +144,7 @@ int openvt_main(int argc UNUSED_PARAM, char **argv) if (!argv[0]) { argv--; - argv[0] = getenv("SHELL"); - if (!argv[0]) - argv[0] = (char *) DEFAULT_SHELL; + argv[0] = (char *) get_shell_name(); /*argv[1] = NULL; - already is */ } diff --git a/coreutils/chroot.c b/coreutils/chroot.c index b80a12ee0..5ac2e890e 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c @@ -23,11 +23,9 @@ int chroot_main(int argc UNUSED_PARAM, char **argv) ++argv; if (!*argv) { /* no 2nd param (PROG), use shell */ argv -= 2; - argv[0] = getenv("SHELL"); - if (!argv[0]) { - argv[0] = (char *) DEFAULT_SHELL; - } - argv[1] = (char *) "-i"; + argv[0] = (char *) get_shell_name(); + argv[1] = (char *) "-i"; /* GNU coreutils 8.4 compat */ + /*argv[2] = NULL; - already is */ } BB_EXECVP_or_die(argv); diff --git a/include/archive.h b/include/archive.h index 181c187f7..b139dc5be 100644 --- a/include/archive.h +++ b/include/archive.h @@ -84,6 +84,7 @@ typedef struct archive_handle_t { # endif #if ENABLE_FEATURE_TAR_TO_COMMAND char* tar__to_command; + const char* tar__to_command_shell; #endif # if ENABLE_FEATURE_TAR_SELINUX char* tar__global_sctx; diff --git a/include/libbb.h b/include/libbb.h index c26012c5d..c371e35f2 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1198,10 +1198,17 @@ char *bb_simplify_path(const char *path) FAST_FUNC; /* Returns ptr to NUL */ char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC; -#define FAIL_DELAY 3 +#define LOGIN_FAIL_DELAY 3 extern void bb_do_delay(int seconds) FAST_FUNC; extern void change_identity(const struct passwd *pw) FAST_FUNC; extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) NORETURN FAST_FUNC; + +/* Returns $SHELL, getpwuid(getuid())->pw_shell, or DEFAULT_SHELL. + * Note that getpwuid result might need xstrdup'ing + * if there is a possibility of intervening getpwxxx() calls. + */ +const char *get_shell_name(void); + #if ENABLE_SELINUX extern void renew_current_security_context(void) FAST_FUNC; extern void set_current_security_context(security_context_t sid) FAST_FUNC; diff --git a/loginutils/adduser.c b/loginutils/adduser.c index 9d3d9cb4c..0c675caf9 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c @@ -132,7 +132,8 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) } pw.pw_gecos = (char *)"Linux User,,,"; - pw.pw_shell = (char *)DEFAULT_SHELL; + /* We assume that newly created users "inherit" root's shell setting */ + pw.pw_shell = (char *)get_shell_name(); pw.pw_dir = NULL; /* exactly one non-option arg */ diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 1fdb2fb38..9c5405332 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c @@ -316,10 +316,8 @@ static NOINLINE void start_shell_in_child(const char* tty_name) int pid = xvfork(); if (pid == 0) { struct termios termchild; - char *shell = getenv("SHELL"); + const char *shell = get_shell_name(); - if (!shell) - shell = (char *) DEFAULT_SHELL; signal(SIGHUP, SIG_IGN); // set tty as a controlling tty setsid(); diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 163e15dce..16d7fdf69 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -20,8 +20,9 @@ static void edit_file(const struct passwd *pas, const char *file) { const char *ptr; - int pid = xvfork(); + pid_t pid; + pid = xvfork(); if (pid) { /* parent */ wait4pid(pid); return; @@ -30,7 +31,7 @@ static void edit_file(const struct passwd *pas, const char *file) /* CHILD - change user and run editor */ /* initgroups, setgid, setuid */ change_identity(pas); - setup_environment(DEFAULT_SHELL, + setup_environment(pas->pw_shell, SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP, pas); ptr = getenv("VISUAL"); @@ -41,7 +42,7 @@ static void edit_file(const struct passwd *pas, const char *file) } BB_EXECLP(ptr, ptr, file, NULL); - bb_perror_msg_and_die("exec %s", ptr); + bb_perror_msg_and_die("can't execute '%s'", ptr); } static int open_as_user(const struct passwd *pas, const char *file) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index c7b560bf8..7706a84b7 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -106,6 +106,7 @@ enum { struct globals { char **my_environ; const char *startup_PATH; + char *shell; } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) #define INIT_G() do { } while (0) @@ -986,11 +987,10 @@ static int doit(char *str) fflush_all(); child = vfork(); - switch (child) { - case -1: /* failure */ + if (child < 0) /* failure */ return 0; - case 0: /* child */ - execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, (char *) NULL, G.my_environ); + if (child == 0) { /* child */ + execle(G.shell, G.shell, "-c", str, (char *) NULL, G.my_environ); _exit(127); } safe_waitpid(child, &status, 0); @@ -1165,6 +1165,7 @@ int ifupdown_main(int argc UNUSED_PARAM, char **argv) INIT_G(); G.startup_PATH = getenv("PATH"); + G.shell = xstrdup(get_shell_name()); cmds = iface_down; if (applet_name[2] == 'u') { diff --git a/runit/svlogd.c b/runit/svlogd.c index cfa20a773..b0ba21bb6 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -187,6 +187,7 @@ struct globals { unsigned nearest_rotate; void* (*memRchr)(const void *, int, size_t); + char *shell; smallint exitasap; smallint rotateasap; @@ -382,6 +383,9 @@ static void processorstart(struct logdir *ld) /* vfork'ed child trashes this byte, save... */ sv_ch = ld->fnsave[26]; + if (!G.shell) + G.shell = xstrdup(get_shell_name()); + while ((pid = vfork()) == -1) pause2cannot("vfork for processor", ld->name); if (!pid) { @@ -416,8 +420,7 @@ static void processorstart(struct logdir *ld) fd = xopen("newstate", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); xmove_fd(fd, 5); -// getenv("SHELL")? - execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c", ld->processor, (char*) NULL); + execl(G.shell, G.shell, "-c", ld->processor, (char*) NULL); bb_perror_msg_and_die(FATAL"can't %s processor %s", "run", ld->name); } ld->fnsave[26] = sv_ch; /* ...restore */ diff --git a/util-linux/script.c b/util-linux/script.c index b9317fc7c..47efc4526 100644 --- a/util-linux/script.c +++ b/util-linux/script.c @@ -65,10 +65,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) if (!(opt & OPT_q)) { printf("Script started, file is %s\n", fname); } - shell = getenv("SHELL"); - if (shell == NULL) { - shell = DEFAULT_SHELL; - } + shell = get_shell_name(); pty = xgetpty(pty_line); -- cgit v1.2.3-55-g6feb From f8416dc6f64244223fbcb20fe504b7a9a764e698 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Mar 2011 21:02:42 +0100 Subject: forgot to add libbb/get_shell_name.c Signed-off-by: Denys Vlasenko --- libbb/get_shell_name.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 libbb/get_shell_name.c diff --git a/libbb/get_shell_name.c b/libbb/get_shell_name.c new file mode 100644 index 000000000..c930afd94 --- /dev/null +++ b/libbb/get_shell_name.c @@ -0,0 +1,25 @@ +/* + * Copyright 2011, Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ + +//kbuild:lib-y += get_shell_name.o + +#include "libbb.h" + +const char *get_shell_name(void) +{ + struct passwd *pw; + char *shell; + + shell = getenv("SHELL"); + if (shell && shell[0]) + return shell; + + pw = getpwuid(getuid()); + if (pw && pw->pw_shell && pw->pw_shell[0]) + return pw->pw_shell; + + return DEFAULT_SHELL; +} -- cgit v1.2.3-55-g6feb From 7d4e7a27aface177b6f6120132cdd6fd7fd371f9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Mar 2011 21:07:05 +0100 Subject: s/FAIL_DELAY/LOGIN_FAIL_DELAY/ Signed-off-by: Denys Vlasenko --- loginutils/login.c | 2 +- loginutils/passwd.c | 2 +- loginutils/sulogin.c | 4 ++-- loginutils/vlock.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/loginutils/login.c b/loginutils/login.c index 028a099b6..5eeb0826d 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -355,7 +355,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) #endif /* ENABLE_PAM */ auth_failed: opt &= ~LOGIN_OPT_f; - bb_do_delay(FAIL_DELAY); + bb_do_delay(LOGIN_FAIL_DELAY); /* TODO: doesn't sound like correct English phrase to me */ puts("Login incorrect"); if (++count == 3) { diff --git a/loginutils/passwd.c b/loginutils/passwd.c index 728e61867..f3928cecc 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -28,7 +28,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, int algo) if (strcmp(encrypted, pw->pw_passwd) != 0) { syslog(LOG_WARNING, "incorrect password for %s", pw->pw_name); - bb_do_delay(FAIL_DELAY); + bb_do_delay(LOGIN_FAIL_DELAY); puts("Incorrect password"); goto err_ret; } diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 307536721..0e5b59433 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -88,8 +88,8 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) if (r == 0) { break; } - bb_do_delay(FAIL_DELAY); - bb_error_msg("login incorrect"); + bb_do_delay(LOGIN_FAIL_DELAY); + bb_info_msg("Login incorrect"); } memset(cp, 0, strlen(cp)); // signal(SIGALRM, SIG_DFL); diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 0d0f3bca2..3299afa50 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c @@ -101,8 +101,8 @@ int vlock_main(int argc UNUSED_PARAM, char **argv) if (correct_password(pw)) { break; } - bb_do_delay(FAIL_DELAY); - puts("Password incorrect"); + bb_do_delay(LOGIN_FAIL_DELAY); + puts("Incorrect password"); } #ifdef __linux__ -- cgit v1.2.3-55-g6feb From 48b6f59e19613d497148ecf1033ce75c74baa8a7 Mon Sep 17 00:00:00 2001 From: Pascal Bellard Date: Fri, 11 Mar 2011 23:40:27 +0100 Subject: chsum: fix Signed-off-by: Pascal Bellard Signed-off-by: Denys Vlasenko --- coreutils/cksum.c | 1 + 1 file changed, 1 insertion(+) diff --git a/coreutils/cksum.c b/coreutils/cksum.c index 7a37e6add..53fb87a78 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c @@ -38,6 +38,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) #define read_buf bb_common_bufsiz1 while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) { + length += bytes_read; crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); } close(fd); -- cgit v1.2.3-55-g6feb From 8345b2bd5ea28bd8d07886e615b9c2d5ab35477d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 12 Mar 2011 02:19:50 +0100 Subject: libbb: make warning go away Signed-off-by: Denys Vlasenko --- libbb/progress.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libbb/progress.c b/libbb/progress.c index df43dad5c..372feb0c2 100644 --- a/libbb/progress.c +++ b/libbb/progress.c @@ -127,10 +127,12 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, /* 32-bit CPU and 64-bit off_t. * Use a 40-bit shift, it is easier to do on 32-bit CPU. */ - if (totalsize >= (uoff_t)(1ULL << 54)) { - totalsize = (uint32_t)(totalsize >> 32) >> 8; - beg_size = (uint32_t)(beg_size >> 32) >> 8; - transferred = (uint32_t)(transferred >> 32) >> 8; +/* ONE suppresses "warning: shift count >= width of type" */ +#define ONE (sizeof(off_t) > 4) + if (totalsize >= (uoff_t)(1ULL << 54*ONE)) { + totalsize = (uint32_t)(totalsize >> 32*ONE) >> 8; + beg_size = (uint32_t)(beg_size >> 32*ONE) >> 8; + transferred = (uint32_t)(transferred >> 32*ONE) >> 8; kiloscale = 4; } } -- cgit v1.2.3-55-g6feb From ea684c6aaf23ead57fac74c3ceaa651c1ae625ec Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 12 Mar 2011 03:12:36 +0100 Subject: ls: fix handling of symlinks by option -1 Signed-off-by: Denys Vlasenko --- coreutils/ls.c | 6 ++++-- testsuite/ls.tests | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/coreutils/ls.c b/coreutils/ls.c index 19c868ca4..847fdec07 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -1,6 +1,5 @@ /* vi: set sw=4 ts=4: */ /* - * tiny-ls.c version 0.1.0: A minimalist 'ls' * Copyright (C) 1996 Brian Candler * * Licensed under GPLv2 or later, see file LICENSE in this source tree. @@ -1145,7 +1144,10 @@ int ls_main(int argc UNUSED_PARAM, char **argv) do { cur = my_stat(*argv, *argv, /* follow links on command line unless -l, -s or -F: */ - !((all_fmt & (STYLE_LONG|LIST_BLOCKS)) || (option_mask32 & OPT_F)) + !((all_fmt & STYLE_MASK) == STYLE_LONG + || (all_fmt & LIST_BLOCKS) + || (option_mask32 & OPT_F) + ) /* ... or if -H: */ || (option_mask32 & OPT_H) ); diff --git a/testsuite/ls.tests b/testsuite/ls.tests index 1669579e7..e2284658d 100755 --- a/testsuite/ls.tests +++ b/testsuite/ls.tests @@ -251,6 +251,16 @@ test x"$CONFIG_UNICODE_SUPPORT" = x"y" \ 0110_5.3.2__U+FFFF_=_ef_bf_bf_=_"?"_______________________________________| ' "" "" +rm -rf ls.testdir 2>/dev/null +mkdir ls.testdir || exit 1 + +# testing "test name" "command" "expected result" "file input" "stdin" + +testing "ls symlink_to_dir" \ +"touch ls.testdir/A ls.testdir/B; ln -s ls.testdir ls.link; ls ls.link; ls -1 ls.link/; ls -1 ls.link; rm -f ls.link" \ +"A\nB\nA\nB\nA\nB\n" \ +"" "" + # Clean up rm -rf ls.testdir 2>/dev/null -- cgit v1.2.3-55-g6feb From 9ac5596a5154d789964150737a784dc4db98265b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 12 Mar 2011 05:37:54 +0100 Subject: udhcpc: emit "correct" secs field In theory, sending secs set to constant zero should be ok too. But some bleeping servers can actually be configured to answer ONLY if secs is bigger than a preset value (!!) http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/bootpd.8.html grep for "reply_threshold_seconds" function old new delta udhcpc_main 2573 2623 +50 Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 14 ++++++++++++++ networking/udhcp/dhcpc.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index e9a841204..ca82d37e6 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -407,11 +407,19 @@ static ALWAYS_INLINE uint32_t random_xid(void) /* Initialize the packet with the proper defaults */ static void init_packet(struct dhcp_packet *packet, char type) { + uint16_t secs; + /* Fill in: op, htype, hlen, cookie fields; message type option: */ udhcp_init_header(packet, type); packet->xid = random_xid(); + client_config.last_secs = monotonic_sec(); + if (client_config.first_secs == 0) + client_config.first_secs = client_config.last_secs; + secs = client_config.last_secs - client_config.first_secs; + packet->secs = htons(secs); + memcpy(packet->chaddr, client_config.client_mac, 6); if (client_config.clientid) udhcp_add_binary_option(packet, client_config.clientid); @@ -848,6 +856,7 @@ static void change_listen_mode(int new_mode) /* else LISTEN_NONE: sockfd stays closed */ } +/* Called only on SIGUSR1 */ static void perform_renew(void) { bb_info_msg("Performing a DHCP renew"); @@ -1260,6 +1269,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) case BOUND: /* 1/2 lease passed, enter renewing state */ state = RENEWING; + client_config.first_secs = 0; /* make secs field count from 0 */ change_listen_mode(LISTEN_KERNEL); log1("Entering renew state"); /* fall right through */ @@ -1299,6 +1309,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) bb_info_msg("Lease lost, entering init state"); udhcp_run_script(NULL, "deconfig"); state = INIT_SELECTING; + client_config.first_secs = 0; /* make secs field count from 0 */ /*timeout = 0; - already is */ packet_num = 0; continue; @@ -1315,6 +1326,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) /* note: udhcp_sp_read checks FD_ISSET before reading */ switch (udhcp_sp_read(&rfds)) { case SIGUSR1: + client_config.first_secs = 0; /* make secs field count from 0 */ perform_renew(); if (state == RENEW_REQUESTED) goto case_RENEW_REQUESTED; @@ -1446,6 +1458,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) udhcp_run_script(NULL, "deconfig"); change_listen_mode(LISTEN_RAW); state = INIT_SELECTING; + client_config.first_secs = 0; /* make secs field count from 0 */ requested_ip = 0; timeout = tryagain_timeout; packet_num = 0; @@ -1493,6 +1506,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) change_listen_mode(LISTEN_RAW); sleep(3); /* avoid excessive network traffic */ state = INIT_SELECTING; + client_config.first_secs = 0; /* make secs field count from 0 */ requested_ip = 0; timeout = 0; packet_num = 0; diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 9ef053a1b..2b3599120 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h @@ -21,6 +21,9 @@ struct client_config_t { uint8_t *vendorclass; /* Optional vendor class-id to use */ uint8_t *hostname; /* Optional hostname to use */ uint8_t *fqdn; /* Optional fully qualified domain name to use */ + + uint16_t first_secs; + uint16_t last_secs; } FIX_ALIASING; /* server_config sits in 1st half of bb_common_bufsiz1 */ -- cgit v1.2.3-55-g6feb From 5c942713b7369d239b1303c0cfc7049d898564d4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 12 Mar 2011 06:08:28 +0100 Subject: busybox: fail if --install is not given an absolute path Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 69cac2e9a..fc84d36ec 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -721,10 +721,9 @@ static int busybox_main(char **argv) * In such case, better use argv[0] as symlink target * if it is a full path name. */ - if (argv[0][0] == '/') - busybox = argv[0]; - else - busybox = bb_busybox_exec_path; + if (argv[0][0] != '/') + bb_error_msg_and_die("'%s' is not an absolute path", argv[0]); + busybox = argv[0]; } /* busybox --install [-s] [DIR]: * -s: make symlinks -- cgit v1.2.3-55-g6feb From cf8b55c40b65a30a6b397f66658d83f0f31f4ed1 Mon Sep 17 00:00:00 2001 From: Pere Orga Date: Sat, 12 Mar 2011 18:13:15 +0100 Subject: pwdx: new applet function old new delta pwdx_main - 197 +197 packed_usage 28237 28261 +24 applet_names 2391 2396 +5 applet_main 1392 1396 +4 applet_nameofs 696 698 +2 applet_install_loc 174 175 +1 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 5/0 up/down: 233/0) Total: 233 bytes Signed-off-by: Pere Orga Signed-off-by: Denys Vlasenko --- procps/pwdx.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 procps/pwdx.c diff --git a/procps/pwdx.c b/procps/pwdx.c new file mode 100644 index 000000000..781810488 --- /dev/null +++ b/procps/pwdx.c @@ -0,0 +1,60 @@ +/* vi: set sw=4 ts=4: */ +/* + * pwdx implementation for busybox + * + * Copyright (c) 2004 Nicholas Miell + * ported from procps by Pere Orga 2011 + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ + +//config:config PWDX +//config: bool "pwdx" +//config: default y +//config: help +//config: Report current working directory of a process + +//applet:IF_PWDX(APPLET(pwdx, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_PWDX) += pwdx.o + +//usage:#define pwdx_trivial_usage +//usage: "PID..." +//usage:#define pwdx_full_usage "\n\n" +//usage: "Show current directory for PIDs\n" + +#include "libbb.h" + +int pwdx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int pwdx_main(int argc UNUSED_PARAM, char **argv) +{ + opt_complementary = "-1"; + getopt32(argv, ""); + argv += optind; + + do { + char buf[sizeof("/proc/%u/cwd") + sizeof(int)*3]; + unsigned pid; + char *s; + char *arg = *argv; + + // Allowed on the command line: + // /proc/NUM + // NUM + if (strncmp(arg, "/proc/", 6) == 0) + arg += 6; + + pid = bb_strtou(arg, NULL, 10); + if (errno) + bb_error_msg_and_die("invalid process id: '%s'", arg); + + sprintf(buf, "/proc/%u/cwd", pid); + + s = xmalloc_readlink(buf); + // "pwdx /proc/1" says "/proc/1: DIR", not "1: DIR" + printf("%s: %s\n", *argv, s ? s : strerror(errno == ENOENT ? ESRCH : errno)); + free(s); + } while (*++argv); + + return EXIT_SUCCESS; +} -- cgit v1.2.3-55-g6feb From c2fda8642dc917e3a95f1a556b0876249a1bb321 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Mar 2011 06:28:28 +0100 Subject: mount: add a test for bind+rshared Signed-off-by: Denys Vlasenko --- testsuite/mount.tests | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/testsuite/mount.tests b/testsuite/mount.tests index d3d2400e8..58eeb2ec5 100755 --- a/testsuite/mount.tests +++ b/testsuite/mount.tests @@ -20,7 +20,7 @@ if test x"$CONFIG_MKFS_MINIX" != x"y" \ exit 0 fi -testdir=$PWD/mount.testdir +testdir="$PWD/mount.testdir" dd if=/dev/zero of=mount.image1m count=1 bs=1M 2>/dev/null || { echo "dd error"; exit 1; } mkfs.minix -v mount.image1m >/dev/null 2>&1 || { echo "mkfs.minix error"; exit 1; } @@ -44,4 +44,41 @@ umount -d "$testdir" rmdir "$testdir" rm mount.image1m + +# Bug: mount.shared1 directory shows no files (has to show files a and b) +testing "mount bind+rshared" "\ +mkdir -p mount.dir mount.shared1 mount.shared2 +touch mount.dir/a mount.dir/b + +mount --bind mount.shared1 mount.shared1 2>&1 +mount --make-rshared mount.shared1 2>&1 +mount --bind mount.shared2 mount.shared2 2>&1 +mount --make-rshared mount.shared2 2>&1 + +mount --bind mount.shared2 mount.shared1 2>&1 +mount --bind mount.dir mount.shared2 2>&1 + +ls -R mount.dir mount.shared1 mount.shared2 2>&1 + +umount mount.dir mount.shared1 mount.shared2 2>/dev/null +umount mount.dir mount.shared1 mount.shared2 2>/dev/null +umount mount.dir mount.shared1 mount.shared2 2>/dev/null +rm -f mount.dir/a mount.dir/b mount.dir/c +rmdir mount.dir mount.shared1 mount.shared2 +" \ +"\ +mount.dir: +a +b + +mount.shared1: +a +b + +mount.shared2: +a +b +" \ + "" "" + exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From 625f218d43ee280da52bb7087236ae5807383082 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Mar 2011 00:29:37 +0100 Subject: wget: fix fname_out usage wrt redirects Signed-off-by: Denys Vlasenko --- networking/wget.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 9d50437d8..bc922836a 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -604,8 +604,14 @@ 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); + } + } } #if ENABLE_FEATURE_WGET_STATUSBAR G.curfile = bb_get_last_path_component_nostrip(G.fname_out); -- cgit v1.2.3-55-g6feb From e2e55b0eb5e3518702f31b122acd9894630b0368 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Mar 2011 00:37:05 +0100 Subject: wget: move help text to .c file Signed-off-by: Denys Vlasenko --- include/usage.src.h | 25 ------------------------- networking/wget.c | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/usage.src.h b/include/usage.src.h index 5a725e305..29f7b2110 100644 --- a/include/usage.src.h +++ b/include/usage.src.h @@ -4067,31 +4067,6 @@ INSERT "\n" \ "\nUse 500ms to specify period in milliseconds" \ -#define wget_trivial_usage \ - IF_FEATURE_WGET_LONG_OPTIONS( \ - "[-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document FILE]\n" \ - " [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]\n" \ - " [--no-check-certificate] [-U|--user-agent AGENT]" \ - IF_FEATURE_WGET_TIMEOUT("[-T SEC] ") " URL" \ - ) \ - IF_NOT_FEATURE_WGET_LONG_OPTIONS( \ - "[-csq] [-O FILE] [-Y on/off] [-P DIR] [-U AGENT]" \ - IF_FEATURE_WGET_TIMEOUT("[-T SEC] ") " URL" \ - ) -#define wget_full_usage "\n\n" \ - "Retrieve files via HTTP or FTP\n" \ - "\nOptions:" \ - "\n -s Spider mode - only check file existence" \ - "\n -c Continue retrieval of aborted transfer" \ - "\n -q Quiet" \ - "\n -P DIR Save to DIR (default .)" \ - IF_FEATURE_WGET_TIMEOUT( \ - "\n -T SEC Network read timeout is SEC seconds" \ - ) \ - "\n -O FILE Save to FILE ('-' for stdout)" \ - "\n -U STR Use STR for User-Agent header" \ - "\n -Y Use proxy ('on' or 'off')" \ - #define which_trivial_usage \ "[COMMAND]..." #define which_full_usage "\n\n" \ diff --git a/networking/wget.c b/networking/wget.c index bc922836a..c22a76b97 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -8,6 +8,32 @@ * Copyright (C) 2010 Bradley M. Kuhn * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2. */ + +//usage:#define wget_trivial_usage +//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..." +//usage: ) +//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS( +//usage: "[-csq] [-O FILE] [-Y on/off] [-P DIR] [-U AGENT]" +//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." +//usage: ) +//usage:#define wget_full_usage "\n\n" +//usage: "Retrieve files via HTTP or FTP\n" +//usage: "\nOptions:" +//usage: "\n -s Spider mode - only check file existence" +//usage: "\n -c Continue retrieval of aborted transfer" +//usage: "\n -q Quiet" +//usage: "\n -P DIR Save to DIR (default .)" +//usage: IF_FEATURE_WGET_TIMEOUT( +//usage: "\n -T SEC Network read timeout is SEC seconds" +//usage: ) +//usage: "\n -O FILE Save to FILE ('-' for stdout)" +//usage: "\n -U STR Use STR for User-Agent header" +//usage: "\n -Y Use proxy ('on' or 'off')" + #include "libbb.h" //#define log_io(...) bb_error_msg(__VA_ARGS__) -- cgit v1.2.3-55-g6feb From 32176ccec4eb1a3bc26b0217fa8d23f6ff44fab8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Mar 2011 05:07:43 +0100 Subject: init: fix a case where execv's 1st arg was wrong Signed-off-by: Denys Vlasenko --- init/init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/init/init.c b/init/init.c index 586e34a18..ff9dc06a4 100644 --- a/init/init.c +++ b/init/init.c @@ -414,6 +414,7 @@ static void init_exec(const char *command) char *word, *next; int i = 0; next = strcpy(buf, command - dash); /* command including "-" */ + command = next + dash; while ((word = strsep(&next, " \t")) != NULL) { if (*word != '\0') { /* not two spaces/tabs together? */ cmd[i] = word; -- cgit v1.2.3-55-g6feb From b0e8ced3589c601ad5c15e74d6f82b1928e1eb8f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Mar 2011 12:36:35 +0100 Subject: ln: explain why we use xstrdup Signed-off-by: Denys Vlasenko --- coreutils/ln.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/coreutils/ln.c b/coreutils/ln.c index ddad120d1..6da290c11 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c @@ -40,8 +40,12 @@ int ln_main(int argc, char **argv) last = argv[argc - 1]; argv += optind; - if (argc == optind + 1) { + if (!argv[1]) { + /* "ln PATH/TO/FILE" -> "ln PATH/TO/FILE FILE" */ *--argv = last; + /* xstrdup is needed: "ln -s PATH/TO/FILE/" is equivalent to + * "ln -s PATH/TO/FILE/ FILE", not "ln -s PATH/TO/FILE FILE" + */ last = bb_get_last_path_component_strip(xstrdup(last)); } -- cgit v1.2.3-55-g6feb From beea5a70c34bdcf2b02c37e6f56d2efcbd90fedb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 22 Mar 2011 06:54:36 +0100 Subject: mesg: make group/all writability configurable Signed-off-by: Denys Vlasenko --- init/mesg.c | 60 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/init/mesg.c b/init/mesg.c index 676ca2e24..8489e621c 100644 --- a/init/mesg.c +++ b/init/mesg.c @@ -7,16 +7,28 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -//applet:IF_MESG(APPLET(mesg, BB_DIR_USR_BIN, BB_SUID_DROP)) - -//kbuild:lib-$(CONFIG_MESG) += mesg.o - //config:config MESG //config: bool "mesg" //config: default y //config: help //config: Mesg controls access to your terminal by others. It is typically //config: used to allow or disallow other users to write to your terminal +//config: +//config:config FEATURE_MESG_ENABLE_ONLY_GROUP +//config: bool "Enable writing to tty only by group, not by everybody" +//config: default y +//config: depends on MESG +//config: help +//config: Usually, ttys are owned by group "tty", and "write" tool is +//config: setgid to this group. This way, "mesg y" only needs to enable +//config: "write by owning group" bit in tty mode. +//config: +//config: If you set this option to N, "mesg y" will enable writing +//config: by anybody at all. This is not recommended. + +//applet:IF_MESG(APPLET(mesg, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_MESG) += mesg.o //usage:#define mesg_trivial_usage //usage: "[y|n]" @@ -27,7 +39,7 @@ #include "libbb.h" -#ifdef USE_TTY_GROUP +#if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP #define S_IWGRP_OR_S_IWOTH S_IWGRP #else #define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH) @@ -37,30 +49,28 @@ int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mesg_main(int argc UNUSED_PARAM, char **argv) { struct stat sb; - const char *tty; + mode_t m; char c = 0; argv++; - if (!argv[0] - || (!argv[1] && ((c = argv[0][0]) == 'y' || c == 'n')) + if (argv[0] + && (argv[1] || ((c = argv[0][0]) != 'y' && c != 'n')) ) { - tty = xmalloc_ttyname(STDERR_FILENO); - if (tty == NULL) { - tty = "ttyname"; - } else if (stat(tty, &sb) == 0) { - mode_t m; - if (c == 0) { - puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n"); - return EXIT_SUCCESS; - } - m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH - : sb.st_mode & ~(S_IWGRP|S_IWOTH); - if (chmod(tty, m) == 0) { - return EXIT_SUCCESS; - } - } - bb_simple_perror_msg_and_die(tty); + bb_show_usage(); + } + + if (!isatty(STDERR_FILENO)) + bb_error_msg_and_die("not a tty"); + + xfstat(STDERR_FILENO, &sb, "stderr"); + if (c == 0) { + puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n"); + return EXIT_SUCCESS; } - bb_show_usage(); + m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH + : sb.st_mode & ~(S_IWGRP|S_IWOTH); + if (fchmod(STDERR_FILENO, m) != 0) + bb_perror_nomsg_and_die(); + return EXIT_SUCCESS; } -- cgit v1.2.3-55-g6feb From f922154f65163bbab164ee377200b6412a367dd2 Mon Sep 17 00:00:00 2001 From: Alexey Soloviev Date: Wed, 16 Mar 2011 10:39:46 +0300 Subject: dd: free allocated memory if CLEANUP enabled Signed-off-by: Alexey Soloviev Signed-off-by: Denys Vlasenko --- coreutils/dd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/coreutils/dd.c b/coreutils/dd.c index 347a19454..9973a145b 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c @@ -397,5 +397,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv) out_status: dd_output_status(0); + if (ENABLE_FEATURE_CLEAN_UP) { + free(obuf); + if (flags & FLAG_TWOBUFS) + free(ibuf); + } + return exitcode; } -- cgit v1.2.3-55-g6feb From cf9074b54bfb5a325ce59127b7afe1e892223a1c Mon Sep 17 00:00:00 2001 From: Ryan Phillips Date: Tue, 22 Mar 2011 18:27:21 +0100 Subject: login: set PAM RHOST Signed-off-by: Ryan Phillips Signed-off-by: Denys Vlasenko --- loginutils/login.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/loginutils/login.c b/loginutils/login.c index 5eeb0826d..ce0d1741f 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -278,6 +278,14 @@ int login_main(int argc UNUSED_PARAM, char **argv) failed_msg = "set_item(TTY)"; goto pam_auth_failed; } + /* set RHOST */ + if (opt_host) { + pamret = pam_set_item(pamh, PAM_RHOST, opt_host); + if (pamret != PAM_SUCCESS) { + failed_msg = "set_item(RHOST)"; + goto pam_auth_failed; + } + } pamret = pam_authenticate(pamh, 0); if (pamret != PAM_SUCCESS) { failed_msg = "authenticate"; -- cgit v1.2.3-55-g6feb From 7f4b769c42f3773ff2e2e749547291dcb7e85d01 Mon Sep 17 00:00:00 2001 From: Vitaly Magerya Date: Tue, 22 Mar 2011 20:14:26 +0100 Subject: don't call freeaddinfo(NULL) Signed-off-by: Vitaly Magerya Signed-off-by: Denys Vlasenko --- libbb/inet_common.c | 16 +++++++++------- libbb/xconnect.c | 5 +++-- networking/nslookup.c | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libbb/inet_common.c b/libbb/inet_common.c index 6f585ebd9..207720e96 100644 --- a/libbb/inet_common.c +++ b/libbb/inet_common.c @@ -164,17 +164,17 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne int FAST_FUNC INET6_resolve(const char *name, struct sockaddr_in6 *sin6) { - struct addrinfo req, *ai; + struct addrinfo req, *ai = NULL; int s; - memset(&req, '\0', sizeof req); + memset(&req, 0, sizeof(req)); req.ai_family = AF_INET6; s = getaddrinfo(name, NULL, &req, &ai); - if (s) { + if (s != 0) { bb_error_msg("getaddrinfo: %s: %d", name, s); return -1; } - memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); + memcpy(sin6, ai->ai_addr, sizeof(*sin6)); freeaddrinfo(ai); return 0; } @@ -209,9 +209,11 @@ char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric) return xstrdup("*"); } - s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), - name, sizeof(name), NULL, 0, 0); - if (s) { + s = getnameinfo((struct sockaddr *) sin6, sizeof(*sin6), + name, sizeof(name), + /*serv,servlen:*/ NULL, 0, + 0); + if (s != 0) { bb_error_msg("getnameinfo failed"); return NULL; } diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 3a6585caa..127e2a5fc 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -255,7 +255,7 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;) memset(&hint, 0 , sizeof(hint)); hint.ai_family = af; - /* Needed. Or else we will get each address thrice (or more) + /* Need SOCK_STREAM, or else we get each address thrice (or more) * for each possible socket type (tcp,udp,raw...): */ hint.ai_socktype = SOCK_STREAM; hint.ai_flags = ai_flags & ~DIE_ON_ERROR; @@ -285,7 +285,8 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;) set_port: set_nport(r, htons(port)); ret: - freeaddrinfo(result); + if (result) + freeaddrinfo(result); return r; } #if !ENABLE_FEATURE_IPV6 diff --git a/networking/nslookup.c b/networking/nslookup.c index dcac7379e..67fc01547 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c @@ -66,7 +66,7 @@ static int print_host(const char *hostname, const char *header) // hint.ai_flags = AI_CANONNAME; rc = getaddrinfo(hostname, NULL /*service*/, &hint, &result); - if (!rc) { + if (rc == 0) { struct addrinfo *cur = result; unsigned cnt = 0; @@ -94,7 +94,7 @@ static int print_host(const char *hostname, const char *header) bb_error_msg("can't resolve '%s'", hostname); #endif } - if (ENABLE_FEATURE_CLEAN_UP) + if (ENABLE_FEATURE_CLEAN_UP && result) freeaddrinfo(result); return (rc != 0); } -- cgit v1.2.3-55-g6feb From 20704f066250744c0c2b84920c27d0fd0aa9e935 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 23 Mar 2011 17:59:27 +0100 Subject: ash,hush: recheck LANG before every line input Signed-off-by: Denys Vlasenko --- include/unicode.h | 4 ++++ libbb/unicode.c | 28 +++++++++++++++++----------- shell/ash.c | 23 +++++++++++++++-------- shell/hush.c | 25 ++++++++++++++++--------- 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/include/unicode.h b/include/unicode.h index dee02e777..0317a2151 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -27,6 +27,7 @@ enum { # define unicode_strwidth(string) strlen(string) # define unicode_status UNICODE_OFF # define init_unicode() ((void)0) +# define reinit_unicode(LANG) ((void)0) #else @@ -67,6 +68,7 @@ char* FAST_FUNC unicode_conv_to_printable_fixedwidth(/*uni_stat_t *stats,*/ cons extern uint8_t unicode_status; void init_unicode(void) FAST_FUNC; +void reinit_unicode(const char *LANG) FAST_FUNC; # else @@ -75,9 +77,11 @@ void init_unicode(void) FAST_FUNC; # if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV # define unicode_status UNICODE_ON # define init_unicode() ((void)0) +# define reinit_unicode(LANG) ((void)0) # else extern uint8_t unicode_status; void init_unicode(void) FAST_FUNC; +void reinit_unicode(const char *LANG) FAST_FUNC; # endif # undef MB_CUR_MAX diff --git a/libbb/unicode.c b/libbb/unicode.c index 08a4c7427..d01efd9a2 100644 --- a/libbb/unicode.c +++ b/libbb/unicode.c @@ -23,37 +23,43 @@ uint8_t unicode_status; /* Unicode support using libc locale support. */ -void FAST_FUNC init_unicode(void) +void FAST_FUNC reinit_unicode(const char *LANG UNUSED_PARAM) { static const char unicode_0x394[] = { 0xce, 0x94, 0 }; size_t width; - if (unicode_status != UNICODE_UNKNOWN) - return; +//TODO: call setlocale(LC_ALL, LANG) here? + /* In unicode, this is a one character string */ // can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused width = mbstowcs(NULL, unicode_0x394, INT_MAX); unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF); } +void FAST_FUNC init_unicode(void) +{ + if (unicode_status == UNICODE_UNKNOWN) + reinit_unicode(NULL /*getenv("LANG")*/); +} + #else /* Homegrown Unicode support. It knows only C and Unicode locales. */ # if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV -void FAST_FUNC init_unicode(void) +void FAST_FUNC reinit_unicode(const char *LANG) { - char *lang; - - if (unicode_status != UNICODE_UNKNOWN) - return; - unicode_status = UNICODE_OFF; - lang = getenv("LANG"); - if (!lang || !(strstr(lang, ".utf") || strstr(lang, ".UTF"))) + if (!LANG || !(strstr(LANG, ".utf") || strstr(LANG, ".UTF"))) return; unicode_status = UNICODE_ON; } + +void FAST_FUNC init_unicode(void) +{ + if (unicode_status == UNICODE_UNKNOWN) + reinit_unicode(getenv("LANG")); +} # endif static size_t wcrtomb_internal(char *s, wchar_t wc) diff --git a/shell/ash.c b/shell/ash.c index 0baf7c8e5..1520c5ae5 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -36,12 +36,14 @@ #define JOBS ENABLE_ASH_JOB_CONTROL -#include "busybox.h" /* for applet_names */ #include #include #include #include +#include "busybox.h" /* for applet_names */ +#include "unicode.h" + #include "shell_common.h" #if ENABLE_SH_MATH_SUPPORT # include "math.h" @@ -72,13 +74,6 @@ # error "Do not even bother, ash will not run on NOMMU machine" #endif -//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP)) -//applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh)) -//applet:IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, bash)) - -//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o -//kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o - //config:config ASH //config: bool "ash" //config: default y @@ -190,6 +185,13 @@ //config: variable each time it is displayed. //config: +//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh)) +//applet:IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, bash)) + +//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o +//kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o + /* ============ Hash table sizes. Configurable. */ @@ -9626,6 +9628,11 @@ preadfd(void) # if ENABLE_FEATURE_TAB_COMPLETION line_input_state->path_lookup = pathval(); # endif + /* Unicode support should be activated even if LANG is set + * _during_ shell execution, not only if it was set when + * shell was started. Therefore, re-check LANG every time: + */ + reinit_unicode(lookupvar("LANG")); nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout); if (nr == 0) { /* Ctrl+C pressed */ diff --git a/shell/hush.c b/shell/hush.c index 64d5e8587..339f3349a 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -81,7 +81,6 @@ * $ "export" i=`echo 'aaa bbb'`; echo "$i" * aaa */ -#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ #if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ || defined(__APPLE__) \ ) @@ -93,6 +92,8 @@ # include #endif +#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ +#include "unicode.h" #include "shell_common.h" #include "math.h" #include "match.h" @@ -105,14 +106,6 @@ # define PIPE_BUF 4096 /* amount of buffering in a pipe */ #endif -//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP)) -//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP)) -//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh)) -//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash)) - -//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o -//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o - //config:config HUSH //config: bool "hush" //config: default y @@ -249,6 +242,14 @@ //config: msh is deprecated and will be removed, please migrate to hush. //config: +//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh)) +//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash)) + +//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o +//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o + /* -i (interactive) and -s (read stdin) are also accepted, * but currently do nothing, therefore aren't shown in help. * NOMMU-specific options are not meant to be used by users, @@ -1906,6 +1907,12 @@ static void get_user_input(struct in_str *i) /* Enable command line editing only while a command line * is actually being read */ do { + /* Unicode support should be activated even if LANG is set + * _during_ shell execution, not only if it was set when + * shell was started. Therefore, re-check LANG every time: + */ + reinit_unicode(get_local_var_value("LANG")); + G.flag_SIGINT = 0; /* buglet: SIGINT will not make new prompt to appear _at once_, * only after . (^C will work) */ -- cgit v1.2.3-55-g6feb From 68d5cb5dacbc80347119ac9cff365e5f04105ef1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Mar 2011 02:50:03 +0100 Subject: hush: fix a case where return in sourced file has no effect Signed-off-by: Denys Vlasenko --- shell/hush.c | 4 ++++ shell/hush_test/hush-misc/return1.right | 1 + shell/hush_test/hush-misc/return1.tests | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 shell/hush_test/hush-misc/return1.right create mode 100755 shell/hush_test/hush-misc/return1.tests diff --git a/shell/hush.c b/shell/hush.c index 339f3349a..8154ac47b 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -5554,6 +5554,10 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger) debug_printf_exec("parse_and_run_stream: run_and_free_list\n"); run_and_free_list(pipe_list); empty = 0; +#if ENABLE_HUSH_FUNCTIONS + if (G.flag_return_in_progress == 1) + break; +#endif } } diff --git a/shell/hush_test/hush-misc/return1.right b/shell/hush_test/hush-misc/return1.right new file mode 100644 index 000000000..7b24a35ff --- /dev/null +++ b/shell/hush_test/hush-misc/return1.right @@ -0,0 +1 @@ +Ok:0 diff --git a/shell/hush_test/hush-misc/return1.tests b/shell/hush_test/hush-misc/return1.tests new file mode 100755 index 000000000..eeb92ef3f --- /dev/null +++ b/shell/hush_test/hush-misc/return1.tests @@ -0,0 +1,4 @@ +echo "true && return; echo Should not be printed" >return_sourced +. ./return_sourced +rm return_sourced +echo Ok:$? -- cgit v1.2.3-55-g6feb From 3eab24e64a65746ed9fcc5bed3e9a19a489b0573 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Mar 2011 05:25:59 +0100 Subject: hush: make parse errors in sourced file non-fatal in interactive script Signed-off-by: Denys Vlasenko --- shell/hush.c | 97 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/shell/hush.c b/shell/hush.c index 8154ac47b..e4c3a7d77 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1095,17 +1095,10 @@ static void syntax_error_unterm_str(unsigned lineno, const char *s) die_if_script(lineno, "syntax error: unterminated %s", s); } -/* It so happens that all such cases are totally fatal - * even if shell is interactive: EOF while looking for closing - * delimiter. There is nowhere to read stuff from after that, - * it's EOF! The only choice is to terminate. - */ -static void syntax_error_unterm_ch(unsigned lineno, char ch) NORETURN; static void syntax_error_unterm_ch(unsigned lineno, char ch) { char msg[2] = { ch, '\0' }; syntax_error_unterm_str(lineno, msg); - xfunc_die(); } static void syntax_error_unexpected_ch(unsigned lineno, int ch) @@ -3539,39 +3532,40 @@ static int parse_group(o_string *dest, struct parse_context *ctx, #if ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS /* Subroutines for copying $(...) and `...` things */ -static void add_till_backquote(o_string *dest, struct in_str *input, int in_dquote); +static int add_till_backquote(o_string *dest, struct in_str *input, int in_dquote); /* '...' */ -static void add_till_single_quote(o_string *dest, struct in_str *input) +static int add_till_single_quote(o_string *dest, struct in_str *input) { while (1) { int ch = i_getch(input); if (ch == EOF) { syntax_error_unterm_ch('\''); - /*xfunc_die(); - redundant */ + return 0; } if (ch == '\'') - return; + return 1; o_addchr(dest, ch); } } /* "...\"...`..`...." - do we need to handle "...$(..)..." too? */ -static void add_till_double_quote(o_string *dest, struct in_str *input) +static int add_till_double_quote(o_string *dest, struct in_str *input) { while (1) { int ch = i_getch(input); if (ch == EOF) { syntax_error_unterm_ch('"'); - /*xfunc_die(); - redundant */ + return 0; } if (ch == '"') - return; + return 1; if (ch == '\\') { /* \x. Copy both chars. */ o_addchr(dest, ch); ch = i_getch(input); } o_addchr(dest, ch); if (ch == '`') { - add_till_backquote(dest, input, /*in_dquote:*/ 1); + if (!add_till_backquote(dest, input, /*in_dquote:*/ 1)) + return 0; o_addchr(dest, ch); continue; } @@ -3592,12 +3586,12 @@ static void add_till_double_quote(o_string *dest, struct in_str *input) * Example Output * echo `echo '\'TEST\`echo ZZ\`BEST` \TESTZZBEST */ -static void add_till_backquote(o_string *dest, struct in_str *input, int in_dquote) +static int add_till_backquote(o_string *dest, struct in_str *input, int in_dquote) { while (1) { int ch = i_getch(input); if (ch == '`') - return; + return 1; if (ch == '\\') { /* \x. Copy both unless it is \`, \$, \\ and maybe \" */ ch = i_getch(input); @@ -3611,7 +3605,7 @@ static void add_till_backquote(o_string *dest, struct in_str *input, int in_dquo } if (ch == EOF) { syntax_error_unterm_ch('`'); - /*xfunc_die(); - redundant */ + return 0; } o_addchr(dest, ch); } @@ -3647,7 +3641,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign ch = i_getch(input); if (ch == EOF) { syntax_error_unterm_ch(end_ch); - /*xfunc_die(); - redundant */ + return 0; } if (ch == end_ch IF_HUSH_BASH_COMPAT( || ch == end_char2)) { if (!dbl) @@ -3661,22 +3655,26 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign o_addchr(dest, ch); if (ch == '(' || ch == '{') { ch = (ch == '(' ? ')' : '}'); - add_till_closing_bracket(dest, input, ch); + if (!add_till_closing_bracket(dest, input, ch)) + return 0; o_addchr(dest, ch); continue; } if (ch == '\'') { - add_till_single_quote(dest, input); + if (!add_till_single_quote(dest, input)) + return 0; o_addchr(dest, ch); continue; } if (ch == '"') { - add_till_double_quote(dest, input); + if (!add_till_double_quote(dest, input)) + return 0; o_addchr(dest, ch); continue; } if (ch == '`') { - add_till_backquote(dest, input, /*in_dquote:*/ 0); + if (!add_till_backquote(dest, input, /*in_dquote:*/ 0)) + return 0; o_addchr(dest, ch); continue; } @@ -3685,7 +3683,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign ch = i_getch(input); if (ch == EOF) { syntax_error_unterm_ch(')'); - /*xfunc_die(); - redundant */ + return 0; } o_addchr(dest, ch); continue; @@ -3756,8 +3754,8 @@ static int parse_dollar(o_string *as_string, ) { bad_dollar_syntax: syntax_error_unterm_str("${name}"); - debug_printf_parse("parse_dollar return 1: unterminated ${name}\n"); - return 1; + debug_printf_parse("parse_dollar return 0: unterminated ${name}\n"); + return 0; } nommu_addchr(as_string, ch); ch |= quote_mask; @@ -3813,6 +3811,8 @@ static int parse_dollar(o_string *as_string, pos = dest->length; #if ENABLE_HUSH_DOLLAR_OPS last_ch = add_till_closing_bracket(dest, input, end_ch); + if (last_ch == 0) /* error? */ + return 0; #else #error Simple code to only allow ${var} is not implemented #endif @@ -3857,7 +3857,8 @@ static int parse_dollar(o_string *as_string, o_addchr(dest, /*quote_mask |*/ '+'); if (!BB_MMU) pos = dest->length; - add_till_closing_bracket(dest, input, ')' | DOUBLE_CLOSE_CHAR_FLAG); + if (!add_till_closing_bracket(dest, input, ')' | DOUBLE_CLOSE_CHAR_FLAG)) + return 0; /* error */ if (as_string) { o_addstr(as_string, dest->data + pos); o_addchr(as_string, ')'); @@ -3872,7 +3873,8 @@ static int parse_dollar(o_string *as_string, o_addchr(dest, quote_mask | '`'); if (!BB_MMU) pos = dest->length; - add_till_closing_bracket(dest, input, ')'); + if (!add_till_closing_bracket(dest, input, ')')) + return 0; /* error */ if (as_string) { o_addstr(as_string, dest->data + pos); o_addchr(as_string, ')'); @@ -3899,8 +3901,8 @@ static int parse_dollar(o_string *as_string, default: o_addQchr(dest, '$'); } - debug_printf_parse("parse_dollar return 0\n"); - return 0; + debug_printf_parse("parse_dollar return 1 (ok)\n"); + return 1; #undef as_string } @@ -3941,13 +3943,13 @@ static int encode_string(o_string *as_string, if (ch != EOF) nommu_addchr(as_string, ch); if (ch == dquote_end) { /* may be only '"' or EOF */ - debug_printf_parse("encode_string return 0\n"); - return 0; + debug_printf_parse("encode_string return 1 (ok)\n"); + return 1; } /* note: can't move it above ch == dquote_end check! */ if (ch == EOF) { syntax_error_unterm_ch('"'); - /*xfunc_die(); - redundant */ + return 0; /* error */ } next = '\0'; if (ch != '\n') { @@ -3978,10 +3980,10 @@ static int encode_string(o_string *as_string, goto again; } if (ch == '$') { - if (parse_dollar(as_string, dest, input, /*quote_mask:*/ 0x80) != 0) { - debug_printf_parse("encode_string return 1: " - "parse_dollar returned non-0\n"); - return 1; + if (!parse_dollar(as_string, dest, input, /*quote_mask:*/ 0x80)) { + debug_printf_parse("encode_string return 0: " + "parse_dollar returned 0 (error)\n"); + return 0; } goto again; } @@ -3990,7 +3992,8 @@ static int encode_string(o_string *as_string, //unsigned pos = dest->length; o_addchr(dest, SPECIAL_VAR_SYMBOL); o_addchr(dest, 0x80 | '`'); - add_till_backquote(dest, input, /*in_dquote:*/ dquote_end == '"'); + if (!add_till_backquote(dest, input, /*in_dquote:*/ dquote_end == '"')) + return 0; /* error */ o_addchr(dest, SPECIAL_VAR_SYMBOL); //debug_printf_subst("SUBST RES3 '%s'\n", dest->data + pos); goto again; @@ -4061,8 +4064,8 @@ static struct pipe *parse_stream(char **pstring, /* end_trigger == '}' case errors out earlier, * checking only ')' */ if (end_trigger == ')') { - syntax_error_unterm_ch('('); /* exits */ - /* goto parse_error; */ + syntax_error_unterm_ch('('); + goto parse_error; } if (done_word(&dest, &ctx)) { @@ -4353,9 +4356,9 @@ static struct pipe *parse_stream(char **pstring, dest.has_quoted_part = 1; break; case '$': - if (parse_dollar(&ctx.as_string, &dest, input, /*quote_mask:*/ 0) != 0) { + if (!parse_dollar(&ctx.as_string, &dest, input, /*quote_mask:*/ 0)) { debug_printf_parse("parse_stream parse error: " - "parse_dollar returned non-0\n"); + "parse_dollar returned 0 (error)\n"); goto parse_error; } break; @@ -4365,7 +4368,7 @@ static struct pipe *parse_stream(char **pstring, ch = i_getch(input); if (ch == EOF) { syntax_error_unterm_ch('\''); - /*xfunc_die(); - redundant */ + goto parse_error; } nommu_addchr(&ctx.as_string, ch); if (ch == '\'') @@ -4377,7 +4380,7 @@ static struct pipe *parse_stream(char **pstring, dest.has_quoted_part = 1; if (dest.o_assignment == NOT_ASSIGNMENT) dest.o_expflags |= EXP_FLAG_ESC_GLOB_CHARS; - if (encode_string(&ctx.as_string, &dest, input, '"', /*process_bkslash:*/ 1)) + if (!encode_string(&ctx.as_string, &dest, input, '"', /*process_bkslash:*/ 1)) goto parse_error; dest.o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS; break; @@ -4388,7 +4391,8 @@ static struct pipe *parse_stream(char **pstring, o_addchr(&dest, SPECIAL_VAR_SYMBOL); o_addchr(&dest, '`'); pos = dest.length; - add_till_backquote(&dest, input, /*in_dquote:*/ 0); + if (!add_till_backquote(&dest, input, /*in_dquote:*/ 0)) + goto parse_error; # if !BB_MMU o_addstr(&ctx.as_string, dest.data + pos); o_addchr(&ctx.as_string, '`'); @@ -4664,6 +4668,7 @@ static char *encode_then_expand_string(const char *str, int process_bkslash, int */ setup_string_in_str(&input, str); encode_string(NULL, &dest, &input, EOF, process_bkslash); +//TODO: error check (encode_string returns 0 on error)? //bb_error_msg("'%s' -> '%s'", str, dest.data); exp_str = expand_string_to_string(dest.data, /*unbackslash:*/ do_unbackslash); //bb_error_msg("'%s' -> '%s'", dest.data, exp_str); @@ -8625,6 +8630,8 @@ static int FAST_FUNC builtin_source(char **argv) #endif save_and_replace_G_args(&sv, argv); +//TODO: syntax errors in sourced file should never abort the "calling" script. +//Try: bash -c '. ./bad_file; echo YES' parse_and_run_file(input); fclose(input); -- cgit v1.2.3-55-g6feb From c162bcdcd1c5cb000a8ceaf4413d4abdfa6e3dfc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Mar 2011 05:38:51 +0100 Subject: hush: document a bug about aborting on sourced file error when non-interactive Signed-off-by: Denys Vlasenko --- shell/hush_test/hush-misc/source1.right | 5 +++++ shell/hush_test/hush-misc/source1.tests | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 shell/hush_test/hush-misc/source1.right create mode 100755 shell/hush_test/hush-misc/source1.tests diff --git a/shell/hush_test/hush-misc/source1.right b/shell/hush_test/hush-misc/source1.right new file mode 100644 index 000000000..d4256034b --- /dev/null +++ b/shell/hush_test/hush-misc/source1.right @@ -0,0 +1,5 @@ +hush: syntax error: unterminated ${name} +line2 +Ok1:0 +hush: syntax error: unterminated ' +Ok2:1 diff --git a/shell/hush_test/hush-misc/source1.tests b/shell/hush_test/hush-misc/source1.tests new file mode 100755 index 000000000..c13888359 --- /dev/null +++ b/shell/hush_test/hush-misc/source1.tests @@ -0,0 +1,10 @@ +echo 'echo ${^} +echo line2' >sourced1 +. ./sourced1 +echo Ok1:$? + +echo "echo '" >sourced1 +. ./sourced1 +echo Ok2:$? + +rm sourced1 -- cgit v1.2.3-55-g6feb From d3679d2491fa85e98db3bf397d5330ddcb9fc98a Mon Sep 17 00:00:00 2001 From: Roman Borisov Date: Wed, 23 Mar 2011 11:20:25 +0300 Subject: mount: rprivate option fix fixed the mistake in writing for -make-rprivate option Signed-off-by: Roman Borisov Signed-off-by: Denys Vlasenko --- 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 989e5d1a8..e672a73f4 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -192,7 +192,7 @@ static const int32_t mount_options[] = { /* "unbindable" */ MS_UNBINDABLE, /* "rshared" */ MS_SHARED|MS_RECURSIVE, /* "rslave" */ MS_SLAVE|MS_RECURSIVE, - /* "rprivate" */ MS_SLAVE|MS_RECURSIVE, + /* "rprivate" */ MS_PRIVATE|MS_RECURSIVE, /* "runbindable" */ MS_UNBINDABLE|MS_RECURSIVE, ) -- cgit v1.2.3-55-g6feb From 19311bfa7b8e8c6effa9c375de9b0eb4338bee12 Mon Sep 17 00:00:00 2001 From: Roman Borisov Date: Thu, 24 Mar 2011 15:08:43 +0300 Subject: mount: add --rbind option support Signed-off-by: Roman Borisov Signed-off-by: Denys Vlasenko --- include/usage.src.h | 2 +- util-linux/mount.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/usage.src.h b/include/usage.src.h index 29f7b2110..d07b408a6 100644 --- a/include/usage.src.h +++ b/include/usage.src.h @@ -2482,7 +2482,7 @@ INSERT "\n [r]slave Convert [recursively] to a slave subtree" \ "\n [r]private Convert [recursively] to a private subtree" \ "\n [un]bindable Make mount point [un]able to be bind mounted" \ - "\n bind Bind a file or directory to another location" \ + "\n [r]bind Bind a file or directory [recursively] to another location" \ "\n move Relocate an existing mount point" \ ) \ "\n remount Remount a mounted filesystem, changing flags" \ diff --git a/util-linux/mount.c b/util-linux/mount.c index e672a73f4..722d0be92 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -181,6 +181,7 @@ static const int32_t mount_options[] = { /* "relatime" */ MS_RELATIME, /* "norelatime" */ ~MS_RELATIME, /* "loud" */ ~MS_SILENT, + /* "rbind" */ MS_BIND|MS_RECURSIVE, // action flags /* "union" */ MS_UNION, @@ -236,6 +237,7 @@ static const char mount_option_str[] = "relatime\0" "norelatime\0" "loud\0" + "rbind\0" // action flags "union\0" -- cgit v1.2.3-55-g6feb