Page MenuHomeFreeBSD

jail(3lua): add a jail.list() method
ClosedPublic

Authored by kevans on Oct 13 2020, 2:27 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 10:29 AM
Unknown Object (File)
Mon, Apr 22, 10:29 AM
Unknown Object (File)
Mon, Apr 22, 10:29 AM
Unknown Object (File)
Mon, Apr 22, 10:25 AM
Unknown Object (File)
Mon, Apr 22, 10:25 AM
Unknown Object (File)
Mon, Apr 22, 10:24 AM
Unknown Object (File)
Mon, Apr 22, 10:24 AM
Unknown Object (File)
Mon, Apr 22, 10:08 AM

Details

Summary

This is implemented as an iterator, reusing parts of the earlier logic to populate jailparams from a passed in table.

The user may request any number of parameters to pull in while we're searching, but we'll force jid and name to appear at a minimum.

Test Plan
local jail = require('jail'
local params = {"path", "host.hostname"}    
for ljail in jail.list(params) do           
    for k, v in pairs(ljail) do             
        print(k .. " = " .. v)              
    end                                     
    print("")                        
end

Diff Detail

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

Event Timeline

Nice work, just a few notes.

Could add to share/examples/flua/jail.lua as well.

lib/flua/libjail/lua_jail.c
376

General note of missing parens around return values.

433

What about the return value?

612

Got a little lazy eh? :)

lib/flua/libjail/lua_jail.c
433

I'm actually going to just go ahead and drop the return value. All paths through getparam_table that aren't a success should (and currently do) luaL_error().

612

Yeah :-) I'll take a stab at documenting it better. It annoys me because l_list is really just a factory of sorts, it returns an iterator function and userdata that's used for iterating, but that's not indicative of how most folks will actually use or interact with it. It perhaps makes sense if you're a luaista, though.

kevans marked 3 inline comments as done.

Review comments addressed, example interspersed in the existing /usr/share/examples/flua

Don't complain about extra arguments, that's not very luaish of you.

  • Add commentary on the return value
  • Add some __dead2 annotations for lua error methods, to help clang-analyze figure out what's happening

When you have the chance, please update these diffs so I can apply them locally for closer inspection.

share/examples/flua/libjail.lua
92

Need to reset has_demo back to false before this loop. The jail does in fact go away before this process ends.

The indentation in the example additions is different as well. It would be nice to keep it consistent.

The indentation in the example additions is different as well. It would be nice to keep it consistent.

Ah, I didn't realize the previous example were using spaces... will fix.

Other than nits in the example, this seems to work just fine. I'll also note that making the example executable in the source tree won't make the installed script executable.

This revision is now accepted and ready to land.Mar 5 2021, 1:05 AM
This revision was automatically updated to reflect the committed changes.