Skip to content

cat is not working #2017

Closed
Closed

Description

@DoBi

I've installed the new release 0.0.5 and now cat is not working any more:
Sometimes it gives me:

$ cat config.log
cat: error: EINVAL: Invalid argument

This file exists and GNU cat is working printing its content.

For some other files there is no output.
I don't know, what causes this different behaviour.
But at least cat is not working as expected.

Activity

  1. sylvestre commented on Apr 3, 2021

    @sylvestre
    SponsorContributor

    Yeah, I noticed that too :(
    I will do a 0.0.6 to fix it.

    I guess it is caused by
    #1978
    cc @ArniDagur

    We should improve the coverage:
    https://codecov.io/gh/uutils/coreutils/src/master/src/uu/cat/src/cat.rs

  2. sylvestre commented on Apr 3, 2021

    @sylvestre
    SponsorContributor

    I yanked 0.0.5 from crates.io because of this

  3. added a commit that references this issue on Apr 3, 2021
  4. ArniDagur commented on Apr 3, 2021

    @ArniDagur
    SponsorContributor

    Well... This is embarrassing. @DoBi could you tell me:

    • The output of uname -a
    • Which kind of file config.log is. Is it regular? A symlink?

    The tests in #2001 find this regression; that's why they fail. The weird thing is however that manually calling cat never fails for me, it only ever fails through cargo test. I will investigate further.

  5. sylvestre commented on Apr 3, 2021

    @sylvestre
    SponsorContributor

    on a regular debian:

    $ echo "foo" >> /tmp/a.xt
    $ /usr/lib/cargo/bin/coreutils/cat /tmp/a.txt
    $ /usr/lib/cargo/bin/coreutils/cat /tmp/a.txt|wc -c
    0
    $ /usr/lib/cargo/bin/coreutils/cat --version
    cat 0.0.5
    $ uname -a
    Linux xxxx 5.10.0-1-amd64 #1 SMP Debian 5.10.4-1 (2020-12-31) x86_64 GNU/Linux
    
    
  6. ArniDagur commented on Apr 3, 2021

    @ArniDagur
    SponsorContributor
    [arni][~/src/coreutils][cat-tests]% yes | head -c16383 > 16k_minus1_file.txt
    [arni][~/src/coreutils][cat-tests]% yes | head -c16384 > 16k_file.txt
    [arni][~/src/coreutils][cat-tests]% yes | head -c16385 > 16k_plus1_file.txt
    [arni][~/src/coreutils][cat-tests]% target/release/cat 16k_plus1_file.txt
    [arni][~/src/coreutils][cat-tests]% target/release/cat 16k_plus1_file.txt | wc -c
    16384
    [arni][~/src/coreutils][cat-tests]% target/release/cat 16k_file.txt | wc -c
    0
    [arni][~/src/coreutils][cat-tests]% target/release/cat 16k_minus1_file.txt | wc -c
    0
    [arni][~/src/coreutils][cat-tests]% yes | head -c16387 > 16k_plus3_file.txt
    [arni][~/src/coreutils][cat-tests]% target/release/cat 16k_plus3_file.txt | wc -c
    16384
    

    It seems that any file of length <= 16384 fails to print anything. That's the buffer size I used for the splice operation. I have an idea of what is wrong.

  7. tertsdiepraam commented on Apr 3, 2021

    @tertsdiepraam
    Collaborator

    @ArniDagur those tests match what's happening on my machine. It only seems to fail without options. Hope that helps!

    $ echo "foo" > /tmp/a.txt
    $ target/debug/coreutils cat /tmp/a.txt
    $ target/debug/coreutils cat -s /tmp/a.txt
    foo
    $ target/debug/coreutils cat -n /tmp/a.txt
         1  foo
    $ target/debug/coreutils cat -v /tmp/a.txt
    foo
    
  8. ArniDagur commented on Apr 3, 2021

    @ArniDagur
    SponsorContributor

    wow I'm so dumb.

    openat(AT_FDCWD, "16k_plus3_file.txt", O_RDONLY|O_CLOEXEC) = 3
    pipe([4, 5])                            = 0
    splice(3, NULL, 5, NULL, 16384, 0)      = 16384
    splice(3, NULL, 5, NULL, 16384, 0)      = 3
    splice(4, NULL, 1, NULL, 16384, 0)      = 16384
    splice(3, NULL, 5, NULL, 16384, 0)      = 0
    

    I'll post a fix in a minute.

  9. DoBi commented on Apr 3, 2021

    @DoBi
    ContributorAuthor

    @ArniDagur in case you need some more info for cat: error: EINVAL: Invalid argument:

    Output of uname -a:
    Linux XXX 5.11.10-hardened1-1-hardened #1 SMP PREEMPT Thu, 25 Mar 2021 21:32:46 +0000 x86_64 unknown unknown GNU/Linux

    It is a regular file. Output of ls -las config.log
    40 -rw-r--r-- 1 <username> <groupname> 38586 3. Apr 17:02 config.log

    The same error appears when executing the command on a symlink to this file.

  10. ArniDagur commented on Apr 3, 2021

    @ArniDagur
    SponsorContributor

    One line fix:

    [arni][~/src/coreutils][cat-tests]% git diff | cat
    diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs
    index f39708fd..5861e348 100644
    --- a/src/uu/cat/src/cat.rs
    +++ b/src/uu/cat/src/cat.rs
    @@ -459,6 +459,7 @@ fn write_fast_using_splice<R: Read>(handle: &mut InputHandle<R>, writer: RawFd)
                 }
             }
         }
    +    splice(pipe_rd, None, writer, None, BUF_SIZE, SpliceFFlags::empty())?;
    
         loop {
             let n = splice(
    [arni][~/src/coreutils][cat-tests]% target/release/cat 16k_plus3_file.txt | wc -c
    16387
    [arni][~/src/coreutils][cat-tests]% cargo test --release test_no_options
    ...
         Running tests/tests.rs (target/release/deps/tests-3f4336eae7fd152c)
    
    running 2 tests
    test test_cat::test_no_options ... ok
    test test_cat::test_no_options_big_input ... ok
    
    test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 764 filtered out; finished in 0.01s
    
  11. ArniDagur commented on Apr 3, 2021

    @ArniDagur
    SponsorContributor

    @DoBi Could you try #2020 and see if that fixes the EINVAL error?

  12. sylvestre commented on Apr 3, 2021

    @sylvestre
    SponsorContributor

    Thanks :)
    by the way, if you want to benchmark it, hyperfine is pretty good
    https://github.com/sharkdp/hyperfine

  13. DoBi commented on Apr 3, 2021

    @DoBi
    ContributorAuthor

    @DoBi Could you try #2020 and see if that fixes the EINVAL error?

    Yes, it works fine with both, the regular file as well as with the symlink 👍

  14. sylvestre commented on Apr 3, 2021

    @sylvestre
    SponsorContributor

    This issue is now fixed in tree. So, closing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions