OSDN Git Service

Merge branch 'master' of https://android.googlesource.com/platform/external/toybox...
authorSteve Kondik <steve@cyngn.com>
Mon, 26 Sep 2016 12:28:18 +0000 (05:28 -0700)
committerSteve Kondik <steve@cyngn.com>
Mon, 26 Sep 2016 12:40:17 +0000 (05:40 -0700)
Change-Id: I30f7024dc0b625c2a0b34907a640052592c3f8c1

1  2 
.config
Android.mk
generated/config.h
generated/flags.h
generated/globals.h
generated/help.h
generated/newtoys.h
lib/lib.h
toys/other/stat.c
toys/posix/cp.c

diff --cc .config
+++ b/.config
@@@ -127,14 -130,14 +129,15 @@@ CONFIG_DD=
  # CONFIG_DHCP is not set
  # CONFIG_DHCPD is not set
  # CONFIG_DEBUG_DHCP is not set
 -# CONFIG_DIFF is not set
 +CONFIG_DIFF=y
  # CONFIG_DUMPLEASES is not set
  CONFIG_EXPR=y
 -# CONFIG_FDISK is not set
 +CONFIG_FDISK=y
 +CONFIG_FILE=y
  # CONFIG_FOLD is not set
  # CONFIG_FSCK is not set
 -# CONFIG_FTPGET is not set
 +CONFIG_FTPGET=y
+ CONFIG_GETFATTR=y
  # CONFIG_GETTY is not set
  # CONFIG_GROUPADD is not set
  # CONFIG_GROUPDEL is not set
@@@ -283,8 -286,11 +288,12 @@@ CONFIG_HOSTNAME=
  CONFIG_KILLALL=y
  CONFIG_MD5SUM=y
  CONFIG_SHA1SUM=y
+ CONFIG_SHA224SUM=y
+ CONFIG_SHA256SUM=y
+ CONFIG_SHA384SUM=y
+ CONFIG_SHA512SUM=y
  CONFIG_MKNOD=y
 +CONFIG_MKNOD_Z=y
  CONFIG_MKTEMP=y
  CONFIG_MOUNT=y
  # CONFIG_PASSWD is not set
diff --cc Android.mk
@@@ -133,13 -118,11 +138,13 @@@ LOCAL_SRC_FILES := 
      toys/other/pmap.c \
      toys/other/printenv.c \
      toys/other/pwdx.c \
 +    toys/other/readahead.c \
      toys/other/readlink.c \
      toys/other/realpath.c \
 +    toys/other/reset.c \
      toys/other/rev.c \
-     toys/other/rfkill.c \
      toys/other/rmmod.c \
+     toys/other/setfattr.c \
      toys/other/setsid.c \
      toys/other/stat.c \
      toys/other/swapoff.c \
      toys/other/which.c \
      toys/other/xxd.c \
      toys/other/yes.c \
 +    toys/pending/arp.c \
+     toys/pending/chrt.c \
      toys/pending/dd.c \
 +    toys/pending/diff.c \
      toys/pending/expr.c \
-     toys/pending/file.c \
 +    toys/pending/fdisk.c \
 +    toys/pending/ftpget.c \
+     toys/pending/getfattr.c \
 +    toys/pending/host.c \
      toys/pending/lsof.c \
      toys/pending/more.c \
-     toys/pending/netstat.c \
 +    toys/pending/resize.c \
 +    toys/pending/route.c \
      toys/pending/tar.c \
 +    toys/pending/telnet.c \
 +    toys/pending/test.c \
      toys/pending/tr.c \
      toys/pending/traceroute.c \
 +    toys/pending/watch.c \
 +    toys/pending/xzcat.c \
      toys/posix/basename.c \
      toys/posix/cal.c \
      toys/posix/cat.c \
      toys/posix/uname.c \
      toys/posix/uniq.c \
      toys/posix/wc.c \
 -    toys/posix/xargs.c \
 -
 -LOCAL_CFLAGS += \
 -    -std=c99 \
 -    -Os \
 -    -Wno-char-subscripts \
 -    -Wno-sign-compare \
 -    -Wno-string-plus-int \
 -    -Wno-uninitialized \
 -    -Wno-unused-parameter \
 -    -funsigned-char \
 -    -ffunction-sections -fdata-sections \
 -    -fno-asynchronous-unwind-tables \
 -
 -toybox_upstream_version := $(shell awk 'match($$0, /TOYBOX_VERSION.*"(.*)"/, ary) {print ary[1]}' $(LOCAL_PATH)/main.c)
 -toybox_sha := $(shell git -C $(LOCAL_PATH) rev-parse --short=12 HEAD 2>/dev/null)
 -
 -toybox_version := $(toybox_upstream_version)-$(toybox_sha)-android
 -LOCAL_CFLAGS += -DTOYBOX_VERSION='"$(toybox_version)"'
 +    toys/posix/xargs.c
  
 +LOCAL_CFLAGS := $(common_cflags)
  LOCAL_CLANG := true
  
- LOCAL_STATIC_LIBRARIES := libselinux
 -LOCAL_SHARED_LIBRARIES := liblog libcutils libselinux libcrypto
++LOCAL_STATIC_LIBRARIES := libselinux libcrypto_static
  
  # This doesn't actually prevent us from dragging in libc++ at runtime
  # because libnetd_client.so is C++.
  LOCAL_CXX_STL := none
  
- LOCAL_SHARED_LIBRARIES := libcutils libselinux
 +LOCAL_C_INCLUDES += bionic/libc/dns/include
 +
 +LOCAL_MODULE := libtoybox
 +
 +include $(BUILD_STATIC_LIBRARY)
 +
 +
 +# Host binary to enumerate the toys
 +include $(CLEAR_VARS)
 +LOCAL_SRC_FILES := scripts/install.c
 +LOCAL_MODULE_TAGS := optional
 +LOCAL_CFLAGS := $(common_cflags)
 +LOCAL_CLANG := true
 +LOCAL_MODULE := toybox-instlist
 +include $(BUILD_HOST_EXECUTABLE)
 +
 +
 +include $(CLEAR_VARS)
 +LOCAL_SRC_FILES := main.c
 +LOCAL_STATIC_LIBRARIES := libtoybox
++LOCAL_SHARED_LIBRARIES := libcutils libselinux libcrypto
 +LOCAL_CFLAGS := $(common_cflags)
 +LOCAL_CXX_STL := none
 +LOCAL_CLANG := true
  LOCAL_MODULE := toybox
  
 -# dupes: dd
 -# useless?: freeramdisk fsfreeze install makedevs mkfifo nbd-client
 -#           partprobe pivot_root pwdx rev rfkill vconfig
 -# prefer BSD netcat instead?: nc netcat
 -# prefer efs2progs instead?: blkid chattr lsattr
 +# for dumping the list of toys
 +TOYBOX_INSTLIST := $(HOST_OUT_EXECUTABLES)/toybox-instlist
 +LOCAL_ADDITIONAL_DEPENDENCIES := toybox_links
  
 -ALL_TOOLS := \
 -    acpi \
 -    base64 \
 -    basename \
 -    blockdev \
 -    bzcat \
 -    cal \
 -    cat \
 -    chcon \
 -    chgrp \
 -    chmod \
 -    chown \
 -    chroot \
 -    chrt \
 -    cksum \
 -    clear \
 -    comm \
 -    cmp \
 -    cp \
 -    cpio \
 -    cut \
 -    date \
 -    df \
 -    dirname \
 -    dmesg \
 -    dos2unix \
 -    du \
 -    echo \
 -    env \
 -    expand \
 -    expr \
 -    fallocate \
 -    false \
 -    file \
 -    find \
 -    flock \
 -    free \
 -    getenforce \
 -    getprop \
 -    groups \
 -    head \
 -    hostname \
 -    hwclock \
 -    id \
 -    ifconfig \
 -    inotifyd \
 -    insmod \
 -    ionice \
 -    iorenice \
 -    kill \
 -    killall \
 -    load_policy \
 -    ln \
 -    log \
 -    logname \
 -    losetup \
 -    ls \
 -    lsmod \
 -    lsof \
 -    lsusb \
 -    md5sum \
 -    mkdir \
 -    mknod \
 -    mkswap \
 -    mktemp \
 -    modinfo \
 -    more \
 -    mount \
 -    mountpoint \
 -    mv \
 -    netstat \
 -    nice \
 -    nl \
 -    nohup \
 -    od \
 -    paste \
 -    patch \
 -    pgrep \
 -    pidof \
 -    pkill \
 -    pmap \
 -    printenv \
 -    printf \
 -    ps \
 -    pwd \
 -    readlink \
 -    realpath \
 -    renice \
 -    restorecon \
 -    rm \
 -    rmdir \
 -    rmmod \
 -    runcon \
 -    sed \
 -    sendevent \
 -    seq \
 -    setenforce \
 -    setprop \
 -    setsid \
 -    sha1sum \
 -    sha224sum \
 -    sha256sum \
 -    sha384sum \
 -    sha512sum \
 -    sleep \
 -    sort \
 -    split \
 -    start \
 -    stat \
 -    stop \
 -    strings \
 -    swapoff \
 -    swapon \
 -    sync \
 -    sysctl \
 -    tac \
 -    tail \
 -    tar \
 -    taskset \
 -    tee \
 -    time \
 -    timeout \
 -    top \
 -    touch \
 -    tr \
 -    true \
 -    truncate \
 -    tty \
 -    ulimit \
 -    umount \
 -    uname \
 -    uniq \
 -    unix2dos \
 -    uptime \
 -    usleep \
 -    vmstat \
 -    wc \
 -    which \
 -    whoami \
 -    xargs \
 -    xxd \
 -    yes \
 +# we still want a link for ps, but the toolbox version needs to
 +# stick around for compatibility reasons, for now.
 +TOYS_FOR_XBIN := ps
  
 -# Install the symlinks.
 -LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_OUT)/bin/$(t);)
 +# skip links for these toys in the system image, they already have
 +# a full-blown counterpart. we still want them for the recovery
 +# image though.
 +TOYS_WITHOUT_LINKS := blkid traceroute6
 +
 +include $(BUILD_EXECUTABLE)
  
- LOCAL_STATIC_LIBRARIES := libc libtoybox libcutils libselinux libmincrypt liblog
 +toybox_links: $(TOYBOX_INSTLIST)
 +toybox_links: TOYBOX_BINARY := $(TARGET_OUT)/bin/toybox
 +toybox_links:
 +      @echo -e ${CL_CYN}"Generate Toybox links:"${CL_RST} $$($(TOYBOX_INSTLIST))
 +      @mkdir -p $(TARGET_OUT_EXECUTABLES) $(TARGET_OUT_OPTIONAL_EXECUTABLES)
 +      $(hide) $(TOYBOX_INSTLIST) | grep -vFx -f <(tr ' ' '\n' <<< '$(TOYS_FOR_XBIN) $(TOYS_WITHOUT_LINKS)') | xargs -I'{}' ln -sf toybox '$(TARGET_OUT_EXECUTABLES)/{}'
 +      $(hide) tr ' ' '\n' <<< '$(TOYS_FOR_XBIN)' | xargs -I'{}' ln -sf ../bin/toybox '$(TARGET_OUT_OPTIONAL_EXECUTABLES)/{}'
 +
 +
 +# This is used by the recovery system
 +include $(CLEAR_VARS)
 +LOCAL_SRC_FILES := main.c
 +LOCAL_WHOLE_STATIC_LIBRARIES := libselinux libtoybox
 +LOCAL_CFLAGS := $(common_cflags)
 +LOCAL_CFLAGS += -Dmain=toybox_driver
 +LOCAL_CXX_STL := none
 +LOCAL_CLANG := true
 +LOCAL_MODULE := libtoybox_driver
 +include $(BUILD_STATIC_LIBRARY)
 +
 +# static executable for use in limited environments
 +include $(CLEAR_VARS)
 +LOCAL_SRC_FILES := main.c
 +LOCAL_CFLAGS := $(common_cflags)
 +LOCAL_CXX_STL := none
 +LOCAL_CLANG := true
 +LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
 +LOCAL_MODULE := toybox_static
 +LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
 +LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
 +LOCAL_MODULE_TAGS := optional
 +LOCAL_MODULE_STEM := toybox
 +LOCAL_PACK_MODULE_RELOCATIONS := false
++LOCAL_STATIC_LIBRARIES := libc libtoybox libcutils libselinux libcrypto_static liblog
 +LOCAL_FORCE_STATIC_EXECUTABLE := true
  include $(BUILD_EXECUTABLE)
  #define USE_FOLD(...)
  #define CFG_FSCK 0
  #define USE_FSCK(...)
 -#define CFG_FTPGET 0
 -#define USE_FTPGET(...)
 +#define CFG_FTPGET 1
 +#define USE_FTPGET(...) __VA_ARGS__
+ #define CFG_GETFATTR 1
+ #define USE_GETFATTR(...) __VA_ARGS__
  #define CFG_GETTY 0
  #define USE_GETTY(...)
  #define CFG_GROUPADD 0
  #define USE_MD5SUM(...) __VA_ARGS__
  #define CFG_SHA1SUM 1
  #define USE_SHA1SUM(...) __VA_ARGS__
+ #define CFG_SHA224SUM 1
+ #define USE_SHA224SUM(...) __VA_ARGS__
+ #define CFG_SHA256SUM 1
+ #define USE_SHA256SUM(...) __VA_ARGS__
+ #define CFG_SHA384SUM 1
+ #define USE_SHA384SUM(...) __VA_ARGS__
+ #define CFG_SHA512SUM 1
+ #define USE_SHA512SUM(...) __VA_ARGS__
  #define CFG_MKNOD 1
  #define USE_MKNOD(...) __VA_ARGS__
 +#define CFG_MKNOD_Z 1
 +#define USE_MKNOD_Z(...) __VA_ARGS__
  #define CFG_MKTEMP 1
  #define USE_MKTEMP(...) __VA_ARGS__
  #define CFG_MOUNT 1
  #undef FOR_brctl
  #endif
  
 -// bunzip2 cftkv cftkv
 +// bunzip2   cftkv
  #undef OPTSTR_bunzip2
- #define OPTSTR_bunzip2  0 
+ #define OPTSTR_bunzip2 "cftkv"
  #ifdef CLEANUP_bunzip2
  #undef CLEANUP_bunzip2
  #undef FOR_bunzip2
@@@ -1193,10 -1242,9 +1242,11 @@@ struct ps_data 
      } pgrep;
    };
  
 +#ifndef __APPLE__
    struct sysinfo si;
 +#endif
    struct ptr_len gg, GG, pp, PP, ss, tt, uu, UU;
+   struct dirtree *threadparent;
    unsigned width, height;
    dev_t tty;
    void *fields, *kfields;
  
  #define HELP_mktemp "usage: mktemp [-dqu] [-p DIR] [TEMPLATE]\n\nSafely create a new file \"DIR/TEMPLATE\" and print its name.\n\n-d  Create directory instead of file (--directory)\n-p      Put new file in DIR (--tmpdir)\n-q      Quiet, no error messages\n-u    Don't create anything, just print what would be created\n\nEach X in TEMPLATE is replaced with a random printable character. The\ndefault TEMPLATE is tmp.XXXXXX, and the default DIR is $TMPDIR if set,\nelse \"/tmp\".\n\n"
  
 -#define HELP_mknod_z "usage: mknod [-Z CONTEXT] ...\n\n-Z     Set security context to created file\n\n"
 -
 -#define HELP_mknod "usage: mknod [-m MODE] NAME TYPE [MAJOR MINOR]\n\nCreate a special file NAME with a given type. TYPE is b for block device,\nc or u for character device, p for named pipe (which ignores MAJOR/MINOR).\n\n-m     Mode (file permissions) of new device, in octal or u+x format\n\n"
 +#define HELP_mknod "usage: mknod [-Z CONTEXT] ... [-m MODE] NAME TYPE [MAJOR MINOR]\n\nCreate a special file NAME with a given type. TYPE is b for block device,\nc or u for character device, p for named pipe (which ignores MAJOR/MINOR).\n-Z      Set security context to created file\n-m        Mode (file permissions) of new device, in octal or u+x format\n"
  
- #define HELP_sha1sum "usage: sha1sum [FILE]...\n\ncalculate sha1 hash for each input file, reading from stdin if none.\nOutput one hash (20 hex digits) for each input file, followed by\nfilename.\n\n-b     brief (hash only, no filename)\n\n"
+ #define HELP_sha512sum "See sha1sum\n\n"
  
- #define HELP_md5sum "usage: md5sum [FILE]...\n\nCalculate md5 hash for each input file, reading from stdin if none.\nOutput one hash (16 hex digits) for each input file, followed by\nfilename.\n\n-b        brief (hash only, no filename)\n\n"
+ #define HELP_sha384sum "See sha1sum\n\n"
+ #define HELP_sha256sum "See sha1sum\n\n"
+ #define HELP_sha224sum "See sha1sum\n\n"
+ #define HELP_sha1sum "usage: sha?sum [-b] [-c FILE] [FILE]...\n\ncalculate sha hash for each input file, reading from stdin if none. Output\none hash (40 hex digits for sha1, 56 for sha224, 64 for sha256, 96 for sha384,\nand 128 for sha512) for each input file, followed by filename.\n\n-b     brief (hash only, no filename)\n-c      Check each line of FILE is the same hash+filename we'd output.\n\n"
+ #define HELP_md5sum "usage: md5sum [-b] [-c FILE] [FILE]...\n\nCalculate md5 hash for each input file, reading from stdin if none.\nOutput one hash (32 hex digits) for each input file, followed by filename.\n\n-b  brief (hash only, no filename)\n-c      Check each line of FILE is the same hash+filename we'd output.\n\n"
  
  #define HELP_killall "usage: killall [-l] [-iqv] [-SIGNAL|-s SIGNAL] PROCESS_NAME...\n\nSend a signal (default: TERM) to all processes with the given names.\n\n-i    ask for confirmation before killing\n-l print list of all available signals\n-q don't print any warnings or error messages\n-s  send SIGNAL instead of SIGTERM\n-v      report if the signal was successfully sent\n\n"
  
  
  #define HELP_dmesg "usage: dmesg [-c] [-r|-t] [-n LEVEL] [-s SIZE]\n\nPrint or control the kernel ring buffer.\n\n-c  Clear the ring buffer after printing\n-n        Set kernel logging LEVEL (1-9)\n-r      Raw output (with <level markers>)\n-s   Show the last SIZE many bytes\n-t       Don't print kernel's timestamps\n\n"
  
 -#define HELP_netcat_listen_tty "usage: netcat [-t]\n\n-t      allocate tty (must come before -l or -L)\n\n"
 -
 -#define HELP_netcat "usage: netcat [-lL COMMAND...] [-u] [-wpq #] [-s addr] {IPADDR PORTNUM|-f FILENAME}\n\n-L        listen for multiple incoming connections (server mode).\n-f     use FILENAME (ala /dev/ttyS0) instead of network\n-l    listen for one incoming connection.\n-p local port number\n-q   SECONDS quit this many seconds after EOF on stdin.\n-s  local ipv4 address\n-w  SECONDS timeout for connection\n\nUse \"stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho\" with\nnetcat -f to connect to a serial port.\n\nThe command line after -l or -L is executed to handle each incoming\nconnection. If none, the connection is forwarded to stdin/stdout.\n\nFor a quick-and-dirty server, try something like:\nnetcat -s 127.0.0.1 -p 1234 -tL /bin/bash -l\n"
+ #define HELP_tunctl "usage: tunctl [-dtT] [-u USER] NAME\n\nCreate and delete tun/tap virtual ethernet devices.\n\n-T Use tap (ethernet frames) instead of tun (ip packets)\n-d       Delete tun/tap device\n-t       Create tun/tap device\n-u       Set owner (user who can read/write device without root access)\n\n\n"
+ #define HELP_rfkill "Usage: rfkill COMMAND [DEVICE]\n\nEnable/disable wireless devices.\n\nCommands:\nlist [DEVICE]   List current state\nblock DEVICE    Disable device\nunblock DEVICE  Enable device\n\nDEVICE is an index number, or one of:\nall, wlan(wifi), bluetooth, uwb(ultrawideband), wimax, wwan, gps, fm.\n\n"
+ #define HELP_netstat "usage: netstat [-pWrxwutneal]\n\nDisplay networking information. Default is netsat -tuwx\n\n-r  routing table\n-a  all sockets (not just connected)\n-l  listening server sockets\n-t  TCP sockets\n-u  UDP sockets\n-w  raw sockets\n-x  unix sockets\n-e  extended info\n-n  don't resolve names\n-W  wide display\n-p  PID/Program name of sockets\n\n"
++#define HELP_netcat "usage: netcat [-tu] [-lL COMMAND...] [-wpq #] [-s addr] {IPADDR PORTNUM|-f FILENAME}\n\n-L       listen for multiple incoming connections (server mode).\n-f     use FILENAME (ala /dev/ttyS0) instead of network\n-l    listen for one incoming connection.\n-p local port number\n-q   SECONDS quit this many seconds after EOF on stdin.\n-s  local ipv4 address\n-t  allocate tty (must come before -l or -L)\n-w    SECONDS timeout for connection\n\nUse \"stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho\" with\nnetcat -f to connect to a serial port.\n\nThe command line after -l or -L is executed to handle each incoming\nconnection. If none, the connection is forwarded to stdin/stdout.\n\nFor a quick-and-dirty server, try something like:\nnetcat -s 127.0.0.1 -p 1234 -tL /bin/bash -l\n"
+ #define HELP_ifconfig "usage: ifconfig [-a] [INTERFACE [ACTION...]]\n\nDisplay or configure network interface.\n\nWith no arguments, display active interfaces. First argument is interface\nto operate on, one argument by itself displays that interface.\n\n-a     Show all interfaces, not just active ones\n\nAdditional arguments are actions to perform on the interface:\n\nADDRESS[/NETMASK] - set IPv4 address (1.2.3.4/5)\ndefault - unset ipv4 address\nadd|del ADDRESS[/PREFIXLEN] - add/remove IPv6 address (1111::8888/128)\nup - enable interface\ndown - disable interface\n\nnetmask|broadcast|pointopoint ADDRESS - set more IPv4 characteristics\nhw ether|infiniband ADDRESS - set LAN hardware address (AA:BB:CC...)\ntxqueuelen LEN - number of buffered packets before output blocks\nmtu LEN - size of outgoing packets (Maximum Transmission Unit)\n\nFlags you can set on an interface (or -remove by prefixing with -):\narp - don't use Address Resolution Protocol to map LAN routes\npromisc - don't discard packets that aren't to this LAN hardware address\nmulticast - force interface into multicast mode if the driver doesn't\nallmulti - promisc for multicast packets\n\nObsolete fields included for historical purposes:\nirq|io_addr|mem_start ADDR - micromanage obsolete hardware\noutfill|keepalive INTEGER - SLIP analog dialup line quality monitoring\nmetric INTEGER - added to Linux 0.9.10 with comment \"never used\", still true\n\n"
  #define HELP_yes "usage: yes [args...]\n\nRepeatedly output line until killed. If no args, output 'y'.\n\n\n"
  
- #define HELP_xxd "usage: xxd [-c n] [-g n] [-l n] [-p] [-r] [file]\n\nHexdump a file to stdout.  If no file is listed, copy from stdin.\nFilename \"-\" is a synonym for stdin.\n\n-c n       Show n bytes per line (default 16).\n-g n       Group bytes by adding a ' ' every n bytes (default 2).\n-l n    Limit of n bytes before stopping (default is no limit).\n-p     Plain hexdump (30 bytes/line, no grouping).\n-r Reverse operation: turn a hexdump into a binary file.\n\n"
+ #define HELP_xxd "usage: xxd [-c n] [-g n] [-l n] [-p] [-r] [-s n] [file]\n\nHexdump a file to stdout.  If no file is listed, copy from stdin.\nFilename \"-\" is a synonym for stdin.\n\n-c n        Show n bytes per line (default 16).\n-g n       Group bytes by adding a ' ' every n bytes (default 2).\n-l n    Limit of n bytes before stopping (default is no limit).\n-p     Plain hexdump (30 bytes/line, no grouping).\n-r Reverse operation: turn a hexdump into a binary file.\n-s n     Skip to offset n.\n\n"
  
  #define HELP_which "usage: which [-a] filename ...\n\nSearch $PATH for executable files matching filename(s).\n\n-a   Show all matches\n\n"
  
  
  #define HELP_pwd "usage: pwd [-L|-P]\n\nPrint working (current) directory.\n\n-L  Use shell's path from $PWD (when applicable)\n-P  Print cannonical absolute path\n\n"
  
- #define HELP_pkill "usage: pkill [-l SIGNAL] [PATTERN]\n\n-l  SIGNAL to send\n-V      verbose\n\n"
 -#define HELP_pgkill_common "usage: * [-fnovx] [-G GID,] [-g PGRP,] [-P PPID,] [-s SID,] [-t TERM,] [-U UID,] [-u EUID,]\n\n-f Check full command line for PATTERN\n-G Match real Group ID(s)\n-g      Match Process Group(s) (0 is current user)\n-n  Newest match only\n-o   Oldest match only\n-P   Match Parent Process ID(s)\n-s  Match Session ID(s) (0 for current)\n-t Match Terminal(s)\n-U   Match real User ID(s)\n-u       Match effective User ID(s)\n-v  Negate the match\n-x    Match whole command (not substring)\n\n"
 -
+ #define HELP_pkill "usage: pkill [-SIGNAL|-l SIGNAL] [PATTERN]\n\n-l  Send SIGNAL (default SIGTERM)\n-V       verbose\n\n"
  
- #define HELP_pgrep "usage: pgrep [-Lcfnovx] [-G GID,] [-g PGRP,] [-P PPID,] [-s SID,] [-t TERM,] [-U UID,] [-u EUID,] [-d DELIM] [-L SIGNAL] [PATTERN]\n\nSearch for process(es). PATTERN is an extended regular expression checked\nagainst command names.\n-G       Match real Group ID(s)\n-L      Send SIGNAL instead of printing name\n-P        Match Parent Process ID(s)\n-U  Match real User ID(s)\n-c       Show only count of matches\n-d  Use DELIM instead of newline\n-f        Check full command line for PATTERN\n-g Match Process Group(s) (0 is current user)\n-l  Show command name\n-n   Newest match only\n-o   Oldest match only\n-s   Match Session ID(s) (0 for current)\n-t Match Terminal(s)\n-u   Match effective User ID(s)\n-v  Negate the match\n-x    Match whole command (not substring)\n"
+ #define HELP_pgrep "usage: pgrep [-cL] [-d DELIM] [-L SIGNAL] [PATTERN]\n\nSearch for process(es). PATTERN is an extended regular expression checked\nagainst command names.\n\n-c    Show only count of matches\n-d  Use DELIM instead of newline\n-L        Send SIGNAL instead of printing name\n-l        Show command name\n\n"
  
- #define HELP_top_common "usage: COMMON [-bq] [-n NUMBER] [-d SECONDS] [-p PID,] [-u USER,]\n\n-b      Batch mode (no tty)\n-d Delay SECONDS between each cycle (default 3)\n-n        Exit after NUMBER iterations\n-p        Show these PIDs\n-u     Show these USERs\n-q    Quiet (no header lines)\n\nCursor LEFT/RIGHT to change sort, UP/DOWN move list, space to force\nupdate, R to reverse sort, Q to exit.\n\n"
 -#define HELP_top_common "usage: * [-bq] [-n NUMBER] [-d SECONDS] [-p PID,] [-u USER,]\n\n-b   Batch mode (no tty)\n-d Delay SECONDS between each cycle (default 3)\n-n        Exit after NUMBER iterations\n-p        Show these PIDs\n-u     Show these USERs\n-q    Quiet (no header lines)\n\nCursor LEFT/RIGHT to change sort, UP/DOWN move list, space to force\nupdate, R to reverse sort, Q to exit.\n\n"
++#define HELP_top_common "usage: * [-bfnoqvx] [-G GID,] [-g PGRP,] [-P PPID,] [-s SID,] [-t TERM,] [-U UID,] [-u EUID,] [-n NUMBER] [-d SECONDS] [-p PID,] [-u USER,]\n\n-G    Match real Group ID(s)\n-P      Match Parent Process ID(s)\n-U  Match real User ID(s)\n-b       Batch mode (no tty)\n-d Delay SECONDS between each cycle (default 3)\n-f        Check full command line for PATTERN\n-g Match Process Group(s) (0 is current user)\n-n  Exit after NUMBER iterations\n-n        Newest match only\n-o   Oldest match only\n-p   Show these PIDs\n-q     Quiet (no header lines)\n-s     Match Session ID(s) (0 for current)\n-t Match Terminal(s)\n-u   Match effective User ID(s)\n-u  Show these USERs\n-v    Negate the match\n-x    Match whole command (not substring)\n\nCursor LEFT/RIGHT to change sort, UP/DOWN move list, space to force\nupdate, R to reverse sort, Q to exit.\n"
  
  #define HELP_iotop "usage: iotop [-AaKO]\n\nRank processes by I/O.\n\n-A      All I/O, not just disk\n-a      Accumulated I/O (not percentage)\n-K    Kilobytes\n-k   Fallback sort FIELDS (default -[D]IO,-ETIME,-PID)\n-O   Only show processes doing I/O\n-o       Show FIELDS (default PID,PR,USER,[D]READ,[D]WRITE,SWAP,[D]IO,COMM)\n-s  Sort by field number (0-X, default 6)\n\n"
  
Simple merge
diff --cc lib/lib.h
Simple merge
@@@ -155,25 -187,18 +187,20 @@@ void stat_main(void
        "Inodes: Total: %c\tFree: %d"
      : "  File: %N\n  Size: %s\t Blocks: %b\t IO Blocks: %B\t%F\n"
        "Device: %Dh/%dd\t Inode: %i\t Links: %h\n"
-       "Access: (%a/%A)\tUid: (%u/%U)\tGid: (%g/%G)\n"
+       "Access: (%a/%A)\tUid: (%5u/%8U)\tGid: (%5g/%8G)\n"
        "Access: %x\nModify: %y\nChange: %z";
 +  char *terse_format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o";
  
    if (toys.optflags & FLAG_c) format = TT.fmt;
 +  if (toys.optflags & FLAG_t) format = terse_format;
  
-   for (; *toys.optargs; toys.optargs++) {
-     char *f;
-     if (flagf && !statfs(*toys.optargs, (void *)&TT.stat));
-     else if (!flagf && !lstat(*toys.optargs, (void *)&TT.stat)) {
-       struct stat *stat = (struct stat*)&TT.stat;
+   for (i = 0; toys.optargs[i]; i++) {
+     int L = toys.optflags & FLAG_L;
  
-       // check user and group name
-       TT.user_name = getpwuid(stat->st_uid);
-       TT.group_name = getgrgid(stat->st_gid);
-     } else {
-       perror_msg("'%s'", *toys.optargs);
+     TT.file = toys.optargs[i];
+     if (flagf && !statfs(TT.file, (void *)&TT.stat));
+     else if (flagf || (L ? stat : lstat)(TT.file, (void *)&TT.stat)) {
+       perror_msg("'%s'", TT.file);
        continue;
      }
  
diff --cc toys/posix/cp.c
@@@ -315,9 -315,15 +315,15 @@@ int cp_node(struct dirtree *try
        // permission bits already correct for mknod and don't apply to symlink
        // If we can't get a filehandle to the actual object, use racy functions
        if (fdout == AT_FDCWD)
 -        rc = fchownat(cfd, catch, try->st.st_uid, try->st.st_gid,
 +        fchownat(cfd, catch, try->st.st_uid, try->st.st_gid,
                        AT_SYMLINK_NOFOLLOW);
-       else fchown(fdout, try->st.st_uid, try->st.st_gid);
+       else rc = fchown(fdout, try->st.st_uid, try->st.st_gid);
+       if (rc && !geteuid()) {
+         char *pp;
+         perror_msg("chown '%s'", pp = dirtree_path(try, 0));
+         free(pp);
+       }
      }
  
      // timestamp