diff options
author | Elliott Hughes <enh@google.com> | 2016-04-24 09:19:49 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-04-24 09:19:49 -0700 |
commit | 1fdd9271635a8681326c756ec43e7b037ca5891d (patch) | |
tree | b87c683068bfa8bc425c045e8f68d611f7da33b2 | |
parent | bba047d92c355e15913c3ab4d3859746b8070571 (diff) | |
parent | 072ea41682be093fd5fb25e7d6669a65a76144e6 (diff) | |
download | android_external_toybox-1fdd9271635a8681326c756ec43e7b037ca5891d.tar.gz android_external_toybox-1fdd9271635a8681326c756ec43e7b037ca5891d.tar.bz2 android_external_toybox-1fdd9271635a8681326c756ec43e7b037ca5891d.zip |
Merge remote-tracking branch 'toybox/master' into HEAD
-rw-r--r-- | lib/dirtree.c | 12 | ||||
-rw-r--r-- | lib/interestingtimes.c | 2 | ||||
-rw-r--r-- | lib/lib.h | 2 | ||||
-rw-r--r-- | lib/xwrap.c | 4 | ||||
-rw-r--r-- | scripts/runtest.sh | 4 | ||||
-rwxr-xr-x | tests/bzcat.test | 30 | ||||
-rwxr-xr-x | tests/touch.test | 12 | ||||
-rw-r--r-- | toys/other/bzcat.c | 8 | ||||
-rw-r--r-- | toys/pending/more.c | 7 | ||||
-rw-r--r-- | toys/posix/ls.c | 4 | ||||
-rw-r--r-- | toys/posix/touch.c | 7 |
11 files changed, 49 insertions, 43 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c index cc1ab90c..8f235ed4 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -110,12 +110,9 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new, if (!callback) return new; flags = callback(new); - if (S_ISDIR(new->st.st_mode)) { - if (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN)) { - new->dirfd = openat(dirtree_parentfd(new), new->name, O_CLOEXEC); - flags = dirtree_recurse(new, callback, flags); - } - } + if (S_ISDIR(new->st.st_mode) && (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN))) + flags = dirtree_recurse(new, callback, + openat(dirtree_parentfd(new), new->name, O_CLOEXEC), flags); // If this had children, it was callback's job to free them already. if (!(flags & DIRTREE_SAVE)) { @@ -130,12 +127,13 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new, // callback(). Uses and closes supplied ->dirfd. int dirtree_recurse(struct dirtree *node, - int (*callback)(struct dirtree *node), int flags) + int (*callback)(struct dirtree *node), int dirfd, int flags) { struct dirtree *new, **ddt = &(node->child); struct dirent *entry; DIR *dir; + node->dirfd = dirfd; if (node->dirfd == -1 || !(dir = fdopendir(node->dirfd))) { if (!(flags & DIRTREE_SHUTUP)) { char *path = dirtree_path(node, 0); diff --git a/lib/interestingtimes.c b/lib/interestingtimes.c index 8337ce8b..62670cbb 100644 --- a/lib/interestingtimes.c +++ b/lib/interestingtimes.c @@ -239,5 +239,5 @@ void tty_reset(void) void tty_sigreset(int i) { tty_reset(); - _exit(128+i); + _exit(i ? 128+i : 0); } @@ -84,7 +84,7 @@ char *dirtree_path(struct dirtree *node, int *plen); int dirtree_notdotdot(struct dirtree *catch); int dirtree_parentfd(struct dirtree *node); int dirtree_recurse(struct dirtree *node, int (*callback)(struct dirtree *node), - int symfollow); + int dirfd, int symfollow); struct dirtree *dirtree_flagread(char *path, int flags, int (*callback)(struct dirtree *node)); struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node)); diff --git a/lib/xwrap.c b/lib/xwrap.c index 0b1ab8e9..36a601c5 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -47,7 +47,9 @@ void xexit(void) // Call toys.xexit functions in reverse order added. while (toys.xexit) { // This is typecasting xexit->arg to a function pointer,then calling it. - ((void (*)(void))(toys.xexit->arg))(); + // Using the invalid signal number 0 lets the signal handlers distinguish + // an actual signal from a regular exit. + ((void (*)(int))(toys.xexit->arg))(0); free(llist_pop(&toys.xexit)); } diff --git a/scripts/runtest.sh b/scripts/runtest.sh index 0c933c2c..875ce572 100644 --- a/scripts/runtest.sh +++ b/scripts/runtest.sh @@ -83,7 +83,7 @@ testing() echo -ne "$3" > expected echo -ne "$4" > input - echo -ne "$5" | eval "$2" > actual + echo -ne "$5" | ${EVAL:-eval} "$2" > actual RETVAL=$? # Catch segfaults @@ -98,7 +98,7 @@ testing() if [ -n "$VERBOSE" ] then [ ! -z "$4" ] && echo "echo -ne \"$4\" > input" - echo "echo -ne '$5' | $2" + echo "echo -ne '$5' |$EVAL $2" diff -au expected actual [ "$VERBOSE" == fail ] && exit 1 fi diff --git a/tests/bzcat.test b/tests/bzcat.test index f57a2f88..0975f3d6 100755 --- a/tests/bzcat.test +++ b/tests/bzcat.test @@ -1,30 +1,16 @@ #!/bin/bash -# Copyright 2014 Divya Kothari <divya.s.kothari@gmail.com> -# Copyright 2014 Naha Maggu <maggu.neha@gmail.com> - [ -f testing.sh ] && . testing.sh #testing "name" "command" "result" "infile" "stdin" +testing "2 known files" \ + 'bzcat "$FILES/blkid/"{minix,ntfs}.bz2 | sha1sum | '"awk '{print \$1}'" \ + 'c0b7469c9660d6056a988ef8a7fe73925efc9266\n' '' '' + testing "overflow" \ 'bzcat "$FILES/bzcat/overflow.bz2" >/dev/null 2>/dev/null ; - [ $? -eq 1 ] && echo good' "good\n" "" "" + [ $? -ne 0 ] && echo good' "good\n" "" "" -echo "hello" > file -tar -cjf file.tar.bz2 file -# Get system bzcat -bzcatExe=`which bzcat` -$bzcatExe file.tar.bz2 > bzcatOut -testing "- decompresses a single file" "bzcat file.tar.bz2 > Tempfile && echo "yes"; diff Tempfile bzcatOut && echo "yes"; rm -rf file* bzcatOut Tempfile" "yes\nyes\n" "" "" - -#testing "name" "command" "result" "infile" "stdin" -echo "hello" > file1 -echo "hi" > file2 -echo "Hi, Good morning !! I am a bzcat tester" > file3 -tar -cjf file1.tar.bz2 file1 -tar -cjf file2.tar.bz2 file2 -tar -cjf file3.tar.bz2 file3 -# Get system bzcat -bzcatExe=`which bzcat` -$bzcatExe file1.tar.bz2 file2.tar.bz2 file3.tar.bz2 > bzcatOut -testing "- decompresses multiple files" "bzcat file1.tar.bz2 file2.tar.bz2 file3.tar.bz2 > Tempfile && echo "yes" ; diff Tempfile bzcatOut && echo "yes"; rm -rf file* bzcatOut Tempfile " "yes\nyes\n" "" "" +testing "badcrc" \ + 'bzcat "$FILES/bzcat/badcrc.bz2" > /dev/null 2>/dev/null ; + [ $? -ne 0 ] && echo good' "good\n" "" "" diff --git a/tests/touch.test b/tests/touch.test index d386156d..d193d7cc 100755 --- a/tests/touch.test +++ b/tests/touch.test @@ -11,6 +11,18 @@ testing "-c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" "" testing "-c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \ "yes\n" "" "" +testing "-t" \ + "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \ + "20120123-123400.000000000\n" "" "" + +testing "-t seconds" \ + "touch -t 201201231234.56 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \ + "20120123-123456.000000000\n" "" "" + +testing "-t nanoseconds" \ + "touch -t 201201231234.56123456789 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \ + "20120123-123456.123456789\n" "" "" + testing "-d" \ "touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \ "1234567890\n" "" "" diff --git a/toys/other/bzcat.c b/toys/other/bzcat.c index fdad9a01..ff598491 100644 --- a/toys/other/bzcat.c +++ b/toys/other/bzcat.c @@ -455,9 +455,6 @@ static void burrows_wheeler_prep(struct bunzip_data *bd, struct bwdata *bw) unsigned int *dbuf = bw->dbuf; int *byteCount = bw->byteCount; - // Technically this part is preparation for the burrows-wheeler - // transform, but it's quick and convenient to do here. - // Turn byteCount into cumulative occurrence counts of 0 to n-1. jj = 0; for (ii=0; ii<256; ii++) { @@ -651,7 +648,10 @@ static char *bunzipStream(int src_fd, int dst_fd) if (!(i = start_bunzip(&bd,src_fd, 0, 0))) { i = write_bunzip_data(bd,bd->bwdata, dst_fd, 0, 0); - if (i==RETVAL_LAST_BLOCK && bd->bwdata[0].headerCRC==bd->totalCRC) i = 0; + if (i==RETVAL_LAST_BLOCK) { + if (bd->bwdata[0].headerCRC==bd->totalCRC) i = 0; + else i = RETVAL_DATA_ERROR; + } } flush_bunzip_outbuf(bd, dst_fd); diff --git a/toys/pending/more.c b/toys/pending/more.c index 55bed363..7923ee4e 100644 --- a/toys/pending/more.c +++ b/toys/pending/more.c @@ -25,7 +25,12 @@ GLOBALS( static void signal_handler(int sig) { + // Reset the terminal whether we were signalled or exited normally. tcsetattr(TT.cin_fd, TCSANOW, &TT.inf); + + if (sig == 0) _exit(0); + + // We were actually signalled, so move to a new line and re-raise the signal. xputc('\n'); signal(sig, SIG_DFL); raise(sig); @@ -63,7 +68,7 @@ static int prompt(FILE *cin, const char* fmt, ...) static void do_cat_operation(int fd, char *name) { if (toys.optc > 1) show_file_header(name); - xsendfile(0, 1); + xsendfile(fd, 1); } void more_main() diff --git a/toys/posix/ls.c b/toys/posix/ls.c index 1d4777b0..94359d7a 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -337,8 +337,8 @@ static void listfiles(int dirfd, struct dirtree *indir) } else { // Read directory contents. We dup() the fd because this will close it. // This reads/saves contents to display later, except for in "ls -1f" mode. - indir->dirfd = dup(dirfd); - dirtree_recurse(indir, filter, DIRTREE_SYMFOLLOW*!!(flags&FLAG_L)); + dirtree_recurse(indir, filter, dup(dirfd), + DIRTREE_SYMFOLLOW*!!(flags&FLAG_L)); } // Copy linked list to array and sort it. Directories go in array because diff --git a/toys/posix/touch.c b/toys/posix/touch.c index 052448ba..22a1e2e8 100644 --- a/toys/posix/touch.c +++ b/toys/posix/touch.c @@ -80,10 +80,13 @@ void touch_main(void) if (s) break; toybuf[1]='y'; } + tm.tm_sec = 0; ts->tv_nsec = 0; if (s && *s=='.' && sscanf(s, ".%2u%n", &(tm.tm_sec), &len) == 1) { - sscanf(s += len, "%lu%n", &ts->tv_nsec, &len); - len++; + if (sscanf(s += len, "%lu%n", &ts->tv_nsec, &len) == 1) { + s--; + len++; + } else len = 0; } else len = 0; } if (len) { |