aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-02-21 17:51:19 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-02-21 17:51:19 +0000
commit4cf32732341f58518bcef2674209551b4d255674 (patch)
tree134b4f0143793dc7efd8f922cfd9abba0c61e641
parentfc265ca00d44e907ef0599ccc67da9ae465c25b5 (diff)
parent7c3d7b13860a5d725a300b71d273cdba5bcd8687 (diff)
downloadtoybox-4cf32732341f58518bcef2674209551b4d255674.tar.gz
Merge remote-tracking branch 'toybox/master' into HEAD
am: 7c3d7b1386 Change-Id: I111760a61b029d81b24eeaa332a951558173d002
-rw-r--r--.config1
-rw-r--r--Android.mk2
-rw-r--r--generated/config.h2
-rw-r--r--generated/flags.h18
-rw-r--r--generated/globals.h20
-rw-r--r--generated/help.h8
-rw-r--r--generated/newtoys.h3
-rw-r--r--lib/portability.h4
-rw-r--r--main.c8
-rw-r--r--toys/other/ascii.c7
-rw-r--r--toys/pending/dmesg.c (renamed from toys/lsb/dmesg.c)46
-rw-r--r--toys/posix/file.c2
12 files changed, 78 insertions, 43 deletions
diff --git a/.config b/.config
index bccc9a59..eb8069eb 100644
--- a/.config
+++ b/.config
@@ -38,6 +38,7 @@ CONFIG_TOYBOX_UID_USR=500
CONFIG_ACPI=y
# CONFIG_ARPING is not set
# CONFIG_ARP is not set
+# CONFIG_ASCII is not set
CONFIG_BASE64=y
CONFIG_BASENAME=y
CONFIG_BLKID=y
diff --git a/Android.mk b/Android.mk
index d00ba175..b0c6ae44 100644
--- a/Android.mk
+++ b/Android.mk
@@ -69,7 +69,6 @@ LOCAL_SRC_FILES := \
toys/android/setenforce.c \
toys/android/setprop.c \
toys/android/start.c \
- toys/lsb/dmesg.c \
toys/lsb/hostname.c \
toys/lsb/killall.c \
toys/lsb/md5sum.c \
@@ -141,6 +140,7 @@ LOCAL_SRC_FILES := \
toys/other/yes.c \
toys/pending/chrt.c \
toys/pending/dd.c \
+ toys/pending/dmesg.c \
toys/pending/expr.c \
toys/pending/getfattr.c \
toys/pending/lsof.c \
diff --git a/generated/config.h b/generated/config.h
index 9bd64b5b..5fb4ecdc 100644
--- a/generated/config.h
+++ b/generated/config.h
@@ -50,6 +50,8 @@
#define USE_ARPING(...)
#define CFG_ARP 0
#define USE_ARP(...)
+#define CFG_ASCII 0
+#define USE_ASCII(...)
#define CFG_BASE64 1
#define USE_BASE64(...) __VA_ARGS__
#define CFG_BASENAME 1
diff --git a/generated/flags.h b/generated/flags.h
index 02476a19..c3205884 100644
--- a/generated/flags.h
+++ b/generated/flags.h
@@ -57,6 +57,14 @@
#undef FLAG_s
#endif
+// ascii
+#undef OPTSTR_ascii
+#define OPTSTR_ascii 0
+#ifdef CLEANUP_ascii
+#undef CLEANUP_ascii
+#undef FOR_ascii
+#endif
+
// base64 diw#<0=76[!dw] diw#<0=76[!dw]
#undef OPTSTR_base64
#define OPTSTR_base64 "diw#<0=76[!dw]"
@@ -564,9 +572,9 @@
#undef FOR_dirname
#endif
-// dmesg w(follow)Ctrs#<1n#c[!tr] w(follow)Ctrs#<1n#c[!tr]
+// dmesg w(follow)Ctrs#<1n#c[!tr][!Cc] w(follow)Ctrs#<1n#c[!tr][!Cc]
#undef OPTSTR_dmesg
-#define OPTSTR_dmesg "w(follow)Ctrs#<1n#c[!tr]"
+#define OPTSTR_dmesg "w(follow)Ctrs#<1n#c[!tr][!Cc]"
#ifdef CLEANUP_dmesg
#undef CLEANUP_dmesg
#undef FOR_dmesg
@@ -3230,6 +3238,12 @@
#define FLAG_s (FORCED_FLAG<<9)
#endif
+#ifdef FOR_ascii
+#ifndef TT
+#define TT this.ascii
+#endif
+#endif
+
#ifdef FOR_base64
#ifndef TT
#define TT this.base64
diff --git a/generated/globals.h b/generated/globals.h
index e00f6b0a..1362502c 100644
--- a/generated/globals.h
+++ b/generated/globals.h
@@ -39,15 +39,6 @@ struct skeleton_data {
int more_globals;
};
-// toys/lsb/dmesg.c
-
-struct dmesg_data {
- long level;
- long size;
-
- int color;
-};
-
// toys/lsb/hostname.c
struct hostname_data {
@@ -558,6 +549,15 @@ struct diff_data {
int *offset[2];
};
+// toys/pending/dmesg.c
+
+struct dmesg_data {
+ long level;
+ long size;
+
+ int color;
+};
+
// toys/pending/dumpleases.c
struct dumpleases_data {
@@ -1384,7 +1384,6 @@ extern union global_union {
struct log_data log;
struct hello_data hello;
struct skeleton_data skeleton;
- struct dmesg_data dmesg;
struct hostname_data hostname;
struct killall_data killall;
struct md5sum_data md5sum;
@@ -1441,6 +1440,7 @@ extern union global_union {
struct dhcp6_data dhcp6;
struct dhcpd_data dhcpd;
struct diff_data diff;
+ struct dmesg_data dmesg;
struct dumpleases_data dumpleases;
struct expr_data expr;
struct fdisk_data fdisk;
diff --git a/generated/help.h b/generated/help.h
index 564f4673..de265384 100644
--- a/generated/help.h
+++ b/generated/help.h
@@ -104,8 +104,6 @@
#define HELP_hostname "usage: hostname [-b] [-F FILENAME] [newname]\n\nGet/Set the current hostname\n\n-b Set hostname to 'localhost' if otherwise unset\n-F Set hostname to contents of FILENAME\n\n"
-#define HELP_dmesg "usage: dmesg [-Cc] [-r|-t] [-n LEVEL] [-s SIZE] [-w]\n\nPrint or control the kernel ring buffer.\n\n-C Clear ring buffer without printing\n-c Clear 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-w Keep waiting for more output (aka --follow)\n\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"
@@ -278,6 +276,8 @@
#define HELP_base64 "usage: base64 [-di] [-w COLUMNS] [FILE...]\n\nEncode or decode in base64.\n\n-d decode\n-i ignore non-alphabetic characters\n-w wrap output at COLUMNS (default 76 or 0 for no wrap)\n\n"
+#define HELP_ascii "usage: ascii\n\nDisplay ascii character set.\n\n"
+
#define HELP_acpi "usage: acpi [-abctV]\n\nShow status of power sources and thermal devices.\n\n-a show power adapters\n-b show batteries\n-c show cooling device state\n-t show temperatures\n-V show everything\n\n"
#define HELP_xzcat "usage: xzcat [filename...]\n\nDecompress listed files to stdout. Use stdin if no files listed.\n\n\n\n"
@@ -386,6 +386,8 @@
#define HELP_dumpleases "usage: dumpleases [-r|-a] [-f LEASEFILE]\n\nDisplay DHCP leases granted by udhcpd\n-f FILE, Lease file\n-r Show remaining time\n-a Show expiration time\n\n"
+#define HELP_dmesg "usage: dmesg [-Cc] [-r|-t] [-n LEVEL] [-s SIZE] [-w]\n\nPrint or control the kernel ring buffer.\n\n-C Clear ring buffer without printing\n-c Clear 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-w Keep waiting for more output (aka --follow)\n\n"
+
#define HELP_diff "usage: diff [-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2\n\n-a Treat all files as text\n-b Ignore changes in the amount of whitespace\n-B Ignore changes whose lines are all blank\n-d Try hard to find a smaller set of changes\n-i Ignore case differences\n-L Use LABEL instead of the filename in the unified header\n-N Treat absent files as empty\n-q Output only whether files differ\n-r Recurse\n-S Start with FILE when comparing directories\n-T Make tabs line up by prefixing a tab when necessary\n-s Report when two files are the same\n-t Expand tabs to spaces in output\n-U Output LINES lines of context\n-w Ignore all whitespace\n\n"
#define HELP_dhcpd "usage: dhcpd [-46fS] [-i IFACE] [-P N] [CONFFILE]\n\n -f Run in foreground\n -i Interface to use\n -S Log to syslog too\n -P N Use port N (default ipv4 67, ipv6 547)\n -4, -6 Run as a DHCPv4 or DHCPv6 server\n\n"
@@ -550,7 +552,7 @@
#define HELP_dirname "usage: dirname PATH\n\nShow directory portion of path.\n\n"
-#define HELP_df "usage: df [-HPkh] [-t type] [FILESYSTEM ...]\n\nThe \"disk free\" command shows total/used/available disk space for\neach filesystem listed on the command line, or all currently mounted\nfilesystems.\n\n-P The SUSv3 \"Pedantic\" option\n-k Sets units back to 1024 bytes (the default without -P)\n-h Human readable output (K=1024)\n-H Human readable output (k=1000)\n-t type Display only filesystems of this type.\n\nPedantic provides a slightly less useful output format dictated by Posix,\nand sets the units to 512 bytes instead of the default 1024 bytes.\n\n"
+#define HELP_df "usage: df [-HPkh] [-t type] [FILESYSTEM ...]\n\nThe \"disk free\" command shows total/used/available disk space for\neach filesystem listed on the command line, or all currently mounted\nfilesystems.\n\n-a Show all (including /proc and friends)\n-P The SUSv3 \"Pedantic\" option\n-k Sets units back to 1024 bytes (the default without -P)\n-h Human readable output (K=1024)\n-H Human readable output (k=1000)\n-t type Display only filesystems of this type.\n\nPedantic provides a slightly less useful output format dictated by Posix,\nand sets the units to 512 bytes instead of the default 1024 bytes.\n\n"
#define HELP_date "usage: date [-u] [-r FILE] [-d DATE] [+DISPLAY_FORMAT] [-D SET_FORMAT] [SET]\n\nSet/get the current date/time. With no SET shows the current date.\n\nDefault SET format is \"MMDDhhmm[[CC]YY][.ss]\", that's (2 digits each)\nmonth, day, hour (0-23), and minute. Optionally century, year, and second.\nAlso accepts \"@UNIXTIME[.FRACTION]\" as seconds since midnight Jan 1 1970.\n\n-d Show DATE instead of current time (convert date format)\n-D +FORMAT for SET or -d (instead of MMDDhhmm[[CC]YY][.ss])\n-r Use modification time of FILE instead of current date\n-u Use UTC instead of current timezone\n\n+FORMAT specifies display format string using these escapes:\n\n%% literal % %n newline %t tab\n%S seconds (00-60) %M minute (00-59) %m month (01-12)\n%H hour (0-23) %I hour (01-12) %p AM/PM\n%y short year (00-99) %Y year %C century\n%a short weekday name %A weekday name %u day of week (1-7, 1=mon)\n%b short month name %B month name %Z timezone name\n%j day of year (001-366) %d day of month (01-31) %e day of month ( 1-31)\n%s seconds past the Epoch\n\n%U Week of year (0-53 start sunday) %W Week of year (0-53 start monday)\n%V Week of year (1-53 start monday, week < 4 days not part of this year)\n\n%D = \"%m/%d/%y\" %r = \"%I : %M : %S %p\" %T = \"%H:%M:%S\" %h = \"%b\"\n%x locale date %X locale time %c locale date/time\n\n"
diff --git a/generated/newtoys.h b/generated/newtoys.h
index 57526d7d..8afcc8bf 100644
--- a/generated/newtoys.h
+++ b/generated/newtoys.h
@@ -7,6 +7,7 @@ USE_GROUPADD(OLDTOY(addgroup, groupadd, TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_USERADD(OLDTOY(adduser, useradd, TOYFLAG_NEEDROOT|TOYFLAG_UMASK|TOYFLAG_SBIN))
USE_ARP(NEWTOY(arp, "vi:nDsdap:A:H:[+Ap][!sd]", TOYFLAG_USR|TOYFLAG_BIN))
USE_ARPING(NEWTOY(arping, "<1>1s:I:w#<0c#<0AUDbqf[+AU][+Df]", TOYFLAG_USR|TOYFLAG_SBIN))
+USE_ASCII(NEWTOY(ascii, 0, TOYFLAG_USR|TOYFLAG_BIN))
USE_BASE64(NEWTOY(base64, "diw#<0=76[!dw]", TOYFLAG_USR|TOYFLAG_BIN))
USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_USR|TOYFLAG_BIN))
USE_BLKID(NEWTOY(blkid, 0, TOYFLAG_BIN))
@@ -49,7 +50,7 @@ USE_DHCP6(NEWTOY(dhcp6, "r:A#<0T#<0t#<0s:p:i:SRvqnbf", TOYFLAG_SBIN|TOYFLAG_ROOT
USE_DHCPD(NEWTOY(dhcpd, ">1P#<0>65535fi:S46[!46]", TOYFLAG_SBIN|TOYFLAG_ROOTONLY))
USE_DIFF(NEWTOY(diff, "<2>2B(ignore-blank-lines)d(minimal)b(ignore-space-change)ut(expand-tabs)w(ignore-all-space)i(ignore-case)T(initial-tab)s(report-identical-files)q(brief)a(text)L(label)*S(starting-file):N(new-file)r(recursive)U(unified)#<0=3", TOYFLAG_USR|TOYFLAG_BIN))
USE_DIRNAME(NEWTOY(dirname, "<1", TOYFLAG_USR|TOYFLAG_BIN))
-USE_DMESG(NEWTOY(dmesg, "w(follow)Ctrs#<1n#c[!tr]", TOYFLAG_BIN))
+USE_DMESG(NEWTOY(dmesg, "w(follow)Ctrs#<1n#c[!tr][!Cc]", TOYFLAG_BIN))
USE_DOS2UNIX(NEWTOY(dos2unix, 0, TOYFLAG_BIN))
USE_DU(NEWTOY(du, "d#<0hmlcaHkKLsx[-HL][-kKmh]", TOYFLAG_USR|TOYFLAG_BIN))
USE_DUMPLEASES(NEWTOY(dumpleases, ">0arf:[!ar]", TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/lib/portability.h b/lib/portability.h
index afe02c1c..e0dd914e 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -45,6 +45,10 @@
#define RLIMIT_RTTIME 15
#endif
+#ifndef SEEK_DATA
+#define SEEK_DATA 3
+#endif
+
// We don't define GNU_dammit because we're not part of the gnu project, and
// don't want to get any FSF on us. Unfortunately glibc (gnu libc)
// won't give us Linux syscall wrappers without claiming to be part of the
diff --git a/main.c b/main.c
index a2267dab..d05cbfe8 100644
--- a/main.c
+++ b/main.c
@@ -213,8 +213,12 @@ int main(int argc, char *argv[])
}
*argv = getbasename(*argv);
- // Bionic's dynamic linker adds a handler to report SIGPIPE as an error,
- // then doesn't want that behavior for toybox. So disable it for bionic.
+ // Up to and including Android M, bionic's dynamic linker added a handler to
+ // cause a crash dump on SIGPIPE. That was removed in Android N, but adbd
+ // was still setting the SIGPIPE disposition to SIG_IGN, and its children
+ // were inheriting that. In Android O, adbd is fixed, but manually asking
+ // for the default disposition is harmless, and it'll be a long time before
+ // no one's using anything older than O!
if (CFG_TOYBOX_ON_ANDROID) signal(SIGPIPE, SIG_DFL);
// If nommu can't fork, special reentry path.
diff --git a/toys/other/ascii.c b/toys/other/ascii.c
index 4d33ae61..6689191c 100644
--- a/toys/other/ascii.c
+++ b/toys/other/ascii.c
@@ -26,13 +26,14 @@ void ascii_main(void)
for (x = 0; x<8; x++) printf("Dec Hex%*c", 2+2*(x<2)+(x>4), ' ');
xputc('\n');
- for (y=0; y<15; y++) {
+ for (y=0; y<=15; y++) {
for (x=0; x<8; x++) {
int i = x*16+y;
+ if (i>95 && i<100) putchar(' ');
printf("% 3d %02X ", i, i);
- if (i<32) printf("%.3s ", low+3*i);
- else printf("%*c ", 2*(i>95 && i<100), i);
+ if (i<32 || i==127) printf("%.3s ", (i==127) ? "DEL" : low+3*i);
+ else printf("%c ", i);
}
xputc('\n');
}
diff --git a/toys/lsb/dmesg.c b/toys/pending/dmesg.c
index c88fe113..40834b0c 100644
--- a/toys/lsb/dmesg.c
+++ b/toys/pending/dmesg.c
@@ -5,11 +5,11 @@
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/dmesg.html
// We care that FLAG_c is 1, so keep c at the end.
-USE_DMESG(NEWTOY(dmesg, "w(follow)Ctrs#<1n#c[!tr]", TOYFLAG_BIN))
+USE_DMESG(NEWTOY(dmesg, "w(follow)Ctrs#<1n#c[!tr][!Cc]", TOYFLAG_BIN))
config DMESG
bool "dmesg"
- default y
+ default n
help
usage: dmesg [-Cc] [-r|-t] [-n LEVEL] [-s SIZE] [-w]
@@ -45,7 +45,8 @@ static int xklogctl(int type, char *buf, int len)
}
// Use klogctl for reading if we're on a pre-3.5 kernel.
-static void legacy_mode() {
+static void legacy_mode()
+{
char *data, *to, *from;
int size;
@@ -75,33 +76,23 @@ static void legacy_mode() {
if (CFG_TOYBOX_FREE) free(data);
}
-static void color(int c) {
+static void color(int c)
+{
if (TT.color) printf("\033[%dm", c);
}
-void dmesg_main(void)
+static void print_all(void)
{
- // For -n just tell kernel which messages to keep.
- if (toys.optflags & FLAG_n) {
- xklogctl(8, 0, TT.level);
-
- return;
- }
-
- // For -C just tell kernel to throw everything out.
- if (toys.optflags & FLAG_C) {
- xklogctl(5, 0, 0);
-
- return;
- }
-
- TT.color = isatty(1);
-
// http://kernel.org/doc/Documentation/ABI/testing/dev-kmsg
// Each read returns one message. By default, we block when there are no
// more messages (--follow); O_NONBLOCK is needed for for usual behavior.
int fd = xopen("/dev/kmsg", O_RDONLY | ((toys.optflags&FLAG_w)?0:O_NONBLOCK));
+
+ // With /dev/kmsg, SYSLOG_ACTION_CLEAR (5) doesn't actually remove anything;
+ // you need to seek to the last clear point.
+ lseek(fd, 0, SEEK_DATA);
+
while (1) {
char msg[8192]; // CONSOLE_EXT_LOG_MAX.
unsigned long long time_us;
@@ -161,3 +152,16 @@ void dmesg_main(void)
}
close(fd);
}
+
+void dmesg_main(void)
+{
+ TT.color = isatty(1);
+
+ if (!(toys.optflags & (FLAG_C|FLAG_n))) print_all();
+
+ // Set the log level?
+ if (toys.optflags & FLAG_n) xklogctl(8, 0, TT.level);
+
+ // Clear the buffer?
+ if (toys.optflags & (FLAG_C|FLAG_c)) xklogctl(5, 0, 0);
+}
diff --git a/toys/posix/file.c b/toys/posix/file.c
index bab59e57..c7c72cd1 100644
--- a/toys/posix/file.c
+++ b/toys/posix/file.c
@@ -249,6 +249,8 @@ static void do_regular_file(int fd, char *name, struct stat *sb)
if (ver)
xprintf(", requires at least v%d.%d to extract", ver/10, ver%10);
xputc('\n');
+ } else if (len>4 && strstart(&s, "BZh") && isdigit(*s)) {
+ xprintf("bzip2 compressed data, block size = %c00k\n", *s);
} else {
char *what = 0;
int i, bytes;