kernelsauce / turbo

Turbo is a framework built for LuaJIT 2 to simplify the task of building fast and scalable network applications. It uses a event-driven, non-blocking, no thread design to deliver excellent performance and minimal footprint to high-load applications while also providing excellent support for embedded uses.
http://turbo.readthedocs.io/
Apache License 2.0
525 stars 84 forks source link

environment issues when using ioloop:add_handler #319

Closed clandmeter closed 6 years ago

clandmeter commented 7 years ago

I'm trying to trigger a shell command when an inotify event happens. For this I've used turbos inotify.lua implementation using ffi and modified it so it can accept a different mask and is able to return me the actual event->name instead of the directory it is listening on. Because I need to know the exist status of the shell command I've used executeex from the penlight project.

When I execute a shell command ie pwd from the add_handler method the result will be: { true, 0, "", "" } Instead of getting the result in the 3rd result I will get the result to stdout.

Running this from a set_interval method the result would be: { true, 0, "/home/clandmeter/test", "" }

It seems that add_handler somehow changes the environment so executeex is unable to redirect correctly.

kernelsauce commented 7 years ago

That sounds strange... Try running the function from a callback inside the handler function:

ioloop:add_handler(function() print("Run executeex here.") end)

clandmeter commented 6 years ago

It was indeed strange. My own wrong usage of ffi.string().

Sorry for the noise.