让Heka支持lua的io操作和os操作

Heka本身编译之后,不支持lua的io操作,貌似是影响什么sandbox机制。详情,https://mail.mozilla.org/pipermail/heka/2015-November/000882.html。

Hrm. There's a *lot* of code and complexity in the LogstreamerInput. And not because it's overengineered, IMHO, but because it's providing a lot of functionality and solving a complicated set of problems. While I'd be thrilled to have a SandboxInput replicating this functionality (mainly so it could be used with Hindsight), I suspect that this is a much larger and more difficult task than you might imagine. If you do end up going down that road, I suggest you start with a tight, well-defined subset of LogstreamerInput's features, and then work your way up from there.

I can't speak to the issues that you're having with trying to use `os.execute` or `io.popen` to run an external sleep command. It's very possible that you're bumping up against Heka bugs with the behaviour you're seeing. But that approach smells a bit off to me, I'm not surprised you're having issues. You might consider one of the other suggested mechanisms (see http://lua-users.org/wiki/SleepFunction), especially using `socket.select`, or writing a trivial C extension that exposes a sleep function. You also might try using Hindsight instead of Heka to test your code, since that's a much lighter code base and is likely to have fewer (or at least different) bugs.

You might already have this on your radar, but if I were working on this I'd almost certainly be using coroutines (http://lua-users.org/wiki/CoroutinesTutorial).

Finally, you say that the reason you're not using LogstreamerInput is because you need to use Lua's `io` module in your decoding code. If you're okay with building your own custom Heka binary, and you don't plan on using a SandboxManagerFilter to support dynamic sandbox injection (i.e. you trust all of the Lua code you'll be deploying) then you might consider rebuilding Heka with support for the io module allowed in all sandboxes. The code that causes the `io` module to not be available is here:

但是我们可以重新编译heka,让其支持io模块,https://github.com/mozilla-services/heka/blob/v0.10.0b1/sandbox/lua/lua_sandbox.go.in#L63有说明,就是heka/sandbox/lua/lua_sandbox.go.in的d963行,disable_modules = {io = 1} 改成=0或者干脆去掉,即可编译实现heka支持lua的io模块。

 

另外,heka支持lua的os模块,但是去掉了很多方法,比如execute,那么如果我非要execute方法,怎么处理?同样是lua_sandbox.go.文件。

51行到61行

os = {'exit', 'setlocale'}}}`

const SandboxTemplate = `{
memory_limit = %d,
instruction_limit = %d,
output_limit = %d,
path = [[%s]],
cpath = [[%s]],
remove_entries = {
[''] = {'collectgarbage','coroutine','dofile','load','loadfile','loadstring','newproxy','print'},
os = {'getenv','execute','exit','remove','rename','setlocale','tmpname'}
}

想使用哪个方法,就去掉哪个即可。

 

转载于:https://my.oschina.net/weikan/blog/718424

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值