diff --git a/CMakeLists.txt b/CMakeLists.txt index 95b5f96..4bf3084 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ -cmake_minimum_required (VERSION 3.12.1) +cmake_minimum_required (VERSION 2.8) project (lcr) 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 68f2a86..72da6a7 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 9ba7311..619c436 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 29a401e..f1c4c18 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 08413d5..288da18 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]);