aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/ls.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-05-18 14:48:11 -0500
committerRob Landley <rob@landley.net>2015-05-18 14:48:11 -0500
commit821f31d237e0232c2810a5ed90889a1ea57134fb (patch)
tree5f05e6788d143330cb99b59010151d2b0c6999f3 /toys/posix/ls.c
parenta8ee470ae3361bb8e6e364f0e8adf61259371e95 (diff)
downloadtoybox-821f31d237e0232c2810a5ed90889a1ea57134fb.tar.gz
Fix "ls -Z . toys" segfaulting, because preprocessing skipped.
strwidth() got called on ->extra which was NULL. Had some other bad effects ala "ls -sk file1 file2 file3" ignored the -k. This should fix that too.
Diffstat (limited to 'toys/posix/ls.c')
-rw-r--r--toys/posix/ls.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index c140d979..46a60ef7 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -195,7 +195,7 @@ static int filter(struct dirtree *new)
lsm_lget_context(path, (char **)&new->extra);
free(path);
} else {
- // Why O_NONBLOCK? No idea. Why not O_PATH|O_NOFOLLOW? Because reasons.
+ // Why O_NONBLOCK? No idea. Why not O_PATH|O_NOFOLLOW? Kernel's broken.
int fd = openat(dirtree_parentfd(new), new->name,
O_RDONLY|O_NONBLOCK|O_NOATIME);
@@ -294,6 +294,10 @@ static void listfiles(int dirfd, struct dirtree *indir)
return;
}
+
+ // Do preprocessing (Dirtree didn't populate, so callback wasn't called.)
+ for (;dt; dt = dt->next) filter(dt);
+ if (flags == (FLAG_1|FLAG_f)) return;
} else {
// Read directory contents. We dup() the fd because this will close it.
// This reads/saves contents to display later, except for in "ls -1f" mode.