]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
added container:attach() into the Lua API
authorPiXy <ashtoreth@ukr.net>
Fri, 7 Nov 2014 09:04:42 +0000 (11:04 +0200)
committerPiXy <ashtoreth@ukr.net>
Fri, 7 Nov 2014 09:04:42 +0000 (11:04 +0200)
src/lua-lxc/core.c
src/lua-lxc/lxc.lua

index ae8ab016ff52bdf591bf34502b44e586d63f8b00..67886a4fca27a60541a07557d576e48a5978040c 100644 (file)
@@ -376,8 +376,34 @@ not_found:
     return 1;
 }
 
+static int container_attach(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    int argc = lua_gettop(L);
+    char **argv = NULL;
+    int i,j;
+
+    if (argc > 1) {
+       argv = alloca((argc+1) * sizeof(char *));
+       for (i = 0, j = 0; i < argc-1; i++) {
+           const char *arg = luaL_checkstring(L, i+2);
+               argv[j++] = strdupa(arg);
+         }
+         argv[j] = NULL;
+    }
+       else
+       {
+         lua_pushnil(L);
+         return 1;
+       }
+
+    lua_pushboolean(L, !!(c->attach_run_wait(c, NULL, argv[0], (const char**)argv)));
+    return 1;
+}
+
 static luaL_Reg lxc_container_methods[] =
 {
+    {"attach",                  container_attach},
     {"create",                 container_create},
     {"defined",                        container_defined},
     {"destroy",                        container_destroy},
index 44e4bf11ed3330e67956dc9c9b2a51f33d2e90a0..6f8583ab330a6c4cc3499ec7a7c314f2238a67c2 100755 (executable)
@@ -91,6 +91,10 @@ function container:new(lname, config)
 end
 
 -- methods interfacing to core functionality
+function container:attach(what, ...)
+    return self.core:attach(what, ...)
+end
+
 function container:config_file_name()
     return self.core:config_file_name()
 end