From 821f31d237e0232c2810a5ed90889a1ea57134fb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 18 May 2015 14:48:11 -0500 Subject: 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. --- toys/posix/ls.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'toys/posix/ls.c') 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. -- cgit v1.2.3