allow tables as arguments to spawn/exec, so e.g. rsyncOpts can include several options

This commit is contained in:
Axel Kittenberger 2010-12-03 19:47:33 +00:00
parent 926033a7d3
commit 07e35ffe60
2 changed files with 28 additions and 0 deletions

View File

@ -804,6 +804,31 @@ l_exec(lua_State *L)
/* pipe file descriptors */
int pipefd[2];
/* expands tables if there are any */
{
int i;
for(i = 1; i <= lua_gettop(L); i++) {
if (lua_istable(L, i)) {
int tlen;
int it;
/* table is now on top of stack */
lua_checkstack(L, lua_gettop(L) + lua_objlen(L, i) + 1);
lua_pushvalue(L, i);
lua_remove(L, i);
argc--;
tlen = lua_objlen(L, -1);
for (it = 1; it <= tlen; it++) {
lua_pushinteger(L, it);
lua_gettable(L, -2);
lua_insert(L,i);
i++;
argc++;
}
i--;
lua_pop(L, 1);
}
}
}
/* writes a log message, prepares the message only if actually needed. */
if (check_logcat("Exec") >= settings.log_level) {
int i;

View File

@ -2728,6 +2728,9 @@ function spawn(agent, binary, ...)
if lsyncdStatus == "fade" then
log("Normal", "ignored spawn processs since status fading")
end
if type(binary) ~= "string" then
error("calling spawn(agent, binary, ...), binary is not a string", 2)
end
local pid = lsyncd.exec(binary, ...)
if pid and pid > 0 then
local sync = InletFactory.getSync(agent)