# HG changeset patch # User Isaac Dunham # Date 1373127975 18000 # Node ID b4faf2ae39e8e372e60e2e4a5bb457192bae6eb9 # Parent 8cb7d65a40e8e4995f865c33851fc68dfc97fd81 This inlines CRC64, and nothing more. The functions involved were called only once. diff -r 8cb7d65a40e8 -r b4faf2ae39e8 lib/dirtree.c --- a/lib/dirtree.c Wed Jul 03 02:29:24 2013 -0500 +++ b/lib/dirtree.c Sat Jul 06 11:26:15 2013 -0500 @@ -138,7 +138,7 @@ 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 -r 8cb7d65a40e8 -r b4faf2ae39e8 toys/other/hello.c --- a/toys/other/hello.c Wed Jul 03 02:29:24 2013 -0500 +++ b/toys/other/hello.c Sat Jul 06 11:26:15 2013 -0500 @@ -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 @@ 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 @@ 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 -r 8cb7d65a40e8 -r b4faf2ae39e8 toys/other/netcat.c --- a/toys/other/netcat.c Wed Jul 03 02:29:24 2013 -0500 +++ b/toys/other/netcat.c Sat Jul 06 11:26:15 2013 -0500 @@ -11,13 +11,13 @@ 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 + -q SECONDS quit this many seconds after EOF on stdin. -s local ipv4 address - -q SECONDS quit this many seconds after EOF on stdin. - -f use FILENAME (ala /dev/ttyS0) instead of network + -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 @@ 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 @@ { 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 @@ 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 @@ } // 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 @@ 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 @@ // (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 -r 8cb7d65a40e8 -r b4faf2ae39e8 toys/pending/xzcat.c --- a/toys/pending/xzcat.c Wed Jul 03 02:29:24 2013 -0500 +++ b/toys/pending/xzcat.c Sat Jul 06 11:26:15 2013 -0500 @@ -249,47 +249,8 @@ 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 @@ 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 @@ 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 -r 8cb7d65a40e8 -r b4faf2ae39e8 toys/posix/paste.c --- a/toys/posix/paste.c Wed Jul 03 02:29:24 2013 -0500 +++ b/toys/posix/paste.c Sat Jul 06 11:26:15 2013 -0500 @@ -28,28 +28,26 @@ 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 @@ 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 -r 8cb7d65a40e8 -r b4faf2ae39e8 toys/posix/xargs.c --- a/toys/posix/xargs.c Wed Jul 03 02:29:24 2013 -0500 +++ b/toys/posix/xargs.c Sat Jul 06 11:26:15 2013 -0500 @@ -25,6 +25,14 @@ #-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 -r 8cb7d65a40e8 -r b4faf2ae39e8 www/news.html --- a/www/news.html Wed Jul 03 02:29:24 2013 -0500 +++ b/www/news.html Sat Jul 06 11:26:15 2013 -0500 @@ -6,6 +6,85 @@ a development environment. See the links on the left for details.

News

+
July 2, 2013 +

"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.

+ +

Toybox 0.4.5 is based on +commit 941. 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". +

+ +

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).

+ +

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.)

+ +

I'm documenting the cleanups to teach +more people to do it, but the writeups aren't caught up yet. The +roadmap also got updated a bit with further analysis +of other projects, and the README and about pages got updated.

+ +

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). +

+ +

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). + +

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.)

+

+ +

LICENSE TWEAK: After discussion on the mailing list the "2 clause +BSD" license got slightly simplified so the first +paragraph now says:

+ +

Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby granted.

+ +

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 files with +both license notices on them (sometimes at opposite ends of the file 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?

+ +

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.

+
March 21, 2013

Video of my ELC talk "Why is Toybox?"