Our popen(3) accepts more than the historical "r" and "w" types. Define
the appropriate macro to provide a custom mode check accepting all valid
pipe types.
Details
Details
- Reviewers
kevans - Commits
- rG8bb34ce5c9f6: liblua: Accept + and e in io.popen mode
Diff Detail
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Comment Actions
This enables io.popen() to invoke a command with a bidirectional pipe by passing "r+" or "r+e" as the mode. For example, calling "cxgbetool stdio" to set up multiple filter rules in one action requires both reading from and writing to the process:
#!/usr/libexec/flua
local cxgbetool <const> = {}
cxgbetool.__index = cxgbetool
setmetatable(cxgbetool, cxgbetool)
function cxgbetool.__call(class, nexus)
return setmetatable({nexus=nexus}, class)
end
function cxgbetool:popen(cmdline, ...)
return io.popen(("cxgbetool %q %s"):format(self.nexus, cmdline), ...)
end
function cxgbetool:stdio()
return self:popen("stdio", "r+e")
end
function cxgbetool:filters(filters)
local p <close> = self:stdio()
for i, rule in ipairs(filters) do
p:read(1) -- consume the prompt
p:write(("filter %d %s\n"):format(i, rule))
end
end
-- snip --
local t5nex0 <const> = cxgbetool "t5nex0"
t5nex0:filters {
pass { iport=0, matchtype=mask(0, 4), prio=1 },
pass { iport=0, matchtype=6, prio=1 },
switch { iport=0, eport=1, prio=1 },
pass { iport=1, matchtype=mask(0, 4), prio=1 },
pass { iport=1, matchtype=6, prio=1 },
switch { iport=1, eport=0, prio=1 },
}
-- snip --Comment Actions
A question this brought up while looking into it: the lib/liblua/luaconf.h file seems stale and unused, and I wonder if it is similar for stand/liblua/luaconf.h? The build seems to be using contrib/lua/src/luaconf.h, which is the copy that actually includes this lib/liblua/luaconf.local.h file.
Comment Actions
Yes, it's probably time to axe those; 8c784bb8cf36911b828652f0bf7e88f443abec50 is where @imp changed the model here.