[Toybox] [PATCH] Implement `file -`.

enh enh at google.com
Sat May 5 16:19:40 PDT 2018


AFK, but I'm using glibc too, from Debian testing.

On Sat, May 5, 2018, 16:01 Rob Landley <rob at landley.net> wrote:

> On 05/05/2018 02:14 PM, enh wrote:
> > On Sat, May 5, 2018 at 10:53 AM, Rob Landley <rob at landley.net> wrote:
> > well, strictly i think only the ELF case actually needs this
> > currently. we could fix the logic for the non-ELF cases (see below)
> > and only copy to a temporary file for the ELF case. (alternatively, we
> > could always read into memory and unify the cases that way --- from
> > strace that seems to be what FSF file does?)
>
> I prefer to have one codepath that works for everything and gets all the
> testing. (The performance penalty was terrible enough I couldn't do it with
> "tail" but that's why it's an exception. :)
>
> >>> [PATCH] Implement `file -`.
> >>>
> >>> Previously we'd just always bogusly report "empty".
> >>
> >> That's not what I was seeing before this patch.
> >>
> >>   $ zcat ../filesystems.tar.gz | file -
> >>   /dev/stdin: POSIX tar archive (GNU)
> >>   $ zcat ../filesystems.tar.gz | ./file -
> >>   -: POSIX tar archive (GNU)
> >>
> >> Even with input from a pipe, we're detecting stuff?
> >>
> >> Could you clarify what problem this patch is trying to solve? I don't
> understand.
> >
> > i don't think you're accidentally running FSF file there, or you're
> > accidentally running toybox file _with_ my patch.
> >
> > here's a clean toybox checkout:
>
> $ git clone https://github.com/landley/toybox walrus
> Cloning into 'walrus'...
> $ cd walrus
> $ make defconfig
> ...
> $ make
> ...
>
> Ok, got a fresh copy, what are the tests...
>
> > $ ./toybox file - < README
> > -: empty
> > $ ./toybox file - < toybox
> > -: empty
> > $ ./toybox file - < tests/files/tar/tar.tgz
> > -: empty
> > $ cat tests/files/tar/tar.tgz | ./toybox file -
> > -: empty
> > $ zcat tests/files/tar/tar.tgz | ./toybox file -
> > -: empty
> > $
>
> Alright:
>
> $ ./toybox file - < README
> -: ASCII text
>
> That's built against glibc, you're building against bionic?
>
> $ ./toybox file - < toybox
> -: file: mmap: Cannot allocate memory
> ELF executable, 64-bit LSB x86-64$
>
> Yeah, mmap is broken and the stdout/stderr out of sequence flushing
> produces a
> screwed up shell prompt due to missing newline afterwards. *jazzhands*
>
> $ ./toybox file - < ../filesystems.tar.gz
> -: gzip compressed data
> $ zcat ../filesystems.tar.gz | ./toybox file -
> -: POSIX tar archive (GNU)
>
> It looks like glibc is behaving very differently than what you're seeing.
>
> Anything I build for x86-64 on the NDK segfaults before main() on the AMD
> C60 in
> this netbook (although I ordered a new netbook from system76 today, which
> cost
> the year the constitution was written _before_ shipping so maybe I'll have
> better luck with that than the $200 thing from target I upgraded the RAM
> on)...
>
> Let's try a static build against musl-libc...
>
> $ zcat ../filesystems.tar.gz | ./toybox file -
> -: empty
> $ ./toybox file - < toybox
> -: empty
> $ ./toybox file - < README
> -: empty
>
> Huh. Ok, that's weird. Yes, glibc is doing something that other C
> libraries are
> not doing, I'll see if I can track it down now that I can reproduce it...
>
> Rob
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20180505/e459b2d6/attachment-0001.htm>


More information about the Toybox mailing list