Page MenuHomeFreeBSD

core.lua: follow symlinks when looking for bootable kernels
ClosedPublic

Authored by leres on Sat, Mar 7, 9:47 PM.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

leres requested review of this revision.Sat, Mar 7, 9:47 PM
stand/lua/core.lua
262

I'd much prefer we continue using ftype and just do an extra lfs.attributes if it's a symlink. stat(2) is super expensive in some of these environments, anything we can do to minimize the impact is ideal

At first I tried to find a DL_* that would identify a symlink but could not (I think I tried DT_LNK). I also tried debugging the logic using lua from the command line but wasn't easily able to figure out how to use the luafilesystem port from the command line...

I recently learned enough lua to write a wireshark dissector and was *not* impressed with the online documentation available.

I'm willing to take another run at this; where are the DL_* tokens defined?

At first I tried to find a DL_* that would identify a symlink but could not (I think I tried DT_LNK). I also tried debugging the logic using lua from the command line but wasn't easily able to figure out how to use the luafilesystem port from the command line...

I recently learned enough lua to write a wireshark dissector and was *not* impressed with the online documentation available.

I'm willing to take another run at this; where are the DL_* tokens defined?

We need to break it out here: https://cgit.freebsd.org/src/tree/libexec/flua/lfs/lfs.c#n445

If you can give me a day or two, I'm happy to fix this. This part of lfs is nonstandard, you would need to test with the userland harness we have in tools/boot. lua-img.sh && lua-test.sh

Address feedback and use ftype to permit symlinks.
Unfortunately lfs.DT_DIR is not defined so use magic value 10

Humm... I found that the value for lfs.DT_LNK will be 10 but I suck at git and my attempt to update this review didn't work. I tried:

git arc update 365c0df83f86c25000fc8d0863d53391f41b27a6

Not sure what I'm doing wrong.

I'm not in a rush to solve this, waiting a few days is fine.

Address feedback and use ftype to permit symlinks.
Unfortunately lfs.DT_DIR is not defined so use magic value 10

leres marked an inline comment as done.

Address feedback and use ftype to permit symlinks.
Unfortunately lfs.DT_DIR is not defined so use magic value 10

Throw this diff on top, please, and we have a deal:

diff --git a/stand/lua/core.lua b/stand/lua/core.lua
index 2d3219ac54c5..92cbd20b25a0 100644
--- a/stand/lua/core.lua
+++ b/stand/lua/core.lua
@@ -255,7 +255,7 @@ function core.kernelList()
                end
 
                if ftype then
-                       if ftype ~= lfs.DT_DIR and ftype ~= 10 then
+                       if ftype ~= lfs.DT_DIR and ftype ~= (lfs.DT_LNK or 10) then
                                goto continue
                        end
                elseif lfs.attributes(fname, "mode") ~= "directory" then

I'm going to add DT_LNK in a separate commit, but we won't be able to use it right away anyways -- we'll have to phase it in over a few years.

Incorporate @kevans 's clever fix that works before and after
lfs.DT_LNK is defined.

This revision is now accepted and ready to land.Mon, Mar 9, 9:33 PM