diff --git a/README.md b/README.md
index 0475907..21f1f27 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,63 @@
-# iSulad
+
-This is a umbrella project for gRPC-services based Lightweight Container Runtime Daemon.
-iSulad provide a unified architecture to meet the different needs of CT and IT.
-Compared with Docker written by Golang, iSulad has the characteristics of light, agile, fast,
-not limited by hardware specifications and architecture, and can be applied more widely.
+## iSulad
+
+`iSulad` is a light weight container runtime daemon which is designed for IOT and Cloud infrastructure.`iSulad` has the characteristics of light, fast and not limited by hardware specifications and architecture, and can be applied more widely.
+
+## Getting Started
+
+### Installing
+To install iSulad, you can use `rpm` or `yum` package manager command with `openEuler` repository.
+
+Install iSulad with yum
+```sh
+yum install -y iSulad
+```
+
+### Run
+We provide `systemd` service to start `iSulad`
+```sh
+systemd start lcrd # run the server with systemd command
+```
+
+You can use direct command to start `iSulad` server:
+```sh
+$ sudo lcrd # run the server with default socket name and default log level and images manage function
+```
+### Operations on containers:
+`iSulad` provides command line `lcrd` to talk with server.
+Here are some sample commands to manager containers.
+
+List all containers in your own environment:
+```sh
+# list containers
+$ sudo lcrc ps -a
+```
+
+Create a container with busybox named `test`
+```sh
+# create a container 'test' with image busybox
+$ sudo lcrc create -t -n test busybox
+```
+
+Start this container `test`
+```sh
+# start the container 'test'
+$ sudo lcrc start test
+```
+Kill the container `test`
+```sh
+# kill the container 'test'
+$ sudo lcrc kill test
+```
+Remove the container `test`
+```sh
+# remove the container 'test'
+$ sudo lcrc rm test
+```
+
+### Build from source
+Build requirements for developers are listed in [build_guide](./docs/build_guide.md)
## How to Contribute
diff --git a/cmake/options.cmake b/cmake/options.cmake
index f03bc84..2004add 100644
--- a/cmake/options.cmake
+++ b/cmake/options.cmake
@@ -33,7 +33,7 @@ endif()
option(VERSION "set lcrd version" ON)
if (VERSION STREQUAL "ON")
- set(LCRD_VERSION "1.1.4")
+ set(LCRD_VERSION "1.1.5")
endif()
option(DEBUG "set lcrd gcc option" ON)
diff --git a/iSulad.spec b/iSulad.spec
index 9699dab..46e2539 100644
--- a/iSulad.spec
+++ b/iSulad.spec
@@ -1,5 +1,5 @@
-%global _version 1.1.4
-%global _release 20191226.061440.gitfa7769d5
+%global _version 1.1.5
+%global _release 20200106.022952.git939935db
%global is_systemd 1
%global debug_package %{nil}
diff --git a/logo/isula-logo.png b/logo/isula-logo.png
new file mode 100644
index 0000000..011d66d
Binary files /dev/null and b/logo/isula-logo.png differ
diff --git a/src/api/services/containers/container.proto b/src/api/services/containers/container.proto
index 69ea47c..73729cf 100644
--- a/src/api/services/containers/container.proto
+++ b/src/api/services/containers/container.proto
@@ -69,20 +69,18 @@ message Container {
message Container_info {
string id = 1;
- int32 pid = 2;
- ContainerStatus status = 3;
- uint64 pids_current = 4;
- uint64 cpu_use_nanos = 5;
- uint64 cpu_use_user = 6;
- uint64 cpu_use_kernel = 7;
- uint64 cpu_system_use = 8;
- uint32 online_cpus = 9;
- uint64 blkio_read = 10;
- uint64 blkio_write = 11;
- uint64 mem_used = 12;
- uint64 mem_limit = 13;
- uint64 kmem_used = 14;
- uint64 kmem_limit = 15;
+ uint64 pids_current = 2;
+ uint64 cpu_use_nanos = 3;
+ uint64 cpu_use_user = 4;
+ uint64 cpu_use_kernel = 5;
+ uint64 cpu_system_use = 6;
+ uint32 online_cpus = 7;
+ uint64 blkio_read = 8;
+ uint64 blkio_write = 9;
+ uint64 mem_used = 10;
+ uint64 mem_limit = 11;
+ uint64 kmem_used = 12;
+ uint64 kmem_limit = 13;
}
message Event {
@@ -114,13 +112,13 @@ service ContainerService {
rpc Info(InfoRequest) returns (InfoResponse);
rpc Update(UpdateRequest) returns (UpdateResponse);
rpc Attach(stream AttachRequest) returns (stream AttachResponse);
- rpc Container_conf(Container_conf_Request) returns (Container_conf_Response);
rpc Restart(RestartRequest) returns (RestartResponse);
rpc Export(ExportRequest) returns (ExportResponse);
rpc CopyFromContainer(CopyFromContainerRequest) returns (stream CopyFromContainerResponse);
rpc CopyToContainer(stream CopyToContainerRequest) returns (stream CopyToContainerResponse);
rpc Rename(RenameRequest) returns (RenameResponse);
rpc Logs(LogsRequest) returns (stream LogsResponse);
+ rpc Resize(ResizeRequest) returns (ResizeResponse);
}
message CreateRequest {
@@ -271,7 +269,6 @@ message ListResponse {
}
message StatsRequest {
- string runtime = 1;
repeated string containers = 2;
bool all = 3;
}
@@ -313,6 +310,7 @@ message ExecRequest {
repeated string argv = 10;
repeated string env = 11;
string user = 12;
+ string suffix = 13;
}
message ExecResponse {
int32 pid = 1;
@@ -390,19 +388,6 @@ message UpdateResponse {
uint32 cc = 2;
string errmsg = 3;
}
-message Container_conf_Request {
- // ContainerID specifies the container in which to get config.
- string container_id = 1;
- string runtime = 2;
-}
-
-message Container_conf_Response {
- string container_logpath = 1;
- string container_logsize = 2;
- uint32 container_logrotate = 3;
- uint32 cc = 4;
- string errmsg = 5;
-}
message ExportRequest {
string id = 1;
@@ -461,3 +446,16 @@ message LogsResponse {
string time = 3;
bytes attrs = 4;
}
+
+message ResizeRequest {
+ string id = 1;
+ string suffix = 2;
+ uint32 height = 3;
+ uint32 width = 4;
+}
+
+message ResizeResponse {
+ string id = 1;
+ uint32 cc = 2;
+ string errmsg = 3;
+}
diff --git a/src/api/services/containers/rest/container.rest.h b/src/api/services/containers/rest/container.rest.h
index 4bf3baf..f848e55 100644
--- a/src/api/services/containers/rest/container.rest.h
+++ b/src/api/services/containers/rest/container.rest.h
@@ -45,8 +45,6 @@
#include "container_resume_response.h"
#include "container_wait_request.h"
#include "container_wait_response.h"
-#include "container_conf_request.h"
-#include "container_conf_response.h"
#ifndef RestHttpHead
#define RestHttpHead "http://localhost"
@@ -67,7 +65,6 @@
#define ContainerServiceAttach "/ContainerService/Attach"
#define ContainerServiceResume "/ContainerService/Resume"
#define ContainerServiceWait "/ContainerService/Wait"
-#define ContainerServiceConf "/ContainerService/Container_conf"
/* "/ContainerService/Kill",
"/ContainerService/Delete",
diff --git a/src/api/services/cri/api.proto b/src/api/services/cri/api.proto
index 5166276..022fa51 100644
--- a/src/api/services/cri/api.proto
+++ b/src/api/services/cri/api.proto
@@ -1,17 +1,19 @@
-// #######################################################################
-// ##- @Copyright (C) Huawei Technologies., Ltd. 2019. All rights reserved.
-// # - iSulad licensed under the Mulan PSL v1.
-// # - You can use this software according to the terms and conditions of the Mulan PSL v1.
-// # - You may obtain a copy of Mulan PSL v1 at:
-// # - http://license.coscl.org.cn/MulanPSL
-// # - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-// # - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-// # - PURPOSE.
-// # - See the Mulan PSL v1 for more details.
-// ##- @Description: generate grpc
-// ##- @Author: wujing
-// ##- @Create: 2019-04-25
-// #######################################################################
+/*
+Copyright 2018 The Kubernetes Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
// To regenerate api.pb.go run hack/update-generated-runtime.sh
syntax = 'proto3';
diff --git a/src/cmd/lcrc/arguments.h b/src/cmd/lcrc/arguments.h
index 4d8bd98..308d45c 100644
--- a/src/cmd/lcrc/arguments.h
+++ b/src/cmd/lcrc/arguments.h
@@ -286,6 +286,9 @@ struct client_arguments {
char *type;
char *tag;
+ // exec
+ char *exec_suffix;
+
// login/logout
char *username;
char *password;
diff --git a/src/cmd/lcrc/base/create.c b/src/cmd/lcrc/base/create.c
index b96dbcc..d22bd8e 100644
--- a/src/cmd/lcrc/base/create.c
+++ b/src/cmd/lcrc/base/create.c
@@ -1273,7 +1273,6 @@ int cmd_create_main(int argc, const char **argv)
printf("%s\n", g_cmd_create_args.name);
nret = EXIT_SUCCESS;
out:
- client_arguments_free(&g_cmd_create_args);
exit(nret);
}
diff --git a/src/cmd/lcrc/base/run.c b/src/cmd/lcrc/base/run.c
index 7cec120..ed2a520 100644
--- a/src/cmd/lcrc/base/run.c
+++ b/src/cmd/lcrc/base/run.c
@@ -12,7 +12,11 @@
* Create: 2018-11-08
* Description: provide container run functions
******************************************************************************/
+#include
#include
+#include
+#include
+
#include "run.h"
#include "arguments.h"
#include "log.h"
@@ -127,6 +131,97 @@ out:
return ret;
}
+static int do_resize_run_console(const struct client_arguments *args, unsigned int height, unsigned int width)
+{
+ int ret = 0;
+ lcrc_connect_ops *ops = NULL;
+ struct lcrc_resize_request request = { 0 };
+ struct lcrc_resize_response *response = NULL;
+ client_connect_config_t config = { 0 };
+
+ ops = get_connect_client_ops();
+ if (ops == NULL || ops->container.resize == NULL) {
+ ERROR("Unimplemented ops");
+ ret = -1;
+ goto out;
+ }
+
+ request.id = args->name;
+ request.height = height;
+ request.width = width;
+
+ response = util_common_calloc_s(sizeof(struct lcrc_resize_response));
+ if (response == NULL) {
+ ERROR("Out of memory");
+ ret = -1;
+ goto out;
+ }
+
+ config = get_connect_config(args);
+ ret = ops->container.resize(&request, response, &config);
+ if (ret != 0) {
+ ERROR("Failed to call resize");
+ goto out;
+ }
+
+out:
+ lcrc_resize_response_free(response);
+ return ret;
+}
+
+static void *run_console_resize_thread(void *arg)
+{
+ int ret = 0;
+ const struct client_arguments *args = arg;
+ static struct winsize s_pre_wsz;
+ struct winsize wsz;
+
+ if (!isatty(STDIN_FILENO)) {
+ goto out;
+ }
+
+ ret = pthread_detach(pthread_self());
+ if (ret != 0) {
+ CRIT("Start: set thread detach fail");
+ goto out;
+ }
+
+ while (true) {
+ sleep(1); // check the windows size per 1s
+ ret = ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz);
+ if (ret < 0) {
+ WARN("Failed to get window size");
+ continue;
+ }
+ if (wsz.ws_row == s_pre_wsz.ws_row && wsz.ws_col == s_pre_wsz.ws_col) {
+ continue;
+ }
+ ret = do_resize_run_console(args, wsz.ws_row, wsz.ws_col);
+ if (ret != 0) {
+ continue;
+ }
+ s_pre_wsz.ws_row = wsz.ws_row;
+ s_pre_wsz.ws_col = wsz.ws_col;
+ }
+
+out:
+ return NULL;
+}
+
+int run_client_console_resize_thread(struct client_arguments *args)
+{
+ int res = 0;
+ pthread_t a_thread;
+
+ res = pthread_create(&a_thread, NULL, run_console_resize_thread, (void *)(args));
+ if (res != 0) {
+ CRIT("Thread creation failed");
+ return -1;
+ }
+
+ return 0;
+}
+
int cmd_run_main(int argc, const char **argv)
{
int ret = 0;
@@ -172,6 +267,10 @@ int cmd_run_main(int argc, const char **argv)
printf("%s\n", g_cmd_run_args.name);
}
+ if (g_cmd_run_args.custom_conf.tty && isatty(STDIN_FILENO)) {
+ (void)run_client_console_resize_thread(&g_cmd_run_args);
+ }
+
if (strncmp(g_cmd_run_args.socket, "tcp://", strlen("tcp://")) == 0) {
ret = remote_cmd_start(&g_cmd_run_args, &exit_code);
if (ret != 0) {
@@ -187,7 +286,6 @@ int cmd_run_main(int argc, const char **argv)
}
free_out:
- client_arguments_free(&g_cmd_run_args);
exit(ret);
}
diff --git a/src/cmd/lcrc/extend/stats.c b/src/cmd/lcrc/extend/stats.c
index aab1db4..36de0b8 100644
--- a/src/cmd/lcrc/extend/stats.c
+++ b/src/cmd/lcrc/extend/stats.c
@@ -213,7 +213,6 @@ static int client_stats(const struct client_arguments *args)
{
struct lcrc_stats_request request = { 0 };
- request.runtime = args->runtime;
request.all = args->showall;
request.containers = (char **)(args->argv);
request.containers_len = (size_t)(args->argc);
diff --git a/src/cmd/lcrc/extend/stats.h b/src/cmd/lcrc/extend/stats.h
index 8f14b91..2535116 100644
--- a/src/cmd/lcrc/extend/stats.h
+++ b/src/cmd/lcrc/extend/stats.h
@@ -18,8 +18,6 @@
#include "arguments.h"
#define STATUS_OPTIONS(cmdargs) \
- { CMD_OPT_TYPE_STRING, false, "runtime", 'R', &(cmdargs).runtime, \
- "Runtime to use for containers(default: lcr)", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).showall, \
"Show all containers (default shows just running)", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "no-stream", 0, &(cmdargs).nostream, \
diff --git a/src/cmd/lcrc/stream/exec.c b/src/cmd/lcrc/stream/exec.c
index d95238d..2b6322c 100644
--- a/src/cmd/lcrc/stream/exec.c
+++ b/src/cmd/lcrc/stream/exec.c
@@ -18,6 +18,8 @@
#include
#include
#include
+#include
+#include
#include "arguments.h"
#include "exec.h"
@@ -52,6 +54,7 @@ static int client_exec(const struct client_arguments *args, const struct command
}
request.name = args->name;
+ request.suffix = args->exec_suffix;
request.tty = args->custom_conf.tty;
request.open_stdin = args->custom_conf.open_stdin;
request.attach_stdin = args->custom_conf.attach_stdin;
@@ -248,6 +251,7 @@ static int remote_cmd_exec(const struct client_arguments *args, uint32_t *exit_c
g_cmd_exec_args.name = util_strdup_s(inspect_data->id);
request.name = args->name;
+ request.suffix = args->exec_suffix;
request.tty = args->custom_conf.tty;
request.open_stdin = args->custom_conf.open_stdin;
request.attach_stdin = args->custom_conf.attach_stdin;
@@ -313,6 +317,119 @@ out:
return ret;
}
+static char *generate_exec_suffix()
+{
+ char *exec_suffix = NULL;
+
+ exec_suffix = util_common_calloc_s(sizeof(char) * (CONTAINER_ID_MAX_LEN + 1));
+ if (exec_suffix == NULL) {
+ ERROR("Out of memory");
+ goto out;
+ }
+
+ if (util_generate_random_str(exec_suffix, (size_t)CONTAINER_ID_MAX_LEN)) {
+ ERROR("Generate exec suffix failed");
+ free(exec_suffix);
+ exec_suffix = NULL;
+ goto out;
+ }
+
+out:
+ return exec_suffix;
+}
+
+static int do_resize_exec_console(const struct client_arguments *args, unsigned int height, unsigned int width)
+{
+ int ret = 0;
+ lcrc_connect_ops *ops = NULL;
+ struct lcrc_resize_request request = { 0 };
+ struct lcrc_resize_response *response = NULL;
+ client_connect_config_t config = { 0 };
+
+ ops = get_connect_client_ops();
+ if (ops == NULL || ops->container.resize == NULL) {
+ ERROR("Unimplemented ops");
+ ret = -1;
+ goto out;
+ }
+
+ request.id = args->name;
+ request.suffix = args->exec_suffix;
+ request.height = height;
+ request.width = width;
+
+ response = util_common_calloc_s(sizeof(struct lcrc_resize_response));
+ if (response == NULL) {
+ ERROR("Out of memory");
+ ret = -1;
+ goto out;
+ }
+
+ config = get_connect_config(args);
+ ret = ops->container.resize(&request, response, &config);
+ if (ret != 0) {
+ ERROR("Failed to call resize");
+ goto out;
+ }
+
+out:
+ lcrc_resize_response_free(response);
+ return ret;
+}
+
+static void *exec_console_resize_thread(void *arg)
+{
+ int ret = 0;
+ const struct client_arguments *args = arg;
+ static struct winsize s_pre_wsz;
+ struct winsize wsz;
+
+ if (!isatty(STDIN_FILENO)) {
+ goto out;
+ }
+
+ ret = pthread_detach(pthread_self());
+ if (ret != 0) {
+ CRIT("Start: set thread detach fail");
+ goto out;
+ }
+
+ while (true) {
+ sleep(1); // check the windows size per 1s
+ ret = ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz);
+ if (ret < 0) {
+ WARN("Failed to get window size");
+ continue;
+ }
+ if (wsz.ws_row == s_pre_wsz.ws_row && wsz.ws_col == s_pre_wsz.ws_col) {
+ continue;
+ }
+ ret = do_resize_exec_console(args, wsz.ws_row, wsz.ws_col);
+ if (ret != 0) {
+ continue;
+ }
+ s_pre_wsz.ws_row = wsz.ws_row;
+ s_pre_wsz.ws_col = wsz.ws_col;
+ }
+
+out:
+ return NULL;
+}
+
+int exec_client_console_resize_thread(struct client_arguments *args)
+{
+ int res = 0;
+ pthread_t a_thread;
+
+ res = pthread_create(&a_thread, NULL, exec_console_resize_thread, (void *)(args));
+ if (res != 0) {
+ CRIT("Thread creation failed");
+ return -1;
+ }
+
+ return 0;
+}
+
int cmd_exec_main(int argc, const char **argv)
{
int ret = 0;
@@ -339,6 +456,18 @@ int cmd_exec_main(int argc, const char **argv)
custom_cfg->open_stdin = false;
}
+ g_cmd_exec_args.exec_suffix = generate_exec_suffix();
+ if (g_cmd_exec_args.exec_suffix == NULL) {
+ ERROR("Failed to generate exec suffix");
+ ret = -1;
+ goto out;
+ }
+
+ if (custom_cfg->tty && isatty(STDIN_FILENO) && (custom_cfg->attach_stdin || custom_cfg->attach_stdout ||
+ custom_cfg->attach_stderr)) {
+ (void)exec_client_console_resize_thread(&g_cmd_exec_args);
+ }
+
if (strncmp(g_cmd_exec_args.socket, "tcp://", strlen("tcp://")) == 0) {
ret = remote_cmd_exec(&g_cmd_exec_args, &exit_code);
if (ret != 0) {
diff --git a/src/connect/client/grpc/grpc_containers_client.cc b/src/connect/client/grpc/grpc_containers_client.cc
index 59b3293..50a1089 100644
--- a/src/connect/client/grpc/grpc_containers_client.cc
+++ b/src/connect/client/grpc/grpc_containers_client.cc
@@ -636,6 +636,61 @@ public:
}
};
+class ContainerResize : public ClientBase {
+public:
+ explicit ContainerResize(void *args)
+ : ClientBase(args)
+ {
+ }
+ ~ContainerResize() = default;
+
+ int request_to_grpc(const lcrc_resize_request *request, ResizeRequest *grequest) override
+ {
+ if (request == nullptr) {
+ return -1;
+ }
+
+ if (request->id != nullptr) {
+ grequest->set_id(request->id);
+ }
+ if (request->suffix != nullptr) {
+ grequest->set_suffix(request->suffix);
+ }
+ grequest->set_height(request->height);
+
+ grequest->set_width(request->width);
+
+ return 0;
+ }
+
+ int response_from_grpc(ResizeResponse *gresponse, lcrc_resize_response *response) override
+ {
+ response->server_errono = gresponse->cc();
+ if (!gresponse->errmsg().empty()) {
+ response->errmsg = util_strdup_s(gresponse->errmsg().c_str());
+ }
+
+ return 0;
+ }
+
+ int check_parameter(const ResizeRequest &req) override
+ {
+ if (req.id().empty()) {
+ ERROR("Missing container id in the request");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ Status grpc_call(ClientContext *context, const ResizeRequest &req, ResizeResponse *reply) override
+ {
+ return stub_->Resize(context, req, reply);
+ }
+};
+
+
class ContainerRestart : public ClientBase {
public:
@@ -752,6 +807,9 @@ public:
if (request->name != nullptr) {
grequest->set_container_id(request->name);
}
+ if (request->suffix != nullptr) {
+ grequest->set_suffix(request->suffix);
+ }
grequest->set_tty(request->tty);
grequest->set_open_stdin(request->open_stdin);
grequest->set_attach_stdin(request->attach_stdin);
@@ -876,6 +934,7 @@ public:
exec.argv_len = (size_t)request->argc;
exec.env = request->env;
exec.env_len = request->env_len;
+ exec.suffix = request->suffix;
json = container_exec_request_generate_json(&exec, &ctx, &err);
if (json == nullptr) {
format_errorf(&response->errmsg, "Can not generate json: %s", err);
@@ -1589,61 +1648,6 @@ cleanup:
}
};
-class ContainerConf : public ClientBase {
-public:
- explicit ContainerConf(void *args)
- : ClientBase(args)
- {
- }
- ~ContainerConf() = default;
-
- int request_to_grpc(const lcrc_container_conf_request *request, Container_conf_Request *grequest) override
- {
- if (request == nullptr) {
- return -1;
- }
-
- if (request->name != nullptr) {
- grequest->set_container_id(request->name);
- }
-
- return 0;
- }
-
- int response_from_grpc(Container_conf_Response *gresponse, lcrc_container_conf_response *response) override
- {
- response->server_errono = gresponse->cc();
- if (!gresponse->errmsg().empty()) {
- response->errmsg = util_strdup_s(gresponse->errmsg().c_str());
- }
- if (!gresponse->container_logpath().empty()) {
- response->container_logpath = util_strdup_s(gresponse->container_logpath().c_str());
- }
- response->container_logrotate = gresponse->container_logrotate();
- if (!gresponse->container_logsize().empty()) {
- response->container_logsize = util_strdup_s(gresponse->container_logsize().c_str());
- }
-
- return 0;
- }
-
- int check_parameter(const Container_conf_Request &req) override
- {
- if (req.container_id().empty()) {
- ERROR("Missing container name in the request");
- return -1;
- }
-
- return 0;
- }
-
- Status grpc_call(ClientContext *context, const Container_conf_Request &req, Container_conf_Response *reply) override
- {
- return stub_->Container_conf(context, req, reply);
- }
-};
-
class ContainerStats : public ClientBase {
public:
@@ -1659,10 +1663,6 @@ public:
return -1;
}
- if (request->runtime != nullptr) {
- grequest->set_runtime(request->runtime);
- }
-
for (size_t i = 0; request->containers != nullptr && i < request->containers_len; i++) {
grequest->add_containers(request->containers[i]);
}
@@ -1686,9 +1686,6 @@ public:
if (!gresponse->containers(i).id().empty()) {
response->container_stats[i].id = util_strdup_s(gresponse->containers(i).id().c_str());
}
- response->container_stats[i].has_pid = (int)gresponse->containers(i).pid() != -1;
- response->container_stats[i].pid = (uint32_t)gresponse->containers(i).pid();
- response->container_stats[i].status = (Container_Status)((int)gresponse->containers(i).status());
response->container_stats[i].pids_current = gresponse->containers(i).pids_current();
response->container_stats[i].cpu_use_nanos = gresponse->containers(i).cpu_use_nanos();
response->container_stats[i].cpu_system_use = gresponse->containers(i).cpu_system_use();
@@ -1712,11 +1709,6 @@ public:
int check_parameter(const StatsRequest &req) override
{
- if (req.runtime().empty()) {
- ERROR("Missing runtime in the request");
- return -1;
- }
-
return 0;
}
@@ -2213,7 +2205,6 @@ int grpc_containers_client_ops_init(lcrc_connect_ops *ops)
ops->container.pause = container_func;
ops->container.resume = container_func;
ops->container.update = container_func;
- ops->container.conf = container_func;
ops->container.kill = container_func;
ops->container.stats = container_func;
ops->container.wait = container_func;
@@ -2226,6 +2217,7 @@ int grpc_containers_client_ops_init(lcrc_connect_ops *ops)
container_func;
ops->container.top = container_func;
ops->container.rename = container_func;
+ ops->container.resize = container_func;
ops->container.logs = container_func;
return 0;
diff --git a/src/connect/client/lcrc_connect.h b/src/connect/client/lcrc_connect.h
index b18e3a5..46635d9 100644
--- a/src/connect/client/lcrc_connect.h
+++ b/src/connect/client/lcrc_connect.h
@@ -83,9 +83,6 @@ typedef struct {
int(*update)(const struct lcrc_update_request *request,
struct lcrc_update_response *response, void *arg);
- int(*conf)(const struct lcrc_container_conf_request *request,
- struct lcrc_container_conf_response *response, void *arg);
-
int(*attach)(const struct lcrc_attach_request *request,
struct lcrc_attach_response *response, void *arg);
@@ -98,7 +95,8 @@ typedef struct {
struct lcrc_top_response *response, void *arg);
int(*rename)(const struct lcrc_rename_request *request,
struct lcrc_rename_response *response, void *arg);
-
+ int(*resize)(const struct lcrc_resize_request *request,
+ struct lcrc_resize_response *response, void *arg);
int(*logs)(const struct lcrc_logs_request *request, struct lcrc_logs_response *response, void *arg);
} container_ops;
diff --git a/src/connect/client/rest/rest_containers_client.c b/src/connect/client/rest/rest_containers_client.c
index 7c0c2a6..f92ead5 100644
--- a/src/connect/client/rest/rest_containers_client.c
+++ b/src/connect/client/rest/rest_containers_client.c
@@ -271,37 +271,6 @@ out:
return ret;
}
-/* container conf request to rest */
-static int container_conf_request_to_rest(const struct lcrc_container_conf_request *lconf_request, char **body,
- size_t *body_len)
-{
- container_conf_request *crequest = NULL;
- struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 };
- parser_error err = NULL;
- int ret = 0;
-
- crequest = util_common_calloc_s(sizeof(container_conf_request));
- if (crequest == NULL) {
- ERROR("Out of memory");
- return -1;
- }
-
- if (lconf_request->name != NULL) {
- crequest->container_id = util_strdup_s(lconf_request->name);
- }
- *body = container_conf_request_generate_json(crequest, &ctx, &err);
- if (*body == NULL) {
- ERROR("Failed to generate conf request json:%s", err);
- ret = -1;
- goto out;
- }
- *body_len = strlen(*body) + 1;
-out:
- free(err);
- free_container_conf_request(crequest);
- return ret;
-}
-
/* wait request to rest */
static int wait_request_to_rest(const struct lcrc_wait_request *lw_request, char **body, size_t *body_len)
{
@@ -568,47 +537,6 @@ out:
return ret;
}
-/* unpack container conf response */
-static int unpack_container_conf_response(const struct parsed_http_message *message, void *arg)
-{
- struct lcrc_container_conf_response *response = arg;
- container_conf_response *cresponse = NULL;
- parser_error err = NULL;
- int ret = 0;
-
- ret = check_status_code(message->status_code);
- if (ret != 0) {
- goto out;
- }
-
- cresponse = container_conf_response_parse_data(message->body, NULL, &err);
- if (cresponse == NULL) {
- ERROR("Invalid create response:%s", err);
- ret = -1;
- goto out;
- }
- response->server_errono = cresponse->cc;
- if (cresponse->errmsg != NULL) {
- response->errmsg = util_strdup_s(cresponse->errmsg);
- }
- if (cresponse->container_logpath != NULL) {
- response->container_logpath = util_strdup_s(cresponse->container_logpath);
- }
- response->container_logrotate = cresponse->container_logrotate;
- if (cresponse->container_logsize != NULL) {
- response->container_logsize = util_strdup_s(cresponse->container_logsize);
- }
- ret = (cresponse->cc == LCRD_SUCCESS) ? 0 : -1;
- if (message->status_code == EVHTP_RES_SERVERR) {
- ret = -1;
- }
-
-out:
- free(err);
- free_container_conf_response(cresponse);
- return ret;
-}
-
/* unpack wait response */
static int unpack_wait_response(const struct parsed_http_message *message, void *arg)
{
@@ -811,39 +739,6 @@ out:
return ret;
}
-/* rest container conf */
-static int rest_container_conf(const struct lcrc_container_conf_request *lc_request,
- struct lcrc_container_conf_response *lc_response, void *arg)
-{
- char *body = NULL;
- int ret = 0;
- size_t len = 0;
- client_connect_config_t *connect_config = (client_connect_config_t *)arg;
- const char *socketname = (const char *)(connect_config->socket);
- Buffer *c_output = NULL;
-
- ret = container_conf_request_to_rest(lc_request, &body, &len);
- if (ret != 0) {
- goto out;
- }
- ret = rest_send_requst(socketname, RestHttpHead ContainerServiceConf, body, len, &c_output);
- if (ret != 0) {
- lc_response->errmsg = util_strdup_s(errno_to_error_message(LCRD_ERR_CONNECT));
- lc_response->cc = LCRD_ERR_EXEC;
- goto out;
- }
- ret = get_response(c_output, unpack_container_conf_response, (void *)lc_response);
- if (ret != 0) {
- goto out;
- }
-out:
- if (c_output != NULL) {
- buffer_free(c_output);
- }
- put_body(body);
- return ret;
-}
-
/* rest container wait */
static int rest_container_wait(const struct lcrc_wait_request *lw_request,
struct lcrc_wait_response *lw_response, void *arg)
@@ -1871,7 +1766,6 @@ int rest_containers_client_ops_init(lcrc_connect_ops *ops)
ops->container.attach = &rest_container_attach;
ops->container.resume = &rest_container_resume;
ops->container.update = &rest_container_update;
- ops->container.conf = &rest_container_conf;
ops->container.kill = &rest_container_kill;
ops->container.version = &rest_container_version;
ops->container.wait = &rest_container_wait;
diff --git a/src/connect/service/grpc/grpc_containers_service.cc b/src/connect/service/grpc/grpc_containers_service.cc
index 5b9f28c..016a959 100644
--- a/src/connect/service/grpc/grpc_containers_service.cc
+++ b/src/connect/service/grpc/grpc_containers_service.cc
@@ -1041,39 +1041,6 @@ Status ContainerServiceImpl::Export(ServerContext *context, const ExportRequest
return Status::OK;
}
-Status ContainerServiceImpl::Container_conf(ServerContext *context, const Container_conf_Request *request,
- Container_conf_Response *reply)
-{
- int ret, tret;
- service_callback_t *cb = nullptr;
- struct lcrd_container_conf_request *lcrdreq = nullptr;
- struct lcrd_container_conf_response *lcrdres = nullptr;
-
- cb = get_service_callback();
- if (cb == nullptr || cb->container.conf == nullptr) {
- return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
- }
-
- tret = container_conf_request_from_grpc(request, &lcrdreq);
- if (tret != 0) {
- ERROR("Failed to transform grpc request");
- reply->set_cc(LCRD_ERR_INPUT);
- return Status::OK;
- }
-
- ret = cb->container.conf(lcrdreq, &lcrdres);
- tret = container_conf_response_to_grpc(lcrdres, reply);
-
- lcrd_container_conf_request_free(lcrdreq);
- lcrd_container_conf_response_free(lcrdres);
- if (tret != 0) {
- reply->set_errmsg(errno_to_error_message(LCRD_ERR_INTERNAL));
- reply->set_cc(LCRD_ERR_INTERNAL);
- ERROR("Failed to translate response to grpc, operation is %s", ret ? "failed" : "success");
- }
- return Status::OK;
-}
-
Status ContainerServiceImpl::Rename(ServerContext *context, const RenameRequest *request,
RenameResponse *reply)
{
@@ -1112,6 +1079,44 @@ Status ContainerServiceImpl::Rename(ServerContext *context, const RenameRequest
return Status::OK;
}
+Status ContainerServiceImpl::Resize(ServerContext *context, const ResizeRequest *request,
+ ResizeResponse *reply)
+{
+ int ret, tret;
+ service_callback_t *cb = nullptr;
+ struct lcrd_container_resize_request *lcrdreq = nullptr;
+ struct lcrd_container_resize_response *lcrdres = nullptr;
+
+ auto status = GrpcServerTlsAuth::auth(context, "container_resize");
+ if (!status.ok()) {
+ return status;
+ }
+
+ cb = get_service_callback();
+ if (cb == nullptr || cb->container.resize == nullptr) {
+ return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
+ }
+
+ tret = container_resize_request_from_grpc(request, &lcrdreq);
+ if (tret != 0) {
+ ERROR("Failed to transform grpc request");
+ reply->set_cc(LCRD_ERR_INPUT);
+ return Status::OK;
+ }
+
+ ret = cb->container.resize(lcrdreq, &lcrdres);
+ tret = container_resize_response_to_grpc(lcrdres, reply);
+
+ lcrd_container_resize_request_free(lcrdreq);
+ lcrd_container_resize_response_free(lcrdres);
+ if (tret != 0) {
+ reply->set_errmsg(errno_to_error_message(LCRD_ERR_INTERNAL));
+ reply->set_cc(LCRD_ERR_INTERNAL);
+ ERROR("Failed to translate response to grpc, operation is %s", ret ? "failed" : "success");
+ }
+ return Status::OK;
+}
+
Status ContainerServiceImpl::Update(ServerContext *context, const UpdateRequest *request, UpdateResponse *reply)
{
int ret, tret;
diff --git a/src/connect/service/grpc/grpc_containers_service.h b/src/connect/service/grpc/grpc_containers_service.h
index 4d903cc..9dee9b1 100644
--- a/src/connect/service/grpc/grpc_containers_service.h
+++ b/src/connect/service/grpc/grpc_containers_service.h
@@ -75,11 +75,10 @@ public:
Status Resume(ServerContext *context, const ResumeRequest *request, ResumeResponse *reply) override;
- Status Container_conf(ServerContext *context, const Container_conf_Request *request,
- Container_conf_Response *reply) override;
-
Status Rename(ServerContext *context, const RenameRequest *request, RenameResponse *reply) override;
+ Status Resize(ServerContext *context, const ResizeRequest *request, ResizeResponse *reply) override;
+
Status Update(ServerContext *context, const UpdateRequest *request, UpdateResponse *reply) override;
@@ -165,18 +164,18 @@ private:
int resume_request_from_grpc(const ResumeRequest *grequest, container_resume_request **request);
- int container_conf_request_from_grpc(const Container_conf_Request *grequest,
- struct lcrd_container_conf_request **request);
-
- int container_conf_response_to_grpc(const struct lcrd_container_conf_response *response,
- Container_conf_Response *gresponse);
-
int container_rename_request_from_grpc(const RenameRequest *grequest,
struct lcrd_container_rename_request **request);
int container_rename_response_to_grpc(const struct lcrd_container_rename_response *response,
RenameResponse *gresponse);
+ int container_resize_request_from_grpc(const ResizeRequest *grequest,
+ struct lcrd_container_resize_request **request);
+
+ int container_resize_response_to_grpc(const struct lcrd_container_resize_response *response,
+ ResizeResponse *gresponse);
+
int update_request_from_grpc(const UpdateRequest *grequest, container_update_request **request);
int update_response_to_grpc(const container_update_response *response, UpdateResponse *gresponse);
diff --git a/src/connect/service/grpc/grpc_containers_service_private.cc b/src/connect/service/grpc/grpc_containers_service_private.cc
index 4454a84..a573f7b 100644
--- a/src/connect/service/grpc/grpc_containers_service_private.cc
+++ b/src/connect/service/grpc/grpc_containers_service_private.cc
@@ -352,6 +352,10 @@ int ContainerServiceImpl::exec_request_from_grpc(const ExecRequest *grequest, co
tmpreq->container_id = util_strdup_s(grequest->container_id().c_str());
}
+ if (!grequest->suffix().empty()) {
+ tmpreq->suffix = util_strdup_s(grequest->suffix().c_str());
+ }
+
tmpreq->tty = grequest->tty();
tmpreq->attach_stdin = grequest->attach_stdin();
tmpreq->attach_stdout = grequest->attach_stdout();
@@ -607,46 +611,6 @@ int ContainerServiceImpl::resume_request_from_grpc(const ResumeRequest *grequest
return 0;
}
-int ContainerServiceImpl::container_conf_request_from_grpc(const Container_conf_Request *grequest,
- struct lcrd_container_conf_request **request)
-{
- struct lcrd_container_conf_request *tmpreq = (struct lcrd_container_conf_request *)util_common_calloc_s(
- sizeof(struct lcrd_container_conf_request));
- if (tmpreq == nullptr) {
- ERROR("Out of memory");
- return -1;
- }
-
- if (!grequest->container_id().empty()) {
- tmpreq->name = util_strdup_s(grequest->container_id().c_str());
- }
-
- *request = tmpreq;
- return 0;
-}
-
-int ContainerServiceImpl::container_conf_response_to_grpc(const struct lcrd_container_conf_response *response,
- Container_conf_Response *gresponse)
-{
- if (response == nullptr) {
- gresponse->set_cc(LCRD_ERR_MEMOUT);
- return 0;
- }
-
- gresponse->set_cc(response->cc);
- if (response->errmsg != nullptr) {
- gresponse->set_errmsg(response->errmsg);
- }
- if (response->container_logpath != nullptr) {
- gresponse->set_container_logpath(response->container_logpath);
- }
- gresponse->set_container_logrotate(response->container_logrotate);
- if (response->container_logsize != nullptr) {
- gresponse->set_container_logsize(response->container_logsize);
- }
- return 0;
-}
-
int ContainerServiceImpl::container_rename_request_from_grpc(const RenameRequest *grequest,
struct lcrd_container_rename_request **request)
{
@@ -688,6 +652,50 @@ int ContainerServiceImpl::container_rename_response_to_grpc(const struct lcrd_co
return 0;
}
+int ContainerServiceImpl::container_resize_request_from_grpc(const ResizeRequest *grequest,
+ struct lcrd_container_resize_request **request)
+{
+ struct lcrd_container_resize_request *tmpreq = (struct lcrd_container_resize_request *)util_common_calloc_s(
+ sizeof(struct lcrd_container_resize_request));
+ if (tmpreq == nullptr) {
+ ERROR("Out of memory");
+ return -1;
+ }
+
+ if (!grequest->id().empty()) {
+ tmpreq->id = util_strdup_s(grequest->id().c_str());
+ }
+
+ if (!grequest->suffix().empty()) {
+ tmpreq->suffix = util_strdup_s(grequest->suffix().c_str());
+ }
+
+ tmpreq->height = grequest->height();
+
+ tmpreq->width = grequest->width();
+
+ *request = tmpreq;
+ return 0;
+}
+
+int ContainerServiceImpl::container_resize_response_to_grpc(const struct lcrd_container_resize_response *response,
+ ResizeResponse *gresponse)
+{
+ if (response == nullptr) {
+ gresponse->set_cc(LCRD_ERR_MEMOUT);
+ return 0;
+ }
+
+ gresponse->set_cc(response->cc);
+ if (response->errmsg != nullptr) {
+ gresponse->set_errmsg(response->errmsg);
+ }
+ if (response->id != nullptr) {
+ gresponse->set_id(response->id);
+ }
+
+ return 0;
+}
int ContainerServiceImpl::update_request_from_grpc(const UpdateRequest *grequest, container_update_request **request)
{
@@ -735,10 +743,6 @@ int ContainerServiceImpl::stats_request_from_grpc(const StatsRequest *grequest,
return -1;
}
- if (!grequest->runtime().empty()) {
- tmpreq->runtime = util_strdup_s(grequest->runtime().c_str());
- }
-
if (grequest->containers_size() > 0) {
tmpreq->containers = (char **)util_common_calloc_s(grequest->containers_size() * sizeof(char *));
if (tmpreq->containers == nullptr) {
@@ -771,12 +775,6 @@ int ContainerServiceImpl::stats_response_to_grpc(const container_stats_response
if (response->container_stats[i]->id != nullptr) {
stats->set_id(response->container_stats[i]->id);
}
- if (response->container_stats[i]->has_pid) {
- stats->set_pid(response->container_stats[i]->pid);
- } else {
- stats->set_pid(-1);
- }
- stats->set_status((ContainerStatus)response->container_stats[i]->status);
stats->set_pids_current(response->container_stats[i]->pids_current);
stats->set_cpu_use_nanos(response->container_stats[i]->cpu_use_nanos);
stats->set_cpu_system_use(response->container_stats[i]->cpu_system_use);
diff --git a/src/connect/service/rest/rest_containers_service.c b/src/connect/service/rest/rest_containers_service.c
index d392094..30ac093 100644
--- a/src/connect/service/rest/rest_containers_service.c
+++ b/src/connect/service/rest/rest_containers_service.c
@@ -150,20 +150,6 @@ static int list_request_check(void *req)
return ret;
}
-/* container conf response check */
-static int container_conf_request_check(void *req)
-{
- int ret = 0;
- struct lcrd_container_conf_request *req_conf = (struct lcrd_container_conf_request *)req;
- if (req_conf->name == NULL) {
- DEBUG("container name error");
- ret = -1;
- goto out;
- }
-
-out:
- return ret;
-}
/* create request check */
static int create_request_check(void *req)
{
@@ -297,11 +283,6 @@ static struct rest_handle_st g_rest_handle[] = {
.request_parse_data = (void *)container_wait_request_parse_data,
.request_check = wait_request_check,
},
- {
- .name = ContainerServiceConf,
- .request_parse_data = (void *)container_conf_request_parse_data,
- .request_check = container_conf_request_check,
- },
{
.name = ContainerServiceInspect,
.request_parse_data = (void *)container_inspect_request_parse_data,
@@ -411,50 +392,6 @@ out:
return;
}
-/* evhtp send container conf repsponse */
-static void evhtp_send_container_conf_repsponse(evhtp_request_t *req, container_conf_response *response, int rescode)
-{
- parser_error err = NULL;
- struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 };
- char *responsedata = NULL;
-
- responsedata = container_conf_response_generate_json(response, &ctx, &err);
- if (responsedata == NULL) {
- ERROR("Failed to generate container_conf request json:%s", err);
- evhtp_send_reply(req, EVHTP_RES_ERROR);
- goto out;
- }
-
- evhtp_send_response(req, responsedata, rescode);
-
-out:
- free(err);
- free(responsedata);
- return;
-}
-
-/* container conf response to rest */
-static int container_conf_response_to_rest(container_conf_response *cresponse,
- struct lcrd_container_conf_response *response)
-{
- if (response == NULL) {
- cresponse->cc = LCRD_ERR_MEMOUT;
- return 0;
- }
- cresponse->cc = response->cc;
- if (response->errmsg) {
- cresponse->errmsg = util_strdup_s(response->errmsg);
- }
- if (response->container_logpath) {
- cresponse->container_logpath = util_strdup_s(response->container_logpath);
- }
- cresponse->container_logrotate = response->container_logrotate;
- if (response->container_logsize) {
- cresponse->container_logsize = util_strdup_s(response->container_logsize);
- }
- return 0;
-}
-
/* evhtp send wait repsponse */
static void evhtp_send_wait_repsponse(evhtp_request_t *req, container_wait_response *response, int rescode)
{
@@ -547,58 +484,6 @@ out:
free_container_start_response(cresponse);
}
-/* rest container conf cb */
-static void rest_container_conf_cb(evhtp_request_t *req, void *arg)
-{
- int ret, tret;
- service_callback_t *cb = NULL;
- struct lcrd_container_conf_request *lcrdreq = NULL;
- struct lcrd_container_conf_response *lcrdres = NULL;
- container_conf_response *cresponse = NULL;
-
- // only deal with POST request
- if (evhtp_request_get_method(req) != htp_method_POST) {
- evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
- return;
- }
- cb = get_service_callback();
- if (cb == NULL || cb->container.conf == NULL) {
- ERROR("Unimplemented callback");
- evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
- return;
- }
-
- cresponse = util_common_calloc_s(sizeof(container_conf_response));
- if (cresponse == NULL) {
- evhtp_send_reply(req, EVHTP_RES_ERROR);
- return;
- }
-
- tret = action_request_from_rest(req, (void **)&lcrdreq, ContainerServiceConf);
- if (tret < 0) {
- ERROR("Bad request");
- cresponse->cc = LCRD_ERR_EXEC;
- evhtp_send_container_conf_repsponse(req, cresponse, EVHTP_RES_SERVERR);
- goto out;
- }
-
- ret = cb->container.conf(lcrdreq, &lcrdres);
-
- tret = container_conf_response_to_rest(cresponse, lcrdres);
- if (tret) {
- ERROR("Failed to translate response to rest,operation is %s", ret ? "failed" : "success");
- cresponse->cc = LCRD_ERR_EXEC;
- if (cresponse->errmsg == NULL) {
- cresponse->errmsg = util_strdup_s(errno_to_error_message(LCRD_ERR_INTERNAL));
- }
- }
- evhtp_send_container_conf_repsponse(req, cresponse, EVHTP_RES_OK);
-out:
- lcrd_container_conf_request_free(lcrdreq);
- lcrd_container_conf_response_free(lcrdres);
- free_container_conf_response(cresponse);
-}
-
/* rest wait cb */
static void rest_wait_cb(evhtp_request_t *req, void *arg)
{
@@ -1213,11 +1098,6 @@ int rest_register_containers_handler(evhtp_t *htp)
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceConf, rest_container_conf_cb, NULL) == NULL) {
- ERROR("Failed to register container_conf callback");
- return -1;
- }
-
if (evhtp_set_cb(htp, ContainerServiceWait, rest_wait_cb, NULL) == NULL) {
ERROR("Failed to register wait callback");
return -1;
diff --git a/src/cutils/utils.c b/src/cutils/utils.c
index d2c50bc..1e30aaf 100644
--- a/src/cutils/utils.c
+++ b/src/cutils/utils.c
@@ -1424,4 +1424,54 @@ void usleep_nointerupt(unsigned long usec)
request = remain;
} while (ret == -1 && errno == EINTR);
}
+int util_generate_random_str(char *id, size_t len)
+{
+ int fd = -1;
+ int num = 0;
+ size_t i;
+ const int m = 256;
+
+ len = len / 2;
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd == -1) {
+ ERROR("Failed to open /dev/urandom");
+ return -1;
+ }
+ for (i = 0; i < len; i++) {
+ int nret;
+ if (read(fd, &num, sizeof(int)) < 0) {
+ ERROR("Failed to read urandom value");
+ close(fd);
+ return -1;
+ }
+ unsigned char rs = (unsigned char)(num % m);
+ nret = snprintf((id + i * 2), ((len - i) * 2 + 1), "%02x", (unsigned int)rs);
+ if (nret < 0 || (size_t)nret >= ((len - i) * 2 + 1)) {
+ ERROR("Failed to snprintf random string");
+ close(fd);
+ return -1;
+ }
+ }
+ close(fd);
+ id[i * 2] = '\0';
+ return 0;
+}
+
+void add_array_elem(char **array, size_t total, size_t *pos, const char *elem)
+{
+ if (*pos + 1 >= total - 1) {
+ return;
+ }
+ array[*pos] = util_strdup_s(elem);
+ *pos += 1;
+}
+
+void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v)
+{
+ if (k == NULL || v == NULL) {
+ return;
+ }
+ add_array_elem(array, total, pos, k);
+ add_array_elem(array, total, pos, v);
+}
diff --git a/src/cutils/utils.h b/src/cutils/utils.h
index 66e737c..ea594a0 100644
--- a/src/cutils/utils.h
+++ b/src/cutils/utils.h
@@ -57,6 +57,8 @@ extern "C" {
#define ECOMMON 1
+#define PARAM_NUM 100
+
/* image error start */
#define EIMAGEBUSY 2
#define ENAMECONFLICT 3
@@ -90,6 +92,8 @@ extern "C" {
/* container id max length */
#define CONTAINER_ID_MAX_LEN 64
+#define CONTAINER_EXEC_ID_MAX_LEN 64
+
#define LIST_SIZE_MAX 1000LL
#define LIST_DEVICE_SIZE_MAX 10000LL
#define LIST_ENV_SIZE_MAX 200000LL
@@ -418,6 +422,12 @@ bool util_check_signal_valid(int sig);
void usleep_nointerupt(unsigned long usec);
+int util_generate_random_str(char *id, size_t len);
+
+void add_array_elem(char **array, size_t total, size_t *pos, const char *elem);
+
+void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/cutils/utils_regex.c b/src/cutils/utils_regex.c
index 68ac587..420f939 100644
--- a/src/cutils/utils_regex.c
+++ b/src/cutils/utils_regex.c
@@ -95,15 +95,15 @@ int util_wildcard_to_regex(const char *wildcard, char **regex)
size_t index = 0;
size_t regex_size;
char escapes[] = { '$', '^', '[', ']', '(', ')', '{', '|', '+', '\\', '.', '<', '>', '}' };
- if (wildcard == NULL) {
- return 0;
- }
+ if (wildcard == NULL || regex == NULL) {
+ ERROR("Invalid output parameter");
+ return -1;
+ }
if (get_regex_size_from_wildcard(wildcard, escapes, sizeof(escapes) / sizeof(char), ®ex_size) != 0) {
return -1;
}
-
- *regex = malloc(regex_size);
+ *regex = (char *)util_common_calloc_s(regex_size);
if (*regex == NULL) {
ERROR("Out of memory");
return -1;
diff --git a/src/cutils/utils_verify.c b/src/cutils/utils_verify.c
index ccd7eb1..562a942 100644
--- a/src/cutils/utils_verify.c
+++ b/src/cutils/utils_verify.c
@@ -622,3 +622,14 @@ cleanup:
return bret;
}
+bool util_valid_exec_suffix(const char *suffix)
+{
+ char *patten = "^[a-f0-9]{64}$";
+
+ if (suffix == NULL) {
+ ERROR("invalid NULL param");
+ return false;
+ }
+
+ return util_reg_match(patten, suffix) == 0;
+}
diff --git a/src/cutils/utils_verify.h b/src/cutils/utils_verify.h
index 148f413..443fe5c 100644
--- a/src/cutils/utils_verify.h
+++ b/src/cutils/utils_verify.h
@@ -96,6 +96,8 @@ bool util_valid_runtime_name(const char *name);
bool util_valid_short_sha256_id(const char *id);
+bool util_valid_exec_suffix(const char *suffix);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/engines/engine.h b/src/engines/engine.h
index c57f05d..f50545f 100644
--- a/src/engines/engine.h
+++ b/src/engines/engine.h
@@ -23,12 +23,6 @@
extern "C" {
#endif
-struct engine_console_config {
- char *log_path;
- unsigned int log_rotate;
- char *log_file_size;
-};
-
struct engine_cgroup_resources {
uint64_t blkio_weight;
uint64_t cpu_shares;
@@ -66,11 +60,13 @@ struct engine_container_summary_info {
char *finishat;
};
-struct engine_container_info {
- char *id;
+struct engine_container_status_info {
bool has_pid;
uint32_t pid;
Engine_Container_Status status;
+};
+
+struct engine_container_resources_stats_info {
uint64_t pids_current;
/* CPU usage */
uint64_t cpu_use_nanos;
@@ -131,6 +127,8 @@ typedef struct _engine_exec_request_t {
size_t args_len;
int64_t timeout;
+
+ const char *suffix;
} engine_exec_request_t;
@@ -149,33 +147,25 @@ typedef bool (*engine_resume_t)(const char *name, const char *enginepath);
typedef bool (*engine_reset_t)(const char *name, const char *enginepath);
+typedef bool (*engine_resize_t)(const char *name, const char *lcrpath, unsigned int height, unsigned int width);
+typedef bool (*engine_exec_resize_t)(const char *name, const char *lcrpath, const char *suffix, unsigned int height,
+ unsigned int width);
+
typedef bool (*engine_update_t)(const char *name, const char *enginepath, const struct engine_cgroup_resources *cr);
typedef bool (*engine_exec_t)(const engine_exec_request_t *request, int *exit_code);
-typedef int (*engine_get_all_containers_info_t)(const char *enginepath, struct engine_container_summary_info **cons);
-
-typedef struct engine_container_summary_info *(*engine_get_container_info_t)(const char *name, const char *enginepath);
-
-typedef void (*engine_free_container_info_t)(struct engine_container_summary_info *info);
-
-typedef void (*engine_free_all_containers_info_t)(struct engine_container_summary_info *info, int num);
-
typedef int (*engine_get_container_status_t)(const char *name, const char *enginepath,
- struct engine_container_info *status);
+ struct engine_container_status_info *status);
-typedef void (*engine_free_container_status_t)(struct engine_container_info *container);
+typedef int (*engine_get_container_resources_stats_t)(const char *name, const char *enginepath,
+ struct engine_container_resources_stats_info *rs_stats);
typedef bool (*engine_get_container_pids_t)(const char *name, const char *rootpath, pid_t **pids, size_t *pids_len);
typedef bool (*engine_console_t)(const char *name, const char *enginepath, char *in_fifo, char *out_fifo,
char *err_fifo);
-typedef bool (*engine_get_console_config_t)(const char *name, const char *enginepath,
- struct engine_console_config *config);
-
-typedef void (*engine_free_console_config_t)(struct engine_console_config *config);
-
typedef int (*engine_log_init_t)(const char *name, const char *file, const char *priority, const char *prefix,
int quiet, const char *enginepath);
@@ -193,17 +183,15 @@ struct engine_operation {
engine_pause_t engine_pause_op;
engine_resume_t engine_resume_op;
engine_reset_t engine_reset_op;
+ engine_resize_t engine_resize_op;
+ engine_exec_resize_t engine_exec_resize_op;
engine_exec_t engine_exec_op;
engine_console_t engine_console_op;
engine_get_container_status_t engine_get_container_status_op;
- engine_free_container_status_t engine_free_container_status_op;
- engine_get_all_containers_info_t engine_get_all_containers_info_op;
- engine_free_all_containers_info_t engine_free_all_containers_info_op;
+ engine_get_container_resources_stats_t engine_get_container_resources_stats_op;
engine_get_container_pids_t engine_get_container_pids_op;
engine_log_init_t engine_log_init_op;
engine_update_t engine_update_op;
- engine_get_console_config_t engine_get_console_config_op;
- engine_free_console_config_t engine_free_console_config_op;
engine_get_errmsg_t engine_get_errmsg_op;
engine_clear_errmsg_t engine_clear_errmsg_op;
engine_clean_t engine_clean_op;
diff --git a/src/engines/lcr/lcr_engine.c b/src/engines/lcr/lcr_engine.c
index 083ec31..922a016 100644
--- a/src/engines/lcr/lcr_engine.c
+++ b/src/engines/lcr/lcr_engine.c
@@ -27,23 +27,15 @@
#include "log.h"
#include "lcrd_config.h"
-typedef int(*lcr_list_all_containers_t)(const char *lcrpath, struct lcr_container_info **info_arr);
-typedef void(*lcr_containers_info_free_t)(struct lcr_container_info **info_arr, size_t size);
typedef bool(*lcr_state_op_t)(const char *name, const char *lcrpath, struct lcr_container_state *lcs);
typedef void(*lcr_container_state_free_t)(struct lcr_container_state *lcs);
typedef bool(*lcr_update_op_t)(const char *name, const char *lcrpath, struct lcr_cgroup_resources *cr);
-typedef bool(*lcr_get_console_config_op_t)(const char *name, const char *lcrpath, struct lcr_console_config *config);
-typedef void(*lcr_free_console_config_op_t)(struct lcr_console_config *config);
typedef bool(*lcr_start_op_t)(struct lcr_start_request *request);
typedef bool(*lcr_exec_op_t)(const struct lcr_exec_request *request, int *exit_code);
-static lcr_list_all_containers_t g_lcr_list_all_containers_op = NULL;
-static lcr_containers_info_free_t g_lcr_containers_info_free_op = NULL;
static lcr_state_op_t g_lcr_state_op = NULL;
static lcr_container_state_free_t g_lcr_container_state_free_op = NULL;
static lcr_update_op_t g_lcr_update_op = NULL;
-static lcr_get_console_config_op_t g_lcr_get_console_config_op = NULL;
-static lcr_free_console_config_op_t g_lcr_free_console_config_op = NULL;
static lcr_start_op_t g_lcr_start_op = NULL;
static lcr_exec_op_t g_lcr_exec_op = NULL;
/*
@@ -120,199 +112,21 @@ static bool lcr_exec_container(const engine_exec_request_t *request, int *exit_c
return g_lcr_exec_op(lcr_request, exit_code);
}
-/* free console config */
-void free_console_config(struct engine_console_config *config)
-{
- if (config == NULL) {
- return;
- }
- free(config->log_path);
- config->log_path = NULL;
-
- free(config->log_file_size);
- config->log_file_size = NULL;
-
- config->log_rotate = 0;
-}
-
-/* get console config */
-bool get_console_config(const char *name, const char *lcrpath, struct engine_console_config *config)
-{
- struct lcr_console_config lcr_config;
- bool ret = false;
-
- if (name == NULL || config == NULL) {
- ERROR("Invalid arguments");
- return ret;
- }
-
- (void)memset(&lcr_config, 0, sizeof(struct lcr_console_config));
-
- if (g_lcr_get_console_config_op != NULL) {
- ret = g_lcr_get_console_config_op(name, lcrpath, &lcr_config);
- }
-
- if (ret) {
- if (lcr_config.log_path) {
- config->log_path = util_strdup_s(lcr_config.log_path);
- } else {
- config->log_path = NULL;
- }
- config->log_rotate = lcr_config.log_rotate;
- if (lcr_config.log_file_size) {
- config->log_file_size = util_strdup_s(lcr_config.log_file_size);
- } else {
- config->log_file_size = NULL;
- }
-
- if (g_lcr_free_console_config_op != NULL) {
- g_lcr_free_console_config_op(&lcr_config);
- }
- }
-
- return ret;
-}
-
-/*
- * Get the containers info by liblcr
- */
-static void get_containers_info(int num, const struct lcr_container_info *info_arr,
- struct engine_container_summary_info *info)
-{
- int i = 0;
- const struct lcr_container_info *in = NULL;
- char *name = NULL;
-
- for (i = 0, in = info_arr; i < num; i++, in++) {
- name = in->name;
- if (name == NULL) {
- continue;
- }
-
- info[i].id = util_strdup_s(name);
- info[i].has_pid = (-1 == in->init) ? false : true;
- info[i].pid = (uint32_t)in->init;
- info[i].status = lcrsta2sta(in->state);
- }
-}
-
/*
* Get the state of container from 'lcr_container_state'
*/
-static void copy_container_status(const struct lcr_container_state *lcs, struct engine_container_info *status)
+static void copy_container_status(const struct lcr_container_state *lcs, struct engine_container_status_info *status)
{
- const char *defvalue = "-";
- const char *name = NULL;
-
- (void)memset(status, 0, sizeof(struct engine_container_info));
-
- name = lcs->name ? lcs->name : defvalue;
- status->id = util_strdup_s(name);
+ (void)memset(status, 0, sizeof(struct engine_container_status_info));
status->has_pid = (-1 == lcs->init) ? false : true;
status->pid = (uint32_t)lcs->init;
status->status = lcrsta2sta(lcs->state);
-
- status->pids_current = lcs->pids_current;
-
- status->cpu_use_nanos = lcs->cpu_use_nanos;
-
- status->blkio_read = lcs->io_service_bytes.read;
- status->blkio_write = lcs->io_service_bytes.write;
-
- status->mem_used = lcs->mem_used;
- status->mem_limit = lcs->mem_limit;
- status->kmem_used = lcs->kmem_used;
- status->kmem_limit = lcs->kmem_limit;
-}
-
-/*
- * Alloc Memory for containerArray and container
- */
-static int service_list_alloc(int num, struct engine_container_summary_info **cons)
-{
- if (num <= 0 || cons == NULL) {
- return -1;
- }
-
- if ((size_t)num > SIZE_MAX / sizeof(struct engine_container_summary_info)) {
- ERROR("Too many engine container summaries!");
- return -1;
- }
- *cons = util_common_calloc_s((size_t)num * sizeof(struct engine_container_summary_info));
- if ((*cons) == NULL) {
- ERROR("Out of memory");
- return -1;
- }
-
- return 0;
-}
-
-/*
- * Free the container** containerArray
- */
-static void free_all_containers_info(struct engine_container_summary_info *info, int num)
-{
- int i = 0;
-
- if (num <= 0 || info == NULL) {
- return;
- }
- for (i = 0; i < num; i++) {
- free(info[i].id);
- info[i].id = NULL;
- free(info[i].command);
- info[i].command = NULL;
- free(info[i].image);
- info[i].image = NULL;
- free(info[i].finishat);
- info[i].finishat = NULL;
- free(info[i].startat);
- info[i].startat = NULL;
- }
- free(info);
-}
-
-/* get all containers info */
-static int get_all_containers_info(const char *enginepath, struct engine_container_summary_info **cons)
-{
- struct lcr_container_info *info_arr = NULL;
- int num = 0;
-
- if (cons == NULL) {
- ERROR("Invalid argument");
- return -1;
- }
-
- if (g_lcr_list_all_containers_op == NULL || g_lcr_containers_info_free_op == NULL) {
- ERROR("Not supported op");
- num = -1;
- goto free_out;
- }
-
- num = g_lcr_list_all_containers_op(enginepath, &info_arr);
- if (num <= 0) {
- num = 0; /* set to 0 if non were found */
- goto free_out;
- }
-
- if (service_list_alloc(num, cons)) {
- g_lcr_containers_info_free_op(&info_arr, (size_t)num);
- ERROR("service list alloc failed");
- num = -1;
- goto free_out;
- }
-
- get_containers_info(num, info_arr, *cons);
- g_lcr_containers_info_free_op(&info_arr, (size_t)num);
-
-free_out:
- return num;
}
/* get container status */
-static int get_container_status(const char *name, const char *enginepath, struct engine_container_info *status)
+static int get_container_status(const char *name, const char *enginepath, struct engine_container_status_info *status)
{
struct lcr_container_state lcs = { 0 };
@@ -331,22 +145,43 @@ static int get_container_status(const char *name, const char *enginepath, struct
return 0;
}
-/* free container status */
-static void free_container_status(struct engine_container_info *status)
+static void copy_container_resources_stats(const struct lcr_container_state *lcs,
+ struct engine_container_resources_stats_info *rs_stats)
{
- if (status == NULL) {
- return;
- }
+ (void)memset(rs_stats, 0, sizeof(struct engine_container_resources_stats_info));
+ rs_stats->pids_current = lcs->pids_current;
- free(status->id);
- status->id = NULL;
+ rs_stats->cpu_use_nanos = lcs->cpu_use_nanos;
+
+ rs_stats->blkio_read = lcs->io_service_bytes.read;
+ rs_stats->blkio_write = lcs->io_service_bytes.write;
+
+ rs_stats->mem_used = lcs->mem_used;
+ rs_stats->mem_limit = lcs->mem_limit;
+ rs_stats->kmem_used = lcs->kmem_used;
+ rs_stats->kmem_limit = lcs->kmem_limit;
}
-#define CHECK_ERROR(P) do { \
- if (dlerror() != NULL) { \
- goto badcleanup; \
- } \
- } while (0)
+/* get container cgroup resources */
+static int lcr_get_container_resources_stats(const char *name, const char *enginepath,
+ struct engine_container_resources_stats_info *rs_stats)
+{
+ struct lcr_container_state lcs = { 0 };
+
+ if (g_lcr_state_op == NULL || g_lcr_container_state_free_op == NULL) {
+ ERROR("Not supported op");
+ return -1;
+ }
+
+ if (!g_lcr_state_op(name, enginepath, &lcs)) {
+ DEBUG("Failed to state for container '%s'", name);
+ g_lcr_container_state_free_op(&lcs);
+ return -1;
+ }
+ copy_container_resources_stats(&lcs, rs_stats);
+ g_lcr_container_state_free_op(&lcs);
+ return 0;
+}
static bool load_lcr_exec_ops(void *lcr_handler, struct engine_operation *eop)
{
@@ -386,6 +221,14 @@ static bool load_lcr_exec_ops(void *lcr_handler, struct engine_operation *eop)
if (dlerror() != NULL) {
return false;
}
+ eop->engine_resize_op = dlsym(lcr_handler, "lcr_resize");
+ if (dlerror() != NULL) {
+ return false;
+ }
+ eop->engine_exec_resize_op = dlsym(lcr_handler, "lcr_exec_resize");
+ if (dlerror() != NULL) {
+ return false;
+ }
return true;
}
@@ -403,22 +246,6 @@ static bool load_lcr_info_ops(void *lcr_handler, struct engine_operation *eop)
if (dlerror() != NULL) {
return false;
}
- g_lcr_get_console_config_op = dlsym(lcr_handler, "lcr_get_console_config");
- if (dlerror() != NULL) {
- return false;
- }
- g_lcr_free_console_config_op = dlsym(lcr_handler, "lcr_free_console_config");
- if (dlerror() != NULL) {
- return false;
- }
- g_lcr_list_all_containers_op = dlsym(lcr_handler, "lcr_list_all_containers");
- if (dlerror() != NULL) {
- return false;
- }
- g_lcr_containers_info_free_op = dlsym(lcr_handler, "lcr_containers_info_free");
- if (dlerror() != NULL) {
- return false;
- }
g_lcr_state_op = dlsym(lcr_handler, "lcr_state");
if (dlerror() != NULL) {
return false;
@@ -464,16 +291,11 @@ struct engine_operation *lcr_engine_init()
ERROR("Load lcr info operations failed");
goto badcleanup;
}
-
- eop->engine_get_all_containers_info_op = get_all_containers_info;
- eop->engine_free_all_containers_info_op = free_all_containers_info;
eop->engine_get_container_status_op = get_container_status;
- eop->engine_free_container_status_op = free_container_status;
+ eop->engine_get_container_resources_stats_op = lcr_get_container_resources_stats;
eop->engine_update_op = lcr_update_container;
eop->engine_start_op = lcr_start_container;
eop->engine_exec_op = lcr_exec_container;
- eop->engine_get_console_config_op = get_console_config;
- eop->engine_free_console_config_op = free_console_config;
goto cleanup;
diff --git a/src/image/image.c b/src/image/image.c
index 180dec1..8e76b17 100644
--- a/src/image/image.c
+++ b/src/image/image.c
@@ -239,18 +239,13 @@ static struct bim *bim_get(const char *image_type, const char *image_name, const
if (image_name != NULL) {
bim->image_name = bim->ops->resolve_image_name(image_name);
if (bim->image_name == NULL) {
- lcrd_append_error_message("Failed to resovle image name%s", bim->image_name);
+ lcrd_append_error_message("Failed to resovle image name%s", image_name);
bim_put(bim);
return NULL;
}
}
if (ext_config_image != NULL) {
bim->ext_config_image = util_strdup_s(ext_config_image);
- if (bim->ext_config_image == NULL) {
- lcrd_append_error_message("Failed to dup external config image %s", bim->ext_config_image);
- bim_put(bim);
- return NULL;
- }
}
if (container_id != NULL) {
bim->container_id = util_strdup_s(container_id);
diff --git a/src/image/oci/global_config.h b/src/image/oci/global_config.h
index 50b64a1..4420224 100644
--- a/src/image/oci/global_config.h
+++ b/src/image/oci/global_config.h
@@ -21,8 +21,6 @@
extern "C" {
#endif
-#define PARAM_NUM 100
-
enum {
GB_OPTION_GRAPH_ROOT = 0,
GB_OPTION_RUN_ROOT,
@@ -37,25 +35,6 @@ enum {
GB_OPTION_MAX, // should not be used
};
-
-static inline void add_array_elem(char **array, size_t total, size_t *pos, const char *elem)
-{
- if (*pos + 1 >= total - 1) {
- return;
- }
- array[*pos] = util_strdup_s(elem);
- *pos += 1;
-}
-
-static inline void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v)
-{
- if (k == NULL || v == NULL) {
- return;
- }
- add_array_elem(array, total, pos, k);
- add_array_elem(array, total, pos, v);
-}
-
int pack_global_options(const char * const *options, char *params[], size_t *count, bool ignore_storage_opt_size);
#ifdef __cplusplus
diff --git a/src/image/oci/isula_image.c b/src/image/oci/isula_image.c
index fa902af..f231f5d 100644
--- a/src/image/oci/isula_image.c
+++ b/src/image/oci/isula_image.c
@@ -61,11 +61,15 @@ void isula_exit(void)
static int start_isula_image_server(void)
{
- struct server_monitor_conf sm_conf = {0};
+#define MIN_OPT_TIMEOUT 15
+ struct server_monitor_conf sm_conf = { 0 };
struct timespec ts = { 0 };
sem_t wait_monitor_sem;
+ unsigned int im_opt_timeout = conf_get_im_opt_timeout();
int ret = 0;
+ im_opt_timeout = im_opt_timeout >= MIN_OPT_TIMEOUT ? im_opt_timeout : MIN_OPT_TIMEOUT;
+
// check whether isula_kit is running by systemd
if (util_file_exists(ISULA_IMAGE_SERVER_DEFAULT_SOCK)) {
if (!conf_update_im_server_sock_addr(ISULA_IMAGE_SERVER_DEFAULT_SOCK)) {
@@ -93,7 +97,7 @@ static int start_isula_image_server(void)
ret = -1;
goto out;
}
- ts.tv_sec += 15; // set deadline 15s
+ ts.tv_sec += (time_t)im_opt_timeout; // set deadline
ret = sem_timedwait(&wait_monitor_sem, &ts);
if (ret != 0) {
diff --git a/src/image/oci/run_image_server.c b/src/image/oci/run_image_server.c
index 41afa1f..01945ca 100644
--- a/src/image/oci/run_image_server.c
+++ b/src/image/oci/run_image_server.c
@@ -245,10 +245,42 @@ static void *heartbeat_for_isulad_kit(void *arg)
return NULL;
}
+static unsigned long get_timeout_secs(bool retry)
+{
+ unsigned long result = RETRY_COUNT_MAX;
+
+ if (retry) {
+ return result;
+ }
+
+ result = conf_get_im_opt_timeout();
+ if (result < RETRY_COUNT_MAX) {
+ result = RETRY_COUNT_MAX;
+ }
+
+ return result;
+}
+
+static bool is_timeout(unsigned long max_second, unsigned long retry_cnt)
+{
+ unsigned long total = retry_cnt;
+
+ if (total >= ULONG_MAX / (total + 1)) {
+ return true;
+ }
+ total = total * (total + 1) / 2;
+ // time unit is second, retry time is 0.1s
+ if (total >= max_second * 10) {
+ return true;
+ }
+ return false;
+}
+
static int isula_image_server_load_first_check(const struct server_monitor_conf *conf, bool retry)
{
int ret = 0;
- unsigned long retry_cnt = 1;
+ unsigned long retry_cnt = 0;
+ unsigned long opt_timeout = get_timeout_secs(retry);
/* parent: check server is running */
while (true) {
@@ -257,13 +289,13 @@ static int isula_image_server_load_first_check(const struct server_monitor_conf
if (ret == 0) {
break;
}
- retry_cnt++;
- if (retry_cnt > RETRY_COUNT_MAX) {
+ if (is_timeout(opt_timeout, retry_cnt)) {
// don't post sem to main thread
ERROR("First load image server failed");
ret = -1;
goto out;
}
+ retry_cnt++;
}
/* 1. If health check success, send a mutex to main thread and make it run again;
diff --git a/src/json/schema/schema/container/exec-request.json b/src/json/schema/schema/container/exec-request.json
index 233c6f0..1482b55 100644
--- a/src/json/schema/schema/container/exec-request.json
+++ b/src/json/schema/schema/container/exec-request.json
@@ -5,6 +5,9 @@
"container_id": {
"type": "string"
},
+ "suffix": {
+ "type": "string"
+ },
"tty": {
"type": "boolean"
},
diff --git a/src/liblcrc.c b/src/liblcrc.c
index 12ec385..9c32de7 100644
--- a/src/liblcrc.c
+++ b/src/liblcrc.c
@@ -648,6 +648,9 @@ void lcrc_exec_request_free(struct lcrc_exec_request *request)
free(request->name);
request->name = NULL;
+ free(request->suffix);
+ request->suffix = NULL;
+
free(request->stdout);
request->stdout = NULL;
@@ -778,38 +781,6 @@ void lcrc_resume_response_free(struct lcrc_resume_response *response)
free(response);
}
-/* lcrc container conf request free */
-void lcrc_container_conf_request_free(struct lcrc_container_conf_request *req)
-{
- if (req == NULL) {
- return;
- }
-
- free(req->name);
- req->name = NULL;
-
- free(req);
-}
-
-/* lcrc container conf response free */
-void lcrc_container_conf_response_free(struct lcrc_container_conf_response *resp)
-{
- if (resp == NULL) {
- return;
- }
-
- free(resp->errmsg);
- resp->errmsg = NULL;
-
- free(resp->container_logpath);
- resp->container_logpath = NULL;
-
- free(resp->container_logsize);
- resp->container_logsize = NULL;
-
- free(resp);
-}
-
/* lcrc kill request free */
void lcrc_kill_request_free(struct lcrc_kill_request *request)
{
@@ -882,12 +853,20 @@ void lcrc_update_response_free(struct lcrc_update_response *response)
/* lcrc stats request free */
void lcrc_stats_request_free(struct lcrc_stats_request *request)
{
+ size_t i = 0;
+
if (request == NULL) {
return;
}
- free(request->runtime);
- request->runtime = NULL;
+ for (i = 0; i < request->containers_len; i++) {
+ free(request->containers[i]);
+ request->containers[i] = NULL;
+ }
+
+ free(request->containers);
+ request->containers = NULL;
+
free(request);
}
@@ -902,8 +881,8 @@ void lcrc_stats_response_free(struct lcrc_stats_response *response)
response->errmsg = NULL;
if (response->container_stats != NULL && response->container_num) {
- int i;
- for (i = 0; i < (int)response->container_num; i++) {
+ size_t i;
+ for (i = 0; i < response->container_num; i++) {
free(response->container_stats[i].id);
response->container_stats[i].id = NULL;
}
@@ -1348,6 +1327,36 @@ void lcrc_rename_response_free(struct lcrc_rename_response *response)
free(response);
}
+/* lcrc resize request free */
+void lcrc_resize_request_free(struct lcrc_resize_request *request)
+{
+ if (request == NULL) {
+ return;
+ }
+
+ free(request->id);
+ request->id = NULL;
+
+ free(request->suffix);
+ request->suffix = NULL;
+
+ free(request);
+}
+
+/* lcrc resize response free */
+void lcrc_resize_response_free(struct lcrc_resize_response *response)
+{
+ if (response == NULL) {
+ return;
+ }
+
+ free(response->errmsg);
+ response->errmsg = NULL;
+
+ free(response);
+}
+
+
/* lcrc logs request free */
void lcrc_logs_request_free(struct lcrc_logs_request *request)
{
diff --git a/src/liblcrc.h b/src/liblcrc.h
index 2b4dbf6..423f7fc 100644
--- a/src/liblcrc.h
+++ b/src/liblcrc.h
@@ -296,9 +296,6 @@ struct lcrc_resume_response {
struct lcrc_container_info {
char *id;
- bool has_pid;
- uint32_t pid;
- Container_Status status;
uint64_t pids_current;
// CPU usage
uint64_t cpu_use_nanos;
@@ -359,7 +356,6 @@ struct lcrc_list_response {
};
struct lcrc_stats_request {
- char *runtime;
char **containers;
size_t containers_len;
bool all;
@@ -449,6 +445,7 @@ struct lcrc_wait_response {
struct lcrc_exec_request {
char *name;
+ char *suffix;
bool tty;
bool open_stdin;
bool attach_stdin;
@@ -542,19 +539,6 @@ struct lcrc_info_response {
char *errmsg;
};
-struct lcrc_container_conf_request {
- char *name;
-};
-
-struct lcrc_container_conf_response {
- uint32_t cc;
- uint32_t server_errono;
- char *container_logpath;
- uint32_t container_logrotate;
- char *container_logsize;
- char *errmsg;
-};
-
typedef struct lcrc_update_config {
char *restart_policy;
container_cgroup_resources_t *cr;
@@ -688,6 +672,19 @@ struct lcrc_rename_response {
char *errmsg;
};
+struct lcrc_resize_request {
+ char *id;
+ char *suffix;
+ uint32_t height;
+ uint32_t width;
+};
+
+struct lcrc_resize_response {
+ uint32_t cc;
+ uint32_t server_errono;
+ char *errmsg;
+};
+
Container_Status lcrcstastr2sta(const char *state);
struct lcrc_filters *lcrc_filters_parse_args(const char **array, size_t len);
@@ -758,10 +755,6 @@ void lcrc_resume_request_free(struct lcrc_resume_request *request);
void lcrc_resume_response_free(struct lcrc_resume_response *response);
-void lcrc_container_conf_request_free(struct lcrc_container_conf_request *req);
-
-void lcrc_container_conf_response_free(struct lcrc_container_conf_response *resp);
-
void lcrc_kill_request_free(struct lcrc_kill_request *request);
void lcrc_kill_response_free(struct lcrc_kill_response *response);
@@ -833,6 +826,10 @@ void lcrc_rename_request_free(struct lcrc_rename_request *request);
void lcrc_rename_response_free(struct lcrc_rename_response *response);
+void lcrc_resize_request_free(struct lcrc_resize_request *request);
+
+void lcrc_resize_response_free(struct lcrc_resize_response *response);
+
void lcrc_logs_request_free(struct lcrc_logs_request *request);
void lcrc_logs_response_free(struct lcrc_logs_response *response);
diff --git a/src/liblcrd.c b/src/liblcrd.c
index 83aa7f6..2fdb820 100644
--- a/src/liblcrd.c
+++ b/src/liblcrd.c
@@ -26,36 +26,6 @@
// record the errno
__thread char *g_lcrd_errmsg = NULL;
-/* lcrd container conf request free */
-void lcrd_container_conf_request_free(struct lcrd_container_conf_request *request)
-{
- if (request == NULL) {
- return;
- }
- free(request->name);
- request->name = NULL;
-
- free(request);
-}
-
-/* lcrd container conf response free */
-void lcrd_container_conf_response_free(struct lcrd_container_conf_response *response)
-{
- if (response == NULL) {
- return;
- }
- free(response->errmsg);
- response->errmsg = NULL;
-
- free(response->container_logpath);
- response->container_logpath = NULL;
-
- free(response->container_logsize);
- response->container_logsize = NULL;
-
- free(response);
-}
-
/* lcrd events request free */
void lcrd_events_request_free(struct lcrd_events_request *request)
{
@@ -193,6 +163,38 @@ void lcrd_container_rename_response_free(struct lcrd_container_rename_response *
free(response);
}
+/* lcrd container rename request free */
+void lcrd_container_resize_request_free(struct lcrd_container_resize_request *request)
+{
+ if (request == NULL) {
+ return;
+ }
+
+ free(request->id);
+ request->id = NULL;
+
+ free(request->suffix);
+ request->suffix = NULL;
+
+ free(request);
+}
+
+/* lcrd container rename response free */
+void lcrd_container_resize_response_free(struct lcrd_container_resize_response *response)
+{
+ if (response == NULL) {
+ return;
+ }
+
+ free(response->id);
+ response->id = NULL;
+ free(response->errmsg);
+ response->errmsg = NULL;
+
+ free(response);
+}
+
+
void lcrd_logs_request_free(struct lcrd_logs_request *request)
{
if (request == NULL) {
diff --git a/src/liblcrd.h b/src/liblcrd.h
index 7b47532..9e31e5f 100644
--- a/src/liblcrd.h
+++ b/src/liblcrd.h
@@ -243,19 +243,6 @@ struct lcrd_health_check_response {
char *errmsg;
};
-struct lcrd_container_conf_request {
- char *name;
-};
-
-struct lcrd_container_conf_response {
- uint32_t cc;
- uint32_t server_errono;
- char *container_logpath;
- uint32_t container_logrotate;
- char *container_logsize;
- char *errmsg;
-};
-
struct lcrd_container_rename_request {
char *old_name;
char *new_name;
@@ -267,6 +254,19 @@ struct lcrd_container_rename_response {
char *errmsg;
};
+struct lcrd_container_resize_request {
+ char *id;
+ char *suffix;
+ uint32_t height;
+ uint32_t width;
+};
+
+struct lcrd_container_resize_response {
+ char *id;
+ uint32_t cc;
+ char *errmsg;
+};
+
struct lcrd_image_info {
char *imageref;
@@ -295,10 +295,6 @@ struct container_log_config {
};
void container_log_config_free(struct container_log_config *conf);
-void lcrd_container_conf_request_free(struct lcrd_container_conf_request *request);
-
-void lcrd_container_conf_response_free(struct lcrd_container_conf_response *response);
-
void lcrd_events_request_free(struct lcrd_events_request *request);
void lcrd_copy_from_container_request_free(struct lcrd_copy_from_container_request *request);
@@ -315,6 +311,10 @@ void lcrd_container_rename_request_free(struct lcrd_container_rename_request *re
void lcrd_container_rename_response_free(struct lcrd_container_rename_response *response);
+void lcrd_container_resize_request_free(struct lcrd_container_resize_request *request);
+
+void lcrd_container_resize_response_free(struct lcrd_container_resize_response *response);
+
void lcrd_logs_request_free(struct lcrd_logs_request *request);
void lcrd_logs_response_free(struct lcrd_logs_response *response);
#ifdef __cplusplus
diff --git a/src/runtime/lcr/lcr_rt_ops.c b/src/runtime/lcr/lcr_rt_ops.c
index dee1d41..e66a8ae 100644
--- a/src/runtime/lcr/lcr_rt_ops.c
+++ b/src/runtime/lcr/lcr_rt_ops.c
@@ -62,12 +62,14 @@ int rt_lcr_create(const char *name, const char *runtime, const rt_create_params_
lcrd_set_error_message("Create container error: %s",
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
: DEF_ERR_RUNTIME_STR);
- engine_ops->engine_clear_errmsg_op();
ret = -1;
goto out;
}
out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
free(runtime_root);
return ret;
}
@@ -138,7 +140,6 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t
: DEF_ERR_RUNTIME_STR);
ERROR("Start container error: %s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
: DEF_ERR_RUNTIME_STR);
- engine_ops->engine_clear_errmsg_op();
ret = -1;
goto out;
}
@@ -149,6 +150,9 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t
goto out;
}
out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
return ret;
}
@@ -247,38 +251,8 @@ out:
return ret;
}
-int rt_lcr_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params)
-{
- int ret = 0;
- struct engine_operation *engine_ops = NULL;
-
- engine_ops = engines_get_handler(runtime);
- if (engine_ops == NULL || (engine_ops->engine_get_console_config_op) == NULL) {
- ERROR("Failed to get engine get_console_config operation");
- ret = -1;
- goto out;
- }
-
- if (!engine_ops->engine_get_console_config_op(name, params->rootpath, params->config)) {
- ERROR("Failed to get console config");
- const char *tmpmsg = NULL;
- tmpmsg = engine_ops->engine_get_errmsg_op();
- lcrd_set_error_message("Get console config error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
- tmpmsg : DEF_ERR_RUNTIME_STR);
- ret = -1;
- goto out;
- }
-
-
-out:
- if (engine_ops != NULL) {
- engine_ops->engine_clear_errmsg_op();
- }
- return ret;
-}
-
int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params,
- struct engine_container_info *status)
+ struct engine_container_status_info *status)
{
int ret = 0;
int nret = 0;
@@ -299,9 +273,39 @@ int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_
}
out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
return ret;
}
+int rt_lcr_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
+ struct engine_container_resources_stats_info *rs_stats)
+{
+ int ret = 0;
+ int nret = 0;
+ struct engine_operation *engine_ops = NULL;
+
+ engine_ops = engines_get_handler(runtime);
+ if (engine_ops == NULL || engine_ops->engine_get_container_resources_stats_op == NULL) {
+ ERROR("Failed to get engine stats operations");
+ ret = -1;
+ goto out;
+ }
+
+ nret = engine_ops->engine_get_container_resources_stats_op(name, params->rootpath, rs_stats);
+ if (nret != 0) {
+ engine_ops->engine_clear_errmsg_op();
+ ret = -1;
+ goto out;
+ }
+
+out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
+ return ret;
+}
int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *params, int *exit_code)
{
int ret = 0;
@@ -326,6 +330,7 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par
request.console_fifos = params->console_fifos;
request.timeout = params->timeout;
request.user = params->user;
+ request.suffix = params->suffix;
if (!engine_ops->engine_exec_op(&request, exit_code)) {
const char *tmpmsg = NULL;
@@ -339,6 +344,9 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par
}
out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
return ret;
}
@@ -360,11 +368,13 @@ int rt_lcr_pause(const char *name, const char *runtime, const rt_pause_params_t
tmpmsg = engine_ops->engine_get_errmsg_op();
lcrd_set_error_message("Pause container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
tmpmsg : DEF_ERR_RUNTIME_STR);
- engine_ops->engine_clear_errmsg_op();
ret = -1;
goto out;
}
out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
return ret;
}
@@ -387,11 +397,177 @@ int rt_lcr_resume(const char *name, const char *runtime, const rt_resume_params_
lcrd_set_error_message("Resume container error;%s",
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
: DEF_ERR_RUNTIME_STR);
-
- engine_ops->engine_clear_errmsg_op();
ret = -1;
goto out;
}
out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
+ return ret;
+}
+
+int rt_lcr_attach(const char *name, const char *runtime, const rt_attach_params_t *params)
+{
+ int ret = 0;
+ struct engine_operation *engine_ops = NULL;
+
+ engine_ops = engines_get_handler(runtime);
+ if (engine_ops == NULL || engine_ops->engine_console_op == NULL) {
+ DEBUG("Failed to get engine attach operations");
+ ret = -1;
+ goto out;
+ }
+
+ if (!engine_ops->engine_console_op(name, params->rootpath, (char *)params->stdin, (char *)params->stdout,
+ (char *)params->stderr)) {
+ ERROR("attach failed");
+ const char *tmpmsg = NULL;
+ tmpmsg = engine_ops->engine_get_errmsg_op();
+ lcrd_set_error_message("Attach container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
+ tmpmsg : DEF_ERR_RUNTIME_STR);
+ ret = -1;
+ goto out;
+ }
+out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
+ return ret;
+}
+
+static void to_engine_resources(const host_config *hostconfig, struct engine_cgroup_resources *cr)
+{
+ if (hostconfig == NULL || cr == NULL) {
+ return;
+ }
+
+ cr->blkio_weight = hostconfig->blkio_weight;
+ cr->cpu_shares = (uint64_t)hostconfig->cpu_shares;
+ cr->cpu_period = (uint64_t)hostconfig->cpu_period;
+ cr->cpu_quota = (uint64_t)hostconfig->cpu_quota;
+ cr->cpuset_cpus = hostconfig->cpuset_cpus;
+ cr->cpuset_mems = hostconfig->cpuset_mems;
+ cr->memory_limit = (uint64_t)hostconfig->memory;
+ cr->memory_swap = (uint64_t)hostconfig->memory_swap;
+ cr->memory_reservation = (uint64_t)hostconfig->memory_reservation;
+ cr->kernel_memory_limit = (uint64_t)hostconfig->kernel_memory;
+}
+
+int rt_lcr_update(const char *id, const char *runtime, const rt_update_params_t *params)
+{
+ int ret = 0;
+ struct engine_operation *engine_ops = NULL;
+ struct engine_cgroup_resources cr = { 0 };
+
+ engine_ops = engines_get_handler(runtime);
+ if (engine_ops == NULL || engine_ops->engine_update_op == NULL) {
+ DEBUG("Failed to get engine update operations");
+ ret = -1;
+ goto out;
+ }
+
+ to_engine_resources(params->hostconfig, &cr);
+
+ if (!engine_ops->engine_update_op(id, params->rootpath, &cr)) {
+ DEBUG("Update container %s failed", id);
+ const char *tmpmsg = NULL;
+ tmpmsg = engine_ops->engine_get_errmsg_op();
+ lcrd_set_error_message("Cannot update container %s: %s", id, (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
+ tmpmsg : DEF_ERR_RUNTIME_STR);
+ ret = -1;
+ goto out;
+ }
+out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
+ return ret;
+}
+
+int rt_lcr_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out)
+{
+ int ret = 0;
+ struct engine_operation *engine_ops = NULL;
+
+ engine_ops = engines_get_handler(runtime);
+ if (engine_ops == NULL || engine_ops->engine_get_container_pids_op == NULL) {
+ DEBUG("Failed to get engine top operations");
+ ret = -1;
+ goto out;
+ }
+
+ if (!engine_ops->engine_get_container_pids_op(name, params->rootpath, &(out->pids), &(out->pids_len))) {
+ DEBUG("Top container %s failed", name);
+ const char *tmpmsg = NULL;
+ tmpmsg = engine_ops->engine_get_errmsg_op();
+ lcrd_set_error_message("Runtime top container error: %s",
+ (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR);
+ ret = -1;
+ goto out;
+ }
+out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
+ return ret;
+}
+
+int rt_lcr_resize(const char *id, const char *runtime, const rt_resize_params_t *params)
+{
+ int ret = 0;
+ struct engine_operation *engine_ops = NULL;
+
+ engine_ops = engines_get_handler(runtime);
+ if (engine_ops == NULL || engine_ops->engine_resize_op == NULL) {
+ DEBUG("Failed to get engine resume operations");
+ ret = -1;
+ goto out;
+ }
+
+ if (!engine_ops->engine_resize_op(id, params->rootpath, params->height, params->width)) {
+ DEBUG("resize container %s failed", id);
+ const char *tmpmsg = NULL;
+ tmpmsg = engine_ops->engine_get_errmsg_op();
+ lcrd_set_error_message("Resize container error;%s",
+ (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
+ : DEF_ERR_RUNTIME_STR);
+
+ ret = -1;
+ goto out;
+ }
+out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
+ return ret;
+}
+
+int rt_lcr_exec_resize(const char *id, const char *runtime, const rt_exec_resize_params_t *params)
+{
+ int ret = 0;
+ struct engine_operation *engine_ops = NULL;
+
+ engine_ops = engines_get_handler(runtime);
+ if (engine_ops == NULL || engine_ops->engine_resize_op == NULL) {
+ DEBUG("Failed to get engine resume operations");
+ ret = -1;
+ goto out;
+ }
+
+ if (!engine_ops->engine_exec_resize_op(id, params->rootpath, params->suffix, params->height, params->width)) {
+ DEBUG("exec resize container %s failed", id);
+ const char *tmpmsg = NULL;
+ tmpmsg = engine_ops->engine_get_errmsg_op();
+ lcrd_set_error_message("Resize container error;%s",
+ (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
+ : DEF_ERR_RUNTIME_STR);
+ ret = -1;
+ goto out;
+ }
+out:
+ if (engine_ops != NULL) {
+ engine_ops->engine_clear_errmsg_op();
+ }
return ret;
}
diff --git a/src/runtime/lcr/lcr_rt_ops.h b/src/runtime/lcr/lcr_rt_ops.h
index a75f8d5..4cf29ef 100644
--- a/src/runtime/lcr/lcr_rt_ops.h
+++ b/src/runtime/lcr/lcr_rt_ops.h
@@ -28,13 +28,21 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t
int rt_lcr_restart(const char *name, const char *runtime, const rt_restart_params_t *params);
int rt_lcr_clean_resource(const char *name, const char *runtime, const rt_clean_params_t *params);
int rt_lcr_rm(const char *name, const char *runtime, const rt_rm_params_t *params);
-int rt_lcr_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params);
int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params,
- struct engine_container_info *status);
+ struct engine_container_status_info *status);
int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *params, int *exit_code);
int rt_lcr_pause(const char *name, const char *runtime, const rt_pause_params_t *params);
int rt_lcr_resume(const char *name, const char *runtime, const rt_resume_params_t *params);
+int rt_lcr_attach(const char *name, const char *runtime, const rt_attach_params_t *params);
+
+int rt_lcr_update(const char *id, const char *runtime, const rt_update_params_t *params);
+
+int rt_lcr_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out);
+int rt_lcr_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
+ struct engine_container_resources_stats_info *rs_stats);
+int rt_lcr_resize(const char *id, const char *runtime, const rt_resize_params_t *params);
+int rt_lcr_exec_resize(const char *id, const char *runtime, const rt_exec_resize_params_t *params);
#ifdef __cplusplus
}
#endif
diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c
index acea344..e9906de 100644
--- a/src/runtime/runtime.c
+++ b/src/runtime/runtime.c
@@ -33,11 +33,16 @@ static const struct rt_ops g_lcr_rt_ops = {
.rt_restart = rt_lcr_restart,
.rt_clean_resource = rt_lcr_clean_resource,
.rt_rm = rt_lcr_rm,
- .rt_get_console_config = rt_lcr_get_console_config,
.rt_status = rt_lcr_status,
.rt_exec = rt_lcr_exec,
.rt_pause = rt_lcr_pause,
.rt_resume = rt_lcr_resume,
+ .rt_attach = rt_lcr_attach,
+ .rt_update = rt_lcr_update,
+ .rt_listpids = rt_lcr_listpids,
+ .rt_resources_stats = rt_lcr_resources_stats,
+ .rt_resize = rt_lcr_resize,
+ .rt_exec_resize = rt_lcr_exec_resize,
};
static const struct rt_ops *g_rt_ops[] = {
@@ -184,38 +189,14 @@ out:
return ret;
}
-int runtime_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params)
-{
- int ret = 0;
- const struct rt_ops *ops = NULL;
-
- if (name == NULL || runtime == NULL) {
- ERROR("Invalide arguments for runtime get console config");
- ret = -1;
- goto out;
- }
-
- ops = rt_ops_query(runtime);
- if (ops == NULL) {
- ERROR("Failed to get runtime ops");
- ret = -1;
- goto out;
- }
-
- ret = ops->rt_get_console_config(name, runtime, params);
-
-out:
- return ret;
-}
-
int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params,
- struct engine_container_info *status)
+ struct engine_container_status_info *status)
{
int ret = 0;
const struct rt_ops *ops = NULL;
if (name == NULL || runtime == NULL || status == NULL) {
- ERROR("Invalide arguments for runtime start");
+ ERROR("Invalide arguments for runtime status");
ret = -1;
goto out;
}
@@ -233,6 +214,31 @@ out:
return ret;
}
+int runtime_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
+ struct engine_container_resources_stats_info *rs_stats)
+{
+ int ret = 0;
+ const struct rt_ops *ops = NULL;
+
+ if (name == NULL || runtime == NULL || rs_stats == NULL) {
+ ERROR("Invalide arguments for runtime stats");
+ ret = -1;
+ goto out;
+ }
+
+ ops = rt_ops_query(runtime);
+ if (ops == NULL) {
+ ERROR("Failed to get runtime ops");
+ ret = -1;
+ goto out;
+ }
+
+ ret = ops->rt_resources_stats(name, runtime, params, rs_stats);
+
+out:
+ return ret;
+}
+
int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *params,
int *exit_code)
{
@@ -305,3 +311,134 @@ int runtime_resume(const char *name, const char *runtime, const rt_resume_params
out:
return ret;
}
+
+int runtime_attach(const char *name, const char *runtime, const rt_attach_params_t *params)
+{
+ int ret = 0;
+ const struct rt_ops *ops = NULL;
+
+ if (name == NULL || runtime == NULL || params == NULL) {
+ ERROR("Invalide arguments for runtime attach");
+ ret = -1;
+ goto out;
+ }
+
+ ops = rt_ops_query(runtime);
+ if (ops == NULL) {
+ ERROR("Failed to get runtime ops");
+ ret = -1;
+ goto out;
+ }
+
+ ret = ops->rt_attach(name, runtime, params);
+
+out:
+ return ret;
+}
+
+int runtime_update(const char *name, const char *runtime, const rt_update_params_t *params)
+{
+ int ret = 0;
+ const struct rt_ops *ops = NULL;
+
+ if (name == NULL || runtime == NULL || params == NULL) {
+ ERROR("Invalide arguments for runtime update");
+ ret = -1;
+ goto out;
+ }
+
+ ops = rt_ops_query(runtime);
+ if (ops == NULL) {
+ ERROR("Failed to get runtime ops");
+ ret = -1;
+ goto out;
+ }
+
+ ret = ops->rt_update(name, runtime, params);
+
+out:
+ return ret;
+}
+
+void free_rt_listpids_out_t(rt_listpids_out_t *out)
+{
+ if (out == NULL) {
+ return;
+ }
+
+ free(out->pids);
+ out->pids = NULL;
+ free(out);
+}
+
+int runtime_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out)
+{
+ int ret = 0;
+ const struct rt_ops *ops = NULL;
+
+ if (name == NULL || runtime == NULL || params == NULL || out == NULL) {
+ ERROR("Invalide arguments for runtime listpids");
+ ret = -1;
+ goto out;
+ }
+
+ ops = rt_ops_query(runtime);
+ if (ops == NULL) {
+ ERROR("Failed to get runtime ops");
+ ret = -1;
+ goto out;
+ }
+
+ ret = ops->rt_listpids(name, runtime, params, out);
+
+out:
+ return ret;
+}
+
+int runtime_resize(const char *name, const char *runtime, const rt_resize_params_t *params)
+{
+ int ret = 0;
+ const struct rt_ops *ops = NULL;
+
+ if (name == NULL || runtime == NULL || params == NULL) {
+ ERROR("Invalide arguments for runtime resize");
+ ret = -1;
+ goto out;
+ }
+
+ ops = rt_ops_query(runtime);
+ if (ops == NULL) {
+ ERROR("Failed to get runtime ops");
+ ret = -1;
+ goto out;
+ }
+
+ ret = ops->rt_resize(name, runtime, params);
+
+out:
+ return ret;
+}
+
+int runtime_exec_resize(const char *name, const char *runtime, const rt_exec_resize_params_t *params)
+{
+ int ret = 0;
+ const struct rt_ops *ops = NULL;
+
+ if (name == NULL || runtime == NULL || params == NULL) {
+ ERROR("Invalide arguments for runtime exec resize");
+ ret = -1;
+ goto out;
+ }
+
+ ops = rt_ops_query(runtime);
+ if (ops == NULL) {
+ ERROR("Failed to get runtime ops");
+ ret = -1;
+ goto out;
+ }
+
+ ret = ops->rt_exec_resize(name, runtime, params);
+
+out:
+ return ret;
+}
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index a63e1aa..5eb0a81 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -73,15 +73,14 @@ typedef struct _rt_rm_params_t {
const char *rootpath;
} rt_rm_params_t;
-typedef struct _rt_get_console_conf_params_t {
- const char *rootpath;
- struct engine_console_config *config;
-} rt_get_console_conf_params_t;
-
typedef struct _rt_status_params_t {
const char *rootpath;
} rt_status_params_t;
+typedef struct _rt_stats_params_t {
+ const char *rootpath;
+} rt_stats_params_t;
+
typedef struct _rt_exec_params_t {
const char *rootpath;
const char *logpath;
@@ -93,6 +92,7 @@ typedef struct _rt_exec_params_t {
size_t args_len;
const char * const *envs;
size_t envs_len;
+ const char *suffix;
} rt_exec_params_t;
typedef struct _rt_pause_params_t {
@@ -103,6 +103,40 @@ typedef struct _rt_resume_params_t {
const char *rootpath;
} rt_resume_params_t;
+typedef struct _rt_attach_params_t {
+ const char *rootpath;
+ const char *stdin;
+ const char *stdout;
+ const char *stderr;
+} rt_attach_params_t;
+
+typedef struct _rt_update_params_t {
+ const char *rootpath;
+ const host_config *hostconfig;
+} rt_update_params_t;
+
+typedef struct _rt_listpids_params_t {
+ const char *rootpath;
+} rt_listpids_params_t;
+
+typedef struct _rt_listpids_out_t {
+ pid_t *pids;
+ size_t pids_len;
+} rt_listpids_out_t;
+
+typedef struct _rt_resize_params_t {
+ const char *rootpath;
+ unsigned int height;
+ unsigned int width;
+} rt_resize_params_t;
+
+typedef struct _rt_exec_resize_params_t {
+ const char *rootpath;
+ const char *suffix;
+ unsigned int height;
+ unsigned int width;
+} rt_exec_resize_params_t;
+
struct rt_ops {
/* detect whether runtime is of this runtime type */
bool (*detect)(const char *runtime);
@@ -118,16 +152,26 @@ struct rt_ops {
int (*rt_rm)(const char *name, const char *runtime, const rt_rm_params_t *params);
- int (*rt_get_console_config)(const char *name, const char *runtime, const rt_get_console_conf_params_t *params);
-
int (*rt_status)(const char *name, const char *runtime, const rt_status_params_t *params,
- struct engine_container_info *status);
+ struct engine_container_status_info *status);
+
+ int (*rt_resources_stats)(const char *name, const char *runtime, const rt_stats_params_t *params,
+ struct engine_container_resources_stats_info *rs_stats);
int (*rt_exec)(const char *name, const char *runtime, const rt_exec_params_t *params,
int *exit_code);
int (*rt_pause)(const char *name, const char *runtime, const rt_pause_params_t *params);
int (*rt_resume)(const char *name, const char *runtime, const rt_resume_params_t *params);
+
+ int (*rt_attach)(const char *name, const char *runtime, const rt_attach_params_t *params);
+
+ int (*rt_update)(const char *name, const char *runtime, const rt_update_params_t *params);
+
+ int (*rt_listpids)(const char *name, const char *runtime, const rt_listpids_params_t *params,
+ rt_listpids_out_t *out);
+ int (*rt_resize)(const char *name, const char *runtime, const rt_resize_params_t *params);
+ int (*rt_exec_resize)(const char *name, const char *runtime, const rt_exec_resize_params_t *params);
};
int runtime_create(const char *name, const char *runtime, const rt_create_params_t *params);
@@ -135,14 +179,22 @@ int runtime_clean_resource(const char *name, const char *runtime, const rt_clean
int runtime_start(const char *name, const char *runtime, const rt_start_params_t *params, container_pid_t *pid_info);
int runtime_restart(const char *name, const char *runtime, const rt_restart_params_t *params);
int runtime_rm(const char *name, const char *runtime, const rt_rm_params_t *params);
-int runtime_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params);
int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params,
- struct engine_container_info *status);
+ struct engine_container_status_info *status);
+int runtime_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
+ struct engine_container_resources_stats_info *rs_stats);
int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *params,
int *exit_code);
int runtime_pause(const char *name, const char *runtime, const rt_pause_params_t *params);
int runtime_resume(const char *name, const char *runtime, const rt_resume_params_t *params);
+int runtime_attach(const char *name, const char *runtime, const rt_attach_params_t *params);
+int runtime_update(const char *name, const char *runtime, const rt_update_params_t *params);
+
+int runtime_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out);
+void free_rt_listpids_out_t(rt_listpids_out_t *out);
+int runtime_resize(const char *name, const char *runtime, const rt_resize_params_t *params);
+int runtime_exec_resize(const char *name, const char *runtime, const rt_exec_resize_params_t *params);
#ifdef __cplusplus
}
#endif
diff --git a/src/services/callback.h b/src/services/callback.h
index 350a2d1..129ecba 100644
--- a/src/services/callback.h
+++ b/src/services/callback.h
@@ -123,8 +123,6 @@ typedef struct {
int(*inspect)(const container_inspect_request *request, container_inspect_response **response);
- int(*conf)(const struct lcrd_container_conf_request *request, struct lcrd_container_conf_response **response);
-
int(*wait)(const container_wait_request *request, container_wait_response **response);
int(*events)(const struct lcrd_events_request *request, const stream_func_wrapper *stream);
@@ -140,6 +138,8 @@ typedef struct {
int(*logs)(const struct lcrd_logs_request *request,
stream_func_wrapper *stream, struct lcrd_logs_response **response);
+
+ int(*resize)(const struct lcrd_container_resize_request *request, struct lcrd_container_resize_response **response);
} service_container_callback_t;
typedef struct {
diff --git a/src/services/cri/cri_container.cc b/src/services/cri/cri_container.cc
index 73b2fea..3f6cc22 100644
--- a/src/services/cri/cri_container.cc
+++ b/src/services/cri/cri_container.cc
@@ -811,14 +811,74 @@ cleanup:
free_container_list_response(response);
}
+void CRIRuntimeServiceImpl::PackContainerStatsAttributes(
+ const char *id,
+ std::unique_ptr &container,
+ Errors &error)
+{
+ if (id == nullptr) {
+ return;
+ }
+
+ container->mutable_attributes()->set_id(id);
+ auto status = ContainerStatus(std::string(id), error);
+ if (status->has_metadata()) {
+ std::unique_ptr metadata(
+ new (std::nothrow) runtime::v1alpha2::ContainerMetadata(status->metadata()));
+ if (metadata == nullptr) {
+ error.SetError("Out of memory");
+ ERROR("Out of memory");
+ return;
+ }
+ container->mutable_attributes()->set_allocated_metadata(metadata.release());
+ }
+ if (status->labels_size() > 0) {
+ auto labels = container->mutable_attributes()->mutable_labels();
+ *labels = status->labels();
+ }
+ if (status->annotations_size() > 0) {
+ auto annotations = container->mutable_attributes()->mutable_annotations();
+ *annotations = status->annotations();
+ }
+}
+
+void CRIRuntimeServiceImpl::PackContainerStatsFilesystemUsage(
+ const char *id, const char *image_type,
+ std::unique_ptr &container,
+ Errors &error)
+{
+ if (id == nullptr || image_type == nullptr) {
+ return;
+ }
+
+ imagetool_fs_info *fs_usage { nullptr };
+ if (im_get_container_filesystem_usage(image_type, id, &fs_usage) != 0) {
+ ERROR("Failed to get container filesystem usage");
+ }
+
+ if (fs_usage == nullptr) {
+ container->mutable_writable_layer()->mutable_used_bytes()->set_value(0);
+ container->mutable_writable_layer()->mutable_inodes_used()->set_value(0);
+ } else {
+ if (fs_usage->image_filesystems[0]->used_bytes->value) {
+ container->mutable_writable_layer()->mutable_used_bytes()->set_value(
+ fs_usage->image_filesystems[0]->used_bytes->value);
+ }
+
+ if (fs_usage->image_filesystems[0]->inodes_used->value) {
+ container->mutable_writable_layer()->mutable_inodes_used()->set_value(
+ fs_usage->image_filesystems[0]->inodes_used->value);
+ }
+ }
+
+ free_imagetool_fs_info(fs_usage);
+}
+
void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
container_stats_response *response,
std::vector> *containerstats, Errors &error)
{
- int ret {};
-
for (size_t i {}; i < response->container_stats_len; i++) {
- imagetool_fs_info *fs_usage { nullptr };
using ContainerStatsPtr = std::unique_ptr;
ContainerStatsPtr container(new (std::nothrow) runtime::v1alpha2::ContainerStats);
if (container == nullptr) {
@@ -826,14 +886,12 @@ void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
return;
}
- if (response->container_stats[i]->id != nullptr && response->container_stats[i]->image_type != nullptr) {
- container->mutable_attributes()->set_id(response->container_stats[i]->id);
- ret = im_get_container_filesystem_usage(response->container_stats[i]->image_type,
- response->container_stats[i]->id, &fs_usage);
- if (ret != 0) {
- ERROR("Failed to get container filesystem usage");
- }
+ PackContainerStatsAttributes(response->container_stats[i]->id, container, error);
+ if (error.NotEmpty()) {
+ return;
}
+ PackContainerStatsFilesystemUsage(response->container_stats[i]->id,
+ response->container_stats[i]->image_type, container, error);
if (response->container_stats[i]->mem_used) {
container->mutable_memory()->mutable_working_set_bytes()->set_value(response->container_stats[i]->mem_used);
@@ -845,23 +903,7 @@ void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
container->mutable_cpu()->set_timestamp((int64_t)(response->container_stats[i]->cpu_system_use));
}
- if (fs_usage == nullptr) {
- container->mutable_writable_layer()->mutable_used_bytes()->set_value(0);
- container->mutable_writable_layer()->mutable_inodes_used()->set_value(0);
- }
- if (fs_usage != nullptr) {
- if (fs_usage->image_filesystems[0]->used_bytes->value) {
- container->mutable_writable_layer()->mutable_used_bytes()->set_value(
- fs_usage->image_filesystems[0]->used_bytes->value);
- }
-
- if (fs_usage->image_filesystems[0]->inodes_used->value) {
- container->mutable_writable_layer()->mutable_inodes_used()->set_value(
- fs_usage->image_filesystems[0]->inodes_used->value);
- }
- }
containerstats->push_back(move(container));
- free_imagetool_fs_info(fs_usage);
}
}
diff --git a/src/services/cri/cri_runtime_service.h b/src/services/cri/cri_runtime_service.h
index ab00a0d..df0a8f9 100644
--- a/src/services/cri/cri_runtime_service.h
+++ b/src/services/cri/cri_runtime_service.h
@@ -143,6 +143,13 @@ private:
void ListContainersToGRPC(container_list_response *response,
std::vector> *pods, Errors &error);
+ void PackContainerStatsAttributes(const char *id, std::unique_ptr &container,
+ Errors &error);
+
+ void PackContainerStatsFilesystemUsage(const char *id, const char *image_type,
+ std::unique_ptr &container,
+ Errors &error);
+
void ContainerStatsToGRPC(container_stats_response *response,
std::vector> *pods, Errors &error);
diff --git a/src/services/cri/cri_sandbox.cc b/src/services/cri/cri_sandbox.cc
index 5c0d0eb..4cf4e2b 100644
--- a/src/services/cri/cri_sandbox.cc
+++ b/src/services/cri/cri_sandbox.cc
@@ -26,6 +26,7 @@
#include
#include
+#include "cxxutils.h"
#include "log.h"
#include "utils.h"
#include "errors.h"
@@ -275,7 +276,7 @@ void CRIRuntimeServiceImpl::SetupSandboxFiles(const std::string &resolvPath,
if (resolvPath.empty()) {
return;
}
- std::string resolvContent;
+ std::vector resolvContentStrs;
/* set DNS options */
int len = config.dns_config().searches_size();
@@ -283,26 +284,24 @@ void CRIRuntimeServiceImpl::SetupSandboxFiles(const std::string &resolvPath,
error.SetError("DNSOption.Searches has more than 6 domains");
return;
}
- resolvContent = "search ";
- int i;
- for (i = 0; i < len - 1; i++) {
- resolvContent += (config.dns_config().searches(i) + " ");
- }
- resolvContent += (config.dns_config().searches(i) + "\n");
- len = config.dns_config().servers_size();
- resolvContent += "nameserver ";
- for (i = 0; i < len - 1; i++) {
- resolvContent += (config.dns_config().servers(i) + "\nnameserver ");
- }
- resolvContent += config.dns_config().servers(i) + "\n";
- len = config.dns_config().options_size();
- resolvContent += "options ";
- for (i = 0; i < len - 1; i++) {
- resolvContent += (config.dns_config().options(i) + " ");
- }
- resolvContent += (config.dns_config().options(i) + "\n");
- if (!resolvContent.empty()) {
+ std::vector servers(config.dns_config().servers().begin(), config.dns_config().servers().end());
+ if (!servers.empty()) {
+ resolvContentStrs.push_back("nameserver " + CXXUtils::StringsJoin(servers, "\nnameserver "));
+ }
+
+ std::vector searchs(config.dns_config().searches().begin(), config.dns_config().searches().end());
+ if (!searchs.empty()) {
+ resolvContentStrs.push_back("search " + CXXUtils::StringsJoin(searchs, " "));
+ }
+
+ std::vector options(config.dns_config().options().begin(), config.dns_config().options().end());
+ if (!options.empty()) {
+ resolvContentStrs.push_back("options " + CXXUtils::StringsJoin(options, " "));
+ }
+
+ if (!resolvContentStrs.empty()) {
+ std::string resolvContent = CXXUtils::StringsJoin(resolvContentStrs, "\n") + "\n";
if (util_write_file(resolvPath.c_str(), resolvContent.c_str(), resolvContent.size()) != 0) {
error.SetError("Failed to write resolv content");
}
diff --git a/src/services/cri/cri_security_context.cc b/src/services/cri/cri_security_context.cc
index d03c383..2ac79eb 100644
--- a/src/services/cri/cri_security_context.cc
+++ b/src/services/cri/cri_security_context.cc
@@ -174,9 +174,10 @@ static void ModifyHostNetworkOptionForSandbox(const runtime::v1alpha2::Namespace
static void ModifyContainerNamespaceOptions(const runtime::v1alpha2::NamespaceOption &nsOpts,
const std::string &podSandboxID, host_config *hostConfig, Errors &error)
{
+ std::string sandboxNSMode = "container:" + podSandboxID;
if (nsOpts.pid() == runtime::v1alpha2::NamespaceMode::POD) {
free(hostConfig->pid_mode);
- hostConfig->pid_mode = util_strdup_s("");
+ hostConfig->pid_mode = util_strdup_s(sandboxNSMode.c_str());
}
/* set common Namespace options */
diff --git a/src/services/execution/execute/execution_create.c b/src/services/execution/execute/execution_create.c
index 312a41c..8cce2ad 100644
--- a/src/services/execution/execute/execution_create.c
+++ b/src/services/execution/execute/execution_create.c
@@ -212,39 +212,6 @@ error_out:
return NULL;
}
-
-static int generateID(char *id, size_t len)
-{
- int fd = -1;
- int num = 0;
- size_t i;
- const int m = 256;
-
- len = len / 2;
- fd = open("/dev/urandom", O_RDONLY);
- if (fd == -1) {
- ERROR("Failed to open /dev/urandom");
- return -1;
- }
- for (i = 0; i < len; i++) {
- int nret;
- if (read(fd, &num, sizeof(int)) < 0) {
- ERROR("Failed to read urandom value");
- close(fd);
- return -1;
- }
- unsigned char rs = (unsigned char)(num % m);
- nret = snprintf((id + i * 2), ((len - i) * 2 + 1), "%02x", (unsigned int)rs);
- if (nret >= ((len - i) * 2 + 1) || nret < 0) {
- close(fd);
- return -1;
- }
- }
- close(fd);
- id[i * 2] = '\0';
- return 0;
-}
-
static oci_runtime_spec *merge_config(const char *id, const char *image_type, const char *image_name,
const char *ext_config_image, host_config *host_spec,
container_custom_config *custom_spec,
@@ -311,7 +278,7 @@ static char *try_generate_id()
}
for (i = 0; i < max_time; i++) {
- if (generateID(id, (size_t)CONTAINER_ID_MAX_LEN)) {
+ if (util_generate_random_str(id, (size_t)CONTAINER_ID_MAX_LEN)) {
ERROR("Generate id failed");
goto err_out;
}
diff --git a/src/services/execution/execute/execution_extend.c b/src/services/execution/execute/execution_extend.c
index cb589f1..be8ea29 100644
--- a/src/services/execution/execute/execution_extend.c
+++ b/src/services/execution/execute/execution_extend.c
@@ -213,7 +213,8 @@ static int copy_map_labels(const container_config *config, map_t **map_labels)
return 0;
}
-static container_info *get_container_stats(const container_t *cont, const struct engine_container_info *einfo,
+static container_info *get_container_stats(const container_t *cont,
+ const struct engine_container_resources_stats_info *einfo,
const struct stats_context *ctx)
{
int ret = 0;
@@ -229,9 +230,6 @@ static container_info *get_container_stats(const container_t *cont, const struct
}
info->id = util_strdup_s(cont->common_config->id);
- info->has_pid = einfo->has_pid;
- info->pid = (int32_t)einfo->pid;
- info->status = (int)einfo->status;
info->pids_current = einfo->pids_current;
info->cpu_use_nanos = einfo->cpu_use_nanos;
info->blkio_read = einfo->blkio_read;
@@ -395,29 +393,12 @@ cleanup:
return ret;
}
-static int get_containers_stats(const char *runtime, char **idsarray, size_t ids_len, const struct stats_context *ctx,
+static int get_containers_stats(char **idsarray, size_t ids_len, const struct stats_context *ctx,
bool check_exists, container_info ***info, size_t *info_len)
{
int ret = 0;
int nret;
size_t i;
- char *engine_path = NULL;
- struct engine_operation *engine_ops = NULL;
-
- engine_ops = engines_get_handler(runtime);
- if (engine_ops == NULL || engine_ops->engine_get_container_status_op == NULL ||
- engine_ops->engine_free_container_status_op == NULL) {
- ERROR("Failed to get engine stats operations");
- ret = -1;
- goto cleanup;
- }
-
- engine_path = conf_get_routine_rootdir(runtime);
- if (engine_path == NULL) {
- ERROR("Get engine path failed");
- ret = -1;
- goto cleanup;
- }
nret = service_stats_make_memory(info, ids_len);
if (nret != 0) {
@@ -426,7 +407,7 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids
}
for (i = 0; i < ids_len; i++) {
- struct engine_container_info einfo = { 0 };
+ struct engine_container_resources_stats_info einfo = { 0 };
container_t *cont = NULL;
cont = containers_store_get(idsarray[i]);
@@ -440,9 +421,11 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids
continue;
}
if (is_running(cont->state)) {
- nret = engine_ops->engine_get_container_status_op(cont->common_config->id, engine_path, &einfo);
+ rt_stats_params_t params = { 0 };
+ params.rootpath = cont->root_path;
+
+ nret = runtime_resources_stats(cont->common_config->id, cont->runtime, ¶ms, &einfo);
if (nret != 0) {
- engine_ops->engine_clear_errmsg_op();
container_unref(cont);
continue;
}
@@ -455,14 +438,12 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids
(*info)[*info_len] = get_container_stats(cont, &einfo, ctx);
container_unref(cont);
- engine_ops->engine_free_container_status_op(&einfo);
if ((*info)[*info_len] == NULL) {
continue;
}
(*info_len)++;
}
cleanup:
- free(engine_path);
return ret;
}
@@ -490,12 +471,6 @@ static int container_stats_cb(const container_stats_request *request,
goto pack_response;
}
- if (request->runtime == NULL) {
- ERROR("Receive NULL Request runtime");
- cc = LCRD_ERR_INPUT;
- goto pack_response;
- }
-
ctx = fold_stats_filter(request);
if (ctx == NULL) {
cc = LCRD_ERR_EXEC;
@@ -510,7 +485,7 @@ static int container_stats_cb(const container_stats_request *request,
goto pack_response;
}
- if (get_containers_stats(request->runtime, idsarray, ids_len, ctx, check_exists, &info, &info_len)) {
+ if (get_containers_stats(idsarray, ids_len, ctx, check_exists, &info, &info_len)) {
cc = LCRD_ERR_EXEC;
goto pack_response;
}
@@ -554,6 +529,8 @@ static int resume_container(container_t *cont)
state_reset_paused(cont->state);
+ update_health_monitor(cont->common_config->id);
+
if (container_to_disk(cont)) {
ERROR("Failed to save container \"%s\" to disk", id);
ret = -1;
@@ -739,6 +716,8 @@ static int pause_container(container_t *cont)
state_set_paused(cont->state);
+ update_health_monitor(cont->common_config->id);
+
if (container_to_disk(cont)) {
ERROR("Failed to save container \"%s\" to disk", id);
ret = -1;
@@ -831,8 +810,6 @@ static int container_pause_cb(const container_pause_request *request,
EVENT("Event: {Object: %s, Type: Paused}", id);
- update_health_monitor(id);
-
pack_response:
pack_pause_response(*response, cc, id);
container_unref(cont);
@@ -840,24 +817,6 @@ pack_response:
return (cc == LCRD_SUCCESS) ? 0 : -1;
}
-static void to_engine_resources(const host_config *hostconfig, struct engine_cgroup_resources *cr)
-{
- if (hostconfig == NULL || cr == NULL) {
- return;
- }
-
- cr->blkio_weight = hostconfig->blkio_weight;
- cr->cpu_shares = (uint64_t)hostconfig->cpu_shares;
- cr->cpu_period = (uint64_t)hostconfig->cpu_period;
- cr->cpu_quota = (uint64_t)hostconfig->cpu_quota;
- cr->cpuset_cpus = hostconfig->cpuset_cpus;
- cr->cpuset_mems = hostconfig->cpuset_mems;
- cr->memory_limit = (uint64_t)hostconfig->memory;
- cr->memory_swap = (uint64_t)hostconfig->memory_swap;
- cr->memory_reservation = (uint64_t)hostconfig->memory_reservation;
- cr->kernel_memory_limit = (uint64_t)hostconfig->kernel_memory;
-}
-
static void host_config_restore_unlocking(container_t *cont, host_config *backup_hostconfig)
{
free_host_config(cont->hostconfig);
@@ -1034,32 +993,6 @@ out:
return ret;
}
-static int runtime_update(const char *id, const char *runtime, const char *rootpath, struct engine_cgroup_resources *cr)
-{
- int ret = 0;
- struct engine_operation *engine_ops = NULL;
-
- engine_ops = engines_get_handler(runtime);
- if (engine_ops == NULL || engine_ops->engine_update_op == NULL) {
- DEBUG("Failed to get engine update operations");
- ret = -1;
- goto out;
- }
-
- if (!engine_ops->engine_update_op(id, rootpath, cr)) {
- DEBUG("Update container %s failed", id);
- const char *tmpmsg = NULL;
- tmpmsg = engine_ops->engine_get_errmsg_op();
- lcrd_set_error_message("Cannot update container %s: %s", id, (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
- tmpmsg : DEF_ERR_RUNTIME_STR);
- engine_ops->engine_clear_errmsg_op();
- ret = -1;
- goto out;
- }
-out:
- return ret;
-}
-
static int do_update_resources(const container_update_request *request, container_t *cont)
{
int ret = 0;
@@ -1067,7 +1000,7 @@ static int do_update_resources(const container_update_request *request, containe
parser_error err = NULL;
host_config *hostconfig = NULL;
host_config *backup_hostconfig = NULL;
- struct engine_cgroup_resources cr = { 0 };
+ rt_update_params_t params = { 0 };
if (request->host_config == NULL) {
DEBUG("receive NULL host config");
@@ -1111,10 +1044,10 @@ static int do_update_resources(const container_update_request *request, containe
container_update_restart_manager(cont, hostconfig->restart_policy);
}
- to_engine_resources(hostconfig, &cr);
- if (runtime_update(id, cont->runtime, cont->root_path, &cr)) {
+ params.rootpath = cont->root_path;
+ params.hostconfig = hostconfig;
+ if (runtime_update(id, cont->runtime, ¶ms)) {
ERROR("Update container %s failed", id);
- host_config_restore_unlocking(cont, backup_hostconfig);
ret = -1;
goto unlock_out;
}
@@ -1291,6 +1224,179 @@ pack_response:
return (cc == LCRD_SUCCESS) ? 0 : -1;
}
+static int runtime_resize_helper(const char *id, const char *runtime, const char *rootpath, unsigned int height,
+ unsigned int width)
+{
+ int ret = 0;
+ rt_resize_params_t params = { 0 };
+
+ params.rootpath = rootpath;
+ params.height = height;
+ params.width = width;
+
+ ret = runtime_resize(id, runtime, ¶ms);
+ if (ret != 0) {
+ ERROR("Failed to resize container %s", id);
+ }
+
+ return ret;
+}
+
+static int runtime_exec_resize_helper(const char *id, const char *runtime, const char *rootpath, const char *suffix,
+ unsigned int height,
+ unsigned int width)
+{
+ int ret = 0;
+ rt_exec_resize_params_t params = { 0 };
+
+ params.rootpath = rootpath;
+ params.suffix = suffix;
+ params.height = height;
+ params.width = width;
+
+ ret = runtime_exec_resize(id, runtime, ¶ms);
+ if (ret != 0) {
+ ERROR("Failed to resize container %s", id);
+ }
+
+ return ret;
+}
+
+static int resize_container(container_t *cont, const char *suffix, unsigned int height, unsigned int width)
+{
+ int ret = 0;
+ const char *id = cont->common_config->id;
+
+ container_lock(cont);
+
+ if (!is_running(cont->state)) {
+ ERROR("Container %s is not running", id);
+ lcrd_set_error_message("Container %s is not running", id);
+ ret = -1;
+ goto out;
+ }
+
+ if (suffix != NULL) {
+ DEBUG("Failed to resize container:%s suffix:%s", id, suffix);
+ if (runtime_exec_resize_helper(id, cont->runtime, cont->root_path, suffix, height, width)) {
+ ERROR("Failed to resize container:%s", id);
+ ret = -1;
+ goto out;
+ }
+ } else {
+ if (runtime_resize_helper(id, cont->runtime, cont->root_path, height, width)) {
+ ERROR("Failed to resize container:%s", id);
+ ret = -1;
+ goto out;
+ }
+ }
+
+out:
+ container_unlock(cont);
+ return ret;
+}
+
+static void pack_resize_response(struct lcrd_container_resize_response *response, uint32_t cc, const char *id)
+{
+ if (response == NULL) {
+ return;
+ }
+ response->cc = cc;
+ if (id != NULL) {
+ response->id = util_strdup_s(id);
+ }
+ if (g_lcrd_errmsg != NULL) {
+ response->errmsg = util_strdup_s(g_lcrd_errmsg);
+ DAEMON_CLEAR_ERRMSG();
+ }
+}
+
+static int resize_request_check(const struct lcrd_container_resize_request *request)
+{
+ int ret = 0;
+
+ char *name = request->id;
+ if (name == NULL) {
+ ERROR("Resume: receive NULL id");
+ ret = -1;
+ goto out;
+ }
+
+ if (!util_valid_container_id_or_name(name)) {
+ ERROR("Invalid container name %s", name);
+ lcrd_set_error_message("Invalid container name %s", name);
+ ret = -1;
+ goto out;
+ }
+
+ if (request->suffix != NULL && !util_valid_exec_suffix(request->suffix)) {
+ ERROR("Invalid suffix name %s", name);
+ lcrd_set_error_message("Invalid suffix name %s", name);
+ ret = -1;
+ goto out;
+ }
+
+out:
+ return ret;
+}
+
+static int container_resize_cb(const struct lcrd_container_resize_request *request,
+ struct lcrd_container_resize_response **response)
+{
+ int ret = 0;
+ uint32_t cc = LCRD_SUCCESS;
+ char *name = NULL;
+ char *id = NULL;
+ container_t *cont = NULL;
+
+ DAEMON_CLEAR_ERRMSG();
+ if (request == NULL || response == NULL) {
+ ERROR("Invalid NULL input");
+ return -1;
+ }
+
+ *response = util_common_calloc_s(sizeof(struct lcrd_container_resize_response));
+ if (*response == NULL) {
+ ERROR("Resume: Out of memory");
+ cc = LCRD_ERR_MEMOUT;
+ goto pack_response;
+ }
+
+ if (resize_request_check(request) != 0) {
+ cc = LCRD_ERR_INPUT;
+ goto pack_response;
+ }
+
+ name = request->id;
+
+ cont = containers_store_get(name);
+ if (cont == NULL) {
+ ERROR("No such container:%s", name);
+ lcrd_set_error_message("No such container:%s", name);
+ cc = LCRD_ERR_EXEC;
+ goto pack_response;
+ }
+
+ id = cont->common_config->id;
+ set_log_prefix(id);
+ EVENT("Event: {Object: %s, Type: Resizing}", id);
+
+ ret = resize_container(cont, request->suffix, request->height, request->width);
+ if (ret != 0) {
+ cc = LCRD_ERR_EXEC;
+ container_state_set_error(cont->state, (const char *)g_lcrd_errmsg);
+ goto pack_response;
+ }
+
+ EVENT("Event: {Object: %s, Type: Resized}", id);
+
+pack_response:
+ pack_resize_response(*response, cc, id);
+ container_unref(cont);
+ free_log_prefix();
+ return (cc == LCRD_SUCCESS) ? 0 : -1;
+}
+
void container_extend_callback_init(service_container_callback_t *cb)
{
cb->update = container_update_cb;
@@ -1299,5 +1405,6 @@ void container_extend_callback_init(service_container_callback_t *cb)
cb->stats = container_stats_cb;
cb->events = container_events_cb;
cb->export_rootfs = container_export_cb;
+ cb->resize = container_resize_cb;
}
diff --git a/src/services/execution/execute/execution_information.c b/src/services/execution/execute/execution_information.c
index 47d68e9..ab8c84c 100644
--- a/src/services/execution/execute/execution_information.c
+++ b/src/services/execution/execute/execution_information.c
@@ -456,7 +456,6 @@ out:
static inline void add_ps_array_elem(char **array, size_t *pos, const char *elem)
{
-#define PARAM_NUM 100
if (*pos + 1 >= (PARAM_NUM - 1)) {
return;
}
@@ -537,26 +536,48 @@ static int get_pids(const char *name, const char *runtime, const char *rootpath,
char **pid_args)
{
int ret = 0;
- struct engine_operation *engine_ops = NULL;
+ size_t i = 0;
+ rt_listpids_params_t params = { 0 };
+ rt_listpids_out_t *out = NULL;
- engine_ops = engines_get_handler(runtime);
- if (engine_ops == NULL || engine_ops->engine_get_container_pids_op == NULL) {
- DEBUG("Failed to get engine top operations");
+ out = util_common_calloc_s(sizeof(rt_listpids_out_t));
+ if (out == NULL) {
+ ERROR("Memeory out");
ret = -1;
goto out;
}
- if (!engine_ops->engine_get_container_pids_op(name, rootpath, pids, pids_len)) {
- DEBUG("Top container %s failed", name);
- const char *tmpmsg = NULL;
- tmpmsg = engine_ops->engine_get_errmsg_op();
- lcrd_set_error_message("Runtime top container error: %s",
- (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR);
+ params.rootpath = rootpath;
+ if (runtime_listpids(name, runtime, ¶ms, out) != 0) {
+ ERROR("runtime failed to list pids");
ret = -1;
goto out;
}
+
+ if (out->pids_len > SIZE_MAX / sizeof(pid_t)) {
+ ERROR("list too many pids");
+ ret = -1;
+ goto out;
+ }
+
+ if (out->pids_len != 0) {
+ pid_t *tmp = NULL;
+ tmp = util_common_calloc_s(sizeof(pid_t) * out->pids_len);
+ if (tmp == NULL) {
+ ERROR("Memory out");
+ ret = -1;
+ goto out;
+ }
+ for (i = 0; i < out->pids_len; i++) {
+ tmp[i] = out->pids[i];
+ }
+ *pids = tmp;
+ }
+
+ *pids_len = out->pids_len;
+
*pid_args = ps_pids_arg(*pids, *pids_len);
if (*pid_args == NULL) {
ERROR("failed to get pid_args");
@@ -564,9 +585,7 @@ static int get_pids(const char *name, const char *runtime, const char *rootpath,
goto out;
}
out:
- if (engine_ops != NULL) {
- engine_ops->engine_clear_errmsg_op();
- }
+ free_rt_listpids_out_t(out);
return ret;
}
@@ -1467,113 +1486,6 @@ pack_response:
return (cc == LCRD_SUCCESS) ? 0 : -1;
}
-static int container_conf_request_check(const struct lcrd_container_conf_request *h)
-{
- int ret = 0;
-
- if (h->name == NULL) {
- ERROR("Receive NULL container name");
- ret = -1;
- goto out;
- }
-
- if (!util_valid_container_id_or_name(h->name)) {
- ERROR("Invalid container name %s", h->name);
- lcrd_set_error_message("Invalid container name %s", h->name);
- ret = -1;
- goto out;
- }
-
-out:
- return ret;
-}
-
-static void pack_container_conf_response(struct lcrd_container_conf_response *response, uint32_t cc,
- const struct engine_console_config *config)
-{
- if (response == NULL) {
- return;
- }
- response->cc = cc;
- if (g_lcrd_errmsg != NULL) {
- response->errmsg = util_strdup_s(g_lcrd_errmsg);
- DAEMON_CLEAR_ERRMSG();
- }
-
- if (config->log_path != NULL) {
- response->container_logpath = util_strdup_s(config->log_path);
- }
- response->container_logrotate = (uint32_t)config->log_rotate;
- if (config->log_file_size != NULL) {
- response->container_logsize = util_strdup_s(config->log_file_size);
- }
-}
-
-static int container_conf_cb(const struct lcrd_container_conf_request *request,
- struct lcrd_container_conf_response **response)
-{
- char *id = NULL;
- uint32_t cc = LCRD_SUCCESS;
- struct engine_operation *engine_ops = NULL;
- struct engine_console_config config = { 0 };
- container_t *cont = NULL;
- rt_get_console_conf_params_t params = { 0 };
-
- DAEMON_CLEAR_ERRMSG();
- if (request == NULL || response == NULL) {
- ERROR("Invalid NULL input");
- return -1;
- }
-
- *response = util_common_calloc_s(sizeof(struct lcrd_container_conf_response));
- if (*response == NULL) {
- ERROR("Out of memory");
- cc = LCRD_ERR_MEMOUT;
- goto pack_response;
- }
-
- if (container_conf_request_check(request) != 0) {
- cc = LCRD_ERR_INPUT;
- goto pack_response;
- }
-
- cont = containers_store_get(request->name);
- if (cont == NULL) {
- ERROR("No such container:%s", request->name);
- lcrd_set_error_message("No such container:%s", request->name);
- cc = LCRD_ERR_EXEC;
- goto pack_response;
- }
-
- engine_ops = engines_get_handler(cont->runtime);
- if (engine_ops == NULL || engine_ops->engine_free_console_config_op == NULL) {
- ERROR("Failed to get engine free_console_config operation");
- cc = LCRD_ERR_EXEC;
- goto pack_response;
- }
-
- id = cont->common_config->id;
- set_log_prefix(id);
-
- params.rootpath = cont->root_path;
- params.config = &config;
-
- if (runtime_get_console_config(id, cont->runtime, ¶ms) != 0) {
- cc = LCRD_ERR_EXEC;
- goto pack_response;
- }
-
-pack_response:
- pack_container_conf_response(*response, cc, &config);
- container_unref(cont);
- if (engine_ops != NULL && engine_ops->engine_free_console_config_op != NULL) {
- engine_ops->engine_free_console_config_op(&config);
- }
-
- free_log_prefix();
- return (cc == LCRD_SUCCESS) ? 0 : -1;
-}
-
static int rename_request_check(const struct lcrd_container_rename_request *request)
{
int ret = 0;
@@ -1745,7 +1657,6 @@ void container_information_callback_init(service_container_callback_t *cb)
cb->inspect = container_inspect_cb;
cb->list = container_list_cb;
cb->wait = container_wait_cb;
- cb->conf = container_conf_cb;
cb->top = container_top_cb;
cb->rename = container_rename_cb;
}
diff --git a/src/services/execution/execute/execution_stream.c b/src/services/execution/execute/execution_stream.c
index 80ebf20..c05bd9a 100644
--- a/src/services/execution/execute/execution_stream.c
+++ b/src/services/execution/execute/execution_stream.c
@@ -250,7 +250,7 @@ out:
static int exec_container(container_t *cont, const char *runtime, char * const console_fifos[], const char *user,
size_t argc, const char **argv, size_t env_len, const char **env,
- int64_t timeout, int *exit_code)
+ int64_t timeout, const char *suffix, int *exit_code)
{
int ret = 0;
char *engine_log_path = NULL;
@@ -287,6 +287,7 @@ static int exec_container(container_t *cont, const char *runtime, char * const c
params.args_len = argc;
params.envs = (const char * const *)env;
params.envs_len = env_len;
+ params.suffix = suffix;
if (runtime_exec(cont->common_config->id, runtime, ¶ms, exit_code)) {
ERROR("Runtime exec container failed");
@@ -332,6 +333,13 @@ static int container_exec_cb_check(const container_exec_request *request, contai
return -1;
}
+ if (request->suffix != NULL && !util_valid_exec_suffix(request->suffix)) {
+ ERROR("Invalid exec suffix %s", request->suffix);
+ lcrd_set_error_message("Invalid exec suffix %s", request->suffix);
+ *cc = LCRD_ERR_EXEC;
+ return -1;
+ }
+
*cont = containers_store_get(container_name);
if (*cont == NULL) {
ERROR("No such container:%s", container_name);
@@ -564,7 +572,7 @@ static int container_exec_cb(const container_exec_request *request, container_ex
if (exec_container(cont, cont->runtime, (char * const *)fifos, user, request->argv_len,
(const char **)request->argv, request->env_len,
- (const char **)request->env, request->timeout, &exit_code)) {
+ (const char **)request->env, request->timeout, request->suffix, &exit_code)) {
cc = LCRD_ERR_EXEC;
goto pack_response;
}
@@ -698,7 +706,7 @@ static int container_attach_cb(const container_attach_request *request, containe
char *fifopath = NULL;
pthread_t tid = 0;
container_t *cont = NULL;
- struct engine_operation *engine_ops = NULL;
+ rt_attach_params_t params = { 0 };
DAEMON_CLEAR_ERRMSG();
if (request == NULL || response == NULL) {
@@ -725,21 +733,14 @@ static int container_attach_cb(const container_attach_request *request, containe
goto pack_response;
}
- engine_ops = engines_get_handler(cont->runtime);
- if (engine_ops == NULL || engine_ops->engine_console_op == NULL) {
- DEBUG("Failed to get engine attach operations");
- cc = LCRD_ERR_EXEC;
- goto pack_response;
- }
+ params.rootpath = cont->root_path;
+ params.stdin = fifos[0];
+ params.stdout = fifos[1];
+ params.stderr = fifos[2];
- if (!engine_ops->engine_console_op(id, cont->root_path, fifos[0], fifos[1], fifos[2])) {
- ERROR("attach failed");
+ if (runtime_attach(cont->common_config->id, cont->runtime, ¶ms)) {
+ ERROR("Runtime attach container failed");
cc = LCRD_ERR_EXEC;
- const char *tmpmsg = NULL;
- tmpmsg = engine_ops->engine_get_errmsg_op();
- lcrd_set_error_message("Attach container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
- tmpmsg : DEF_ERR_RUNTIME_STR);
- engine_ops->engine_clear_errmsg_op();
goto pack_response;
}
@@ -1796,6 +1797,20 @@ static int handle_rotate(int fd, int wd, const char *path)
return watch_fd;
}
+static void cleanup_handler(void *arg)
+{
+ int *fds = (int *)arg;
+
+ if (fds[0] < 0) {
+ return;
+ }
+
+ if (fds[1] >= 0 && inotify_rm_watch(fds[0], fds[1]) < 0) {
+ SYSERROR("Rm watch failed");
+ }
+ close(fds[0]);
+}
+
static int hanlde_events(int fd, const struct follow_args *farg)
{
int write_cnt, rename_cnt;
@@ -1805,17 +1820,21 @@ static int hanlde_events(int fd, const struct follow_args *farg)
ssize_t len = 0;
struct inotify_event *c_event = NULL;
char buf[MAXLINE] __attribute__((aligned(__alignof__(struct inotify_event)))) = { 0 };
+ int clean_fds[2] = { fd, -1 };
struct last_log_file_position last_pos = {
.file_index = farg->last_file_index,
.pos = farg->last_file_pos,
};
+ pthread_cleanup_push(cleanup_handler, clean_fds);
+
watch_fd = inotify_add_watch(fd, farg->path, IN_MODIFY | IN_DELETE | IN_MOVED_FROM | IN_MOVE_SELF);
if (watch_fd < 0) {
SYSERROR("Add watch %s failed", farg->path);
goto out;
}
+ clean_fds[1] = watch_fd;
for (;;) {
if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) {
@@ -1866,9 +1885,7 @@ static int hanlde_events(int fd, const struct follow_args *farg)
}
out:
- if (inotify_rm_watch(fd, watch_fd) < 0) {
- SYSERROR("Rm watch failed");
- }
+ pthread_cleanup_pop(1);
return ret;
}
@@ -1881,7 +1898,7 @@ static void *follow_thread_func(void *arg)
INFO("Get args, path: %s, last pos: %ld, last file: %d", farg->path, farg->last_file_pos, farg->last_file_index);
- inotify_fd = inotify_init();
+ inotify_fd = inotify_init1(IN_CLOEXEC);
if (inotify_fd < 0) {
SYSERROR("Init inotify failed");
goto set_flag;
@@ -1891,7 +1908,6 @@ static void *follow_thread_func(void *arg)
ERROR("Handle inotify event failed");
}
- close(inotify_fd);
set_flag:
*(farg->finish) = true;
return NULL;
diff --git a/src/services/execution/manager/container_unix.c b/src/services/execution/manager/container_unix.c
index eb34534..9c4c32b 100644
--- a/src/services/execution/manager/container_unix.c
+++ b/src/services/execution/manager/container_unix.c
@@ -1255,46 +1255,6 @@ unlock:
return ret;
}
-static container_pid_t *parse_container_pid(const char *S)
-{
- int num;
- container_pid_t *P = NULL;
-
- if (S == NULL) {
- return NULL;
- }
-
- P = util_common_calloc_s(sizeof(container_pid_t));
- if (P == NULL) {
- return NULL;
- }
-
- num = sscanf(S, "%d %Lu %d %Lu", &P->pid, &P->start_time, &P->ppid, &P->pstart_time);
- if (num != 4) { // args num to read is 4
- ERROR("Call sscanf error: %s", errno ? strerror(errno) : "");
- free(P);
- return NULL;
- }
-
- return P;
-}
-
-container_pid_t *container_read_pidfile(const char *pidfile)
-{
- if (pidfile == NULL) {
- ERROR("Invalid input arguments");
- return NULL;
- }
-
- char sbuf[1024] = { 0 }; /* bufs for stat */
-
- if ((util_file2str(pidfile, sbuf, sizeof(sbuf))) == -1) {
- return NULL;
- }
-
- return parse_container_pid(sbuf);
-}
-
char *container_get_env_nolock(const container_t *cont, const char *key)
{
size_t i = 0;
@@ -1340,3 +1300,38 @@ char *container_get_env_nolock(const container_t *cont, const char *key)
return val;
}
+int container_read_proc(uint32_t pid, container_pid_t *pid_info)
+{
+ int ret = 0;
+ proc_t *proc = NULL;
+ proc_t *p_proc = NULL;
+
+ if (pid == 0) {
+ ret = -1;
+ goto out;
+ }
+
+ proc = util_get_process_proc_info((pid_t)pid);
+ if (proc == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ p_proc = util_get_process_proc_info((pid_t)proc->ppid);
+ if (p_proc == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ pid_info->pid = proc->pid;
+ pid_info->start_time = proc->start_time;
+ pid_info->ppid = proc->ppid;
+ pid_info->pstart_time = p_proc->start_time;
+
+out:
+ free(proc);
+ free(p_proc);
+ return ret;
+}
+
+
diff --git a/src/services/execution/manager/container_unix.h b/src/services/execution/manager/container_unix.h
index 55d8311..cf89139 100644
--- a/src/services/execution/manager/container_unix.h
+++ b/src/services/execution/manager/container_unix.h
@@ -106,11 +106,11 @@ int container_wait_stop_locking(container_t *cont, int timeout);
void container_wait_rm_cond_broadcast(container_t *cont);
int container_wait_rm_locking(container_t *cont, int timeout);
-container_pid_t *container_read_pidfile(const char *pidfile);
-
int save_host_config(const char *id, const char *rootpath, const char *hostconfigstr);
int save_config_v2_json(const char *id, const char *rootpath, const char *v2configstr);
+int container_read_proc(uint32_t pid, container_pid_t *pid_info);
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
diff --git a/src/services/execution/manager/restore.c b/src/services/execution/manager/restore.c
index 60d9d15..46ff8ae 100644
--- a/src/services/execution/manager/restore.c
+++ b/src/services/execution/manager/restore.c
@@ -28,6 +28,7 @@
#include "container_unix.h"
#include "error.h"
#include "image.h"
+#include "runtime.h"
#ifdef ENABLE_OCI_IMAGE
#include "oci_images_store.h"
@@ -36,15 +37,17 @@
#include "execution.h"
/* restore supervisor */
-static int restore_supervisor(const char *id, const char *runtime, const char *statepath)
+static int restore_supervisor(const container_t *cont)
{
int ret = 0;
int nret = 0;
int exit_fifo_fd = -1;
char container_state[PATH_MAX] = { 0 };
- char pidfile[PATH_MAX] = { 0 };
char *exit_fifo = NULL;
- container_pid_t *pid_info = NULL;
+ char *id = cont->common_config->id;
+ char *statepath = cont->state_path;
+ char *runtime = cont->runtime;
+ container_pid_t pid_info = { 0 };
nret = snprintf(container_state, sizeof(container_state), "%s/%s", statepath, id);
if (nret < 0 || (size_t)nret >= sizeof(container_state)) {
@@ -67,23 +70,12 @@ static int restore_supervisor(const char *id, const char *runtime, const char *s
goto out;
}
- nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state);
- if (nret < 0 || (size_t)nret >= sizeof(pidfile)) {
- close(exit_fifo_fd);
- ERROR("Failed to sprintf pidfile");
- ret = -1;
- goto out;
- }
+ pid_info.pid = cont->state->state->pid;
+ pid_info.ppid = cont->state->state->p_pid;
+ pid_info.start_time = cont->state->state->start_time;
+ pid_info.pstart_time = cont->state->state->p_start_time;
- pid_info = container_read_pidfile(pidfile);
- if (pid_info == NULL) {
- close(exit_fifo_fd);
- ERROR("Failed to get started container's pid info");
- ret = -1;
- goto out;
- }
-
- if (supervisor_add_exit_monitor(exit_fifo_fd, pid_info, id, runtime)) {
+ if (supervisor_add_exit_monitor(exit_fifo_fd, &pid_info, id, runtime)) {
ERROR("Failed to add exit monitor to supervisor");
ret = -1;
goto out;
@@ -91,115 +83,31 @@ static int restore_supervisor(const char *id, const char *runtime, const char *s
out:
free(exit_fifo);
- free(pid_info);
return ret;
}
-static container_pid_t *container_read_proc(uint32_t pid)
-{
- container_pid_t *pid_info = NULL;
- proc_t *proc_info = NULL;
-
- if (pid == 0) {
- goto out;
- }
-
- proc_info = util_get_process_proc_info((pid_t)pid);
- if (proc_info == NULL) {
- goto out;
- }
-
- pid_info = util_common_calloc_s(sizeof(container_pid_t));
- if (pid_info == NULL) {
- goto out;
- }
-
- pid_info->pid = proc_info->pid;
- pid_info->start_time = proc_info->start_time;
-
-out:
- free(proc_info);
- return pid_info;
-}
-
/* post stopped container to gc */
static int post_stopped_container_to_gc(const char *id, const char *runtime, const char *statepath, uint32_t pid)
{
int ret = 0;
- int nret = 0;
- char container_state[PATH_MAX] = { 0 };
- char pidfile[PATH_MAX] = { 0 };
- container_pid_t *pid_info = NULL;
+ container_pid_t pid_info = { 0 };
- nret = snprintf(container_state, sizeof(container_state), "%s/%s", statepath, id);
- if (nret < 0 || (size_t)nret >= sizeof(container_state)) {
- ERROR("Failed to sprintf container state %s/%s", statepath, id);
- ret = -1;
- goto out;
- }
+ (void)container_read_proc(pid, &pid_info);
- nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state);
- if (nret < 0 || (size_t)nret >= sizeof(pidfile)) {
- ERROR("Failed to sprintf pidfile");
- ret = -1;
- goto out;
- }
-
- pid_info = container_read_pidfile(pidfile);
- if (pid_info == NULL) {
- WARN("Failed to get started container's pid info, try to read proc filesystem");
- pid_info = container_read_proc(pid);
- if (pid_info == NULL) {
- ERROR("Failed to get started container's pid info");
- ret = -1;
- goto out;
- }
- }
-
- if (gc_add_container(id, runtime, pid_info)) {
+ if (gc_add_container(id, runtime, &pid_info)) {
ERROR("Failed to post container %s to garbage collector", id);
ret = -1;
goto out;
}
out:
- free(pid_info);
return ret;
}
-static container_pid_t *load_running_container_pid_info(const container_t *cont)
-{
- int nret = 0;
- const char *id = cont->common_config->id;
- char pidfile[PATH_MAX] = { 0 };
- char container_state[PATH_MAX] = { 0 };
- container_pid_t *pid_info = NULL;
-
- nret = snprintf(container_state, sizeof(container_state), "%s/%s", cont->state_path, id);
- if (nret < 0 || (size_t)nret >= sizeof(container_state)) {
- ERROR("Failed to sprintf container_state for container %s", id);
- goto out;
- }
-
- nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state);
- if (nret < 0 || (size_t)nret >= sizeof(pidfile)) {
- ERROR("Failed to sprintf pidfile");
- goto out;
- }
-
- pid_info = container_read_pidfile(pidfile);
- if (pid_info == NULL) {
- goto out;
- }
-
-out:
- return pid_info;
-}
-
#ifdef ENABLE_OCI_IMAGE
static void post_nonexist_image_containers(const container_t *cont, Container_Status status,
- const struct engine_container_summary_info *info)
+ const struct engine_container_status_info *info)
{
int nret;
const char *id = cont->common_config->id;
@@ -267,50 +175,31 @@ out:
}
#endif
-static void try_to_set_container_running(Container_Status status, const container_t *cont,
- const container_pid_t *pid_info)
+static bool is_same_process(const container_t *cont, const container_pid_t *pid_info)
{
- int pid = 0;
-
- pid = state_get_pid(cont->state);
- if (status != CONTAINER_STATUS_RUNNING || pid != pid_info->pid) {
- state_set_running(cont->state, pid_info, true);
+ if (pid_info->pid == cont->state->state->pid &&
+ pid_info->ppid == cont->state->state->p_pid &&
+ pid_info->start_time == cont->state->state->start_time &&
+ pid_info->pstart_time == cont->state->state->p_start_time) {
+ return true;
}
+ return false;
}
static void try_to_set_paused_container_pid(Container_Status status, const container_t *cont,
const container_pid_t *pid_info)
{
- int pid = 0;
-
- pid = state_get_pid(cont->state);
- if (status != CONTAINER_STATUS_RUNNING || pid != pid_info->pid) {
+ if (status != CONTAINER_STATUS_RUNNING || !is_same_process(cont, pid_info)) {
state_set_running(cont->state, pid_info, false);
}
}
-static int restore_check_id_valid(const char *id, const struct engine_container_summary_info *info,
- size_t container_num)
+static void try_to_set_container_running(Container_Status status, container_t *cont,
+ const container_pid_t *pid_info)
{
- size_t i = 0;
-
- if (id == NULL) {
- ERROR("Cannot get container id from config v2");
- return -1;
+ if (status != CONTAINER_STATUS_RUNNING || !is_same_process(cont, pid_info)) {
+ state_set_running(cont->state, pid_info, true);
}
-
- for (i = 0; i < container_num; i++) {
- if (strcmp(id, info[i].id) == 0) {
- break;
- }
- }
-
- if (i >= container_num) {
- ERROR("Container %s is not in runtime container array", id);
- return -1;
- }
-
- return (int)i;
}
static int restore_stopped_container(Container_Status status, const container_t *cont, bool *need_save)
@@ -333,16 +222,19 @@ static int restore_stopped_container(Container_Status status, const container_t
}
static int restore_running_container(Container_Status status, container_t *cont,
- const struct engine_container_summary_info *info)
+ const struct engine_container_status_info *info)
{
int ret = 0;
+ int nret = 0;
const char *id = cont->common_config->id;
- container_pid_t *pid_info = NULL;
+ container_pid_t pid_info = { 0 };
- pid_info = load_running_container_pid_info(cont);
- if (pid_info == NULL) {
- ERROR("Failed to restore container:%s due to unable to read container pid info", id);
- int nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, info->pid);
+ nret = container_read_proc(info->pid, &pid_info);
+ if (nret == 0) {
+ try_to_set_container_running(status, cont, &pid_info);
+ } else {
+ ERROR("Failed to restore container:%s due to unable to read container pid information", id);
+ nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, 0);
if (nret != 0) {
ERROR("Failed to post container %s to garbage"
"collector, that may lost some resources"
@@ -350,29 +242,30 @@ static int restore_running_container(Container_Status status, container_t *cont,
}
ret = -1;
goto out;
- } else {
- try_to_set_container_running(status, cont, pid_info);
}
+
container_reset_manually_stopped(cont);
out:
- free(pid_info);
return ret;
}
static int restore_paused_container(Container_Status status, container_t *cont,
- const struct engine_container_summary_info *info)
+ const struct engine_container_status_info *info)
{
int ret = 0;
+ int nret = 0;
const char *id = cont->common_config->id;
- container_pid_t *pid_info = NULL;
+ container_pid_t pid_info = { 0 };
state_set_paused(cont->state);
- pid_info = load_running_container_pid_info(cont);
- if (pid_info == NULL) {
- ERROR("Failed to restore container:%s due to unable to read container pid info", id);
- int nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, info->pid);
+ nret = container_read_proc(info->pid, &pid_info);
+ if (nret == 0) {
+ try_to_set_paused_container_pid(status, cont, &pid_info);
+ } else {
+ ERROR("Failed to restore container:%s due to unable to read container pid information", id);
+ nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, 0);
if (nret != 0) {
ERROR("Failed to post container %s to garbage"
"collector, that may lost some resources"
@@ -380,27 +273,31 @@ static int restore_paused_container(Container_Status status, container_t *cont,
}
ret = -1;
goto out;
- } else {
- try_to_set_paused_container_pid(status, cont, pid_info);
}
+
container_reset_manually_stopped(cont);
out:
- free(pid_info);
return ret;
}
/* restore state */
-static int restore_state(container_t *cont, const struct engine_container_summary_info *info, size_t container_num)
+static int restore_state(container_t *cont)
{
int ret = 0;
- int c_index = 0;
+ int nret = 0;
bool need_save = false;
const char *id = cont->common_config->id;
+ const char *runtime = cont->runtime;
+ rt_status_params_t params = { 0 };
+ struct engine_container_status_info real_status = { 0 };
Container_Status status = CONTAINER_STATUS_UNKNOWN;
- c_index = restore_check_id_valid(id, info, container_num);
- if (c_index < 0) {
+ params.rootpath = cont->root_path;
+
+ nret = runtime_status(id, runtime, ¶ms, &real_status);
+ if (nret != 0) {
+ ERROR("Failed to restore container %s, due to can not load container status", id);
ret = -1;
goto out;
}
@@ -411,29 +308,31 @@ static int restore_state(container_t *cont, const struct engine_container_summar
#ifdef ENABLE_OCI_IMAGE
if (check_container_image_exist(cont) != 0) {
ERROR("Failed to restore container:%s due to image not exist", id);
- post_nonexist_image_containers(cont, status, &info[c_index]);
+ post_nonexist_image_containers(cont, status, &real_status);
ret = -1;
goto out;
}
#endif
- if (info[c_index].status == ENGINE_CONTAINER_STATUS_STOPPED) {
+ if (real_status.status == ENGINE_CONTAINER_STATUS_STOPPED) {
ret = restore_stopped_container(status, cont, &need_save);
if (ret != 0) {
goto out;
}
- } else if (info[c_index].status == ENGINE_CONTAINER_STATUS_RUNNING) {
- ret = restore_running_container(status, cont, &info[c_index]);
+ } else if (real_status.status == ENGINE_CONTAINER_STATUS_RUNNING) {
+ ret = restore_running_container(status, cont, &real_status);
if (ret != 0) {
goto out;
}
- } else if (info[c_index].status == ENGINE_CONTAINER_STATUS_PAUSED) {
- ret = restore_paused_container(status, cont, &info[c_index]);
+ } else if (real_status.status == ENGINE_CONTAINER_STATUS_PAUSED) {
+ ret = restore_paused_container(status, cont, &real_status);
if (ret != 0) {
goto out;
}
} else {
- ERROR("Container %s get invalid status %d", id, info[c_index].status);
+ ERROR("Container %s get invalid status %d", id, real_status.status);
+ ret = -1;
+ goto out;
}
if (is_removal_in_progress(cont->state)) {
@@ -538,7 +437,7 @@ static void handle_restored_container()
id = cont->common_config->id;
if (is_running(cont->state)) {
- if (restore_supervisor(id, cont->runtime, cont->state_path)) {
+ if (restore_supervisor(cont)) {
ERROR("Failed to restore %s supervisor", id);
}
init_health_monitor(id);
@@ -563,8 +462,7 @@ static void handle_restored_container()
/* scan dir to add store */
static void scan_dir_to_add_store(const char *runtime, const char *rootpath, const char *statepath,
- const size_t subdir_num, const char **subdir, const size_t container_num,
- const struct engine_container_summary_info *info)
+ const size_t subdir_num, const char **subdir)
{
size_t i = 0;
container_t *cont = NULL;
@@ -579,7 +477,7 @@ static void scan_dir_to_add_store(const char *runtime, const char *rootpath, con
goto error_load;
}
- if (restore_state(cont, info, container_num)) {
+ if (restore_state(cont)) {
WARN("Failed to restore container %s state", subdir[i]);
goto error_load;
}
@@ -609,83 +507,14 @@ error_load:
}
}
-/* query all containers info */
-static int query_all_containers_info(const char *runtime, struct engine_container_summary_info **container_summary,
- size_t *container_num)
-{
- int ret = 0;
- int container_nums = 0;
- char *engine_path = NULL;
- struct engine_operation *engine_ops = NULL;
-
- if (runtime == NULL || container_summary == NULL || container_num == NULL) {
- ERROR("invalid NULL param");
- return -1;
- }
-
- engine_ops = engines_get_handler(runtime);
- if (engine_ops == NULL || engine_ops->engine_get_all_containers_info_op == NULL) {
- ERROR("Failed to get list op of engine %s", runtime);
- ret = -1;
- goto out;
- }
-
- engine_path = conf_get_routine_rootdir(runtime);
- if (engine_path == NULL) {
- ret = -1;
- goto out;
- }
- container_nums = engine_ops->engine_get_all_containers_info_op(engine_path, container_summary);
- if (container_nums < 0) {
- ERROR("Engine %s get all containers info failed", runtime);
- ret = -1;
- goto out;
- }
- *container_num = (size_t)container_nums;
-
-out:
- free(engine_path);
- if (engine_ops != NULL) {
- engine_ops->engine_clear_errmsg_op();
- }
-
- return ret;
-}
-
-/* all containers info free */
-static void all_containers_info_free(const char *runtime, struct engine_container_summary_info *container_summary,
- size_t container_num)
-{
- struct engine_operation *engine_ops = NULL;
-
- if (container_summary == NULL || runtime == NULL) {
- return;
- }
-
- engine_ops = engines_get_handler(runtime);
- if (engine_ops == NULL || engine_ops->engine_free_all_containers_info_op == NULL) {
- ERROR("Failed to get free op of engine %s", runtime);
- return;
- }
-
- engine_ops->engine_free_all_containers_info_op(container_summary, (int)container_num);
-
- if (engine_ops->engine_clear_errmsg_op != NULL) {
- engine_ops->engine_clear_errmsg_op();
- }
- return;
-}
-
/* restore container by runtime */
static int restore_container_by_runtime(const char *runtime)
{
int ret = 0;
char *rootpath = NULL;
char *statepath = NULL;
- size_t container_num = 0;
size_t subdir_num = 0;
char **subdir = NULL;
- struct engine_container_summary_info *info = NULL;
rootpath = conf_get_routine_rootdir(runtime);
if (rootpath == NULL) {
@@ -712,17 +541,9 @@ static int restore_container_by_runtime(const char *runtime)
goto out;
}
- ret = query_all_containers_info(runtime, &info, &container_num);
- if (ret < 0) {
- ERROR("query all containers info failed");
- ret = -1;
- goto out;
- }
-
- scan_dir_to_add_store(runtime, rootpath, statepath, subdir_num, (const char **)subdir, container_num, info);
+ scan_dir_to_add_store(runtime, rootpath, statepath, subdir_num, (const char **)subdir);
out:
- all_containers_info_free(runtime, info, container_num);
free(rootpath);
free(statepath);
util_free_array(subdir);
diff --git a/src/services/execution/spec/specs_extend.c b/src/services/execution/spec/specs_extend.c
index fb5a0c9..1a36f81 100644
--- a/src/services/execution/spec/specs_extend.c
+++ b/src/services/execution/spec/specs_extend.c
@@ -468,34 +468,35 @@ out:
static int read_user_file(const char *basefs, const char *user_path, FILE **stream)
{
- int nret;
+ int ret = 0;
int64_t filesize = 0;
- char path[PATH_MAX] = {0};
- char real_path[PATH_MAX] = {0};
+ char *real_path = NULL;
- nret = snprintf(path, sizeof(path), "%s/%s", basefs, user_path);
- if (nret < 0 || (size_t)nret >= sizeof(path)) {
- ERROR("Path is too long");
- return -1;
- }
- if (cleanpath(path, real_path, sizeof(real_path)) == NULL) {
- ERROR("Failed to clean path");
- return -1;
+ if (realpath_in_scope(basefs, user_path, &real_path) < 0) {
+ ERROR("user target file '%s' real path must be under '%s'", user_path, basefs);
+ lcrd_set_error_message("user target file '%s' real path must be under '%s'", user_path, basefs);
+ ret = -1;
+ goto out;
}
filesize = util_file_size(real_path);
if (filesize > REGULAR_FILE_SIZE) {
ERROR("File %s is more than %lld", real_path, (long long)REGULAR_FILE_SIZE);
lcrd_set_error_message("File %s is more than %lld", real_path, (long long)REGULAR_FILE_SIZE);
- return -1;
+ ret = -1;
+ goto out;
}
*stream = util_fopen(real_path, "r");
if (*stream == NULL) {
ERROR("Failed to open %s: %s", real_path, strerror(errno));
- return 0;
+ ret = 0;
+ goto out;
}
- return 0;
+
+out:
+ free(real_path);
+ return ret;
}
static void parse_user_group(const char *username, char **user, char **group, char **tmp_dup)
diff --git a/test/cutils/utils_array/CMakeLists.txt b/test/cutils/utils_array/CMakeLists.txt
index 6f7c8dd..df29cef 100644
--- a/test/cutils/utils_array/CMakeLists.txt
+++ b/test/cutils/utils_array/CMakeLists.txt
@@ -24,5 +24,5 @@ target_include_directories(${EXE} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils
${CMAKE_BINARY_DIR}/json
)
-set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc -Wl,--wrap,memcpy_s")
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
+set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc")
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
diff --git a/test/cutils/utils_array/utils_array_llt.cc b/test/cutils/utils_array/utils_array_llt.cc
index 830e3c9..cb18c74 100644
--- a/test/cutils/utils_array/utils_array_llt.cc
+++ b/test/cutils/utils_array/utils_array_llt.cc
@@ -16,7 +16,6 @@
#include
#include
#include
-#include
#include
#include "mock.h"
#include "utils_array.h"
@@ -25,10 +24,6 @@
extern "C" {
DECLARE_WRAPPER(calloc, void *, (size_t nmemb, size_t size));
DEFINE_WRAPPER(calloc, void *, (size_t nmemb, size_t size), (nmemb, size));
-
- DECLARE_WRAPPER(memcpy_s, errno_t, (void* dest, size_t destMax, const void* src, size_t count));
- DEFINE_WRAPPER(memcpy_s, errno_t, (void* dest, size_t destMax, const void* src, size_t count),
- (dest, destMax, src, count));
}
TEST(utils_array, test_util_array_len)
@@ -158,17 +153,6 @@ TEST(utils_array, test_util_grow_array)
util_free_array(array);
array = nullptr;
capacity = 0;
-
- capacity = 1;
- array = (char **)util_common_calloc_s(capacity * sizeof(char *));
- ASSERT_NE(array, nullptr);
- MOCK_SET(memcpy_s, EINVAL);
- ret = util_grow_array(&array, &capacity, 1, 1);
- ASSERT_NE(ret, 0);
- MOCK_CLEAR(memcpy_s);
- util_free_array(array);
- array = nullptr;
- capacity = 0;
}
TEST(utils_array, test_util_array_append)
@@ -219,17 +203,4 @@ TEST(utils_array, test_util_array_append)
MOCK_CLEAR(calloc);
util_free_array(array);
array = nullptr;
-
- array_three = (char **)util_common_calloc_s(4 * sizeof(char *));
- ASSERT_NE(array_three, nullptr);
- array_three[0] = util_strdup_s("test1");
- array_three[1] = util_strdup_s("test2");
- array_three[2] = util_strdup_s("test3");
- array_three[3] = nullptr;
- MOCK_SET(memcpy_s, EINVAL);
- ret = util_array_append(&array_three, "123");
- ASSERT_NE(ret, 0);
- MOCK_CLEAR(memcpy_s);
- util_free_array(array_three);
- array_three = nullptr;
}
diff --git a/test/cutils/utils_convert/CMakeLists.txt b/test/cutils/utils_convert/CMakeLists.txt
index 53886ad..265ac1d 100644
--- a/test/cutils/utils_convert/CMakeLists.txt
+++ b/test/cutils/utils_convert/CMakeLists.txt
@@ -24,4 +24,4 @@ target_include_directories(${EXE} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils
${CMAKE_BINARY_DIR}/json
)
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
diff --git a/test/cutils/utils_convert/utils_convert_llt.cc b/test/cutils/utils_convert/utils_convert_llt.cc
index 9808c93..0ad48f8 100644
--- a/test/cutils/utils_convert/utils_convert_llt.cc
+++ b/test/cutils/utils_convert/utils_convert_llt.cc
@@ -16,7 +16,6 @@
#include
#include
#include
-#include
#include
#include "mock.h"
#include "utils_convert.h"
diff --git a/test/cutils/utils_string/CMakeLists.txt b/test/cutils/utils_string/CMakeLists.txt
index 1b9d0bd..33c2373 100644
--- a/test/cutils/utils_string/CMakeLists.txt
+++ b/test/cutils/utils_string/CMakeLists.txt
@@ -25,4 +25,4 @@ target_include_directories(${EXE} PUBLIC
${CMAKE_BINARY_DIR}/json
)
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_strdup_s -Wl,--wrap,calloc -Wl,--wrap,strcat_s")
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
diff --git a/test/cutils/utils_string/utils_string_llt.cc b/test/cutils/utils_string/utils_string_llt.cc
index bf2486a..04210bd 100644
--- a/test/cutils/utils_string/utils_string_llt.cc
+++ b/test/cutils/utils_string/utils_string_llt.cc
@@ -15,7 +15,6 @@
#include
#include
-#include
#include
#include "mock.h"
#include "utils_string.h"
@@ -26,26 +25,6 @@ extern "C" {
DECLARE_WRAPPER(calloc, void *, (size_t nmemb, size_t size));
DEFINE_WRAPPER(calloc, void *, (size_t nmemb, size_t size), (nmemb, size));
-
- DECLARE_WRAPPER_V(strcat_s, errno_t, (char *strDest, size_t destMax, const char *strSrc));
- DEFINE_WRAPPER_V(strcat_s, errno_t, (char *strDest, size_t destMax, const char *strSrc),
- (strDest, destMax, strSrc));
-}
-
-static int g_strcat_s_cnt = 0;
-
-static errno_t strcat_s_fail(char *strDest, size_t destMax, const char *strSrc)
-{
- return (errno_t)EINVAL;
-}
-
-static errno_t strcat_s_second_fail(char *strDest, size_t destMax, const char *strSrc)
-{
- g_strcat_s_cnt++;
- if (g_strcat_s_cnt == 1) {
- return __real_strcat_s(strDest, destMax, strSrc);
- }
- return (errno_t)EINVAL;
}
TEST(utils_string_llt, test_strings_count)
@@ -681,22 +660,6 @@ TEST(utils_string_llt, test_util_string_join)
result = util_string_join(nullptr, array_long, array_long_len);
ASSERT_STREQ(result, nullptr);
-
- MOCK_SET_V(strcat_s, strcat_s_fail);
- result = util_string_join(" ", array_short, array_short_len);
- ASSERT_STREQ(result, nullptr);
- MOCK_CLEAR(strcat_s);
-
- MOCK_SET_V(strcat_s, strcat_s_fail);
- result = util_string_join(" ", array_long, array_long_len);
- ASSERT_STREQ(result, nullptr);
- MOCK_CLEAR(strcat_s);
-
- g_strcat_s_cnt = 0;
- MOCK_SET_V(strcat_s, strcat_s_second_fail);
- result = util_string_join(" ", array_long, array_long_len);
- ASSERT_STREQ(result, nullptr);
- MOCK_CLEAR(strcat_s);
}
TEST(utils_string_llt, test_util_string_append)
@@ -742,17 +705,6 @@ TEST(utils_string_llt, test_util_string_append)
result = util_string_append("abc", "123");
ASSERT_STREQ(result, nullptr);
MOCK_CLEAR(calloc);
-
- MOCK_SET_V(strcat_s, strcat_s_fail);
- result = util_string_append("abc", "123");
- ASSERT_STREQ(result, nullptr);
- MOCK_CLEAR(strcat_s);
-
- g_strcat_s_cnt = 0;
- MOCK_SET_V(strcat_s, strcat_s_second_fail);
- result = util_string_append("abc", "123");
- ASSERT_STREQ(result, nullptr);
- MOCK_CLEAR(strcat_s);
}
TEST(utils_string_llt, test_dup_array_of_strings)
diff --git a/test/image/oci/oci_config_merge/CMakeLists.txt b/test/image/oci/oci_config_merge/CMakeLists.txt
index 23c3f18..141d120 100644
--- a/test/image/oci/oci_config_merge/CMakeLists.txt
+++ b/test/image/oci/oci_config_merge/CMakeLists.txt
@@ -57,4 +57,4 @@ target_include_directories(${EXE} PUBLIC
)
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_common_calloc_s -Wl,--wrap,util_smart_calloc_s -Wl,--wrap,merge_env")
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
diff --git a/test/image/oci/oci_config_merge/oci_config_merge_llt.cc b/test/image/oci/oci_config_merge/oci_config_merge_llt.cc
index 9437b14..25728ec 100644
--- a/test/image/oci/oci_config_merge/oci_config_merge_llt.cc
+++ b/test/image/oci/oci_config_merge/oci_config_merge_llt.cc
@@ -15,7 +15,6 @@
#include
#include
-#include
#include
#include "mock.h"
#include "oci_runtime_spec.h"
diff --git a/test/path/CMakeLists.txt b/test/path/CMakeLists.txt
index f9afca9..62d4a10 100644
--- a/test/path/CMakeLists.txt
+++ b/test/path/CMakeLists.txt
@@ -24,4 +24,4 @@ target_include_directories(${EXE} PUBLIC
${CMAKE_BINARY_DIR}/json
)
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,getcwd -Wl,--wrap,readlink")
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
diff --git a/test/path/path_llt.cc b/test/path/path_llt.cc
index 557573f..ba7ef7c 100644
--- a/test/path/path_llt.cc
+++ b/test/path/path_llt.cc
@@ -16,7 +16,6 @@
#include
#include
#include
-#include
#include
#include "mock.h"
#include "utils.h"
@@ -36,13 +35,16 @@ extern "C" {
static char *getcwd_specify(char *str, size_t size)
{
+ const char *dst = "/home";
if (str == nullptr) {
return nullptr;
}
- if (strcpy_s(str, size, "/home") != EOK) {
+ if (size <= strlen(dst)) {
return nullptr;
}
+ (void)strcpy(str, dst);
+
return str;
}
@@ -74,9 +76,10 @@ static ssize_t readlink_specify(const char *path, char *buf, size_t bufsize)
return -1;
}
- if (strcpy_s(buf, bufsize, linkpath) != EOK) {
+ if (bufsize <= linkpath_length) {
return -1;
}
+ (void)strcpy(buf, linkpath);
if (linkpath_length > bufsize) {
return bufsize;
diff --git a/test/llt.sh b/test/test.sh
similarity index 100%
rename from test/llt.sh
rename to test/test.sh