Skip to content

bug: eza silently exits without listing when stdin is /dev/null #1725

@mijoharas

Description

@mijoharas

When stdin is redirected to /dev/null, eza with no arguments exits silently without listing the current directory. Now... this might sound weird, but redirecting /dev/null to stdin is how a lot of sandboxes work.

eza < /dev/null  # No output, exits 0

This breaks in sandboxed environments (bubblewrap (i.e. claude code), docker, etc.) where stdin is commonly /dev/null.

This was introduced in https://github.com/eza-community/eza/commits/c0153503635fc221442ac8bad43686a2a8b2e917 which made the stdin piping behaviour better.

// Before: Read stdin only if BOTH --stdin flag AND non-terminal

if matches.has(&flags::STDIN)? && !io::stdin().is_terminal()

// After: Read stdin if EITHER --stdin flag OR non-terminal

if matches.has(&flags::STDIN)? || !io::stdin().is_terminal()

Now !io::stdin().is_terminal() triggers for both pipes with data and /dev/null.

When stdin is /dev/null, eza reads EOF immediately, input_paths remains empty, and nothing is listed (so having claude code run ls will produce no output in a sandbox)

I had a think, and I've come up with two options that I like. The first (more conservative) option:

if matches.get_flag("stdin") || (!io::stdin().is_terminal() && !is_stdin_dev_null())

check for /dev/null, and don't try and read from stdin if so.

or... Exclude all character devices

if matches.get_flag("stdin") || (stdin_is_fifo())

Only auto-read from pipes/FIFOs, not character devices (/dev/null, /dev/zero, etc.).

I like this one because it feels cleaner (both null and tty's are character devices), but we'd need to grab use std::os::unix::fs::FileTypeExt; to check that, so it'd still require some branching depending on cfg(unix).

What I'm not sure about is if there would be any reasons that people might want to do that? (and wouldn't specify the --stdin flag I guess). I can't think of any reasons I'd wanna redirect character devices to my ls, but I can't really see myself doing the same with /dev/null, but here we are I guess...

Metadata

Metadata

Assignees

No one assigned

    Labels

    errorsSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions