diff --git a/CMakeLists.txt b/CMakeLists.txt index 95b5f96dc495cd9eedeba3f842e915e30af8233b..9fa9f353a3123165402f1db11aba4c2d7a8ca882 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include(cmake/set_build_flags.cmake) option(VERSION "set lcr version" ON) if (VERSION STREQUAL "ON") - set(LCR_VERSION "1.0.17") + set(LCR_VERSION "1.0.18") endif() option(DEBUG "set lcr gcc option" ON) diff --git a/lcr.spec b/lcr.spec index 68f2a86825f567cf9502a03bbed4ab487ab52500..72da6a7a4856d7f6c095600e6d427e1eb4b14ab5 100644 --- a/lcr.spec +++ b/lcr.spec @@ -1,5 +1,5 @@ -%global _version 1.0.17 -%global _release 20191222.223702.gita44996d6 +%global _version 1.0.18 +%global _release 20200105.223545.git6259bd3e Name: lcr Version: %{_version} Release: %{_release} diff --git a/src/lcrcontainer.c b/src/lcrcontainer.c index 9ba7311e2ab368cfcabf5ae4e04df0d38180a345..619c4366899e6e85df94b6f10438c993866d9e1e 100644 --- a/src/lcrcontainer.c +++ b/src/lcrcontainer.c @@ -1592,6 +1592,106 @@ out: return bret; } +bool lcr_resize(const char *name, const char *lcrpath, unsigned int height, unsigned int width) +{ + struct lxc_container *c = NULL; + const char *tmp_path = lcrpath ? lcrpath : LCRPATH; + bool bret = true; + + clear_error_message(&g_lcr_error); + + if (name == NULL) { + ERROR("Missing container name"); + return false; + } + + engine_set_log_prefix(name); + c = lxc_container_new(name, tmp_path); + if (c == NULL) { + ERROR("Failed to pause container"); + engine_free_log_prefix(); + return false; + } + + if (!is_container_exists(c)) { + ERROR("No such container"); + bret = false; + goto out_put; + } + + if (!is_container_can_control(c)) { + ERROR("Insufficent privleges to contol"); + bret = false; + goto out_put; + } + + if (!lcr_check_container_running(c, name)) { + bret = false; + goto out_put; + } + + if (!c->set_terminal_winch(c, height, width)) { + ERROR("Failed to pause"); + bret = false; + goto out_put; + } + +out_put: + lxc_container_put(c); + engine_free_log_prefix(); + return bret; +} + +bool lcr_exec_resize(const char *name, const char *lcrpath, const char *suffix, unsigned int height, unsigned int width) +{ + struct lxc_container *c = NULL; + const char *tmp_path = lcrpath ? lcrpath : LCRPATH; + bool bret = true; + + clear_error_message(&g_lcr_error); + + if (name == NULL) { + ERROR("Missing container name"); + return false; + } + + engine_set_log_prefix(name); + c = lxc_container_new(name, tmp_path); + if (c == NULL) { + ERROR("Failed to pause container"); + engine_free_log_prefix(); + return false; + } + + if (!is_container_exists(c)) { + ERROR("No such container"); + bret = false; + goto out_put; + } + + if (!is_container_can_control(c)) { + ERROR("Insufficent privleges to contol"); + bret = false; + goto out_put; + } + + if (!lcr_check_container_running(c, name)) { + bret = false; + goto out_put; + } + + if (!c->set_exec_terminal_winch(c, suffix, height, width)) { + ERROR("Failed to resize exec terminal"); + bret = false; + goto out_put; + } + +out_put: + lxc_container_put(c); + engine_free_log_prefix(); + return bret; +} + bool lcr_console(const char *name, const char *lcrpath, const char *in_fifo, const char *out_fifo, const char *err_fifo) { struct lxc_container *c = NULL; diff --git a/src/lcrcontainer.h b/src/lcrcontainer.h index 29a401e63c3eb49947ea1389d8bd19026be56132..f1c4c18ed10f5071d2afc1b3e2f767205a48673b 100644 --- a/src/lcrcontainer.h +++ b/src/lcrcontainer.h @@ -274,6 +274,8 @@ struct lcr_exec_request { size_t args_len; int64_t timeout; + + const char *suffix; }; /* * Execute process inside a container @@ -289,7 +291,9 @@ void lcr_free_errmsg(); bool lcr_get_container_pids(const char *name, const char *lcrpath, pid_t **pids, size_t *pids_len); bool translate_spec(const struct lxc_container *c, const char *oci_json_data, const char *container_rootfs); - +bool lcr_resize(const char *name, const char *lcrpath, unsigned int height, unsigned int width); +bool lcr_exec_resize(const char *name, const char *lcrpath, const char *suffix, unsigned int height, + unsigned int width); #ifdef __cplusplus } #endif diff --git a/src/lcrcontainer_execute.c b/src/lcrcontainer_execute.c index 08413d5d313a264fa089a94ee23a9a3e8a3de56f..288da1830b4bf791b3f4a8dd1eb76218b4c6ce98 100644 --- a/src/lcrcontainer_execute.c +++ b/src/lcrcontainer_execute.c @@ -943,6 +943,8 @@ static void execute_lxc_attach(const char *name, const char *path, const struct add_array_elem(params, args_len, &i, request->user); } + add_array_kv(params, args_len, &i, "--suffix", request->suffix); + add_array_elem(params, args_len, &i, "--"); for (j = 0; j < request->args_len; j++) { add_array_elem(params, args_len, &i, request->args[j]);