[lxc-devel] [lxc/master] Switch allocated pty to full raw mode.

LynxChaus on Github lxc-bot at linuxcontainers.org
Mon Apr 18 15:27:12 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 471 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160418/eff9d642/attachment.bin>
-------------- next part --------------
From 42d134f14c26711b31c1b93fd19162a4f2ef674a Mon Sep 17 00:00:00 2001
From: "Andrey Jr. Melnikov" <temnota.am at gmail.com>
Date: Wed, 2 Dec 2015 22:29:54 +0300
Subject: [PATCH 1/4] Add LUA api get_ips(), get_interfaces(), rename()
 functions

---
 src/lua-lxc/core.c  | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lua-lxc/lxc.lua | 15 +++++++++
 2 files changed, 102 insertions(+)

diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index 34180a7..3fb915b 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -58,6 +58,9 @@
 
 #define CONTAINER_TYPENAME	"lxc.container"
 
+/* Max Lua arguments for function */
+#define MAXVARS	200
+
 static int container_new(lua_State *L)
 {
     struct lxc_container *c;
@@ -194,6 +197,20 @@ static int container_wait(lua_State *L)
     return 1;
 }
 
+static int container_rename(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    const char *new_name;
+    int argc = lua_gettop(L);
+
+    if (argc > 1) {
+	new_name = luaL_checkstring(L, 2);
+	lua_pushboolean(L, !!c->rename(c, new_name));
+    } else
+	lua_pushnil(L);
+    return 1;
+}
+
 static int container_freeze(lua_State *L)
 {
     struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
@@ -407,6 +424,73 @@ static int container_attach(lua_State *L)
     return 1;
 }
 
+static int container_get_interfaces(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    char **ifaces;
+    int i;
+
+    ifaces = c->get_interfaces(c);
+
+    if (!ifaces){
+	lua_pushnil(L);
+	return 1;
+    }
+
+    for (i = 0; ifaces[i]; i++);
+
+    /* protect LUA stack form overflow */
+    if (i > MAXVARS || !lua_checkstack(L, i)){
+        for (i = 0; ifaces[i]; i++)
+	    free(ifaces[i]);
+	lua_pushnil(L);
+	return 1;
+    }
+    for (i = 0; ifaces[i]; i++){
+	lua_pushstring(L, ifaces[i]);
+	free(ifaces[i]);
+    }
+    return i;
+}
+
+static int container_get_ips(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    int argc = lua_gettop(L);
+    char **addresses;
+    char *iface = NULL, *family = NULL;
+    int i, scope = 0;
+
+    if (argc > 1)
+	iface = (char *)luaL_checkstring(L, 2);
+    if (argc > 2)
+	family = (char *)luaL_checkstring(L, 3);
+    if (argc > 3)
+	scope = luaL_checkinteger(L, 4);
+
+    addresses = c->get_ips(c, iface, family, scope);
+
+    if (!addresses){
+	lua_pushnil(L);
+	return 1;
+    }
+
+    for (i = 0; addresses[i]; i++);
+
+    /* protect LUA stack form overflow */
+    if (i > MAXVARS || !lua_checkstack(L, i)){
+        for (i = 0; addresses[i]; i++)
+	    free(addresses[i]);
+	lua_pushnil(L);
+	return 1;
+    }
+    for (i = 0; addresses[i]; i++){
+	lua_pushstring(L, addresses[i]);
+	free(addresses[i]);
+    }
+    return i;
+}
+
 static luaL_Reg lxc_container_methods[] =
 {
     {"attach",                  container_attach},
@@ -423,6 +507,7 @@ static luaL_Reg lxc_container_methods[] =
     {"stop",			container_stop},
     {"shutdown",		container_shutdown},
     {"wait",			container_wait},
+    {"rename",			container_rename},
 
     {"config_file_name",	container_config_file_name},
     {"load_config",		container_load_config},
@@ -435,6 +520,8 @@ static luaL_Reg lxc_container_methods[] =
     {"set_config_item",		container_set_config_item},
     {"clear_config_item",	container_clear_config_item},
     {"get_keys",		container_get_keys},
+    {"get_interfaces",		container_get_interfaces},
+    {"get_ips",			container_get_ips},
     {NULL, NULL}
 };
 
diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua
index 122a482..3d1de10 100755
--- a/src/lua-lxc/lxc.lua
+++ b/src/lua-lxc/lxc.lua
@@ -151,6 +151,11 @@ function container:destroy()
     return self.core:destroy()
 end
 
+-- return nil if name missing
+function container:rename(name)
+    return self.core:rename(name)
+end
+
 function container:get_config_path()
     return self.core:get_config_path()
 end
@@ -221,6 +226,16 @@ function container:get_keys(base)
     return ktab
 end
 
+-- return nil or more args
+function container:get_interfaces()
+    return self.core:get_interfaces()
+end
+
+-- return nil or more args
+function container:get_ips(...)
+    return self.core:get_ips(...)
+end
+
 function container:load_config(alt_path)
     if (alt_path) then
 	return self.core:load_config(alt_path)

From fb7bb231d57b3d328d7a5a92aef28ab0f7d4bb93 Mon Sep 17 00:00:00 2001
From: "Andrey Jr. Melnikov" <temnota.am at gmail.com>
Date: Wed, 2 Dec 2015 22:29:54 +0300
Subject: [PATCH 2/4] Add LUA api get_ips(), get_interfaces(), rename()
 functions

Signed-off-by: Andrey Jr. Melnikov <temnota.am at gmail.com>
---
 src/lua-lxc/core.c  | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lua-lxc/lxc.lua | 15 +++++++++
 2 files changed, 102 insertions(+)

diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index 34180a7..3fb915b 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -58,6 +58,9 @@
 
 #define CONTAINER_TYPENAME	"lxc.container"
 
+/* Max Lua arguments for function */
+#define MAXVARS	200
+
 static int container_new(lua_State *L)
 {
     struct lxc_container *c;
@@ -194,6 +197,20 @@ static int container_wait(lua_State *L)
     return 1;
 }
 
+static int container_rename(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    const char *new_name;
+    int argc = lua_gettop(L);
+
+    if (argc > 1) {
+	new_name = luaL_checkstring(L, 2);
+	lua_pushboolean(L, !!c->rename(c, new_name));
+    } else
+	lua_pushnil(L);
+    return 1;
+}
+
 static int container_freeze(lua_State *L)
 {
     struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
@@ -407,6 +424,73 @@ static int container_attach(lua_State *L)
     return 1;
 }
 
+static int container_get_interfaces(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    char **ifaces;
+    int i;
+
+    ifaces = c->get_interfaces(c);
+
+    if (!ifaces){
+	lua_pushnil(L);
+	return 1;
+    }
+
+    for (i = 0; ifaces[i]; i++);
+
+    /* protect LUA stack form overflow */
+    if (i > MAXVARS || !lua_checkstack(L, i)){
+        for (i = 0; ifaces[i]; i++)
+	    free(ifaces[i]);
+	lua_pushnil(L);
+	return 1;
+    }
+    for (i = 0; ifaces[i]; i++){
+	lua_pushstring(L, ifaces[i]);
+	free(ifaces[i]);
+    }
+    return i;
+}
+
+static int container_get_ips(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    int argc = lua_gettop(L);
+    char **addresses;
+    char *iface = NULL, *family = NULL;
+    int i, scope = 0;
+
+    if (argc > 1)
+	iface = (char *)luaL_checkstring(L, 2);
+    if (argc > 2)
+	family = (char *)luaL_checkstring(L, 3);
+    if (argc > 3)
+	scope = luaL_checkinteger(L, 4);
+
+    addresses = c->get_ips(c, iface, family, scope);
+
+    if (!addresses){
+	lua_pushnil(L);
+	return 1;
+    }
+
+    for (i = 0; addresses[i]; i++);
+
+    /* protect LUA stack form overflow */
+    if (i > MAXVARS || !lua_checkstack(L, i)){
+        for (i = 0; addresses[i]; i++)
+	    free(addresses[i]);
+	lua_pushnil(L);
+	return 1;
+    }
+    for (i = 0; addresses[i]; i++){
+	lua_pushstring(L, addresses[i]);
+	free(addresses[i]);
+    }
+    return i;
+}
+
 static luaL_Reg lxc_container_methods[] =
 {
     {"attach",                  container_attach},
@@ -423,6 +507,7 @@ static luaL_Reg lxc_container_methods[] =
     {"stop",			container_stop},
     {"shutdown",		container_shutdown},
     {"wait",			container_wait},
+    {"rename",			container_rename},
 
     {"config_file_name",	container_config_file_name},
     {"load_config",		container_load_config},
@@ -435,6 +520,8 @@ static luaL_Reg lxc_container_methods[] =
     {"set_config_item",		container_set_config_item},
     {"clear_config_item",	container_clear_config_item},
     {"get_keys",		container_get_keys},
+    {"get_interfaces",		container_get_interfaces},
+    {"get_ips",			container_get_ips},
     {NULL, NULL}
 };
 
diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua
index 122a482..3d1de10 100755
--- a/src/lua-lxc/lxc.lua
+++ b/src/lua-lxc/lxc.lua
@@ -151,6 +151,11 @@ function container:destroy()
     return self.core:destroy()
 end
 
+-- return nil if name missing
+function container:rename(name)
+    return self.core:rename(name)
+end
+
 function container:get_config_path()
     return self.core:get_config_path()
 end
@@ -221,6 +226,16 @@ function container:get_keys(base)
     return ktab
 end
 
+-- return nil or more args
+function container:get_interfaces()
+    return self.core:get_interfaces()
+end
+
+-- return nil or more args
+function container:get_ips(...)
+    return self.core:get_ips(...)
+end
+
 function container:load_config(alt_path)
     if (alt_path) then
 	return self.core:load_config(alt_path)

From fc48e661ce1d0413df4f9acf483a3a623dd6bf5b Mon Sep 17 00:00:00 2001
From: "Andrey Jr. Melnikov" <temnota.am at gmail.com>
Date: Wed, 2 Dec 2015 22:29:54 +0300
Subject: [PATCH 3/4] Add LUA api get_ips(), get_interfaces(), rename()
 functions

---
 src/lua-lxc/core.c  | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lua-lxc/lxc.lua | 15 +++++++++
 2 files changed, 102 insertions(+)

diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index 34180a7..3fb915b 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -58,6 +58,9 @@
 
 #define CONTAINER_TYPENAME	"lxc.container"
 
+/* Max Lua arguments for function */
+#define MAXVARS	200
+
 static int container_new(lua_State *L)
 {
     struct lxc_container *c;
@@ -194,6 +197,20 @@ static int container_wait(lua_State *L)
     return 1;
 }
 
+static int container_rename(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    const char *new_name;
+    int argc = lua_gettop(L);
+
+    if (argc > 1) {
+	new_name = luaL_checkstring(L, 2);
+	lua_pushboolean(L, !!c->rename(c, new_name));
+    } else
+	lua_pushnil(L);
+    return 1;
+}
+
 static int container_freeze(lua_State *L)
 {
     struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
@@ -407,6 +424,73 @@ static int container_attach(lua_State *L)
     return 1;
 }
 
+static int container_get_interfaces(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    char **ifaces;
+    int i;
+
+    ifaces = c->get_interfaces(c);
+
+    if (!ifaces){
+	lua_pushnil(L);
+	return 1;
+    }
+
+    for (i = 0; ifaces[i]; i++);
+
+    /* protect LUA stack form overflow */
+    if (i > MAXVARS || !lua_checkstack(L, i)){
+        for (i = 0; ifaces[i]; i++)
+	    free(ifaces[i]);
+	lua_pushnil(L);
+	return 1;
+    }
+    for (i = 0; ifaces[i]; i++){
+	lua_pushstring(L, ifaces[i]);
+	free(ifaces[i]);
+    }
+    return i;
+}
+
+static int container_get_ips(lua_State *L)
+{
+    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+    int argc = lua_gettop(L);
+    char **addresses;
+    char *iface = NULL, *family = NULL;
+    int i, scope = 0;
+
+    if (argc > 1)
+	iface = (char *)luaL_checkstring(L, 2);
+    if (argc > 2)
+	family = (char *)luaL_checkstring(L, 3);
+    if (argc > 3)
+	scope = luaL_checkinteger(L, 4);
+
+    addresses = c->get_ips(c, iface, family, scope);
+
+    if (!addresses){
+	lua_pushnil(L);
+	return 1;
+    }
+
+    for (i = 0; addresses[i]; i++);
+
+    /* protect LUA stack form overflow */
+    if (i > MAXVARS || !lua_checkstack(L, i)){
+        for (i = 0; addresses[i]; i++)
+	    free(addresses[i]);
+	lua_pushnil(L);
+	return 1;
+    }
+    for (i = 0; addresses[i]; i++){
+	lua_pushstring(L, addresses[i]);
+	free(addresses[i]);
+    }
+    return i;
+}
+
 static luaL_Reg lxc_container_methods[] =
 {
     {"attach",                  container_attach},
@@ -423,6 +507,7 @@ static luaL_Reg lxc_container_methods[] =
     {"stop",			container_stop},
     {"shutdown",		container_shutdown},
     {"wait",			container_wait},
+    {"rename",			container_rename},
 
     {"config_file_name",	container_config_file_name},
     {"load_config",		container_load_config},
@@ -435,6 +520,8 @@ static luaL_Reg lxc_container_methods[] =
     {"set_config_item",		container_set_config_item},
     {"clear_config_item",	container_clear_config_item},
     {"get_keys",		container_get_keys},
+    {"get_interfaces",		container_get_interfaces},
+    {"get_ips",			container_get_ips},
     {NULL, NULL}
 };
 
diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua
index 122a482..3d1de10 100755
--- a/src/lua-lxc/lxc.lua
+++ b/src/lua-lxc/lxc.lua
@@ -151,6 +151,11 @@ function container:destroy()
     return self.core:destroy()
 end
 
+-- return nil if name missing
+function container:rename(name)
+    return self.core:rename(name)
+end
+
 function container:get_config_path()
     return self.core:get_config_path()
 end
@@ -221,6 +226,16 @@ function container:get_keys(base)
     return ktab
 end
 
+-- return nil or more args
+function container:get_interfaces()
+    return self.core:get_interfaces()
+end
+
+-- return nil or more args
+function container:get_ips(...)
+    return self.core:get_ips(...)
+end
+
 function container:load_config(alt_path)
     if (alt_path) then
 	return self.core:load_config(alt_path)

From 0550121967f13e2ad1e1f77d7eca6e29ff05d23e Mon Sep 17 00:00:00 2001
From: "Andrey Jr. Melnikov" <temnota.am at gmail.com>
Date: Mon, 18 Apr 2016 18:20:21 +0300
Subject: [PATCH 4/4] Swith pty to full raw mode.

---
 src/lxc/console.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/lxc/console.c b/src/lxc/console.c
index a346377..c6f6adc 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -262,9 +262,10 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
 
 	/* Remove the echo characters and signal reception, the echo
 	 * will be done with master proxying */
-	newtios.c_iflag &= ~IGNBRK;
+	newtios.c_iflag &= ~(IGNBRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXANY|IXOFF);
 	newtios.c_iflag &= BRKINT;
-	newtios.c_lflag &= ~(ECHO|ICANON|ISIG);
+	newtios.c_lflag &= ~(ECHO|ICANON|ISIG|IEXTEN|ECHOE|ECHOK|ECHONL);
+	newtios.c_oflag &= ~OPOST;
 	newtios.c_cc[VMIN] = 1;
 	newtios.c_cc[VTIME] = 0;
 


More information about the lxc-devel mailing list