diff options
-rw-r--r-- | lib/dirtree.c | 2 | ||||
-rw-r--r-- | toys/other/hello.c | 13 | ||||
-rw-r--r-- | toys/other/netcat.c | 30 | ||||
-rw-r--r-- | toys/pending/xzcat.c | 63 | ||||
-rw-r--r-- | toys/posix/paste.c | 17 | ||||
-rw-r--r-- | toys/posix/xargs.c | 8 | ||||
-rwxr-xr-x | www/news.html | 79 |
7 files changed, 141 insertions, 71 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c index e119c5d1..361686aa 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -138,7 +138,7 @@ void dirtree_recurse(struct dirtree *node, struct dirent *entry; DIR *dir; - if (!(dir = fdopendir(node->data))) { + if (node->data == -1 || !(dir = fdopendir(node->data))) { char *path = dirtree_path(node, 0); perror_msg("No %s", path); free(path); diff --git a/toys/other/hello.c b/toys/other/hello.c index b0fc5381..a6bc69eb 100644 --- a/toys/other/hello.c +++ b/toys/other/hello.c @@ -5,7 +5,9 @@ * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html -USE_HELLO(NEWTOY(hello, "e@d*c#b:a", TOYFLAG_USR|TOYFLAG_BIN)) +// Accept many different kinds of command line argument: + +USE_HELLO(NEWTOY(hello, "(walrus)(blubber):e@d*c#b:a", TOYFLAG_USR|TOYFLAG_BIN)) config HELLO bool "hello" @@ -29,14 +31,18 @@ GLOBALS( long c_number; struct arg_list *d_list; long e_count; + char *blubber_string; int more_globals; ) +// Parse many different kinds of command line argument: + void hello_main(void) { printf("Hello world\n"); + if (toys.optflags) printf("flags=%x\n", toys.optflags); if (toys.optflags & FLAG_a) printf("Saw a\n"); if (toys.optflags & FLAG_b) printf("b=%s\n", TT.b_string); if (toys.optflags & FLAG_c) printf("c=%ld\n", TT.c_number); @@ -44,7 +50,8 @@ void hello_main(void) printf("d=%s\n", TT.d_list->arg); TT.d_list = TT.d_list->next; } - if (TT.e_count) printf("e was seen %ld times", TT.e_count); - + if (TT.e_count) printf("e was seen %ld times\n", TT.e_count); while (*toys.optargs) printf("optarg=%s\n", *(toys.optargs++)); + if (toys.optflags & FLAG_walrus) printf("Saw --walrus\n"); + if (TT.blubber_string) printf("--blubber=%s\n", TT.blubber_string); } diff --git a/toys/other/netcat.c b/toys/other/netcat.c index 0173e6db..a245d119 100644 --- a/toys/other/netcat.c +++ b/toys/other/netcat.c @@ -11,13 +11,13 @@ config NETCAT bool "netcat" default y help - usage: netcat [-wpq #] [-s addr] {IPADDR PORTNUM|-f FILENAME|-let} [-e COMMAND] + usage: netcat [-wpq #] [-s addr] [-u] {IPADDR PORTNUM|-f FILENAME} - -w SECONDS timeout for connection + -f use FILENAME (ala /dev/ttyS0) instead of network -p local port number - -s local ipv4 address -q SECONDS quit this many seconds after EOF on stdin. - -f use FILENAME (ala /dev/ttyS0) instead of network + -s local ipv4 address + -w SECONDS timeout for connection Use "stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho" with netcat -f to connect to a serial port. @@ -27,13 +27,14 @@ config NETCAT_LISTEN default y depends on NETCAT help + usage: netcat [-t] [-lL COMMAND...] + -t allocate tty (must come before -l or -L) -l listen for one incoming connection. -L listen for multiple incoming connections (server mode). - Any additional command line arguments after -l or -L are executed - to handle each incoming connection. If none, the connection is - forwarded to stdin/stdout. + The command line after -l or -L is executed to handle each incoming + connection. If none, the connection is forwarded to stdin/stdout. For a quick-and-dirty server, try something like: netcat -s 127.0.0.1 -p 1234 -tL /bin/bash -l @@ -68,7 +69,7 @@ static void lookup_name(char *name, uint32_t *result) { struct hostent *hostbyname; - hostbyname = gethostbyname(name); + hostbyname = gethostbyname(name); // getaddrinfo if (!hostbyname) error_exit("no host '%s'", name); *result = *(uint32_t *)*hostbyname->h_addr_list; } @@ -102,8 +103,7 @@ void netcat_main(void) struct sockaddr_in address; // Setup socket - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (-1 == sockfd) perror_exit("socket"); + sockfd = xsocket(AF_INET, SOCK_STREAM, 0); fcntl(sockfd, F_SETFD, FD_CLOEXEC); temp = 1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &temp, sizeof(temp)); @@ -140,7 +140,7 @@ void netcat_main(void) } // Do we need to return immediately because -l has arguments? - if ((toys.optflags&FLAG_l) && toys.optc) { + if ((toys.optflags & FLAG_l) && toys.optc) { if (fork()) goto cleanup; close(0); close(1); @@ -170,7 +170,7 @@ void netcat_main(void) if (!temp) close(sockfd); dup2(fd, 0); dup2(fd, 1); - dup2(fd, 2); + if (toys.optflags&FLAG_L) dup2(fd, 2); if (fd>2) close(fd); } } @@ -186,10 +186,8 @@ void netcat_main(void) // (Does not play well with -L, but what _should_ that do?) set_alarm(0); - if (CFG_NETCAT_LISTEN && (toys.optflags&(FLAG_L|FLAG_l) && toys.optc)) { - execvp(*toys.optargs, toys.optargs); - error_exit("Exec failed"); - } + if (CFG_NETCAT_LISTEN && (toys.optflags&(FLAG_L|FLAG_l) && toys.optc)) + xexec(toys.optargs); // Poll loop copying stdin->socket and socket->stdout. for (;;) { diff --git a/toys/pending/xzcat.c b/toys/pending/xzcat.c index 5d69087c..3bbb8230 100644 --- a/toys/pending/xzcat.c +++ b/toys/pending/xzcat.c @@ -249,47 +249,8 @@ uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc) return ~crc; } -/* - * This must be called before any other xz_* function (but after crc_init()) - * to initialize the CRC64 lookup table. - */ static uint64_t xz_crc64_table[256]; -void xz_crc64_init(void) -{ - const uint64_t poly = 0xC96C5795D7870F42ULL; - - uint32_t i; - uint32_t j; - uint64_t r; - - for (i = 0; i < 256; ++i) { - r = i; - for (j = 0; j < 8; ++j) - r = (r >> 1) ^ (poly & ~((r & 1) - 1)); - - xz_crc64_table[i] = r; - } - - return; -} - -/* - * Update CRC64 value using the polynomial from ECMA-182. To start a new - * calculation, the third argument must be zero. To continue the calculation, - * the previously returned value is passed as the third argument. - */ -uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc) -{ - crc = ~crc; - - while (size != 0) { - crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8); - --size; - } - - return ~crc; -} // END xz.h @@ -304,7 +265,19 @@ void xzcat_main(void) const char *msg; crc_init(xz_crc32_table, 1); - xz_crc64_init(); + const uint64_t poly = 0xC96C5795D7870F42ULL; + uint32_t i; + uint32_t j; + uint64_t r; + + /* initialize CRC64 table*/ + for (i = 0; i < 256; ++i) { + r = i; + for (j = 0; j < 8; ++j) + r = (r >> 1) ^ (poly & ~((r & 1) - 1)); + + xz_crc64_table[i] = r; + } /* * Support up to 64 MiB dictionary. The actually needed memory @@ -2767,8 +2740,14 @@ static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b) s->crc = xz_crc32(b->out + s->out_start, b->out_pos - s->out_start, s->crc); else if (s->check_type == XZ_CHECK_CRC64) - s->crc = xz_crc64(b->out + s->out_start, - b->out_pos - s->out_start, s->crc); + s->crc = ~(s->crc); + size_t size = b->out_pos - s->out_start; + uint8_t *buf = b->out + s->out_start; + while (size) { + s->crc = xz_crc64_table[*buf++ ^ (s->crc & 0xFF)] ^ (s->crc >> 8); + --size; + } + s->crc=~(s->crc); if (ret == XZ_STREAM_END) { if (s->block_header.compressed != VLI_UNKNOWN diff --git a/toys/posix/paste.c b/toys/posix/paste.c index 92a52534..0e170cdb 100644 --- a/toys/posix/paste.c +++ b/toys/posix/paste.c @@ -28,28 +28,26 @@ GLOBALS( void paste_main(void) { - char *p, *buf = toybuf; - char **args = toys.optargs; + char *p, *buf = toybuf, **args = toys.optargs; size_t ndelim = 0; int i, j, c; // Process delimiter list // TODO: Handle multibyte characters if (!(toys.optflags & FLAG_d)) TT.delim = "\t"; - p = TT.delim; - for (; *p; p++, buf++, ndelim++) { + for (p = TT.delim; *p; p++, buf++, ndelim++) { if (*p == '\\') { p++; if (-1 == (i = stridx("nt\\0", *p))) error_exit("bad delimiter: \\%c", *p); *buf = "\n\t\\\0"[i]; - } - else *buf = *p; + } else *buf = *p; } *buf = 0; if (toys.optflags & FLAG_s) { // Sequential FILE *f; + for (; *args; args++) { if ((*args)[0] == '-' && !(*args)[1]) f = stdin; else if (!(f = fopen(*args, "r"))) perror_exit("%s", *args); @@ -66,20 +64,21 @@ void paste_main(void) if (f != stdin) fclose(f); putchar('\n'); } - } - else { // Parallel + } else { // Parallel // Need to be careful not to print an extra line at the end FILE **files; int anyopen = 1; + files = (FILE**)(buf + 1); for (; *args; args++, files++) { if ((*args)[0] == '-' && !(*args)[1]) *files = stdin; else if (!(*files = fopen(*args, "r"))) perror_exit("%s", *args); } - for (; anyopen;) { + while (anyopen) { anyopen = 0; for (i = 0; i < toys.optc; i++) { FILE **f = (FILE**)(buf + 1) + i; + if (*f) for (;;) { c = getc(*f); if (c != EOF) { diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c index 18b70f2e..e1611ec3 100644 --- a/toys/posix/xargs.c +++ b/toys/posix/xargs.c @@ -25,6 +25,14 @@ config XARGS #-r Don't run command with empty input #-L Max number of lines of input per command -E stop at line matching string + +config XARGS_PEDANTIC + bool "TODO xargs pedantic posix compatability" + default n + depends on XARGS + help + This version supports insane posix whitespace handling rendered obsolete + by -0 mode. */ #define FOR_xargs diff --git a/www/news.html b/www/news.html index f1c85948..66f25711 100755 --- a/www/news.html +++ b/www/news.html @@ -6,6 +6,85 @@ reasonably standards-compliant, and powerful enough to turn Android into a development environment.</b> See the links on the left for details.</p> <h2>News</h2> +<hr><b>July 2, 2013</b> +<blockquote><p>"Time is an illusion. Lunchtime doubly so." "Very deep. You +should send that in to the Reader's Digest. They've got a page for people +like you." - +The Hitchhiker's Guide to the Galaxy.</p></blockquote> + +<p><a href=downloads/toybox-0.4.5.tar.bz2>Toybox 0.4.5</a> is based on +<a href=http://landley.net/hg/toybox/shortlog/941>commit 941</a>. It adds +uuencode and uudecode from Erich Plondke, and enables Luis Morales' "who" by +default. Felix Janda and I cleaned up last year's "stat" submission and +enabled it. Ivo van Poorten added "groups". +Andre Renaud added "lsusb". I implemented "split", "pivot_root", and "mv". +</p> + +<p>The "help" command is implemented differently now (lib/help.c) and +each command can now understand --help (including both "toybox --help" +and "toybox --help command" in the multiplexer).</p> + +<p>The "pending" directory has several commands (find, xzcat, nbd-client, +logger, expr) which work but are not enabled by default pending further cleanup. +Ifconfig is enabled, but still in pending because it's only 2/3 cleaned up. +(It's an awkward halfway state but I'm not holding up the release for it.)</p> + +<p>I'm <a href=cleanup.html>documenting the cleanups</a> to teach +more people to do it, but the writeups aren't caught up yet. The +<a href=roadmap.html>roadmap</a> also got updated a bit with further analysis +of other projects, and the README and about pages got updated.</p> + +<p>Fixed _another_ "ls -C" segfault when terminal size can't be detected, +condensed the ls help text to fit on one page, implented --color, and taught +-l to print the major, minor numbers when showing block/char devices. +Argument parsing now handles "--" properly (to end option checking), +and the infrastructure can now handle bare --longopts that have no +corresponding short option (both were implemented before but didn't work). +Fixed an old bug in "patch", chmod grew -f, who grew -a. Isaac Dunham +fixed "-" vs "_" handling in modinfo, added a "firmware" output +field, added -b and -k support, and taught it that the ".ko" extension means +to look for the file at the specified path instead of under /lib. Felix Janda +moved file permission display code to lib so ls and +stat could share it. Ashwini Sharma spotted a bug in xabspath when the +last path component exists but we haven't got permissions to open it +(ala readlink -f /dev/sda as a normal user). +</p> + +<p>In the build infrastructure, scripts/findglobals.sh finds leaked global +variables. (Leaked means they aren't part of the global union: Other than glibc +debris, toybox should define "this", "toy_list", "toybuf", and "toys", and +that's it; the rest add memory footprint to every command for the benefit of +just one command; use GLOBALS() to stick 'em in the union.) Static linking +against libraries other than the host's libc now applies to feature probes +for unshare and such. Neuter stupid internationalization support that makes +various host "sort" commands put things in an order other than alphabetical +(breaking the multiplexer's binary search on command names). + +<p>You should now be able to build from a source control snapshot on a build +system that hasn't got python: if you disable CONFIG_TOYBOX_HELP. (The +release tarballs ship generated/help.h, but it's not in source control. +Eventually I should rewrite that python script in C.)</p> +</p> + +<p><b>LICENSE TWEAK</b>: After <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-March/000794.html>discussion</a> on the mailing list the "2 clause +BSD" <a href=license.html>license</a> got slightly simplified so the first +paragraph now says:</p> + +<blockquote><p>Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby granted.</p></blockquote> + +<p>It used to continue "provided that the above copyright notice and this +permission notice appear in all copies", but A) what's the point? B) does "all +copies" mean binaries, or just source code, or what? C) lots of projects +that consider BSD and GPL compatible have <a href=https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/crypto/aes_generic.c>files with +both license notices</a> on them (sometimes at <a href=http://git.busybox.net/busybox/tree/shell/ash.c>opposite ends of the file</a> to make the conflict +less obvious) because "all copies must include this function" would violate +the GPL but "all copies must include this magic text blob" somehow don't?</p> + +<p>I don't want to have to care about this anymore. The tweaked version is more +or less public domain with a liability disclaimer, but we're still calling it +BSD (sometimes "0 clause BSD") to avoid explaining.</p> + <hr><b>March 21, 2013</b> <p>Video of my ELC talk "<a href=http://youtu.be/SGmtP5Lg_t0>Why is Toybox?</a>" |