aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2020-08-20xputsl: write to stdout, not stdin!Elliott Hughes
This is why the tests have been failing since 42303209f44a335025b9cd1dbe5dd2f3069f2e99.
2020-08-19xputsl: remove unused variable.Elliott Hughes
2020-08-15If we fflush(stdout) first we can just write to filehandle.Rob Landley
2020-08-13list_signals: fit to window size.Elliott Hughes
Helps for terminals narrower than 80 columns (such as ConnectBot on a current Android device).
2020-08-04Inline convert_tz()Rob Landley
2020-08-04xparsedate: support UTC offsets.Elliott Hughes
Requested in https://github.com/landley/toybox/issues/130, quoting an old version of the toybox help. This is also supported by coreutils. Set $LANG to C in the date tests so that they pass with TEST_HOST=1 (they were already failing for me, presumably related to a newer glibc).
2020-08-04Toysh signal handling adds a few EINTR recovery corner cases to lib.Rob Landley
2020-08-04echo: fix trailing \0.Elliott Hughes
This is a follow-on from 310eefe, addressing the case where sscanf fails and returns -1.
2020-06-19Bugfix: the code to trim \n off xgetline() was using allocated not read length.Rob Landley
2020-06-01Use copy_file_range() when available.Rob Landley
2020-05-28portability.c: fix macOS build.Elliott Hughes
I suspect the rest of the non-POSIX signals might end up like this, but this is the subset that needs to be #ifdef'ed to fix the macOS build.
2020-05-26Instead of ifdef linux or macos, just ifdef the signals.Rob Landley
2020-05-21Check the signal rather than special case a library and a target.Rob Landley
2020-05-21glibc on mips is missing SIGSTKFLTKhem Raj
Do not therefore assume it being available linuxwide Fixes | lib/portability.c:433:3: error: use of undeclared identifier 'SIGSTKFLT' | SIGNIFY(STKFLT), SIGNIFY(POLL), SIGNIFY(PWR), | ^ Signed-off-by: Khem Raj <raj.khem@gmail.com>
2020-05-21David Legault reported that unescape2() doesn't handle \0 rightRob Landley
because scanf("0%o") needs a 0 _and_ one or more digits. So add it to the end of the \n translation list (where it returns the null terminator).
2020-05-19xsignal_all_killers() should install the handler given to it, and do someRob Landley
refactoring while I was looking at the codepath.
2020-05-05Fix 32 bit option parsing for long long optflag values.Rob Landley
2020-05-03Next round of shell work.Rob Landley
2020-04-13Add unescape2(), migrate some unescape() users over.Rob Landley
2020-04-02Move #include <linux/*.h> into individual commands, initialize structRob Landley
with memset() instead of = {}, and move TT.alarm to local variable.
2020-04-02More shell plumbing. Redo of variable storage, add export.Rob Landley
2020-04-01Add rtcwake.Elliott Hughes
Some of the bringup folks are debugging RTC issues and asked for this. Rather than duplicate the weird xtzset dance with mktime, I've factored that out into a new xmktime that takes a boolean for whether to use UTC or local time. Otherwise, the slight cleanup of hwclock.c is entirely optional. The only functional change there is that util-linux 2.34's hwclock uses ISO time format, which is the usual toybox preference anyway, so I've switched it over to that rather than ctime(3). Bug: http://b/152042947
2020-03-18Fix WARN_ONLY (and the one caller feeding it in the field it was checking).Rob Landley
2020-03-12Fix get_block_device_size() for linuxGreg Kaiser
We were incorrectly passing a pointer to a pointer of an unsigned long long, when we just wanted to pass a pointer to the unsigned long long. This is especially bad on 32-bit systems, where we're then writing a 64-bits into a 32-bit value within ioctl. We fix this to pass a pointer to the unsigned long long. Test: On 32-bit device, no longer see native crash from toybox Bug: http://b/151311535 Signed-off-by: Elliott Hughes <enh@google.com>
2020-03-11fdlength: device size is reported in bytes, not blocks.Elliott Hughes
The shift was a remnant from when BLKGETSIZE (which measures in blocks) was being used on Linux. The Mac has two separate ioctls for block count and block size, which we're already multiplying together. And on Linux we're using BLKGETSIZE64, which returns a result in bytes, not blocks. So lose the shift.
2020-03-11Fix Mac build.Elliott Hughes
The recent re-enablement of the BLKGETSIZE64 code broke the Mac build. Use the equivalent <sys/disk.h> ioctl() pair instead.
2020-03-10modinfo: various fixes.Elliott Hughes
I came here because the new -Wno-unreachable-code-loop-increment warning didn't like the for loop on line 86. That loop is indeed not necessary. Use strend() to do a string suffix match. Use memmem() to search. It's available on macOS and Android by default, but it's behind _GNU_SOURCE for glibc, so add that to portability.h. Output the tags in the same order as the Debian modinfo. I've left "parmtype" in even though the Debian modinfo doesn't output it at all. Also fix the tests so that they work on a device that has modules for multiple kernels installed (like my laptop) --- make sure that the two modules we pick come from the same kernel.
2020-03-01Park Ju Hyung pointed out the fast path of fdlength() was commented out.Rob Landley
(Update to the 64 bit API while we're there. And yes, I checked in the kernel, it's 512 byte units.)
2020-02-26Fix xclearenv() breakage pointed out by Derrick Pallas.Rob Landley
Toybox doesn't modify inherited environ[] (the same way we don't modify our inherited argv[]), so instead of freeing our allocated environ[] when we want to clear it we need to allocate a new environ[] in the else path (at a length compatible with the existing plumbing's add stride), set the first entry of _that_ to 0, and set toys.envc = 1 to record it's an alloced environ.
2020-02-10Factor out readfd()Rob Landley
2020-01-16The expand should expand.Rob Landley
2020-01-08Implement readelf(1).Elliott Hughes
Basic readelf(1) implementation, with output close enough to the binutils version to be usable with scripts that expect the binutils version. This started as an implementation of nm(1) until I realized that I almost always want readelf instead, and that you actually have to do much of the work needed for readelf just to implement nm. Arguably nm (being part of POSIX) belongs in toybox while readelf doesn't. An argument could also be made that neither really belongs in toybox, belonging in a separate set of development tools (such as binutils or the LLVM binutils). Doesn't support most of the architecture-specific stuff, most notably relocations, but is aware of things like ARM exidx sections and the common register state notes in core dumps for the "big four" architectures: arm, arm64, x86, and x86-64. Doesn't support symbol versions (but probably should). Doesn't support section groups or the -t "section details" (which is a long form of -S "section headers" that I've never seen used in practice and which isn't part of -a). Doesn't support dumping unwind info or the hash table bucket histograms. Reuses the table of ELF architectures from file(1). Not fuzzed, but successfully parses all the ELF files in my Ubuntu 18.04 system's lib directories. Attempts to exit with an error when presented with an invalid ELF file rather than struggle on as binutils seems to.
2020-01-06SebiderSushi reported that chmod g+s wasn't working.Rob Landley
2020-01-03Only free the environment variables we didn't inherit from exec.Rob Landley
2020-01-03No, optflags gets cleared by toy_init(), use toys.rebound instead.Rob Landley
2020-01-03Add MAYFORK to "help", teach it to behave differently when called as aRob Landley
builtin, and add -u.
2019-12-28Allow dlist_terminate() to be called repeatedly on same list.Rob Landley
2019-12-14Bugfix: xgetline() wasn't returning NULL at EOF.Rob Landley
2019-12-14dirtree.c: avoid spurious EINVAL warnings.Elliott Hughes
An Android engineer complained that they were seeing this when not running as root: $ adb shell ls ls: ./postinstall: Invalid argument ls: ./init: Permission denied ls: ./data_mirror: Invalid argument ls: ./init.environ.rc: Invalid argument ls: ./metadata: Invalid argument acct adb_keys apex From strace, it was here: newfstatat(4, "adb_keys", 0x7fc67eca88, AT_SYMLINK_NOFOLLOW) = -1 EACCES (Permission denied) readlinkat(4, "adb_keys", 0x5e843c7720, 4095) = -1 EINVAL (Invalid argument) So stop looking at st.st_mode (and then deciding to do a readlinkat()) if we didn't actually successfully stat().
2019-12-12Next round of toysh work, with associated lib plumbing.Rob Landley
2019-12-06Squash a warning.Rob Landley
2019-12-06stat: fix filesystem type on macOS.Elliott Hughes
(Also show unknown values on Linux in hex rather than just "unknown".)
2019-11-23Fix dev_minor()/dev_major()/dev_makedev() for Mac.Elliott Hughes
Major/minor device encoding is not portable. No two BSDs agree with each other, and Darwin is different again. Everyone does agree on having major()/minor()/makedev() macros, but they disagree whether they should be in <sys/types.h> (the BSDs including Darwin, and old versions of glibc) or <sys/sysmacros.h> (glibc >= 2.26 and bionic). This fixes `ls -l /dev/zero` and `stat /dev/zero` on Mac.
2019-11-23Elliott pointed out a codepath that could use uninitialized data.Rob Landley
(If DIRTREE_SYMFOLLOW returns ENOENT, skipping the second fstatat() would also skip the else goto error)
2019-11-22Add getopt(1).Elliott Hughes
Includes new tests.
2019-11-13Old gcc versions are confused by __has_include(), so nest the #ifdefsRob Landley
and #define/#undef a second symbol for the else case.
2019-10-29Let "find -L -type -l" find dangling symlinks.Rob Landley
2019-10-27macOS: implement posix_fallocate().Elliott Hughes
2019-10-27Tar extract should delete files or symlinks where it's making a directory,Rob Landley
but --restrict checking should run on the path up to the last component before unlinking so tar can't be tricked into deleting random files off the system.
2019-10-26Add ln -r and relative_path() to lib, plus test.Rob Landley
And a few small cleanups while I was there.