Page MenuHomeFreeBSD

ls: check fts_children() for errors that may not surface otherwise
AcceptedPublic

Authored by kevans on Jun 26 2025, 5:59 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Oct 9, 1:35 AM
Unknown Object (File)
Wed, Oct 1, 2:40 AM
Unknown Object (File)
Sep 19 2025, 9:01 AM
Unknown Object (File)
Sep 11 2025, 2:36 PM
Unknown Object (File)
Sep 5 2025, 9:18 AM
Unknown Object (File)
Sep 4 2025, 5:08 PM
Unknown Object (File)
Aug 28 2025, 11:08 AM
Unknown Object (File)
Aug 27 2025, 11:37 PM
Subscribers

Details

Reviewers
des
kib
Summary

In particular, if one simply does a non-recursive ls on a directory
that is not accessible, there are some classes of errors that may cause
it to fail that wouldn't be surfaced unless we do an fts_read() that
will recurse into the inaccessible directory. Catch those kinds of
errors here since we cannot expect to an FTS_ERR/FTS_DNR entry to follow
up on them.

PR: 287451

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 65097
Build 61980: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Jun 26 2025, 9:21 PM
bin/ls/ls.c
710

The errno check is redundant, chp == NULL && errno == 0 can only happen if a) ftsp is not of type FTS_D or b) FTS_STOP is set on ftsp. Neither is possible here.

bin/ls/tests/ls_tests.sh
505

why not simply use -o match and -e match here?

bin/ls/ls.c
710

The manpage claims it returns NULL and errno will be set to 0 if the directory is empty. I don't see how that is falls within your two cases, because an empty directory would otherwise get an FTS_D + FTD_DP pair just like a non-empty.

bin/ls/ls.c
710

Ah, I failed to consider that the directory might be empty.