!16 iSulad: internal change at 3.6
Merge pull request !16 from lifeng_isula/3.6
This commit is contained in:
commit
61b7a0fae6
@ -69,6 +69,14 @@ find_library(CURL_LIBRARY curl
|
|||||||
HINTS ${PC_CURL_LIBDIR} ${PC_CURL_LIBRARY_DIRS})
|
HINTS ${PC_CURL_LIBDIR} ${PC_CURL_LIBRARY_DIRS})
|
||||||
_CHECK(CURL_LIBRARY "CURL_LIBRARY-NOTFOUND" "libcurl.so")
|
_CHECK(CURL_LIBRARY "CURL_LIBRARY-NOTFOUND" "libcurl.so")
|
||||||
|
|
||||||
|
pkg_check_modules(PC_SELINUX "libselinux>=2.0")
|
||||||
|
find_path(SELINUX_INCLUDE_DIR "selinux/selinux.h"
|
||||||
|
HINTS ${PC_SELINUX_INCLUDEDIR} ${PC_SELINUX_INCLUDE_DIRS})
|
||||||
|
_CHECK(SELINUX_INCLUDE_DIR "SELINUX_INCLUDE_DIR-NOTFOUND" "selinux/selinux.h")
|
||||||
|
find_library(SELINUX_LIBRARY selinux
|
||||||
|
HINTS ${PC_SELINUX_LIBDIR} ${PC_SELINUX_LIBRARY_DIRS})
|
||||||
|
_CHECK(SELINUX_LIBRARY "SELINUX_LIBRARY-NOTFOUND" "libselinux.so")
|
||||||
|
|
||||||
if (OPENSSL_VERIFY)
|
if (OPENSSL_VERIFY)
|
||||||
find_path(OPENSSL_INCLUDE_DIR openssl/x509.h)
|
find_path(OPENSSL_INCLUDE_DIR openssl/x509.h)
|
||||||
_CHECK(OPENSSL_INCLUDE_DIR "OPENSSL_INCLUDE_DIR-NOTFOUND" "openssl/x509.h")
|
_CHECK(OPENSSL_INCLUDE_DIR "OPENSSL_INCLUDE_DIR-NOTFOUND" "openssl/x509.h")
|
||||||
|
|||||||
@ -33,7 +33,7 @@ endif()
|
|||||||
|
|
||||||
option(VERSION "set isulad version" ON)
|
option(VERSION "set isulad version" ON)
|
||||||
if (VERSION STREQUAL "ON")
|
if (VERSION STREQUAL "ON")
|
||||||
set(ISULAD_VERSION "1.1.11")
|
set(ISULAD_VERSION "1.1.12")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(DEBUG "set isulad gcc option" ON)
|
option(DEBUG "set isulad gcc option" ON)
|
||||||
|
|||||||
15
iSulad.spec
15
iSulad.spec
@ -1,5 +1,5 @@
|
|||||||
%global _version 1.1.11
|
%global _version 1.1.12
|
||||||
%global _release 20200204.221506.git50cfadfa
|
%global _release 20200306.143730.gitb83d1ed8
|
||||||
%global is_systemd 1
|
%global is_systemd 1
|
||||||
%global debug_package %{nil}
|
%global debug_package %{nil}
|
||||||
|
|
||||||
@ -30,18 +30,18 @@ Requires(preun): initscripts
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
BuildRequires: cmake gcc-c++ lxc lxc-devel lcr yajl yajl-devel clibcni-devel
|
BuildRequires: cmake gcc-c++ lxc lxc-devel lcr yajl yajl-devel clibcni-devel
|
||||||
BuildRequires: grpc grpc-devel protobuf-devel
|
BuildRequires: grpc grpc-plugins grpc-devel protobuf-devel
|
||||||
BuildRequires: libcurl libcurl-devel sqlite-devel
|
BuildRequires: libcurl libcurl-devel sqlite-devel
|
||||||
BuildRequires: http-parser-devel libevhtp-devel libevent-devel
|
BuildRequires: http-parser-devel
|
||||||
BuildRequires: libseccomp-devel libcap-devel libwebsockets libwebsockets-devel
|
BuildRequires: libseccomp-devel libcap-devel libselinux-devel libwebsockets libwebsockets-devel
|
||||||
BuildRequires: systemd-devel git python3
|
BuildRequires: systemd-devel git python3
|
||||||
|
|
||||||
Requires: iSulad-img lcr lxc clibcni
|
Requires: iSulad-img lcr lxc clibcni
|
||||||
Requires: grpc protobuf yajl
|
Requires: grpc protobuf yajl
|
||||||
Requires: libcurl
|
Requires: libcurl
|
||||||
Requires: sqlite http-parser libseccomp
|
Requires: sqlite http-parser libseccomp
|
||||||
Requires: libcap libwebsockets
|
Requires: libcap libselinux libwebsockets
|
||||||
Requires: libevhtp libevent systemd
|
Requires: systemd
|
||||||
|
|
||||||
%description
|
%description
|
||||||
This is a umbrella project for gRPC-services based Lightweight Container
|
This is a umbrella project for gRPC-services based Lightweight Container
|
||||||
@ -68,6 +68,7 @@ install -m 0640 ./conf/isulad.pc %{buildroot}/%{_libdir}/pkgconfig/
|
|||||||
|
|
||||||
install -d $RPM_BUILD_ROOT/%{_bindir}
|
install -d $RPM_BUILD_ROOT/%{_bindir}
|
||||||
install -m 0755 ./src/isula %{buildroot}/%{_bindir}/isula
|
install -m 0755 ./src/isula %{buildroot}/%{_bindir}/isula
|
||||||
|
install -m 0755 ./src/isulad-shim %{buildroot}/%{_bindir}/isulad-shim
|
||||||
install -m 0755 ./src/isulad %{buildroot}/%{_bindir}/isulad
|
install -m 0755 ./src/isulad %{buildroot}/%{_bindir}/isulad
|
||||||
|
|
||||||
install -d $RPM_BUILD_ROOT/%{_includedir}/isulad
|
install -d $RPM_BUILD_ROOT/%{_includedir}/isulad
|
||||||
|
|||||||
@ -13,7 +13,6 @@ list(REMOVE_DUPLICATES JSON_FILES)
|
|||||||
set(CHECKED_INCLUDE_DIRS
|
set(CHECKED_INCLUDE_DIRS
|
||||||
${STD_HEADER_CTYPE}
|
${STD_HEADER_CTYPE}
|
||||||
${STD_HEADER_SYS_PARAM}
|
${STD_HEADER_SYS_PARAM}
|
||||||
${LIBSECUREC_INCLUDE_DIR}
|
|
||||||
${LIBYAJL_INCLUDE_DIR}
|
${LIBYAJL_INCLUDE_DIR}
|
||||||
${HTTP_PARSER_INCLUDE_DIR}
|
${HTTP_PARSER_INCLUDE_DIR}
|
||||||
${OPENSSL_INCLUDE_DIR}
|
${OPENSSL_INCLUDE_DIR}
|
||||||
@ -123,7 +122,7 @@ target_include_directories(libisula PUBLIC
|
|||||||
|
|
||||||
# set libisula FLAGS
|
# set libisula FLAGS
|
||||||
set_target_properties(libisula PROPERTIES PREFIX "")
|
set_target_properties(libisula PROPERTIES PREFIX "")
|
||||||
target_link_libraries(libisula ${LIBYAJL_LIBRARY} ${LIBSECUREC_LIBRARY})
|
target_link_libraries(libisula ${LIBYAJL_LIBRARY} ${SELINUX_LIBRARY})
|
||||||
|
|
||||||
if (GRPC_CONNECTOR)
|
if (GRPC_CONNECTOR)
|
||||||
target_link_libraries(libisula -Wl,--as-needed -lstdc++ -lcrypto)
|
target_link_libraries(libisula -Wl,--as-needed -lstdc++ -lcrypto)
|
||||||
@ -143,6 +142,18 @@ target_include_directories(isula PUBLIC ${ISULA_INCS} ${SHARED_INCS})
|
|||||||
target_link_libraries(isula libisula -lpthread)
|
target_link_libraries(isula libisula -lpthread)
|
||||||
# ------ build isula finish -------
|
# ------ build isula finish -------
|
||||||
|
|
||||||
|
# ------ build isulad-shim -------
|
||||||
|
add_executable(isulad-shim
|
||||||
|
${ISULAD_SHIM_SRCS}
|
||||||
|
${CMAKE_BINARY_DIR}/json/shim_client_process_state.c
|
||||||
|
${CMAKE_BINARY_DIR}/json/json_common.c
|
||||||
|
${commonjsonsrcs}
|
||||||
|
)
|
||||||
|
target_include_directories(isulad-shim PUBLIC ${ISULAD_SHIM_INCS} ${SHARED_INCS})
|
||||||
|
target_link_libraries(isulad-shim ${LIBYAJL_LIBRARY} -lpthread)
|
||||||
|
|
||||||
|
# ------ build isula-shim finish -------
|
||||||
|
|
||||||
# ------ build isulad -------
|
# ------ build isulad -------
|
||||||
add_subdirectory(services)
|
add_subdirectory(services)
|
||||||
add_subdirectory(image)
|
add_subdirectory(image)
|
||||||
@ -201,7 +212,7 @@ target_include_directories(isulad PUBLIC
|
|||||||
${WEBSOCKET_SERVICE_INCS}
|
${WEBSOCKET_SERVICE_INCS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(isulad ${LIBYAJL_LIBRARY} ${LIBSECUREC_LIBRARY} ${SYSTEMD_LIBRARY})
|
target_link_libraries(isulad ${LIBYAJL_LIBRARY} ${SYSTEMD_LIBRARY} ${SELINUX_LIBRARY})
|
||||||
target_link_libraries(isulad -ldl ${ZLIB_LIBRARY} -lpthread libhttpclient)
|
target_link_libraries(isulad -ldl ${ZLIB_LIBRARY} -lpthread libhttpclient)
|
||||||
if (ENABLE_EMBEDDED_IMAGE)
|
if (ENABLE_EMBEDDED_IMAGE)
|
||||||
target_link_libraries(isulad ${SQLITE3_LIBRARY})
|
target_link_libraries(isulad ${SQLITE3_LIBRARY})
|
||||||
@ -237,5 +248,7 @@ install(TARGETS libisula
|
|||||||
LIBRARY DESTINATION ${LIB_INSTALL_DIR_DEFAULT} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
|
LIBRARY DESTINATION ${LIB_INSTALL_DIR_DEFAULT} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
|
||||||
install(TARGETS isula
|
install(TARGETS isula
|
||||||
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
|
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
|
||||||
|
install(TARGETS isulad-shim
|
||||||
|
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
|
||||||
install(TARGETS isulad
|
install(TARGETS isulad
|
||||||
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
|
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
|
||||||
|
|||||||
@ -84,11 +84,10 @@ message Container_info {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message Event {
|
message Event {
|
||||||
string id = 1;
|
google.protobuf.Timestamp timestamp = 1;
|
||||||
EventType type = 2;
|
string opt = 2;
|
||||||
int32 pid = 3;
|
string id = 3;
|
||||||
uint32 exit_status = 4;
|
map<string, string> annotations= 4;
|
||||||
google.protobuf.Timestamp timestamp = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
service ContainerService {
|
service ContainerService {
|
||||||
|
|||||||
@ -8,3 +8,7 @@ set(ISULA_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMD_ISULA_INCS} PARENT_SCOPE)
|
|||||||
add_subdirectory(isulad)
|
add_subdirectory(isulad)
|
||||||
set(ISULAD_SRCS ${comm_srcs} ${CMD_ISULAD_SRCS} PARENT_SCOPE)
|
set(ISULAD_SRCS ${comm_srcs} ${CMD_ISULAD_SRCS} PARENT_SCOPE)
|
||||||
set(ISULAD_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMD_ISULAD_INCS} PARENT_SCOPE)
|
set(ISULAD_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMD_ISULAD_INCS} PARENT_SCOPE)
|
||||||
|
|
||||||
|
add_subdirectory(isulad-shim)
|
||||||
|
set(ISULAD_SHIM_SRCS ${CMD_ISULAD_SHIM_SRCS} PARENT_SCOPE)
|
||||||
|
set(ISULAD_SHIM_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMD_ISULAD_SHIM_INCS} PARENT_SCOPE)
|
||||||
|
|||||||
@ -737,6 +737,23 @@ int command_convert_memswapbytes(command_option_t *option, const char *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int command_convert_swappiness(command_option_t *option, const char *arg)
|
||||||
|
{
|
||||||
|
if (option == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (strcmp(arg, "-1") == 0) {
|
||||||
|
*(int64_t *)(option->data) = -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (util_parse_byte_size_string(arg, option->data) || (*(int64_t *)(option->data)) < 0 ||
|
||||||
|
(*(int64_t *)(option->data)) > 100) {
|
||||||
|
COMMAND_ERROR("Invalid value \"%s\" for flag --%s. Valid memory swappiness range is 0-100", arg, option->large);
|
||||||
|
return EINVALIDARGS;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
size_t ulimit_array_len(host_config_ulimits_element **default_ulimit)
|
size_t ulimit_array_len(host_config_ulimits_element **default_ulimit)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|||||||
@ -21,6 +21,10 @@
|
|||||||
|
|
||||||
#include "host_config.h"
|
#include "host_config.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef COMMANDER_MAX_OPTIONS
|
#ifndef COMMANDER_MAX_OPTIONS
|
||||||
#define COMMANDER_MAX_OPTIONS 64
|
#define COMMANDER_MAX_OPTIONS 64
|
||||||
#endif
|
#endif
|
||||||
@ -112,5 +116,11 @@ int check_default_ulimit_type(const char *type);
|
|||||||
|
|
||||||
void free_default_ulimit(host_config_ulimits_element **default_ulimit);
|
void free_default_ulimit(host_config_ulimits_element **default_ulimit);
|
||||||
|
|
||||||
|
int command_convert_swappiness(command_option_t *option, const char *arg);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* COMMANDER_H */
|
#endif /* COMMANDER_H */
|
||||||
|
|
||||||
|
|||||||
@ -135,6 +135,9 @@ int client_arguments_init(struct client_arguments *args)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// default swappiness should be set to -1
|
||||||
|
args->cr.swappiness = -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,10 @@
|
|||||||
#include "json_common.h"
|
#include "json_common.h"
|
||||||
#include "isula_connect.h"
|
#include "isula_connect.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/* max arguments can be specify in client */
|
/* max arguments can be specify in client */
|
||||||
#define MAX_CLIENT_ARGS 1000
|
#define MAX_CLIENT_ARGS 1000
|
||||||
|
|
||||||
@ -39,6 +43,12 @@ struct custom_configs {
|
|||||||
/* environment variables file */
|
/* environment variables file */
|
||||||
char **env_file;
|
char **env_file;
|
||||||
|
|
||||||
|
/* label */
|
||||||
|
char **label;
|
||||||
|
|
||||||
|
/* label file */
|
||||||
|
char **label_file;
|
||||||
|
|
||||||
/* hugepage limits */
|
/* hugepage limits */
|
||||||
char **hugepage_limits;
|
char **hugepage_limits;
|
||||||
|
|
||||||
@ -202,6 +212,7 @@ struct args_cgroup_resources {
|
|||||||
int64_t memory_swap;
|
int64_t memory_swap;
|
||||||
int64_t memory_reservation;
|
int64_t memory_reservation;
|
||||||
int64_t kernel_memory_limit;
|
int64_t kernel_memory_limit;
|
||||||
|
int64_t swappiness;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct client_arguments {
|
struct client_arguments {
|
||||||
@ -322,15 +333,15 @@ struct client_arguments {
|
|||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "host", 'H', &(cmdargs).socket, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "host", 'H', &(cmdargs).socket, \
|
||||||
"Daemon socket(s) to connect to", command_valid_socket }, \
|
"Daemon socket(s) to connect to", command_valid_socket }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "tls", 0, &(cmdargs).tls, \
|
{ CMD_OPT_TYPE_BOOL, false, "tls", 0, &(cmdargs).tls, \
|
||||||
"Use TLS; implied by --tlsverify", NULL}, \
|
"Use TLS; implied by --tlsverify", NULL}, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "tlsverify", 0, &(cmdargs).tls_verify, \
|
{ CMD_OPT_TYPE_BOOL, false, "tlsverify", 0, &(cmdargs).tls_verify, \
|
||||||
"Use TLS and verify the remote", NULL}, \
|
"Use TLS and verify the remote", NULL}, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "tlscacert", 0, &(cmdargs).ca_file, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "tlscacert", 0, &(cmdargs).ca_file, \
|
||||||
"Trust certs signed only by this CA (default \"/root/.iSulad/ca.pem\")", NULL }, \
|
"Trust certs signed only by this CA (default \"/root/.iSulad/ca.pem\")", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "tlscert", 0, &(cmdargs).cert_file, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "tlscert", 0, &(cmdargs).cert_file, \
|
||||||
"Path to TLS certificate file (default \"/root/.iSulad/cert.pem\")", NULL }, \
|
"Path to TLS certificate file (default \"/root/.iSulad/cert.pem\")", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "tlskey", 0, &(cmdargs).key_file, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "tlskey", 0, &(cmdargs).key_file, \
|
||||||
"Path to TLS key file (default \"/root/.iSulad/key.pem\")", NULL }, \
|
"Path to TLS key file (default \"/root/.iSulad/key.pem\")", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "help", 0, NULL, "Print usage", NULL }
|
{ CMD_OPT_TYPE_STRING, false, "help", 0, NULL, "Print usage", NULL }
|
||||||
|
|
||||||
#define VERSION_OPTIONS(cmdargs) \
|
#define VERSION_OPTIONS(cmdargs) \
|
||||||
@ -350,5 +361,9 @@ extern void client_print_error(uint32_t cc, uint32_t server_errono, const char *
|
|||||||
|
|
||||||
extern client_connect_config_t get_connect_config(const struct client_arguments *args);
|
extern client_connect_config_t get_connect_config(const struct client_arguments *args);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __ISULA_ARGUMENTS_H */
|
#endif /* __ISULA_ARGUMENTS_H */
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
* Description: provide container create functions
|
* Description: provide container create functions
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdio_ext.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -37,7 +38,7 @@ const char g_cmd_create_desc[] = "Create a new container";
|
|||||||
const char g_cmd_create_usage[] = "create [OPTIONS] --external-rootfs=PATH|IMAGE [COMMAND] [ARG...]";
|
const char g_cmd_create_usage[] = "create [OPTIONS] --external-rootfs=PATH|IMAGE [COMMAND] [ARG...]";
|
||||||
|
|
||||||
struct client_arguments g_cmd_create_args = {
|
struct client_arguments g_cmd_create_args = {
|
||||||
.runtime = "lcr",
|
.runtime = "",
|
||||||
.restart = "no",
|
.restart = "no",
|
||||||
.log_file_size = "1MB",
|
.log_file_size = "1MB",
|
||||||
.log_file_rotate = 7,
|
.log_file_rotate = 7,
|
||||||
@ -172,6 +173,8 @@ static int request_pack_host_config_cgroup(const struct client_arguments *args,
|
|||||||
/* kernel memory limit */
|
/* kernel memory limit */
|
||||||
hostconfig->cr->kernel_memory = args->cr.kernel_memory_limit;
|
hostconfig->cr->kernel_memory = args->cr.kernel_memory_limit;
|
||||||
|
|
||||||
|
hostconfig->cr->swappiness = args->cr.swappiness;
|
||||||
|
|
||||||
request_pack_host_config_limit(args, hostconfig);
|
request_pack_host_config_limit(args, hostconfig);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -414,6 +417,149 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool validate_label(const char *label)
|
||||||
|
{
|
||||||
|
bool ret = true;
|
||||||
|
char **arr = util_string_split_n(label, '=', 2);
|
||||||
|
if (arr == NULL) {
|
||||||
|
ERROR("Failed to split label string");
|
||||||
|
ret = false;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(arr[0]) == 0) {
|
||||||
|
ERROR("Invalid label: %s, empty name", label);
|
||||||
|
ret = false;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
util_free_array(arr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int request_pack_custom_label(struct client_arguments *args, isula_container_config_t *conf)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (args->custom_conf.label == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < util_array_len((const char **)(args->custom_conf.label)); i++) {
|
||||||
|
if (!validate_label(args->custom_conf.label[i])) {
|
||||||
|
COMMAND_ERROR("Invalid label '%s': empty name", args->custom_conf.label[i]);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (util_array_append(&conf->label, args->custom_conf.label[i]) != 0) {
|
||||||
|
COMMAND_ERROR("Failed to append custom config label list");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
util_free_array(args->custom_conf.label);
|
||||||
|
args->custom_conf.label = conf->label; /* make sure args->custom_conf.label point to valid memory. */
|
||||||
|
conf->label_len = util_array_len((const char **)(conf->label));
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_label_from_file(const char *path, size_t file_size, isula_container_config_t *conf)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
FILE *fp = NULL;
|
||||||
|
char *buf = NULL;
|
||||||
|
size_t len;
|
||||||
|
ssize_t num;
|
||||||
|
|
||||||
|
if (file_size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fp = fopen(path, "re");
|
||||||
|
if (fp == NULL) {
|
||||||
|
ERROR("Failed to open '%s'", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
__fsetlocking(fp, FSETLOCKING_BYCALLER);
|
||||||
|
num = getline(&buf, &len, fp);
|
||||||
|
while (num != -1) {
|
||||||
|
size_t len = strlen(buf);
|
||||||
|
if (len == 1) {
|
||||||
|
num = getline(&buf, &len, fp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
buf[len - 1] = '\0';
|
||||||
|
if (!validate_label(buf)) {
|
||||||
|
COMMAND_ERROR("Invalid label '%s': empty name", buf);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (util_array_append(&conf->label, buf) != 0) {
|
||||||
|
ERROR("Failed to append label");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
num = getline(&buf, &len, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(buf);
|
||||||
|
fclose(fp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int append_labels_to_conf(const char *label_file, isula_container_config_t *conf)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
size_t file_size;
|
||||||
|
|
||||||
|
if (!util_file_exists(label_file)) {
|
||||||
|
COMMAND_ERROR("label file not exists: %s", label_file);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
file_size = util_file_size(label_file);
|
||||||
|
if (file_size > REGULAR_FILE_SIZE) {
|
||||||
|
COMMAND_ERROR("label file '%s', size exceed limit: %lld", label_file, REGULAR_FILE_SIZE);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read_label_from_file(label_file, file_size, conf) != 0) {
|
||||||
|
COMMAND_ERROR("failed to read label from file: %s", label_file);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int request_pack_custom_label_file(const struct client_arguments *args, isula_container_config_t *conf)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
size_t i;
|
||||||
|
char **label_files = args->custom_conf.label_file;
|
||||||
|
size_t label_files_size = util_array_len((const char **)label_files);
|
||||||
|
if (label_files_size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < label_files_size; i++) {
|
||||||
|
if (append_labels_to_conf(label_files[i], conf) != 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
conf->label_len = util_array_len((const char **)(conf->label));
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void request_pack_custom_user(const struct client_arguments *args, isula_container_config_t *conf)
|
static void request_pack_custom_user(const struct client_arguments *args, isula_container_config_t *conf)
|
||||||
{
|
{
|
||||||
if (args->custom_conf.user != NULL) {
|
if (args->custom_conf.user != NULL) {
|
||||||
@ -577,17 +723,27 @@ static int request_pack_custom_conf(struct client_arguments *args, isula_contain
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure --env has higher priority than --env-file */
|
/* make sure --env has higher priority than --env-file */
|
||||||
if (request_pack_custom_env(args, conf) != 0) {
|
if (request_pack_custom_env(args, conf) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* append labels from label file */
|
||||||
|
if (request_pack_custom_label_file(args, conf) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* make sure --label has higher priority than --label-file */
|
||||||
|
if (request_pack_custom_label(args, conf) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* user and group */
|
/* user and group */
|
||||||
request_pack_custom_user(args, conf);
|
request_pack_custom_user(args, conf);
|
||||||
|
|
||||||
request_pack_custom_hostname(args, conf);
|
request_pack_custom_hostname(args, conf);
|
||||||
|
|
||||||
/* alldevices */
|
/* all devices */
|
||||||
request_pack_custom_all_devices(args, conf);
|
request_pack_custom_all_devices(args, conf);
|
||||||
|
|
||||||
/* system container */
|
/* system container */
|
||||||
@ -1225,6 +1381,7 @@ out:
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int callback_annotation(command_option_t *option, const char *value)
|
int callback_annotation(command_option_t *option, const char *value)
|
||||||
{
|
{
|
||||||
struct client_arguments *args = (struct client_arguments *)option->data;
|
struct client_arguments *args = (struct client_arguments *)option->data;
|
||||||
|
|||||||
@ -17,137 +17,147 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CREATE_OPTIONS(cmdargs) \
|
#define CREATE_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "accel", 0, &(cmdargs).custom_conf.accel, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "accel", 0, &(cmdargs).custom_conf.accel, \
|
||||||
"Accelerator bindings (format: [<name>=]<runtime>[@<driver>[,<options>]])", \
|
"Accelerator bindings (format: [<name>=]<runtime>[@<driver>[,<options>]])", \
|
||||||
command_append_array }, \
|
command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "read-only", 0, &(cmdargs).custom_conf.readonly, \
|
{ CMD_OPT_TYPE_BOOL, false, "read-only", 0, &(cmdargs).custom_conf.readonly, \
|
||||||
"Make container rootfs readonly", NULL }, \
|
"Make container rootfs readonly", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "cap-add", 0, &(cmdargs).custom_conf.cap_adds, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "cap-add", 0, &(cmdargs).custom_conf.cap_adds, \
|
||||||
"Add Linux capabilities ('ALL' to add all capabilities)", command_append_array }, \
|
"Add Linux capabilities ('ALL' to add all capabilities)", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "cap-drop", 0, &(cmdargs).custom_conf.cap_drops, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "cap-drop", 0, &(cmdargs).custom_conf.cap_drops, \
|
||||||
"Drop Linux capabilities ('ALL' to drop all capabilities)", command_append_array }, \
|
"Drop Linux capabilities ('ALL' to drop all capabilities)", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-shares", 0, &(cmdargs).cr.cpu_shares, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-shares", 0, &(cmdargs).cr.cpu_shares, \
|
||||||
"CPU shares (relative weight)", command_convert_llong }, \
|
"CPU shares (relative weight)", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-period", 0, &(cmdargs).cr.cpu_period, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-period", 0, &(cmdargs).cr.cpu_period, \
|
||||||
"Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \
|
"Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-quota", 0, &(cmdargs).cr.cpu_quota, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-quota", 0, &(cmdargs).cr.cpu_quota, \
|
||||||
"Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \
|
"Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "cpuset-cpus", 0, &(cmdargs).cr.cpuset_cpus, \
|
{ CMD_OPT_TYPE_STRING, false, "cpuset-cpus", 0, &(cmdargs).cr.cpuset_cpus, \
|
||||||
"CPUs in which to allow execution (e.g. 0-3, 0,1)", NULL }, \
|
"CPUs in which to allow execution (e.g. 0-3, 0,1)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "cpuset-mems", 0, &(cmdargs).cr.cpuset_mems, \
|
{ CMD_OPT_TYPE_STRING, false, "cpuset-mems", 0, &(cmdargs).cr.cpuset_mems, \
|
||||||
"MEMs in which to allow execution (0-3, 0,1)", NULL }, \
|
"MEMs in which to allow execution (0-3, 0,1)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "device-read-bps", 0, &(cmdargs).custom_conf.blkio_throttle_read_bps_device, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "device-read-bps", 0, &(cmdargs).custom_conf.blkio_throttle_read_bps_device, \
|
||||||
"Limit read rate (bytes per second) from a device (default [])", command_append_array }, \
|
"Limit read rate (bytes per second) from a device (default [])", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "device-write-bps", 0, &(cmdargs).custom_conf.blkio_throttle_write_bps_device, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "device-write-bps", 0, &(cmdargs).custom_conf.blkio_throttle_write_bps_device, \
|
||||||
"Limit write rate (bytes per second) to a device (default [])", command_append_array }, \
|
"Limit write rate (bytes per second) to a device (default [])", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "oom-score-adj", 0, &(cmdargs).cr.oom_score_adj, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "oom-score-adj", 0, &(cmdargs).cr.oom_score_adj, \
|
||||||
"Tune host's OOM preferences (-1000 to 1000)", command_convert_llong }, \
|
"Tune host's OOM preferences (-1000 to 1000)", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "device", 0, &(cmdargs).custom_conf.devices, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "device", 0, &(cmdargs).custom_conf.devices, \
|
||||||
"Add a host device to the container", command_append_array }, \
|
"Add a host device to the container", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "env", 'e', &(cmdargs).custom_conf.env, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "env", 'e', &(cmdargs).custom_conf.env, \
|
||||||
"Set environment variables", command_append_array }, \
|
"Set environment variables", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "env-file", 0, &(cmdargs).custom_conf.env_file, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "env-file", 0, &(cmdargs).custom_conf.env_file, \
|
||||||
"Read in a file of environment variables", command_append_array }, \
|
"Read in a file of environment variables", command_append_array }, \
|
||||||
|
{ CMD_OPT_TYPE_CALLBACK, false, "label", 'l', &(cmdargs).custom_conf.label, \
|
||||||
|
"Set metadata on container (default [])", command_append_array }, \
|
||||||
|
{ CMD_OPT_TYPE_CALLBACK, false, "label-file", 0, &(cmdargs).custom_conf.label_file, \
|
||||||
|
"Read in a line delimited file of labels (default [])", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "entrypoint", 0, &(cmdargs).custom_conf.entrypoint, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "entrypoint", 0, &(cmdargs).custom_conf.entrypoint, \
|
||||||
"Entrypoint to run when starting the container", NULL }, \
|
"Entrypoint to run when starting the container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "external-rootfs", 0, &(cmdargs).external_rootfs, \
|
{ CMD_OPT_TYPE_STRING, false, "external-rootfs", 0, &(cmdargs).external_rootfs, \
|
||||||
"Specify the custom rootfs that is not managed by isulad for the container, directory or block device", NULL }, \
|
"Specify the custom rootfs that is not managed by isulad for the container, directory or block device", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "files-limit", 0, &(cmdargs).custom_conf.files_limit, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "files-limit", 0, &(cmdargs).custom_conf.files_limit, \
|
||||||
"Tune container files limit (set -1 for unlimited)", command_convert_llong }, \
|
"Tune container files limit (set -1 for unlimited)", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "hook-spec", 0, &(cmdargs).custom_conf.hook_spec, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "hook-spec", 0, &(cmdargs).custom_conf.hook_spec, \
|
||||||
"File containing hook definition(prestart, poststart, poststop)", NULL }, \
|
"File containing hook definition(prestart, poststart, poststop)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "hostname", 'h', &(cmdargs).custom_conf.hostname, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "hostname", 'h', &(cmdargs).custom_conf.hostname, \
|
||||||
"Container host name", NULL }, \
|
"Container host name", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "add-host", 0, &(cmdargs).custom_conf.extra_hosts, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "add-host", 0, &(cmdargs).custom_conf.extra_hosts, \
|
||||||
"Add a custom host-to-IP mapping (host:ip)", command_append_array }, \
|
"Add a custom host-to-IP mapping (host:ip)", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "dns", 0, &(cmdargs).custom_conf.dns, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "dns", 0, &(cmdargs).custom_conf.dns, \
|
||||||
"Set custom DNS servers", command_append_array }, \
|
"Set custom DNS servers", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "dns-opt", 0, &(cmdargs).custom_conf.dns_options, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "dns-opt", 0, &(cmdargs).custom_conf.dns_options, \
|
||||||
"Set DNS options", command_append_array }, \
|
"Set DNS options", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "dns-search", 0, &(cmdargs).custom_conf.dns_search, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "dns-search", 0, &(cmdargs).custom_conf.dns_search, \
|
||||||
"Set custom DNS search domains", command_append_array }, \
|
"Set custom DNS search domains", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "user-remap", 0, &(cmdargs).custom_conf.user_remap, \
|
{ CMD_OPT_TYPE_STRING, false, "user-remap", 0, &(cmdargs).custom_conf.user_remap, \
|
||||||
"Set user remap for container", NULL }, \
|
"Set user remap for container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "ipc", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_IPC], \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "ipc", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_IPC], \
|
||||||
"IPC namespace to use", NULL }, \
|
"IPC namespace to use", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "shm-size", 0, &(cmdargs).custom_conf.shm_size, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "shm-size", 0, &(cmdargs).custom_conf.shm_size, \
|
||||||
"Size of /dev/shm, default value is 64MB", command_convert_membytes }, \
|
"Size of /dev/shm, default value is 64MB", command_convert_membytes }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "kernel-memory", 0, &(cmdargs).cr.kernel_memory_limit, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "kernel-memory", 0, &(cmdargs).cr.kernel_memory_limit, \
|
||||||
"Kernel memory limit", command_convert_membytes }, \
|
"Kernel memory limit", command_convert_membytes }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "hugetlb-limit", 0, &(cmdargs).custom_conf.hugepage_limits, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "hugetlb-limit", 0, &(cmdargs).custom_conf.hugepage_limits, \
|
||||||
"Huge page limit (format: [size:]<limit>, e.g. --hugetlb-limit 2MB:32MB)", command_append_array }, \
|
"Huge page limit (format: [size:]<limit>, e.g. --hugetlb-limit 2MB:32MB)", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "log-opt", 0, &(cmdargs), \
|
{ CMD_OPT_TYPE_CALLBACK, false, "log-opt", 0, &(cmdargs), \
|
||||||
"Container log options, value formate: key=value", callback_log_opt }, \
|
"Container log options, value formate: key=value", callback_log_opt }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "memory", 'm', &(cmdargs).cr.memory_limit, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "memory", 'm', &(cmdargs).cr.memory_limit, \
|
||||||
"Memory limit", command_convert_membytes }, \
|
"Memory limit", command_convert_membytes }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "memory-reservation", 0, &(cmdargs).cr.memory_reservation, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "memory-reservation", 0, &(cmdargs).cr.memory_reservation, \
|
||||||
"Memory soft limit", command_convert_membytes }, \
|
"Memory soft limit", command_convert_membytes }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "memory-swap", 0, &(cmdargs).cr.memory_swap, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "memory-swap", 0, &(cmdargs).cr.memory_swap, \
|
||||||
"Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \
|
"Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \
|
||||||
|
{ CMD_OPT_TYPE_CALLBACK, false, "memory-swappiness", 0, &(cmdargs).cr.swappiness, \
|
||||||
|
"Tune container memory swappiness (0 to 100) (default -1)", command_convert_swappiness }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "mount", 0, &(cmdargs).custom_conf.mounts, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "mount", 0, &(cmdargs).custom_conf.mounts, \
|
||||||
"Attach a filesystem mount to the service", command_append_array }, \
|
"Attach a filesystem mount to the service", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "group-add", 0, &(cmdargs).custom_conf.group_add, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "group-add", 0, &(cmdargs).custom_conf.group_add, \
|
||||||
"Add additional groups to join", command_append_array }, \
|
"Add additional groups to join", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "name", 'n', &(cmdargs).name, "Name of the container", NULL }, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "name", 'n', &(cmdargs).name, "Name of the container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "net", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_NET], \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "net", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_NET], \
|
||||||
"Connect a container to a network", NULL }, \
|
"Connect a container to a network", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "pid", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_PID], \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "pid", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_PID], \
|
||||||
"PID namespace to use", NULL }, \
|
"PID namespace to use", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "pids-limit", 0, &(cmdargs).custom_conf.pids_limit, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "pids-limit", 0, &(cmdargs).custom_conf.pids_limit, \
|
||||||
"Tune container pids limit (set -1 for unlimited)", command_convert_llong }, \
|
"Tune container pids limit (set -1 for unlimited)", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "privileged", 0, &(cmdargs).custom_conf.privileged, \
|
{ CMD_OPT_TYPE_BOOL, false, "privileged", 0, &(cmdargs).custom_conf.privileged, \
|
||||||
"Give extended privileges to this container", NULL }, \
|
"Give extended privileges to this container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "tty", 't', &(cmdargs).custom_conf.tty, "Allocate a pseudo-TTY", NULL }, \
|
{ CMD_OPT_TYPE_BOOL, false, "tty", 't', &(cmdargs).custom_conf.tty, "Allocate a pseudo-TTY", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "restart", 0, &(cmdargs).restart, \
|
{ CMD_OPT_TYPE_STRING, false, "restart", 0, &(cmdargs).restart, \
|
||||||
"Restart policy to apply when a container exits(no, always, on-reboot, on-failure[:max-retries])", NULL }, \
|
"Restart policy to apply when a container exits(no, always, on-reboot, on-failure[:max-retries])", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "host-channel", 0, &(cmdargs).host_channel, \
|
{ CMD_OPT_TYPE_STRING, false, "host-channel", 0, &(cmdargs).host_channel, \
|
||||||
"Create share memory between host and container", NULL }, \
|
"Create share memory between host and container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "runtime", 'R', &(cmdargs).runtime, \
|
{ CMD_OPT_TYPE_STRING, false, "runtime", 'R', &(cmdargs).runtime, \
|
||||||
"Runtime to use for containers(default: lcr)", NULL }, \
|
"Runtime to use for containers(default: lcr)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "user", 'u', &(cmdargs).custom_conf.user, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "user", 'u', &(cmdargs).custom_conf.user, \
|
||||||
"Username or UID (format: <name|uid>[:<group|gid>])", NULL }, \
|
"Username or UID (format: <name|uid>[:<group|gid>])", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "uts", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_UTS], \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "uts", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_UTS], \
|
||||||
"UTS namespace to use", NULL }, \
|
"UTS namespace to use", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "volume", 'v', &(cmdargs).custom_conf.volumes, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "volume", 'v', &(cmdargs).custom_conf.volumes, \
|
||||||
"Bind mount a volume", command_append_array }, \
|
"Bind mount a volume", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "annotation", 0, &(cmdargs), \
|
{ CMD_OPT_TYPE_CALLBACK, false, "annotation", 0, &(cmdargs), \
|
||||||
"Set annotations on a container", callback_annotation }, \
|
"Set annotations on a container", callback_annotation }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "workdir", 0, &(cmdargs).custom_conf.workdir, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "workdir", 0, &(cmdargs).custom_conf.workdir, \
|
||||||
"Working directory inside the container", NULL }, \
|
"Working directory inside the container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "system-container", 0, &(cmdargs).custom_conf.system_container, \
|
{ CMD_OPT_TYPE_BOOL, false, "system-container", 0, &(cmdargs).custom_conf.system_container, \
|
||||||
"Extend some features only needed by running system container", NULL }, \
|
"Extend some features only needed by running system container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "oom-kill-disable", 0, &(cmdargs).custom_conf.oom_kill_disable, \
|
{ CMD_OPT_TYPE_BOOL, false, "oom-kill-disable", 0, &(cmdargs).custom_conf.oom_kill_disable, \
|
||||||
"Disable OOM Killer", NULL }, \
|
"Disable OOM Killer", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "security-opt", 0, &(cmdargs).custom_conf.security, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "security-opt", 0, &(cmdargs).custom_conf.security, \
|
||||||
"Security Options (default [])", command_append_array }, \
|
"Security Options (default [])", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "storage-opt", 0, &(cmdargs).custom_conf.storage_opts, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "storage-opt", 0, &(cmdargs).custom_conf.storage_opts, \
|
||||||
"Storage driver options for the container", command_append_array }, \
|
"Storage driver options for the container", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "health-cmd", 0, &(cmdargs).custom_conf.health_cmd, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "health-cmd", 0, &(cmdargs).custom_conf.health_cmd, \
|
||||||
"Command to run to check health", NULL }, \
|
"Command to run to check health", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "sysctl", 0, &(cmdargs).custom_conf.sysctls, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "sysctl", 0, &(cmdargs).custom_conf.sysctls, \
|
||||||
"Sysctl options", command_append_array }, \
|
"Sysctl options", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "env-target-file", 0, &(cmdargs).custom_conf.env_target_file, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "env-target-file", 0, &(cmdargs).custom_conf.env_target_file, \
|
||||||
"Export env to target file path in rootfs", NULL }, \
|
"Export env to target file path in rootfs", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING_DUP, false, "cgroup-parent", 0, &(cmdargs).custom_conf.cgroup_parent, \
|
{ CMD_OPT_TYPE_STRING_DUP, false, "cgroup-parent", 0, &(cmdargs).custom_conf.cgroup_parent, \
|
||||||
"Optional parent cgroup for the container", NULL }, \
|
"Optional parent cgroup for the container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "health-interval", 0, &(cmdargs).custom_conf.health_interval, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "health-interval", 0, &(cmdargs).custom_conf.health_interval, \
|
||||||
"Time between running the check (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \
|
"Time between running the check (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "health-retries", 0, &(cmdargs).custom_conf.health_retries, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "health-retries", 0, &(cmdargs).custom_conf.health_retries, \
|
||||||
"Consecutive failures needed to report unhealthy (default 3)", command_convert_int }, \
|
"Consecutive failures needed to report unhealthy (default 3)", command_convert_int }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "health-timeout", 0, &(cmdargs).custom_conf.health_timeout, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "health-timeout", 0, &(cmdargs).custom_conf.health_timeout, \
|
||||||
"Maximum time to allow one check to run (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \
|
"Maximum time to allow one check to run (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "health-start-period", 0, &(cmdargs).custom_conf.health_start_period, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "health-start-period", 0, &(cmdargs).custom_conf.health_start_period, \
|
||||||
"Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) " \
|
"Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) " \
|
||||||
"(default 0s)", command_convert_nanoseconds }, \
|
"(default 0s)", command_convert_nanoseconds }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "no-healthcheck", 0, &(cmdargs).custom_conf.no_healthcheck, \
|
{ CMD_OPT_TYPE_BOOL, false, "no-healthcheck", 0, &(cmdargs).custom_conf.no_healthcheck, \
|
||||||
"Disable any container-specified HEALTHCHECK", NULL }, \
|
"Disable any container-specified HEALTHCHECK", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "health-exit-on-unhealthy", 0, &(cmdargs).custom_conf.exit_on_unhealthy, \
|
{ CMD_OPT_TYPE_BOOL, false, "health-exit-on-unhealthy", 0, &(cmdargs).custom_conf.exit_on_unhealthy, \
|
||||||
"Kill the container when it is detected to be unhealthy", NULL }, \
|
"Kill the container when it is detected to be unhealthy", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "ns-change-opt", 0, &(cmdargs).custom_conf.ns_change_opt, \
|
{ CMD_OPT_TYPE_STRING, false, "ns-change-opt", 0, &(cmdargs).custom_conf.ns_change_opt, \
|
||||||
"Namespaced kernel param options for system container (default [])", NULL }, \
|
"Namespaced kernel param options for system container (default [])", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "ulimit", 0, &(cmdargs).custom_conf.ulimits, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "ulimit", 0, &(cmdargs).custom_conf.ulimits, \
|
||||||
"Ulimit options (default [])", command_append_array }
|
"Ulimit options (default [])", command_append_array }
|
||||||
|
|
||||||
#define CREATE_EXTEND_OPTIONS(cmdargs) \
|
#define CREATE_EXTEND_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "interactive", 'i', &(cmdargs).custom_conf.open_stdin, \
|
{ CMD_OPT_TYPE_BOOL, false, "interactive", 'i', &(cmdargs).custom_conf.open_stdin, \
|
||||||
@ -169,5 +179,9 @@ int callback_annotation(command_option_t *option, const char *value);
|
|||||||
|
|
||||||
int cmd_create_main(int argc, const char **argv);
|
int cmd_create_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_CREATE_H */
|
#endif /* __CMD_CREATE_H */
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,10 @@
|
|||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
#include "wait.h"
|
#include "wait.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define KILL_OPTIONS(cmdargs) \
|
#define KILL_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "signal", 's', &(cmdargs).signal, \
|
{ CMD_OPT_TYPE_STRING, false, "signal", 's', &(cmdargs).signal, \
|
||||||
"Signal to send to the container (default \"SIGKILL\")", NULL }
|
"Signal to send to the container (default \"SIGKILL\")", NULL }
|
||||||
@ -26,5 +30,10 @@ extern const char g_cmd_kill_desc[];
|
|||||||
extern const char g_cmd_kill_usage[];
|
extern const char g_cmd_kill_usage[];
|
||||||
extern struct client_arguments g_cmd_kill_args;
|
extern struct client_arguments g_cmd_kill_args;
|
||||||
int cmd_kill_main(int argc, const char **argv);
|
int cmd_kill_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,18 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_rename_desc[];
|
extern const char g_cmd_rename_desc[];
|
||||||
extern const char g_cmd_rename_usage[];
|
extern const char g_cmd_rename_usage[];
|
||||||
extern struct client_arguments g_cmd_rename_args;
|
extern struct client_arguments g_cmd_rename_args;
|
||||||
int cmd_rename_main(int argc, const char **argv);
|
int cmd_rename_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,10 @@
|
|||||||
#ifndef __CMD_RESTART_H
|
#ifndef __CMD_RESTART_H
|
||||||
#define __CMD_RESTART_H
|
#define __CMD_RESTART_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RESTART_OPTIONS(cmdargs) \
|
#define RESTART_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
|
||||||
"Seconds to wait for stop before killing it (default 10)", command_convert_int }
|
"Seconds to wait for stop before killing it (default 10)", command_convert_int }
|
||||||
@ -24,5 +28,9 @@ extern const char g_cmd_restart_usage[];
|
|||||||
extern struct client_arguments g_cmd_restart_args;
|
extern struct client_arguments g_cmd_restart_args;
|
||||||
int cmd_restart_main(int argc, const char **argv);
|
int cmd_restart_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_RESTART_H */
|
#endif /* __CMD_RESTART_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,16 +17,24 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DELETE_OPTIONS(cmdargs) \
|
#define DELETE_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, \
|
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, \
|
||||||
"Force the removal of a running container (uses SIGKILL)", NULL }, \
|
"Force the removal of a running container (uses SIGKILL)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "volumes", 'v', &(cmdargs).volume, \
|
{ CMD_OPT_TYPE_BOOL, false, "volumes", 'v', &(cmdargs).volume, \
|
||||||
"Remove the volumes associated with the container", NULL }
|
"Remove the volumes associated with the container", NULL }
|
||||||
|
|
||||||
extern const char g_cmd_delete_desc[];
|
extern const char g_cmd_delete_desc[];
|
||||||
extern const char g_cmd_delete_usage[];
|
extern const char g_cmd_delete_usage[];
|
||||||
extern struct client_arguments g_cmd_delete_args;
|
extern struct client_arguments g_cmd_delete_args;
|
||||||
int cmd_delete_main(int argc, const char **argv);
|
int cmd_delete_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_DELETE_H */
|
#endif /* __CMD_DELETE_H */
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ const char g_cmd_run_desc[] = "Run a command in a new container";
|
|||||||
const char g_cmd_run_usage[] = "run [OPTIONS] ROOTFS|IMAGE [COMMAND] [ARG...]";
|
const char g_cmd_run_usage[] = "run [OPTIONS] ROOTFS|IMAGE [COMMAND] [ARG...]";
|
||||||
static int run_checker(struct client_arguments *args);
|
static int run_checker(struct client_arguments *args);
|
||||||
struct client_arguments g_cmd_run_args = {
|
struct client_arguments g_cmd_run_args = {
|
||||||
.runtime = "lcr",
|
.runtime = "",
|
||||||
.restart = "no",
|
.restart = "no",
|
||||||
.log_file = NULL,
|
.log_file = NULL,
|
||||||
.log_file_size = "1MB",
|
.log_file_size = "1MB",
|
||||||
|
|||||||
@ -19,16 +19,24 @@
|
|||||||
#include "start.h"
|
#include "start.h"
|
||||||
#include "wait.h"
|
#include "wait.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RUN_OPTIONS(cmdargs) \
|
#define RUN_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "detach", 'd', &(cmdargs).detach, \
|
{ CMD_OPT_TYPE_BOOL, false, "detach", 'd', &(cmdargs).detach, \
|
||||||
"Run container in background and print container ID", NULL }, \
|
"Run container in background and print container ID", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "rm", 0, &(cmdargs).custom_conf.auto_remove, \
|
{ CMD_OPT_TYPE_BOOL, false, "rm", 0, &(cmdargs).custom_conf.auto_remove, \
|
||||||
"Automatically remove the container when it exits", NULL }
|
"Automatically remove the container when it exits", NULL }
|
||||||
|
|
||||||
extern const char g_cmd_run_desc[];
|
extern const char g_cmd_run_desc[];
|
||||||
extern const char g_cmd_run_usage[];
|
extern const char g_cmd_run_usage[];
|
||||||
extern struct client_arguments g_cmd_run_args;
|
extern struct client_arguments g_cmd_run_args;
|
||||||
int cmd_run_main(int argc, const char **argv);
|
int cmd_run_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_RUN_H */
|
#endif /* __CMD_RUN_H */
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,10 @@
|
|||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_start_desc[];
|
extern const char g_cmd_start_desc[];
|
||||||
extern struct client_arguments g_cmd_start_args;
|
extern struct client_arguments g_cmd_start_args;
|
||||||
|
|
||||||
@ -28,5 +32,10 @@ void client_restore_console(bool reset_tty, const struct termios *oldtios, struc
|
|||||||
int client_start(const struct client_arguments *args, bool *reset_tty, struct termios *oldtios,
|
int client_start(const struct client_arguments *args, bool *reset_tty, struct termios *oldtios,
|
||||||
struct command_fifo_config **console_fifos);
|
struct command_fifo_config **console_fifos);
|
||||||
int cmd_start_main(int argc, const char **argv);
|
int cmd_start_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_START_H */
|
#endif /* __CMD_START_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,14 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define STOP_OPTIONS(cmdargs) \
|
#define STOP_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, "Stop by force killing", NULL }, \
|
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, "Stop by force killing", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
|
||||||
"Seconds to wait for stop before killing it (default 10)", command_convert_int }
|
"Seconds to wait for stop before killing it (default 10)", command_convert_int }
|
||||||
|
|
||||||
extern const char g_cmd_stop_desc[];
|
extern const char g_cmd_stop_desc[];
|
||||||
extern const char g_cmd_stop_usage[];
|
extern const char g_cmd_stop_usage[];
|
||||||
@ -28,5 +32,9 @@ extern struct client_arguments g_cmd_stop_args;
|
|||||||
|
|
||||||
int cmd_stop_main(int argc, const char **argv);
|
int cmd_stop_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_STOP_H */
|
#endif /* __CMD_STOP_H */
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,10 @@
|
|||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CLIENT_RUNDIR "/var/run/isula"
|
#define CLIENT_RUNDIR "/var/run/isula"
|
||||||
|
|
||||||
// A command is described by:
|
// A command is described by:
|
||||||
@ -69,5 +73,10 @@ int commmand_default_help(const char * const program_name,
|
|||||||
const char **argv);
|
const char **argv);
|
||||||
|
|
||||||
int run_command(struct command *commands, int argc, const char **argv);
|
int run_command(struct command *commands, int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __COMMAND_H */
|
#endif /* __COMMAND_H */
|
||||||
|
|
||||||
|
|||||||
@ -26,53 +26,119 @@ struct client_arguments g_cmd_events_args = {
|
|||||||
.until = NULL,
|
.until = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const g_strtype[] = {
|
static size_t calacute_annotations_msg_len(const container_events_format_t *event)
|
||||||
"EXIT", "STOPPED", "STARTING", "RUNNING", "STOPPING", "ABORTING", "FREEZING",
|
|
||||||
"FROZEN", "THAWED", "OOM", "CREATE", "START", "EXEC_ADDED", "PAUSED1",
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *lcrsta2str(container_events_type_t sta)
|
|
||||||
{
|
{
|
||||||
if (sta > EVENTS_TYPE_PAUSED1) {
|
size_t annos_msg_len = 0;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < event->annotations_len; i++) {
|
||||||
|
annos_msg_len += strlen(event->annotations[i]);
|
||||||
|
}
|
||||||
|
annos_msg_len += event->annotations_len * 2;
|
||||||
|
|
||||||
|
return annos_msg_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t calacute_event_msg_len(const container_events_format_t *event, const char *timebuffer)
|
||||||
|
{
|
||||||
|
size_t msg_len = 0;
|
||||||
|
// format : timestamp (container|image opt) id (annotaions)
|
||||||
|
msg_len += strlen(timebuffer) + 1 + strlen(event->opt) + 1 + strlen(event->id) + 1;
|
||||||
|
msg_len += calacute_annotations_msg_len(event);
|
||||||
|
msg_len += 1; // '\0'
|
||||||
|
|
||||||
|
return msg_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int generate_annotations_msg(const container_events_format_t *event, char **anno_msg)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t anno_msg_len = calacute_annotations_msg_len(event) + 1;
|
||||||
|
|
||||||
|
if (anno_msg_len == 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*anno_msg = (char *)util_common_calloc_s(anno_msg_len);
|
||||||
|
if (*anno_msg == NULL) {
|
||||||
|
ERROR("Event: Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)strcat(*anno_msg, "(");
|
||||||
|
for (i = 0; i < event->annotations_len; i++) {
|
||||||
|
(void)strcat(*anno_msg, event->annotations[i]);
|
||||||
|
if (i != event->annotations_len - 1) {
|
||||||
|
(void)strcat(*anno_msg, ", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(void)strcat(*anno_msg, ")");
|
||||||
|
(*anno_msg)[anno_msg_len - 1] = '\0';
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *generate_event_msg(const container_events_format_t *event, const char *timebuffer, size_t len)
|
||||||
|
{
|
||||||
|
int nret = 0;
|
||||||
|
char *anno_msg = NULL;
|
||||||
|
char *msg = NULL;
|
||||||
|
|
||||||
|
if (generate_annotations_msg(event, &anno_msg) != 0) {
|
||||||
|
ERROR("Event: Failed to generate annotations msg");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return g_strtype[sta];
|
|
||||||
|
msg = (char *)util_common_calloc_s(len);
|
||||||
|
if (msg == NULL) {
|
||||||
|
ERROR("Event: Out of memory");
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
if (anno_msg != NULL) {
|
||||||
|
nret = snprintf(msg, len, "%s %s %s %s", timebuffer, event->opt, event->id, anno_msg);
|
||||||
|
} else {
|
||||||
|
nret = snprintf(msg, len, "%s %s %s", timebuffer, event->opt, event->id);
|
||||||
|
}
|
||||||
|
if (nret < 0 || (size_t)nret >= len) {
|
||||||
|
ERROR("Event: compose event massage failed");
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
msg[len - 1] = '\0';
|
||||||
|
|
||||||
|
free(anno_msg);
|
||||||
|
return msg;
|
||||||
|
|
||||||
|
err_out:
|
||||||
|
free(anno_msg);
|
||||||
|
free(msg);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_events_callback(const container_events_format_t *event)
|
static void print_events_callback(const container_events_format_t *event)
|
||||||
{
|
{
|
||||||
char timebuffer[512] = { 0 };
|
char timebuffer[512] = { 0 };
|
||||||
|
char *msg = NULL;
|
||||||
|
size_t msg_len = 0;
|
||||||
|
|
||||||
if (event == NULL) {
|
if (event == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("--------------------------------------------------\n");
|
if (!get_time_buffer(&(event->timestamp), timebuffer, sizeof(timebuffer))) {
|
||||||
printf("%-15s %s\n", "Name:", event->id);
|
(void)strcpy(timebuffer, "-");
|
||||||
|
|
||||||
if (get_time_buffer(&(event->timestamp), timebuffer, sizeof(timebuffer))) {
|
|
||||||
printf("%-15s %s\n", "Time:", timebuffer);
|
|
||||||
} else {
|
|
||||||
printf("%-15s %s\n", "Time:", "-");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->has_type) {
|
msg_len = calacute_event_msg_len(event, timebuffer);
|
||||||
printf("%-15s %s\n", "EventType:", lcrsta2str(event->type));
|
|
||||||
} else {
|
msg = generate_event_msg(event, timebuffer, msg_len);
|
||||||
printf("%-15s %s\n", "EventType:", "-");
|
if (msg == NULL) {
|
||||||
|
printf("generate event message failed\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->has_pid) {
|
printf("%s\n", msg);
|
||||||
printf("%-15s %u\n", "Pid:", event->pid);
|
|
||||||
} else {
|
|
||||||
printf("%-15s %s\n", "Pid:", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event->has_exit_status) {
|
free(msg);
|
||||||
printf("%-15s %u\n", "Exit_Status:", event->exit_status);
|
|
||||||
} else {
|
|
||||||
printf("%-15s %s\n", "Exit_Status:", "-");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -116,7 +182,7 @@ static int client_event(struct client_arguments *args)
|
|||||||
|
|
||||||
config = get_connect_config(args);
|
config = get_connect_config(args);
|
||||||
ret = ops->container.events(&request, response, &config);
|
ret = ops->container.events(&request, response, &config);
|
||||||
if (ret) {
|
if (ret != 0) {
|
||||||
COMMAND_ERROR("Failed to get container events, %s",
|
COMMAND_ERROR("Failed to get container events, %s",
|
||||||
response->errmsg ? response->errmsg : errno_to_error_message(response->cc));
|
response->errmsg ? response->errmsg : errno_to_error_message(response->cc));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,18 +17,26 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define EVENTS_OPTIONS(cmdargs) \
|
#define EVENTS_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "name", 'n', &(cmdargs).name, \
|
{ CMD_OPT_TYPE_STRING, false, "name", 'n', &(cmdargs).name, \
|
||||||
"Name of the container", NULL }, \
|
"Name of the container", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "since", 'S', &(cmdargs).since, \
|
{ CMD_OPT_TYPE_STRING, false, "since", 'S', &(cmdargs).since, \
|
||||||
"Show all events created since this timestamp", NULL }, \
|
"Show all events created since this timestamp", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "until", 'U', &(cmdargs).until, \
|
{ CMD_OPT_TYPE_STRING, false, "until", 'U', &(cmdargs).until, \
|
||||||
"Show all events created until this timestamp", NULL }
|
"Show all events created until this timestamp", NULL }
|
||||||
|
|
||||||
extern const char g_cmd_events_desc[];
|
extern const char g_cmd_events_desc[];
|
||||||
extern const char g_cmd_events_usage[];
|
extern const char g_cmd_events_usage[];
|
||||||
extern struct client_arguments g_cmd_events_args;
|
extern struct client_arguments g_cmd_events_args;
|
||||||
int cmd_events_main(int argc, const char **argv);
|
int cmd_events_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_EVENT_H */
|
#endif /* __CMD_EVENT_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define EXPORT_OPTIONS(cmdargs) \
|
#define EXPORT_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "output", 'o', &(cmdargs).file, "Write to a file", NULL }
|
{ CMD_OPT_TYPE_STRING, false, "output", 'o', &(cmdargs).file, "Write to a file", NULL }
|
||||||
|
|
||||||
@ -25,5 +29,9 @@ extern const char g_cmd_export_usage[];
|
|||||||
extern struct client_arguments g_cmd_export_args;
|
extern struct client_arguments g_cmd_export_args;
|
||||||
int cmd_export_main(int argc, const char **argv);
|
int cmd_export_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,18 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_pause_desc[];
|
extern const char g_cmd_pause_desc[];
|
||||||
extern const char g_cmd_pause_usage[];
|
extern const char g_cmd_pause_usage[];
|
||||||
extern struct client_arguments g_cmd_pause_args;
|
extern struct client_arguments g_cmd_pause_args;
|
||||||
int cmd_pause_main(int argc, const char **argv);
|
int cmd_pause_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,18 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_resume_desc[];
|
extern const char g_cmd_resume_desc[];
|
||||||
extern const char g_cmd_resume_usage[];
|
extern const char g_cmd_resume_usage[];
|
||||||
extern struct client_arguments g_cmd_resume_args;
|
extern struct client_arguments g_cmd_resume_args;
|
||||||
int cmd_resume_main(int argc, const char **argv);
|
int cmd_resume_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -17,16 +17,24 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define STATUS_OPTIONS(cmdargs) \
|
#define STATUS_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).showall, \
|
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).showall, \
|
||||||
"Show all containers (default shows just running)", NULL }, \
|
"Show all containers (default shows just running)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "no-stream", 0, &(cmdargs).nostream, \
|
{ CMD_OPT_TYPE_BOOL, false, "no-stream", 0, &(cmdargs).nostream, \
|
||||||
"Disable streaming stats and only pull the first result", NULL }
|
"Disable streaming stats and only pull the first result", NULL }
|
||||||
|
|
||||||
extern const char g_cmd_stats_desc[];
|
extern const char g_cmd_stats_desc[];
|
||||||
extern const char g_cmd_stats_usage[];
|
extern const char g_cmd_stats_usage[];
|
||||||
extern struct client_arguments g_cmd_stats_args;
|
extern struct client_arguments g_cmd_stats_args;
|
||||||
int cmd_stats_main(int argc, const char **argv);
|
int cmd_stats_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_STATS_H */
|
#endif /* __CMD_STATS_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,27 +17,31 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define UPDATE_OPTIONS(cmdargs) \
|
#define UPDATE_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-shares", 0, &(cmdargs).cr.cpu_shares, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-shares", 0, &(cmdargs).cr.cpu_shares, \
|
||||||
"CPU shares (relative weight)", command_convert_llong }, \
|
"CPU shares (relative weight)", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-period", 0, &(cmdargs).cr.cpu_period, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-period", 0, &(cmdargs).cr.cpu_period, \
|
||||||
"Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \
|
"Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-quota", 0, &(cmdargs).cr.cpu_quota, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-quota", 0, &(cmdargs).cr.cpu_quota, \
|
||||||
"Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \
|
"Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "cpuset-cpus", 0, &(cmdargs).cr.cpuset_cpus, \
|
{ CMD_OPT_TYPE_STRING, false, "cpuset-cpus", 0, &(cmdargs).cr.cpuset_cpus, \
|
||||||
"CPUs in which to allow execution (0-3, 0,1)", NULL }, \
|
"CPUs in which to allow execution (0-3, 0,1)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "cpuset-mems", 0, &(cmdargs).cr.cpuset_mems, \
|
{ CMD_OPT_TYPE_STRING, false, "cpuset-mems", 0, &(cmdargs).cr.cpuset_mems, \
|
||||||
"MEMs in which to allow execution (0-3, 0,1)", NULL }, \
|
"MEMs in which to allow execution (0-3, 0,1)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "kernel-memory", 0, &(cmdargs).cr.kernel_memory_limit, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "kernel-memory", 0, &(cmdargs).cr.kernel_memory_limit, \
|
||||||
"Kernel memory limit", command_convert_membytes }, \
|
"Kernel memory limit", command_convert_membytes }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "memory", 'm', &(cmdargs).cr.memory_limit, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "memory", 'm', &(cmdargs).cr.memory_limit, \
|
||||||
"Memory limit", command_convert_membytes }, \
|
"Memory limit", command_convert_membytes }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "memory-reservation", 0, &(cmdargs).cr.memory_reservation, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "memory-reservation", 0, &(cmdargs).cr.memory_reservation, \
|
||||||
"Memory soft limit", command_convert_membytes }, \
|
"Memory soft limit", command_convert_membytes }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "memory-swap", 0, &(cmdargs).cr.memory_swap, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "memory-swap", 0, &(cmdargs).cr.memory_swap, \
|
||||||
"Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \
|
"Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "restart", 0, &(cmdargs).restart, \
|
{ CMD_OPT_TYPE_STRING, false, "restart", 0, &(cmdargs).restart, \
|
||||||
"Restart policy to apply when a container exits", NULL }
|
"Restart policy to apply when a container exits", NULL }
|
||||||
|
|
||||||
extern const char g_cmd_update_desc[];
|
extern const char g_cmd_update_desc[];
|
||||||
extern const char g_cmd_update_usage[];
|
extern const char g_cmd_update_usage[];
|
||||||
@ -45,5 +49,9 @@ extern struct client_arguments g_cmd_update_args;
|
|||||||
int cmd_update_main(int argc, const char **argv);
|
int cmd_update_main(int argc, const char **argv);
|
||||||
int update_checker(const struct client_arguments *args);
|
int update_checker(const struct client_arguments *args);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_UPDATE_H */
|
#endif /* __CMD_UPDATE_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,18 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_images_desc[];
|
extern const char g_cmd_images_desc[];
|
||||||
extern const char g_cmd_images_usage[];
|
extern const char g_cmd_images_usage[];
|
||||||
extern struct client_arguments g_cmd_images_args;
|
extern struct client_arguments g_cmd_images_args;
|
||||||
int cmd_images_main(int argc, const char **argv);
|
int cmd_images_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_IMAGES_LIST_H */
|
#endif /* __CMD_IMAGES_LIST_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,14 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LOAD_OPTIONS(cmdargs) \
|
#define LOAD_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "input", 'i', &(cmdargs).file, "Read from a manifest or an archive", NULL }, \
|
{ CMD_OPT_TYPE_STRING, false, "input", 'i', &(cmdargs).file, "Read from a manifest or an archive", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "tag", 0, &(cmdargs).tag, \
|
{ CMD_OPT_TYPE_STRING, false, "tag", 0, &(cmdargs).tag, \
|
||||||
"Name and optionally a tag in the 'name:tag' format, valid if type is docker", NULL }
|
"Name and optionally a tag in the 'name:tag' format, valid if type is docker", NULL }
|
||||||
|
|
||||||
#define EMBEDDED_OPTIONS(cmdargs) \
|
#define EMBEDDED_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "type", 't', &(cmdargs).type, "Image type, embedded or docker(default)", NULL }
|
{ CMD_OPT_TYPE_STRING, false, "type", 't', &(cmdargs).type, "Image type, embedded or docker(default)", NULL }
|
||||||
@ -29,5 +33,9 @@ extern const char g_cmd_load_desc[];
|
|||||||
extern struct client_arguments g_cmd_load_args;
|
extern struct client_arguments g_cmd_load_args;
|
||||||
int cmd_load_main(int argc, const char **argv);
|
int cmd_load_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_LOAD_H */
|
#endif /* __CMD_LOAD_H */
|
||||||
|
|
||||||
|
|||||||
@ -16,11 +16,15 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LOGIN_OPTIONS(cmdargs) \
|
#define LOGIN_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "username", 'u', &(cmdargs).username, "Username", NULL }, \
|
{ CMD_OPT_TYPE_STRING, false, "username", 'u', &(cmdargs).username, "Username", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "password", 'p', &(cmdargs).password, "Password", NULL }, \
|
{ CMD_OPT_TYPE_STRING, false, "password", 'p', &(cmdargs).password, "Password", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "password-stdin", 0, &(cmdargs).password_stdin, \
|
{ CMD_OPT_TYPE_BOOL, false, "password-stdin", 0, &(cmdargs).password_stdin, \
|
||||||
"Take the password from stdin", NULL }, \
|
"Take the password from stdin", NULL }, \
|
||||||
|
|
||||||
|
|
||||||
extern const char g_cmd_login_desc[];
|
extern const char g_cmd_login_desc[];
|
||||||
@ -28,5 +32,9 @@ extern const char g_cmd_login_usage[];
|
|||||||
extern struct client_arguments g_cmd_login_args;
|
extern struct client_arguments g_cmd_login_args;
|
||||||
int cmd_login_main(int argc, const char **argv);
|
int cmd_login_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_LOGIN_H */
|
#endif /* __CMD_LOGIN_H */
|
||||||
|
|
||||||
|
|||||||
@ -16,10 +16,18 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_logout_desc[];
|
extern const char g_cmd_logout_desc[];
|
||||||
extern const char g_cmd_logout_usage[];
|
extern const char g_cmd_logout_usage[];
|
||||||
extern struct client_arguments g_cmd_logout_args;
|
extern struct client_arguments g_cmd_logout_args;
|
||||||
int cmd_logout_main(int argc, const char **argv);
|
int cmd_logout_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_LOGOUT_H */
|
#endif /* __CMD_LOGOUT_H */
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,10 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_pull_desc[];
|
extern const char g_cmd_pull_desc[];
|
||||||
extern const char g_cmd_pull_usage[];
|
extern const char g_cmd_pull_usage[];
|
||||||
extern struct client_arguments g_cmd_pull_args;
|
extern struct client_arguments g_cmd_pull_args;
|
||||||
@ -25,5 +29,9 @@ int client_pull(const struct client_arguments *args);
|
|||||||
|
|
||||||
int cmd_pull_main(int argc, const char **argv);
|
int cmd_pull_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_PULL_IMAGE_H */
|
#endif /* __CMD_PULL_IMAGE_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RMI_OPTIONS(cmdargs) \
|
#define RMI_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, "Force removal of the image", NULL }
|
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, "Force removal of the image", NULL }
|
||||||
|
|
||||||
@ -25,5 +29,9 @@ extern const char g_cmd_rmi_usage[];
|
|||||||
extern struct client_arguments g_cmd_rmi_args;
|
extern struct client_arguments g_cmd_rmi_args;
|
||||||
int cmd_rmi_main(int argc, const char **argv);
|
int cmd_rmi_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_REMOVE_IMAGE_H */
|
#endif /* __CMD_REMOVE_IMAGE_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define HEALTH_OPTIONS(cmdargs) \
|
#define HEALTH_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "service", 'S', &(cmdargs).service, "GRPC service name", NULL }
|
{ CMD_OPT_TYPE_STRING, false, "service", 'S', &(cmdargs).service, "GRPC service name", NULL }
|
||||||
|
|
||||||
@ -25,5 +29,9 @@ extern const char g_cmd_health_check_usage[];
|
|||||||
extern struct client_arguments g_cmd_health_check_args;
|
extern struct client_arguments g_cmd_health_check_args;
|
||||||
int cmd_health_check_main(int argc, const char **argv);
|
int cmd_health_check_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,18 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_info_desc[];
|
extern const char g_cmd_info_desc[];
|
||||||
extern const char g_cmd_info_usage[];
|
extern const char g_cmd_info_usage[];
|
||||||
extern struct client_arguments g_cmd_info_args;
|
extern struct client_arguments g_cmd_info_args;
|
||||||
int cmd_info_main(int argc, const char **argv);
|
int cmd_info_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_INFO_H */
|
#endif /* __CMD_INFO_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,16 +17,24 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define INSPECT_OPTIONS(cmdargs) \
|
#define INSPECT_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "format", 'f', &(cmdargs).format, \
|
{ CMD_OPT_TYPE_STRING, false, "format", 'f', &(cmdargs).format, \
|
||||||
"Format the output using the given go template", NULL }, \
|
"Format the output using the given go template", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
|
||||||
"Seconds to wait for inspect timeout (default 120)", command_convert_int }
|
"Seconds to wait for inspect timeout (default 120)", command_convert_int }
|
||||||
|
|
||||||
extern const char g_cmd_inspect_desc[];
|
extern const char g_cmd_inspect_desc[];
|
||||||
extern const char g_cmd_inspect_usage[];
|
extern const char g_cmd_inspect_usage[];
|
||||||
extern struct client_arguments g_cmd_inspect_args;
|
extern struct client_arguments g_cmd_inspect_args;
|
||||||
int cmd_inspect_main(int argc, const char **argv);
|
int cmd_inspect_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_INSPECT_H */
|
#endif /* __CMD_INSPECT_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,14 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LOGS_OPTIONS(cmdargs) \
|
#define LOGS_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "follow", 'f', &(cmdargs).follow, "Follow log output", NULL }, \
|
{ CMD_OPT_TYPE_BOOL, false, "follow", 'f', &(cmdargs).follow, "Follow log output", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "tail", 0, &(cmdargs).tail, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "tail", 0, &(cmdargs).tail, \
|
||||||
"Number of lines to show from the end of the logs", callback_tail }
|
"Number of lines to show from the end of the logs", callback_tail }
|
||||||
|
|
||||||
extern const char g_cmd_logs_desc[];
|
extern const char g_cmd_logs_desc[];
|
||||||
extern const char g_cmd_logs_usage[];
|
extern const char g_cmd_logs_usage[];
|
||||||
@ -28,5 +32,10 @@ extern struct client_arguments g_cmd_logs_args;
|
|||||||
|
|
||||||
int callback_tail(command_option_t *option, const char *arg);
|
int callback_tail(command_option_t *option, const char *arg);
|
||||||
int cmd_logs_main(int argc, const char **argv);
|
int cmd_logs_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_LOGS_H */
|
#endif /* __CMD_LOGS_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,21 +17,29 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LIST_OPTIONS(cmdargs) \
|
#define LIST_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).list_all, \
|
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).list_all, \
|
||||||
"Display all containers (default shows just running)", NULL }, \
|
"Display all containers (default shows just running)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "quiet", 'q', &(cmdargs).dispname, "Only display numeric IDs", NULL }, \
|
{ CMD_OPT_TYPE_BOOL, false, "quiet", 'q', &(cmdargs).dispname, "Only display numeric IDs", NULL }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "filter", 'f', &(cmdargs).filters, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "filter", 'f', &(cmdargs).filters, \
|
||||||
"Filter output based on conditions provided", command_append_array }, \
|
"Filter output based on conditions provided", command_append_array }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "no-trunc", 0, &(cmdargs).no_trunc, \
|
{ CMD_OPT_TYPE_BOOL, false, "no-trunc", 0, &(cmdargs).no_trunc, \
|
||||||
"Don't truncate output", NULL }, \
|
"Don't truncate output", NULL }, \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "format", 0, &(cmdargs).format, \
|
{ CMD_OPT_TYPE_STRING, false, "format", 0, &(cmdargs).format, \
|
||||||
"Format the output using the given go template", NULL }
|
"Format the output using the given go template", NULL }
|
||||||
|
|
||||||
extern const char g_cmd_list_desc[];
|
extern const char g_cmd_list_desc[];
|
||||||
extern const char g_cmd_list_usage[];
|
extern const char g_cmd_list_usage[];
|
||||||
extern struct client_arguments g_cmd_list_args;
|
extern struct client_arguments g_cmd_list_args;
|
||||||
int cmd_list_main(int argc, const char **argv);
|
int cmd_list_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_LIST_H */
|
#endif /* __CMD_LIST_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,18 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_top_desc[];
|
extern const char g_cmd_top_desc[];
|
||||||
extern const char g_cmd_top_usage[];
|
extern const char g_cmd_top_usage[];
|
||||||
extern struct client_arguments g_cmd_top_args;
|
extern struct client_arguments g_cmd_top_args;
|
||||||
int cmd_top_main(int argc, const char **argv);
|
int cmd_top_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_TOP_H */
|
#endif /* __CMD_TOP_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,18 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_version_desc[];
|
extern const char g_cmd_version_desc[];
|
||||||
extern const char g_cmd_version_usage[];
|
extern const char g_cmd_version_usage[];
|
||||||
extern struct client_arguments g_cmd_version_args;
|
extern struct client_arguments g_cmd_version_args;
|
||||||
int cmd_version_main(int argc, const char **argv);
|
int cmd_version_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_VERSION_H */
|
#endif /* __CMD_VERSION_H */
|
||||||
|
|
||||||
|
|||||||
@ -17,11 +17,19 @@
|
|||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char g_cmd_wait_desc[];
|
extern const char g_cmd_wait_desc[];
|
||||||
extern const char g_cmd_wait_usage[];
|
extern const char g_cmd_wait_usage[];
|
||||||
extern struct client_arguments g_cmd_wait_args;
|
extern struct client_arguments g_cmd_wait_args;
|
||||||
int cmd_wait_main(int argc, const char **argv);
|
int cmd_wait_main(int argc, const char **argv);
|
||||||
int client_wait(const struct client_arguments *args, unsigned int *exit_code);
|
int client_wait(const struct client_arguments *args, unsigned int *exit_code);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CMD_WAIT_H */
|
#endif /* __CMD_WAIT_H */
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
#include "pause.h"
|
#include "pause.h"
|
||||||
#include "resume.h"
|
#include "resume.h"
|
||||||
#include "logs.h"
|
#include "logs.h"
|
||||||
|
#include "events.h"
|
||||||
#include "kill.h"
|
#include "kill.h"
|
||||||
#include "load.h"
|
#include "load.h"
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
@ -137,6 +138,10 @@ struct command g_commands[] = {
|
|||||||
// `logs` sub-command
|
// `logs` sub-command
|
||||||
"logs", cmd_logs_main, g_cmd_logs_desc, NULL, &g_cmd_logs_args
|
"logs", cmd_logs_main, g_cmd_logs_desc, NULL, &g_cmd_logs_args
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// `events` sub-command
|
||||||
|
"events", cmd_events_main, g_cmd_events_desc, NULL, &g_cmd_events_args
|
||||||
|
},
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// `kill` sub-command
|
// `kill` sub-command
|
||||||
|
|||||||
12
src/cmd/isulad-shim/CMakeLists.txt
Normal file
12
src/cmd/isulad-shim/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# get current directory sources files
|
||||||
|
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} isulad_shim_srcs)
|
||||||
|
|
||||||
|
set(CMD_ISULAD_SHIM_SRCS
|
||||||
|
${isulad_shim_srcs}
|
||||||
|
PARENT_SCOPE
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CMD_ISULAD_SHIM_INCS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
PARENT_SCOPE
|
||||||
|
)
|
||||||
301
src/cmd/isulad-shim/common.c
Normal file
301
src/cmd/isulad-shim/common.c
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. 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.
|
||||||
|
* Author: leizhongkai
|
||||||
|
* Create: 2020-1-21
|
||||||
|
* Description: common functions of isulad-shim
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
extern int g_log_fd;
|
||||||
|
|
||||||
|
int set_fd_no_inherited(int fd)
|
||||||
|
{
|
||||||
|
int ret = SHIM_ERR;
|
||||||
|
int flag = -1;
|
||||||
|
|
||||||
|
flag = fcntl(fd, F_GETFD, 0);
|
||||||
|
if (flag < 0) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fcntl(fd, F_SETFD, flag | FD_CLOEXEC);
|
||||||
|
if (ret != 0) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SHIM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t read_nointr(int fd, void *buf, size_t count)
|
||||||
|
{
|
||||||
|
ssize_t nret;
|
||||||
|
|
||||||
|
if (buf == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
nret = read(fd, buf, count);
|
||||||
|
if (nret < 0 && (errno == EINTR || errno == EAGAIN)) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t write_nointr(int fd, const void *buf, size_t count)
|
||||||
|
{
|
||||||
|
ssize_t nret;
|
||||||
|
|
||||||
|
if (buf == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
nret = write(fd, buf, count);
|
||||||
|
if (nret < 0 && (errno == EINTR || errno == EAGAIN)) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool file_exists(const char *f)
|
||||||
|
{
|
||||||
|
struct stat buf;
|
||||||
|
int nret;
|
||||||
|
|
||||||
|
if (f == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
nret = stat(f, &buf);
|
||||||
|
if (nret < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmd_combined_output(const char *binary, const char *params[], void *output, int *output_len)
|
||||||
|
{
|
||||||
|
int ret = SHIM_ERR;
|
||||||
|
int exec_fd[2] = { -1, -1 };
|
||||||
|
int stdio[2] = { -1, -1 };
|
||||||
|
pid_t pid = 0;
|
||||||
|
char exec_buff[BUFSIZ + 1] = { 0 };
|
||||||
|
ssize_t nread;
|
||||||
|
|
||||||
|
if (pipe2(exec_fd, O_CLOEXEC) != 0) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pipe2(stdio, O_CLOEXEC) != 0) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
if (pid == (pid_t) - 1) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// child
|
||||||
|
if (pid == (pid_t)0) {
|
||||||
|
close(exec_fd[0]);
|
||||||
|
close(stdio[0]);
|
||||||
|
dup2(stdio[1], 1);
|
||||||
|
dup2(stdio[1], 2);
|
||||||
|
execvp(binary, (char * const *)params);
|
||||||
|
(void)dprintf(exec_fd[1], "fork/exec error: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
// parent
|
||||||
|
close(exec_fd[1]);
|
||||||
|
close(stdio[1]);
|
||||||
|
nread = read_nointr(exec_fd[0], exec_buff, sizeof(exec_buff));
|
||||||
|
if (nread > 0) {
|
||||||
|
ret = SHIM_ERR;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
*output_len = read_nointr(stdio[0], output, 8191);
|
||||||
|
|
||||||
|
close(stdio[0]);
|
||||||
|
close(exec_fd[0]);
|
||||||
|
int status = 0;
|
||||||
|
wait(&status);
|
||||||
|
ret = SHIM_OK;
|
||||||
|
out:
|
||||||
|
if (ret != SHIM_OK && pid != 0) {
|
||||||
|
kill(pid, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int 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) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
int nret;
|
||||||
|
if (read(fd, &num, sizeof(int)) < 0) {
|
||||||
|
close(fd);
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
unsigned char rs = (unsigned char)(num % m);
|
||||||
|
nret = snprintf((id + i * 2), ((len - i) * 2 + 1), "%02x", (unsigned int)rs);
|
||||||
|
if (nret < 0) {
|
||||||
|
close(fd);
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
id[i * 2] = '\0';
|
||||||
|
|
||||||
|
return SHIM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_message(int fd, const char *level, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
#define MAX_MSG_JSON_TEMPLATE 32
|
||||||
|
#define MAX_MESSAGE_CONTENT_LEN 128
|
||||||
|
#define MAX_MESSAGE_LEN (MAX_MSG_JSON_TEMPLATE + MAX_MESSAGE_CONTENT_LEN)
|
||||||
|
if (fd < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[MAX_MESSAGE_CONTENT_LEN] = { 0 };
|
||||||
|
char msg[MAX_MESSAGE_LEN] = { 0 };
|
||||||
|
int nwrite = -1;
|
||||||
|
|
||||||
|
va_list arg_list;
|
||||||
|
va_start(arg_list, fmt);
|
||||||
|
vsnprintf(buf, MAX_MESSAGE_CONTENT_LEN, fmt, arg_list);
|
||||||
|
va_end(arg_list);
|
||||||
|
|
||||||
|
snprintf(msg, MAX_MESSAGE_LEN - 1, "{\"level\": \"%s\", \"msg\": \"%s\"}\n", level, buf);
|
||||||
|
nwrite = write(fd, msg, strlen(msg));
|
||||||
|
if (nwrite != strlen(msg)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* note: This function can only read small text file. */
|
||||||
|
char *read_text_file(const char *path)
|
||||||
|
{
|
||||||
|
char *buf = NULL;
|
||||||
|
long len = 0;
|
||||||
|
size_t readlen = 0;
|
||||||
|
FILE *filp = NULL;
|
||||||
|
const long max_size = 10 * 1024 * 1024; /* 10M */
|
||||||
|
|
||||||
|
if (path == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
filp = fopen(path, "r");
|
||||||
|
if (filp == NULL) {
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
if (fseek(filp, 0, SEEK_END)) {
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = ftell(filp);
|
||||||
|
if (len > max_size) {
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
if (fseek(filp, 0, SEEK_SET)) {
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = (char *)calloc(1, (size_t)(len + 1));
|
||||||
|
if (buf == NULL) {
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
readlen = fread(buf, 1, (size_t)len, filp);
|
||||||
|
if (((readlen < (size_t)len) && (!feof(filp))) || (readlen > (size_t)len)) {
|
||||||
|
if (buf != NULL) {
|
||||||
|
free(buf);
|
||||||
|
buf = NULL;
|
||||||
|
}
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[(size_t)len] = 0;
|
||||||
|
|
||||||
|
err_out:
|
||||||
|
|
||||||
|
if (filp != NULL) {
|
||||||
|
fclose(filp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void close_fd(int *pfd)
|
||||||
|
{
|
||||||
|
if (pfd != NULL && *pfd != -1) {
|
||||||
|
close(*pfd);
|
||||||
|
*pfd = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int open_no_inherit(const char *path, int flag, mode_t mode)
|
||||||
|
{
|
||||||
|
int fd = -1;
|
||||||
|
int ret = SHIM_ERR;
|
||||||
|
|
||||||
|
fd = open(path, flag, mode);
|
||||||
|
if (fd < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = set_fd_no_inherited(fd);
|
||||||
|
if (ret != SHIM_OK) {
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
72
src/cmd/isulad-shim/common.h
Normal file
72
src/cmd/isulad-shim/common.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. 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.
|
||||||
|
* Author: leizhongkai
|
||||||
|
* Create: 2020-1-20
|
||||||
|
* Description: common definition of isulad-shim
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __COMMON_H_
|
||||||
|
#define __COMMON_H_
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// error code
|
||||||
|
#define SHIM_ERR_BASE (-10000)
|
||||||
|
#define SHIM_SYS_ERR(err) (SHIM_ERR_BASE-err)
|
||||||
|
#define SHIM_OK 0
|
||||||
|
#define SHIM_ERR -1
|
||||||
|
#define SHIM_ERR_WAIT -2
|
||||||
|
#define SHIM_ERR_NOT_REQUIRED -3
|
||||||
|
|
||||||
|
#define INFO_MSG "info"
|
||||||
|
#define WARN_MSG "warn"
|
||||||
|
#define ERR_MSG "error"
|
||||||
|
|
||||||
|
#define DEFAULT_TIMEOUT 120 // sec
|
||||||
|
#define CONTAINER_ID_LEN 64
|
||||||
|
#define MAX_RT_NAME_LEN 64
|
||||||
|
#define MAX_CONSOLE_SOCK_LEN 32
|
||||||
|
|
||||||
|
#define MAX_RUNTIME_ARGS 20
|
||||||
|
|
||||||
|
#define SHIM_BINARY "isulad-shim"
|
||||||
|
#define SHIM_LOG_NAME "shim-log.json"
|
||||||
|
|
||||||
|
#define CONTAINER_ACTION_REBOOT 129
|
||||||
|
#define CONTAINER_ACTION_SHUTDOWN 130
|
||||||
|
|
||||||
|
ssize_t read_nointr(int fd, void *buf, size_t count);
|
||||||
|
ssize_t write_nointr(int fd, const void *buf, size_t count);
|
||||||
|
|
||||||
|
char *read_text_file(const char *path);
|
||||||
|
|
||||||
|
bool file_exists(const char *f);
|
||||||
|
|
||||||
|
int cmd_combined_output(const char *binary, const char *params[], void *output, int *output_len);
|
||||||
|
|
||||||
|
void write_message(int fd, const char *level, const char *fmt, ...);
|
||||||
|
|
||||||
|
int generate_random_str(char *id, size_t len);
|
||||||
|
|
||||||
|
void close_fd(int *pfd);
|
||||||
|
|
||||||
|
int open_no_inherit(const char *path, int flag, mode_t mode);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
162
src/cmd/isulad-shim/main.c
Normal file
162
src/cmd/isulad-shim/main.c
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. 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.
|
||||||
|
* Author: leizhongkai
|
||||||
|
* Create: 2020-1-20
|
||||||
|
* Description: main process of isulad-shim
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "process.h"
|
||||||
|
|
||||||
|
int g_log_fd = -1;
|
||||||
|
|
||||||
|
void signal_routine(int sig)
|
||||||
|
{
|
||||||
|
switch (sig) {
|
||||||
|
case SIGALRM:
|
||||||
|
write_message(g_log_fd, ERR_MSG, "runtime timeout");
|
||||||
|
exit(1);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_timeout_exit(unsigned int timeout)
|
||||||
|
{
|
||||||
|
signal(SIGALRM, signal_routine);
|
||||||
|
(void)alarm(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void released_timeout_exit()
|
||||||
|
{
|
||||||
|
(void)alarm(0);
|
||||||
|
signal(SIGALRM, SIG_IGN);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int set_subreaper()
|
||||||
|
{
|
||||||
|
int ret = SHIM_ERR;
|
||||||
|
ret = prctl(PR_SET_CHILD_SUBREAPER, 1);
|
||||||
|
if (ret != SHIM_OK) {
|
||||||
|
return SHIM_SYS_ERR(errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SHIM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int parse_args(int argc, char **argv, char **cid, char **bundle, char **rt_name, char **log_level)
|
||||||
|
{
|
||||||
|
if (argc < 4) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
*cid = strdup(argv[1]);
|
||||||
|
*bundle = strdup(argv[2]);
|
||||||
|
*rt_name = strdup(argv[3]);
|
||||||
|
if (*cid == NULL || *bundle == NULL || rt_name == NULL) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > 4) {
|
||||||
|
*log_level = strdup(argv[4]);
|
||||||
|
if (*log_level == NULL) {
|
||||||
|
return SHIM_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SHIM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *container_id = NULL;
|
||||||
|
char *bundle = NULL;
|
||||||
|
char *rt_name = NULL;
|
||||||
|
char *log_level = NULL;
|
||||||
|
int ret = SHIM_ERR;
|
||||||
|
int efd = -1;
|
||||||
|
process_t *p = NULL;
|
||||||
|
|
||||||
|
g_log_fd = open_no_inherit(SHIM_LOG_NAME, O_CREAT | O_WRONLY | O_APPEND | O_SYNC, 0640);
|
||||||
|
if (g_log_fd < 0) {
|
||||||
|
_exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_timeout_exit(DEFAULT_TIMEOUT);
|
||||||
|
|
||||||
|
ret = set_subreaper();
|
||||||
|
if (ret != SHIM_OK) {
|
||||||
|
write_message(g_log_fd, ERR_MSG, "set subreaper failed:%d", ret);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = parse_args(argc, argv, &container_id, &bundle, &rt_name, &log_level);
|
||||||
|
if (ret != SHIM_OK) {
|
||||||
|
write_message(g_log_fd, ERR_MSG, "parse args failed:%d", ret);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
p = new_process(container_id, bundle, rt_name);
|
||||||
|
if (p == NULL) {
|
||||||
|
write_message(g_log_fd, ERR_MSG, "new process failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// open exit pipe
|
||||||
|
if (!p->state->exec) {
|
||||||
|
if (p->state->exit_fifo != NULL) {
|
||||||
|
efd = open_no_inherit("exit_fifo", O_WRONLY, -1);
|
||||||
|
if (efd < 0) {
|
||||||
|
write_message(g_log_fd, ERR_MSG, "open exit pipe failed:%d", SHIM_SYS_ERR(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
p->exit_fd = efd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create main loop and start epoll
|
||||||
|
ret = process_io_init(p);
|
||||||
|
if (ret != SHIM_OK) {
|
||||||
|
write_message(g_log_fd, ERR_MSG, "process io init failed:%d", ret);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = open_io(p);
|
||||||
|
if (ret != SHIM_OK) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = create_process(p);
|
||||||
|
if (ret != SHIM_OK) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
released_timeout_exit();
|
||||||
|
|
||||||
|
ret = process_signal_handle_routine(p);
|
||||||
|
if (ret != SHIM_OK) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
1018
src/cmd/isulad-shim/process.c
Normal file
1018
src/cmd/isulad-shim/process.c
Normal file
File diff suppressed because it is too large
Load Diff
100
src/cmd/isulad-shim/process.h
Normal file
100
src/cmd/isulad-shim/process.h
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. 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.
|
||||||
|
* Author: leizhongkai
|
||||||
|
* Create: 2020-1-20
|
||||||
|
* Description: process definition
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __SHIM_PROCESS_H_
|
||||||
|
#define __SHIM_PROCESS_H_
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "shim_client_process_state.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
stdid_in = 0,
|
||||||
|
stdid_out,
|
||||||
|
stdid_err
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int in;
|
||||||
|
int out;
|
||||||
|
int err;
|
||||||
|
} stdio_t;
|
||||||
|
|
||||||
|
typedef struct fd_node {
|
||||||
|
int fd;
|
||||||
|
struct fd_node *next;
|
||||||
|
} fd_node_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int fd_from;
|
||||||
|
fd_node_t *fd_to;
|
||||||
|
int id;// 0,1,2
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
} io_copy_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int epfd;
|
||||||
|
pthread_t tid;
|
||||||
|
pthread_attr_t attr;
|
||||||
|
sem_t sem_thd;
|
||||||
|
io_copy_t *ioc;
|
||||||
|
bool shutdown;
|
||||||
|
} io_thread_t;
|
||||||
|
|
||||||
|
typedef struct process {
|
||||||
|
char *id;
|
||||||
|
char *bundle;
|
||||||
|
char *runtime;
|
||||||
|
char *console_sock_path;
|
||||||
|
int io_loop_fd;
|
||||||
|
int exit_fd;
|
||||||
|
int ctr_pid;
|
||||||
|
stdio_t *stdio;
|
||||||
|
stdio_t *shim_io;
|
||||||
|
io_thread_t *io_threads[3];// stdin,stdout,stderr
|
||||||
|
shim_client_process_state *state;
|
||||||
|
} process_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int listen_fd;
|
||||||
|
process_t *p;
|
||||||
|
} console_accept_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int pid;
|
||||||
|
int status;
|
||||||
|
} process_exit_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
process_t* new_process(char *id, char *bundle, char *runtime);
|
||||||
|
|
||||||
|
int open_io(process_t *p);
|
||||||
|
int process_io_init(process_t *p);
|
||||||
|
int create_process(process_t *p);
|
||||||
|
int process_signal_handle_routine(process_t *p);
|
||||||
|
void process_delete(process_t *p);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@ -157,6 +157,7 @@ int service_arguments_init(struct service_arguments *args)
|
|||||||
args->default_ulimit = NULL;
|
args->default_ulimit = NULL;
|
||||||
args->default_ulimit_len = 0;
|
args->default_ulimit_len = 0;
|
||||||
args->json_confs->websocket_server_listening_port = DEFAULT_WEBSOCKET_SERVER_LISTENING_PORT;
|
args->json_confs->websocket_server_listening_port = DEFAULT_WEBSOCKET_SERVER_LISTENING_PORT;
|
||||||
|
args->json_confs->selinux_enabled = false;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
|||||||
@ -102,7 +102,9 @@ int update_default_ulimit(struct service_arguments *args);
|
|||||||
"Default ulimits for containers (default [])", command_default_ulimit_append }, \
|
"Default ulimits for containers (default [])", command_default_ulimit_append }, \
|
||||||
{ CMD_OPT_TYPE_CALLBACK, false, "websocket-server-listening-port", 0, \
|
{ CMD_OPT_TYPE_CALLBACK, false, "websocket-server-listening-port", 0, \
|
||||||
&(cmdargs)->json_confs->websocket_server_listening_port, \
|
&(cmdargs)->json_confs->websocket_server_listening_port, \
|
||||||
"CRI websocket streaming service listening port (default 10350)", command_convert_uint }
|
"CRI websocket streaming service listening port (default 10350)", command_convert_uint }, \
|
||||||
|
{ CMD_OPT_TYPE_BOOL, false, "selinux-enabled", 0, &(cmdargs)->json_confs->selinux_enabled, \
|
||||||
|
"Enable selinux support", NULL}
|
||||||
|
|
||||||
#endif /* __COMMAND_H */
|
#endif /* __COMMAND_H */
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdio_ext.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -56,6 +57,7 @@
|
|||||||
#include "supervisor.h"
|
#include "supervisor.h"
|
||||||
#include "containers_gc.h"
|
#include "containers_gc.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
#include "selinux_label.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_OCI_IMAGE
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
@ -772,6 +774,80 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int overlay_supports_selinux(bool *supported)
|
||||||
|
{
|
||||||
|
#define KALLSYMS_ITEM_MAX_LEN 100
|
||||||
|
int ret = 0;
|
||||||
|
FILE *fp = NULL;
|
||||||
|
char *buf = NULL;
|
||||||
|
size_t len;
|
||||||
|
ssize_t num;
|
||||||
|
|
||||||
|
*supported = false;
|
||||||
|
fp = fopen("/proc/kallsyms", "re");
|
||||||
|
if (fp == NULL) {
|
||||||
|
ERROR("Failed to open /proc/kallsyms: %s", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
__fsetlocking(fp, FSETLOCKING_BYCALLER);
|
||||||
|
|
||||||
|
for (num = getline(&buf, &len, fp); num != -1; num = getline(&buf, &len, fp)) {
|
||||||
|
char sym_addr[KALLSYMS_ITEM_MAX_LEN] = { 0 };
|
||||||
|
char sym_type[KALLSYMS_ITEM_MAX_LEN] = { 0 };
|
||||||
|
char sym_name[KALLSYMS_ITEM_MAX_LEN] = { 0 };
|
||||||
|
|
||||||
|
if (sscanf(buf, "%s %s %s", sym_addr, sym_type, sym_name) != 3) {
|
||||||
|
ERROR("sscanf buffer failed");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for presence of symbol security_inode_copy_up.
|
||||||
|
if (strcmp(sym_name, "security_inode_copy_up") == 0) {
|
||||||
|
*supported = true;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(buf);
|
||||||
|
fclose(fp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int configure_kernel_security_support(const struct service_arguments *args)
|
||||||
|
{
|
||||||
|
if (selinux_state_init() != 0) {
|
||||||
|
ERROR("Failed to init selinux state");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->json_confs->selinux_enabled) {
|
||||||
|
if (!selinux_get_enable()) {
|
||||||
|
WARN("iSulad could not enable SELinux on the host system");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(args->json_confs->storage_driver, "overlay") == 0 ||
|
||||||
|
strcmp(args->json_confs->storage_driver, "overlay2") == 0) {
|
||||||
|
// If driver is overlay or overlay2, make sure kernel
|
||||||
|
// supports selinux with overlay.
|
||||||
|
bool supported = false;
|
||||||
|
|
||||||
|
if (overlay_supports_selinux(&supported)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!supported) {
|
||||||
|
WARN("SELinux is not supported with the %s graph driver on this kernel",
|
||||||
|
args->json_confs->storage_driver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selinux_set_disabled();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int update_server_args(struct service_arguments *args)
|
static int update_server_args(struct service_arguments *args)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -819,6 +895,13 @@ static int update_server_args(struct service_arguments *args)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure and validate the kernels security support. Note this is a Linux/FreeBSD
|
||||||
|
// operation only, so it is safe to pass *just* the runtime OS graphdriver.
|
||||||
|
if (configure_kernel_security_support(args)) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_OCI_IMAGE
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
args->driver = graphdriver_init(args->json_confs->storage_driver, args->json_confs->storage_opts,
|
args->driver = graphdriver_init(args->json_confs->storage_driver, args->json_confs->storage_opts,
|
||||||
args->json_confs->storage_opts_len);
|
args->json_confs->storage_opts_len);
|
||||||
|
|||||||
@ -806,7 +806,7 @@ char *conf_get_isulad_log_gather_fifo_path()
|
|||||||
ERROR("Out of memory");
|
ERROR("Out of memory");
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
nret = snprintf(logfile, len, "%s%s", statedir, "LOG_GATHER_FIFO_NAME");
|
nret = snprintf(logfile, len, "%s%s", statedir, LOG_GATHER_FIFO_NAME);
|
||||||
if (nret < 0 || (size_t)nret >= len) {
|
if (nret < 0 || (size_t)nret >= len) {
|
||||||
ERROR("Sprintf log file failed");
|
ERROR("Sprintf log file failed");
|
||||||
goto err_out;
|
goto err_out;
|
||||||
@ -1206,6 +1206,28 @@ out:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *conf_get_default_runtime()
|
||||||
|
{
|
||||||
|
struct service_arguments *conf = NULL;
|
||||||
|
char *result = NULL;
|
||||||
|
|
||||||
|
if (isulad_server_conf_rdlock()) {
|
||||||
|
ERROR("BUG conf_rdlock failed");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf = conf_get_server_conf();
|
||||||
|
if (conf == NULL || conf->json_confs == NULL) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = strings_to_lower(conf->json_confs->default_runtime);
|
||||||
|
|
||||||
|
out:
|
||||||
|
(void)isulad_server_conf_unlock();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool conf_update_im_server_sock_addr(const char *new_sock_addr)
|
bool conf_update_im_server_sock_addr(const char *new_sock_addr)
|
||||||
{
|
{
|
||||||
struct service_arguments *conf = NULL;
|
struct service_arguments *conf = NULL;
|
||||||
@ -1765,6 +1787,7 @@ int merge_json_confs_into_global(struct service_arguments *args)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override_string_value(&args->json_confs->default_runtime, &tmp_json_confs->default_runtime);
|
||||||
override_string_value(&args->json_confs->group, &tmp_json_confs->group);
|
override_string_value(&args->json_confs->group, &tmp_json_confs->group);
|
||||||
override_string_value(&args->json_confs->graph, &tmp_json_confs->graph);
|
override_string_value(&args->json_confs->graph, &tmp_json_confs->graph);
|
||||||
override_string_value(&args->json_confs->state, &tmp_json_confs->state);
|
override_string_value(&args->json_confs->state, &tmp_json_confs->state);
|
||||||
@ -1790,6 +1813,9 @@ int merge_json_confs_into_global(struct service_arguments *args)
|
|||||||
override_string_value(&args->json_confs->cni_bin_dir, &tmp_json_confs->cni_bin_dir);
|
override_string_value(&args->json_confs->cni_bin_dir, &tmp_json_confs->cni_bin_dir);
|
||||||
override_string_value(&args->json_confs->cni_conf_dir, &tmp_json_confs->cni_conf_dir);
|
override_string_value(&args->json_confs->cni_conf_dir, &tmp_json_confs->cni_conf_dir);
|
||||||
|
|
||||||
|
args->json_confs->runtimes = tmp_json_confs->runtimes;
|
||||||
|
tmp_json_confs->runtimes = NULL;
|
||||||
|
|
||||||
// Daemon storage-driver
|
// Daemon storage-driver
|
||||||
if (merge_storage_conf_into_global(args, tmp_json_confs)) {
|
if (merge_storage_conf_into_global(args, tmp_json_confs)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -1836,6 +1862,8 @@ int merge_json_confs_into_global(struct service_arguments *args)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args->json_confs->selinux_enabled = tmp_json_confs->selinux_enabled;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(err);
|
free(err);
|
||||||
free_isulad_daemon_configs(tmp_json_confs);
|
free_isulad_daemon_configs(tmp_json_confs);
|
||||||
|
|||||||
@ -25,6 +25,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_IM_SERVER_SOCK_ADDR "unix:///var/run/isulad/isula_image.sock"
|
#define DEFAULT_IM_SERVER_SOCK_ADDR "unix:///var/run/isulad/isula_image.sock"
|
||||||
|
#define DEFAULT_RUNTIME_NAME "lcr"
|
||||||
|
|
||||||
struct isulad_conf {
|
struct isulad_conf {
|
||||||
pthread_rwlock_t isulad_conf_rwlock;
|
pthread_rwlock_t isulad_conf_rwlock;
|
||||||
@ -92,6 +93,8 @@ unsigned int conf_get_im_opt_timeout();
|
|||||||
|
|
||||||
char *conf_get_im_server_sock_addr();
|
char *conf_get_im_server_sock_addr();
|
||||||
|
|
||||||
|
char *conf_get_default_runtime();
|
||||||
|
|
||||||
bool conf_update_im_server_sock_addr(const char *new_sock_addr);
|
bool conf_update_im_server_sock_addr(const char *new_sock_addr);
|
||||||
|
|
||||||
char *conf_get_graph_check_flag_file();
|
char *conf_get_graph_check_flag_file();
|
||||||
|
|||||||
@ -113,16 +113,12 @@ public:
|
|||||||
context.set_deadline(tDeadline);
|
context.set_deadline(tDeadline);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set common name from cert.perm
|
// Set metadata for authorization
|
||||||
char common_name_value[ClientBaseConstants::COMMON_NAME_LEN] = { 0 };
|
if (SetMetadataInfo(context) != 0) {
|
||||||
ret = get_common_name_from_tls_cert(m_certFile.c_str(), common_name_value,
|
ERROR("Failed to set metadata info for authorization");
|
||||||
ClientBaseConstants::COMMON_NAME_LEN);
|
response->cc = ISULAD_ERR_INPUT;
|
||||||
if (ret != 0) {
|
|
||||||
ERROR("Failed to get common name in: %s", m_certFile.c_str());
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
context.AddMetadata("username", std::string(common_name_value, strlen(common_name_value)));
|
|
||||||
context.AddMetadata("tls_mode", m_tlsMode);
|
|
||||||
|
|
||||||
ret = request_to_grpc(request, &req);
|
ret = request_to_grpc(request, &req);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@ -175,7 +171,7 @@ protected:
|
|||||||
return Status::OK;
|
return Status::OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::string ReadTextFile(const char *file)
|
std::string ReadTextFile(const char *file)
|
||||||
{
|
{
|
||||||
char *real_file = verify_file_and_get_real_path(file);
|
char *real_file = verify_file_and_get_real_path(file);
|
||||||
if (real_file == nullptr) {
|
if (real_file == nullptr) {
|
||||||
@ -195,6 +191,22 @@ protected:
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SetMetadataInfo(ClientContext &context)
|
||||||
|
{
|
||||||
|
// Set common name from cert.perm
|
||||||
|
char common_name_value[ClientBaseConstants::COMMON_NAME_LEN] = { 0 };
|
||||||
|
int ret = get_common_name_from_tls_cert(m_certFile.c_str(), common_name_value,
|
||||||
|
ClientBaseConstants::COMMON_NAME_LEN);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Failed to get common name in: %s", m_certFile.c_str());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
context.AddMetadata("username", std::string(common_name_value, strlen(common_name_value)));
|
||||||
|
context.AddMetadata("tls_mode", m_tlsMode);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<sTB> stub_;
|
std::unique_ptr<sTB> stub_;
|
||||||
std::string m_tlsMode { ClientBaseConstants::TLS_OFF };
|
std::string m_tlsMode { ClientBaseConstants::TLS_OFF };
|
||||||
std::string m_certFile { "" };
|
std::string m_certFile { "" };
|
||||||
|
|||||||
@ -230,10 +230,6 @@ public:
|
|||||||
{
|
{
|
||||||
int nret = -1;
|
int nret = -1;
|
||||||
|
|
||||||
if (req.runtime().empty()) {
|
|
||||||
ERROR("Missing runtime in the request");
|
|
||||||
return nret;
|
|
||||||
}
|
|
||||||
if (req.rootfs().empty() && req.image().empty()) {
|
if (req.rootfs().empty() && req.image().empty()) {
|
||||||
ERROR("Missing container rootfs or image arguments in the request");
|
ERROR("Missing container rootfs or image arguments in the request");
|
||||||
return nret;
|
return nret;
|
||||||
@ -1745,7 +1741,13 @@ public:
|
|||||||
Event event;
|
Event event;
|
||||||
ClientContext context;
|
ClientContext context;
|
||||||
Status status;
|
Status status;
|
||||||
container_events_format_t isula_event;
|
container_events_format_t *isula_event = nullptr;
|
||||||
|
|
||||||
|
if (SetMetadataInfo(context)) {
|
||||||
|
ERROR("Failed to set metadata info for authorization");
|
||||||
|
response->cc = ISULAD_ERR_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
ret = events_request_to_grpc(request, &req);
|
ret = events_request_to_grpc(request, &req);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@ -1756,10 +1758,18 @@ public:
|
|||||||
|
|
||||||
std::unique_ptr<ClientReader<Event>> reader(stub_->Events(&context, req));
|
std::unique_ptr<ClientReader<Event>> reader(stub_->Events(&context, req));
|
||||||
while (reader->Read(&event)) {
|
while (reader->Read(&event)) {
|
||||||
event_from_grpc(&isula_event, &event);
|
isula_event = (container_events_format_t *)util_common_calloc_s(sizeof(container_events_format_t));
|
||||||
if (request->cb != nullptr) {
|
if (isula_event == nullptr) {
|
||||||
request->cb(&isula_event);
|
ERROR("Out of memory");
|
||||||
|
response->server_errono = ISULAD_ERR_EXEC;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
event_from_grpc(isula_event, &event);
|
||||||
|
if (request->cb != nullptr) {
|
||||||
|
request->cb(isula_event);
|
||||||
|
}
|
||||||
|
container_events_format_free(isula_event);
|
||||||
|
isula_event = nullptr;
|
||||||
}
|
}
|
||||||
status = reader->Finish();
|
status = reader->Finish();
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
@ -1793,20 +1803,25 @@ private:
|
|||||||
void event_from_grpc(container_events_format_t *event, Event *gevent)
|
void event_from_grpc(container_events_format_t *event, Event *gevent)
|
||||||
{
|
{
|
||||||
(void)memset(event, 0, sizeof(*event));
|
(void)memset(event, 0, sizeof(*event));
|
||||||
if (!gevent->id().empty()) {
|
|
||||||
event->id = (char *)gevent->id().c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
event->has_type = true;
|
|
||||||
event->type = (container_events_type_t)((int)gevent->type());
|
|
||||||
event->has_pid = (int)gevent->pid() != -1;
|
|
||||||
event->pid = (uint32_t)gevent->pid();
|
|
||||||
event->has_exit_status = true;
|
|
||||||
event->exit_status = gevent->exit_status();
|
|
||||||
|
|
||||||
if (gevent->has_timestamp()) {
|
if (gevent->has_timestamp()) {
|
||||||
protobuf_timestamp_from_grpc(&event->timestamp, gevent->timestamp());
|
protobuf_timestamp_from_grpc(&event->timestamp, gevent->timestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!gevent->opt().empty()) {
|
||||||
|
event->opt = util_strdup_s(gevent->opt().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gevent->id().empty()) {
|
||||||
|
event->id = util_strdup_s(gevent->id().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
google::protobuf::Map<std::string, std::string> map = gevent->annotations();
|
||||||
|
for (auto iter = map.cbegin(); iter != map.cend(); ++iter) {
|
||||||
|
std::string anno = iter->first + "=" + iter->second;
|
||||||
|
(void)util_array_append(&event->annotations, anno.c_str());
|
||||||
|
event->annotations_len++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int events_request_to_grpc(const struct isula_events_request *request, EventsRequest *grequest)
|
int events_request_to_grpc(const struct isula_events_request *request, EventsRequest *grequest)
|
||||||
|
|||||||
@ -119,6 +119,7 @@ public:
|
|||||||
explicit ISulaContainerPrepare(void *args) : ClientBase(args)
|
explicit ISulaContainerPrepare(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaContainerPrepare() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_prepare_request *req, isula::ContainerPrepareRequest *grequest) override
|
int request_to_grpc(const isula_prepare_request *req, isula::ContainerPrepareRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -184,6 +185,8 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~ISulaContainerRemove() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_remove_request *req, isula::ContainerRemoveRequest *grequest) override
|
int request_to_grpc(const isula_remove_request *req, isula::ContainerRemoveRequest *grequest) override
|
||||||
{
|
{
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
@ -227,6 +230,8 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~ISulaContainerMount() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_mount_request *req, isula::ContainerMountRequest *grequest) override
|
int request_to_grpc(const isula_mount_request *req, isula::ContainerMountRequest *grequest) override
|
||||||
{
|
{
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
@ -270,6 +275,8 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~ISulaContainerUmount() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_umount_request *req, isula::ContainerUmountRequest *grequest) override
|
int request_to_grpc(const isula_umount_request *req, isula::ContainerUmountRequest *grequest) override
|
||||||
{
|
{
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
@ -314,6 +321,8 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~ISulaContainersList() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_containers_list_request *req, isula::ListContainersRequest *grequest) override
|
int request_to_grpc(const isula_containers_list_request *req, isula::ListContainersRequest *grequest) override
|
||||||
{
|
{
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
@ -359,6 +368,8 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~ISulaImagePull() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_pull_request *req, isula::PullImageRequest *grequest) override
|
int request_to_grpc(const isula_pull_request *req, isula::PullImageRequest *grequest) override
|
||||||
{
|
{
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
@ -437,6 +448,7 @@ public:
|
|||||||
explicit ISulaImageStatus(void *args) : ClientBase(args)
|
explicit ISulaImageStatus(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaImageStatus() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_status_request *req, isula::ImageStatusRequest *grequest) override
|
int request_to_grpc(const isula_status_request *req, isula::ImageStatusRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -508,6 +520,7 @@ public:
|
|||||||
explicit ISulaListImages(void *args) : ClientBase(args)
|
explicit ISulaListImages(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaListImages() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_list_request *req, isula::ListImagesRequest *grequest) override
|
int request_to_grpc(const isula_list_request *req, isula::ListImagesRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -574,6 +587,7 @@ public:
|
|||||||
explicit ISulaRmi(void *args) : ClientBase(args)
|
explicit ISulaRmi(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaRmi() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_rmi_request *req, isula::RemoveImageRequest *grequest) override
|
int request_to_grpc(const isula_rmi_request *req, isula::RemoveImageRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -625,6 +639,7 @@ public:
|
|||||||
explicit ISulaLoad(void *args) : ClientBase(args)
|
explicit ISulaLoad(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaLoad() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_load_request *req, isula::LoadImageRequest *grequest) override
|
int request_to_grpc(const isula_load_request *req, isula::LoadImageRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -682,6 +697,7 @@ public:
|
|||||||
explicit ISulaLogin(void *args) : ClientBase(args)
|
explicit ISulaLogin(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaLogin() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_login_request *req, isula::LoginRequest *grequest) override
|
int request_to_grpc(const isula_login_request *req, isula::LoginRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -736,6 +752,7 @@ public:
|
|||||||
explicit ISulaLogout(void *args) : ClientBase(args)
|
explicit ISulaLogout(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaLogout() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_logout_request *req, isula::LogoutRequest *grequest) override
|
int request_to_grpc(const isula_logout_request *req, isula::LogoutRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -780,6 +797,7 @@ public:
|
|||||||
explicit ISulaExport(void *args) : ClientBase(args)
|
explicit ISulaExport(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaExport() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_export_request *req, isula::ContainerExportRequest *grequest) override
|
int request_to_grpc(const isula_export_request *req, isula::ContainerExportRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -835,6 +853,7 @@ public:
|
|||||||
explicit ISulaStorageStatus(void *args) : ClientBase(args)
|
explicit ISulaStorageStatus(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaStorageStatus() = default;
|
||||||
|
|
||||||
int response_from_grpc(isula::GraphdriverStatusResponse *gresp, isula_storage_status_response *resp) override
|
int response_from_grpc(isula::GraphdriverStatusResponse *gresp, isula_storage_status_response *resp) override
|
||||||
{
|
{
|
||||||
@ -863,6 +882,7 @@ public:
|
|||||||
explicit ISulaContainerFsUsage(void *args) : ClientBase(args)
|
explicit ISulaContainerFsUsage(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaContainerFsUsage() = default;
|
||||||
|
|
||||||
int request_to_grpc(const isula_container_fs_usage_request *req, isula::ContainerFsUsageRequest *grequest) override
|
int request_to_grpc(const isula_container_fs_usage_request *req, isula::ContainerFsUsageRequest *grequest) override
|
||||||
{
|
{
|
||||||
@ -912,6 +932,7 @@ public:
|
|||||||
explicit ISulaImageFsInfo(void *args) : ClientBase(args)
|
explicit ISulaImageFsInfo(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaImageFsInfo() = default;
|
||||||
|
|
||||||
int response_from_grpc(isula::ImageFsInfoResponse *gresp, isula_image_fs_info_response *resp) override
|
int response_from_grpc(isula::ImageFsInfoResponse *gresp, isula_image_fs_info_response *resp) override
|
||||||
{
|
{
|
||||||
@ -993,6 +1014,7 @@ public:
|
|||||||
explicit ISulaHealthCheck(void *args) : ClientBase(args)
|
explicit ISulaHealthCheck(void *args) : ClientBase(args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ISulaHealthCheck() = default;
|
||||||
|
|
||||||
int response_from_grpc(isula::HealthCheckResponse *gresp, isula_health_check_response *resp) override
|
int response_from_grpc(isula::HealthCheckResponse *gresp, isula_health_check_response *resp) override
|
||||||
{
|
{
|
||||||
|
|||||||
@ -330,7 +330,7 @@ static int unpack_create_response(const struct parsed_http_message *message, voi
|
|||||||
response->id = util_strdup_s(cresponse->id);
|
response->id = util_strdup_s(cresponse->id);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +364,7 @@ static int unpack_start_response(const struct parsed_http_message *message, void
|
|||||||
start_response->errmsg = util_strdup_s(cresponse->errmsg);
|
start_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,7 +455,7 @@ static int unpack_list_response(const struct parsed_http_message *message, void
|
|||||||
response->errmsg = util_strdup_s(cresponse->errmsg);
|
response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
if (unpack_container_info_for_list_response(cresponse, response)) {
|
if (unpack_container_info_for_list_response(cresponse, response)) {
|
||||||
@ -493,7 +493,7 @@ static int unpack_attach_response(const struct parsed_http_message *message, voi
|
|||||||
attach_response->errmsg = util_strdup_s(cresponse->errmsg);
|
attach_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +527,7 @@ static int unpack_resume_response(const struct parsed_http_message *message, voi
|
|||||||
resume_response->errmsg = util_strdup_s(cresponse->errmsg);
|
resume_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,7 +562,7 @@ static int unpack_wait_response(const struct parsed_http_message *message, void
|
|||||||
response->errmsg = util_strdup_s(cresponse->errmsg);
|
response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -830,7 +830,7 @@ static int unpack_stop_response(const struct parsed_http_message *message, void
|
|||||||
stop_response->errmsg = util_strdup_s(cresponse->errmsg);
|
stop_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -930,7 +930,7 @@ static int unpack_restart_response(const struct parsed_http_message *message, vo
|
|||||||
response->errmsg = util_strdup_s(cres->errmsg);
|
response->errmsg = util_strdup_s(cres->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cres->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cres->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1043,7 +1043,7 @@ static int unpack_update_response(const struct parsed_http_message *message, voi
|
|||||||
update_response->errmsg = util_strdup_s(cresponse->errmsg);
|
update_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1150,7 +1150,7 @@ static int unpack_version_response(const struct parsed_http_message *message, vo
|
|||||||
version_response->errmsg = util_strdup_s(cresponse->errmsg);
|
version_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1249,7 +1249,7 @@ static int unpack_pause_response(const struct parsed_http_message *message, void
|
|||||||
pause_response->errmsg = util_strdup_s(cresponse->errmsg);
|
pause_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1349,7 +1349,7 @@ static int unpack_kill_response(const struct parsed_http_message *message, void
|
|||||||
kill_response->errmsg = util_strdup_s(cresponse->errmsg);
|
kill_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1449,7 +1449,7 @@ static int unpack_remove_response(const struct parsed_http_message *message, voi
|
|||||||
delete_response->errmsg = util_strdup_s(cresponse->errmsg);
|
delete_response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1554,7 +1554,7 @@ static int unpack_inspect_response(const struct parsed_http_message *message, vo
|
|||||||
response->errmsg = util_strdup_s(cresponse->errmsg);
|
response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1704,7 +1704,7 @@ static int unpack_exec_response(const struct parsed_http_message *message, void
|
|||||||
response->errmsg = util_strdup_s(cresponse->errmsg);
|
response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -174,7 +174,7 @@ static int unpack_image_list_response(const struct parsed_http_message *message,
|
|||||||
response->errmsg = util_strdup_s(cresponse->errmsg);
|
response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ static int unpack_image_load_response(const struct parsed_http_message *message,
|
|||||||
c_load_response->errmsg = util_strdup_s(load_response->errmsg);
|
c_load_response->errmsg = util_strdup_s(load_response->errmsg);
|
||||||
}
|
}
|
||||||
ret = (load_response->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (load_response->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ static int unpack_image_delete_response(const struct parsed_http_message *messag
|
|||||||
c_rmi_response->errmsg = util_strdup_s(delete_response->errmsg);
|
c_rmi_response->errmsg = util_strdup_s(delete_response->errmsg);
|
||||||
}
|
}
|
||||||
ret = (delete_response->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (delete_response->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,7 +416,7 @@ static int unpack_inspect_response(const struct parsed_http_message *message, vo
|
|||||||
response->errmsg = util_strdup_s(cresponse->errmsg);
|
response->errmsg = util_strdup_s(cresponse->errmsg);
|
||||||
}
|
}
|
||||||
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
ret = (cresponse->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,28 +41,37 @@ void protobuf_timestamp_from_grpc(types_timestamp_t *timestamp, const Timestamp
|
|||||||
timestamp->nanos = gtimestamp.nanos();
|
timestamp->nanos = gtimestamp.nanos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_to_grpc(const struct isulad_events_format *event, Event *gevent)
|
int event_to_grpc(const struct isulad_events_format *event, Event *gevent)
|
||||||
{
|
{
|
||||||
gevent->Clear();
|
gevent->Clear();
|
||||||
if (event->id != nullptr) {
|
|
||||||
gevent->set_id(event->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event->has_type != 0) {
|
|
||||||
gevent->set_type((EventType)event->type);
|
|
||||||
}
|
|
||||||
if (event->has_pid != 0) {
|
|
||||||
gevent->set_pid((int32_t)(event->pid));
|
|
||||||
} else {
|
|
||||||
gevent->set_pid(-1);
|
|
||||||
}
|
|
||||||
if (event->has_exit_status != 0) {
|
|
||||||
gevent->set_exit_status(event->exit_status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event->timestamp.has_seconds != 0 || event->timestamp.has_nanos != 0) {
|
if (event->timestamp.has_seconds != 0 || event->timestamp.has_nanos != 0) {
|
||||||
protobuf_timestamp_to_grpc((const types_timestamp_t *)(&event->timestamp), gevent->mutable_timestamp());
|
protobuf_timestamp_to_grpc((const types_timestamp_t *)(&event->timestamp), gevent->mutable_timestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event->opt != nullptr) {
|
||||||
|
gevent->set_opt(event->opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->id != nullptr) {
|
||||||
|
gevent->set_id(event->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->annotations_len != 0 && event->annotations != nullptr) {
|
||||||
|
google::protobuf::Map<std::string, std::string> *map = gevent->mutable_annotations();
|
||||||
|
for (size_t i {0}; i < event->annotations_len; i++) {
|
||||||
|
char **elems = util_string_split_n(event->annotations[i], '=', 2);
|
||||||
|
if (util_array_len((const char **)elems) != 2) {
|
||||||
|
ERROR("Invalid annotation info");
|
||||||
|
util_free_array(elems);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
(*map)[elems[0]] = elems[1];
|
||||||
|
util_free_array(elems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void copy_from_container_response_to_grpc(const struct isulad_copy_from_container_response *copy,
|
void copy_from_container_response_to_grpc(const struct isulad_copy_from_container_response *copy,
|
||||||
@ -93,7 +102,9 @@ bool grpc_event_write_function(void *writer, void *data)
|
|||||||
struct isulad_events_format *event = (struct isulad_events_format *)data;
|
struct isulad_events_format *event = (struct isulad_events_format *)data;
|
||||||
ServerWriter<Event> *gwriter = (ServerWriter<Event> *)writer;
|
ServerWriter<Event> *gwriter = (ServerWriter<Event> *)writer;
|
||||||
Event gevent;
|
Event gevent;
|
||||||
event_to_grpc(event, &gevent);
|
if (event_to_grpc(event, &gevent) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return gwriter->Write(gevent);
|
return gwriter->Write(gevent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1258,6 +1269,7 @@ Status ContainerServiceImpl::Events(ServerContext *context, const EventsRequest
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return Status(StatusCode::INTERNAL, "Failed to execute events callback");
|
return Status(StatusCode::INTERNAL, "Failed to execute events callback");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -194,7 +194,7 @@ grpc::Status RuntimeRuntimeServiceImpl::RunPodSandbox(
|
|||||||
runtime::v1alpha2::RunPodSandboxResponse *reply)
|
runtime::v1alpha2::RunPodSandboxResponse *reply)
|
||||||
{
|
{
|
||||||
Errors error;
|
Errors error;
|
||||||
std::string responseID = rService.RunPodSandbox(request->config(), error);
|
std::string responseID = rService.RunPodSandbox(request->config(), request->runtime_handler(), error);
|
||||||
if (!error.Empty() || responseID.empty()) {
|
if (!error.Empty() || responseID.empty()) {
|
||||||
return grpc::Status(grpc::StatusCode::UNKNOWN, error.GetMessage());
|
return grpc::Status(grpc::StatusCode::UNKNOWN, error.GetMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -208,14 +208,14 @@ static void evhtp_send_create_repsponse(evhtp_request_t *req, container_create_r
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate create response info");
|
ERROR("Failed to generate create response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata = container_create_response_generate_json(response, &ctx, &err);
|
responsedata = container_create_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Create: failed to generate request json:%s", err);
|
ERROR("Create: failed to generate request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,14 +345,14 @@ static void evhtp_send_start_repsponse(evhtp_request_t *req, container_start_res
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate start response info");
|
ERROR("Failed to generate start response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata = container_start_response_generate_json(response, &ctx, &err);
|
responsedata = container_start_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate start request json:%s", err);
|
ERROR("Failed to generate start request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,14 +373,14 @@ static void evhtp_send_list_repsponse(evhtp_request_t *req, container_list_respo
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate inspect response info");
|
ERROR("Failed to generate inspect response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata = container_list_response_generate_json(response, &ctx, &err);
|
responsedata = container_list_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate list request json:%s", err);
|
ERROR("Failed to generate list request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,7 +402,7 @@ static void evhtp_send_wait_repsponse(evhtp_request_t *req, container_wait_respo
|
|||||||
responsedata = container_wait_response_generate_json(response, &ctx, &err);
|
responsedata = container_wait_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate wait request json:%s", err);
|
ERROR("Failed to generate wait request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,26 +424,26 @@ static void rest_create_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.create == NULL) {
|
if (cb == NULL || cb->container.create == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceCreate);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceCreate);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.create(crequest, &cresponse);
|
(void)cb->container.create(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_create_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_create_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_create_response(cresponse);
|
free_container_create_response(cresponse);
|
||||||
free_container_create_request(crequest);
|
free_container_create_request(crequest);
|
||||||
@ -459,26 +459,26 @@ static void rest_start_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.start == NULL) {
|
if (cb == NULL || cb->container.start == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceStart);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceStart);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.start(crequest, &cresponse, -1, NULL, NULL);
|
(void)cb->container.start(crequest, &cresponse, -1, NULL, NULL);
|
||||||
|
|
||||||
evhtp_send_start_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_start_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_start_request(crequest);
|
free_container_start_request(crequest);
|
||||||
free_container_start_response(cresponse);
|
free_container_start_response(cresponse);
|
||||||
@ -494,26 +494,26 @@ static void rest_wait_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.wait == NULL) {
|
if (cb == NULL || cb->container.wait == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceWait);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceWait);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.wait(crequest, &cresponse);
|
(void)cb->container.wait(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_wait_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_wait_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_wait_request(crequest);
|
free_container_wait_request(crequest);
|
||||||
free_container_wait_response(cresponse);
|
free_container_wait_response(cresponse);
|
||||||
@ -528,14 +528,14 @@ static void evhtp_send_stop_repsponse(evhtp_request_t *req, container_stop_respo
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate stop response info");
|
ERROR("Failed to generate stop response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata = container_stop_response_generate_json(response, &ctx, &err);
|
responsedata = container_stop_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate stop request json:%s", err);
|
ERROR("Failed to generate stop request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,26 +557,26 @@ static void rest_stop_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.stop == NULL) {
|
if (cb == NULL || cb->container.stop == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceStop);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceStop);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.stop(crequest, &cresponse);
|
(void)cb->container.stop(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_stop_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_stop_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_stop_response(cresponse);
|
free_container_stop_response(cresponse);
|
||||||
free_container_stop_request(crequest);
|
free_container_stop_request(crequest);
|
||||||
@ -591,13 +591,13 @@ static void evhtp_send_restart_response(evhtp_request_t *req, container_restart_
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate restart response info");
|
ERROR("Failed to generate restart response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
responsedata = container_restart_response_generate_json(response, &ctx, &err);
|
responsedata = container_restart_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate restart response json: %s", err);
|
ERROR("Failed to generate restart response json: %s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,27 +618,27 @@ static void rest_restart_cb(evhtp_request_t *req, void *arg)
|
|||||||
container_restart_response *cresponse = NULL;
|
container_restart_response *cresponse = NULL;
|
||||||
|
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.restart == NULL) {
|
if (cb == NULL || cb->container.restart == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceRestart);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceRestart);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.restart(crequest, &cresponse);
|
(void)cb->container.restart(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_restart_response(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_restart_response(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_restart_request(crequest);
|
free_container_restart_request(crequest);
|
||||||
free_container_restart_response(cresponse);
|
free_container_restart_response(cresponse);
|
||||||
@ -654,7 +654,7 @@ static void evhtp_send_version_repsponse(evhtp_request_t *req, container_version
|
|||||||
responsedata = container_version_response_generate_json(response, &ctx, &err);
|
responsedata = container_version_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate version request json:%s", err);
|
ERROR("Failed to generate version request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,26 +676,26 @@ static void rest_version_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.version == NULL) {
|
if (cb == NULL || cb->container.version == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceVersion);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceVersion);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.version(crequest, &cresponse);
|
(void)cb->container.version(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_version_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_version_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_version_request(crequest);
|
free_container_version_request(crequest);
|
||||||
free_container_version_response(cresponse);
|
free_container_version_response(cresponse);
|
||||||
@ -710,14 +710,14 @@ static void evhtp_send_update_repsponse(evhtp_request_t *req, container_update_r
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Invalid NULL response");
|
ERROR("Invalid NULL response");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata = container_update_response_generate_json(response, &ctx, &err);
|
responsedata = container_update_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate update request json:%s", err);
|
ERROR("Failed to generate update request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,25 +739,25 @@ static void rest_update_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.update == NULL) {
|
if (cb == NULL || cb->container.update == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&container_req, ContainerServiceUpdate);
|
tret = action_request_from_rest(req, (void **)&container_req, ContainerServiceUpdate);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.update(container_req, &container_res);
|
(void)cb->container.update(container_req, &container_res);
|
||||||
evhtp_send_update_repsponse(req, container_res, EVHTP_RES_OK);
|
evhtp_send_update_repsponse(req, container_res, RESTFUL_RES_OK);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free_container_update_request(container_req);
|
free_container_update_request(container_req);
|
||||||
@ -773,13 +773,13 @@ static void evhtp_send_kill_repsponse(evhtp_request_t *req, container_kill_respo
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate kill response info");
|
ERROR("Failed to generate kill response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
responsedata = container_kill_response_generate_json(response, &ctx, &err);
|
responsedata = container_kill_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate kill request json:%s", err);
|
ERROR("Failed to generate kill request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,26 +801,26 @@ static void rest_kill_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.kill == NULL) {
|
if (cb == NULL || cb->container.kill == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceKill);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceKill);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("bad request");
|
ERROR("bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.kill(crequest, &cresponse);
|
(void)cb->container.kill(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_kill_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_kill_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_kill_request(crequest);
|
free_container_kill_request(crequest);
|
||||||
free_container_kill_response(cresponse);
|
free_container_kill_response(cresponse);
|
||||||
@ -836,14 +836,14 @@ static void evhtp_send_container_inspect_repsponse(evhtp_request_t *req, contain
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate inspect response info");
|
ERROR("Failed to generate inspect response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata = container_inspect_response_generate_json(response, &ctx, &err);
|
responsedata = container_inspect_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate inspect request json:%s", err);
|
ERROR("Failed to generate inspect request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -865,26 +865,26 @@ static void rest_container_inspect_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.inspect == NULL) {
|
if (cb == NULL || cb->container.inspect == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceInspect);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceInspect);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("bad request");
|
ERROR("bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.inspect(crequest, &cresponse);
|
(void)cb->container.inspect(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_container_inspect_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_container_inspect_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_inspect_request(crequest);
|
free_container_inspect_request(crequest);
|
||||||
free_container_inspect_response(cresponse);
|
free_container_inspect_response(cresponse);
|
||||||
@ -899,14 +899,14 @@ static void evhtp_send_exec_repsponse(evhtp_request_t *req, container_exec_respo
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate exec response info");
|
ERROR("Failed to generate exec response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata = container_exec_response_generate_json(response, &ctx, &err);
|
responsedata = container_exec_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate exec request json:%s", err);
|
ERROR("Failed to generate exec request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -928,26 +928,26 @@ static void rest_exec_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || !cb->container.exec) {
|
if (cb == NULL || !cb->container.exec) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceExec);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceExec);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("bad request");
|
ERROR("bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.exec(crequest, &cresponse, -1, NULL);
|
(void)cb->container.exec(crequest, &cresponse, -1, NULL);
|
||||||
|
|
||||||
evhtp_send_exec_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_exec_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_exec_request(crequest);
|
free_container_exec_request(crequest);
|
||||||
free_container_exec_response(cresponse);
|
free_container_exec_response(cresponse);
|
||||||
@ -962,13 +962,13 @@ static void evhtp_send_remove_repsponse(evhtp_request_t *req, container_delete_r
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate remove response info");
|
ERROR("Failed to generate remove response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
responsedata = container_delete_response_generate_json(response, &ctx, &err);
|
responsedata = container_delete_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate remove request json:%s", err);
|
ERROR("Failed to generate remove request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -990,26 +990,26 @@ static void rest_remove_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.remove == NULL) {
|
if (cb == NULL || cb->container.remove == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceRemove);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceRemove);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.remove(crequest, &cresponse);
|
(void)cb->container.remove(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_remove_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_remove_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_delete_request(crequest);
|
free_container_delete_request(crequest);
|
||||||
free_container_delete_response(cresponse);
|
free_container_delete_response(cresponse);
|
||||||
@ -1025,26 +1025,26 @@ static void rest_list_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->container.list == NULL) {
|
if (cb == NULL || cb->container.list == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceList);
|
tret = action_request_from_rest(req, (void **)&crequest, ContainerServiceList);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.list(crequest, &cresponse);
|
(void)cb->container.list(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_list_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_list_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_container_list_request(crequest);
|
free_container_list_request(crequest);
|
||||||
free_container_list_response(cresponse);
|
free_container_list_response(cresponse);
|
||||||
|
|||||||
@ -78,7 +78,7 @@ static void evhtp_send_image_load_repsponse(evhtp_request_t *req,
|
|||||||
responsedata = image_load_image_response_generate_json(response, NULL, &err);
|
responsedata = image_load_image_response_generate_json(response, NULL, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Load: failed to generate request json:%s", err);
|
ERROR("Load: failed to generate request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
evhtp_send_response(req, responsedata, rescode);
|
evhtp_send_response(req, responsedata, rescode);
|
||||||
@ -126,7 +126,7 @@ static void evhtp_send_image_list_repsponse(evhtp_request_t *req,
|
|||||||
responsedata = image_list_images_response_generate_json(response, NULL, &err);
|
responsedata = image_list_images_response_generate_json(response, NULL, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("List: failed to generate request json:%s", err);
|
ERROR("List: failed to generate request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
evhtp_send_response(req, responsedata, rescode);
|
evhtp_send_response(req, responsedata, rescode);
|
||||||
@ -198,7 +198,7 @@ static void evhtp_send_image_delete_repsponse(evhtp_request_t *req,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ERROR("Delete: failed to generate request json:%s", err);
|
ERROR("Delete: failed to generate request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
out:
|
out:
|
||||||
free(responsedata);
|
free(responsedata);
|
||||||
free(err);
|
free(err);
|
||||||
@ -259,14 +259,14 @@ static void evhtp_send_image_inspect_repsponse(evhtp_request_t *req,
|
|||||||
|
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Failed to generate inspect response info");
|
ERROR("Failed to generate inspect response info");
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsedata = image_inspect_response_generate_json(response, &ctx, &err);
|
responsedata = image_inspect_response_generate_json(response, &ctx, &err);
|
||||||
if (responsedata == NULL) {
|
if (responsedata == NULL) {
|
||||||
ERROR("Failed to generate inspect request json:%s", err);
|
ERROR("Failed to generate inspect request json:%s", err);
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,26 +288,26 @@ static void rest_image_load_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->image.load == NULL) {
|
if (cb == NULL || cb->image.load == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = image_load_request_from_rest(req, &crequest);
|
tret = image_load_request_from_rest(req, &crequest);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->image.load(crequest, &cresponse);
|
(void)cb->image.load(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_image_load_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_image_load_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_image_load_image_request(crequest);
|
free_image_load_image_request(crequest);
|
||||||
free_image_load_image_response(cresponse);
|
free_image_load_image_response(cresponse);
|
||||||
@ -323,26 +323,26 @@ static void rest_image_list_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->image.list == NULL) {
|
if (cb == NULL || cb->image.list == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = image_list_request_from_rest(req, &crequest);
|
tret = image_list_request_from_rest(req, &crequest);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->image.list(crequest, &cresponse);
|
(void)cb->image.list(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_image_list_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_image_list_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_image_list_images_request(crequest);
|
free_image_list_images_request(crequest);
|
||||||
free_image_list_images_response(cresponse);
|
free_image_list_images_response(cresponse);
|
||||||
@ -358,26 +358,26 @@ static void rest_image_delete_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->image.remove == NULL) {
|
if (cb == NULL || cb->image.remove == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = image_delete_request_from_rest(req, &crequest);
|
tret = image_delete_request_from_rest(req, &crequest);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->image.remove(crequest, &cresponse);
|
(void)cb->image.remove(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_image_delete_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_image_delete_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_image_delete_image_request(crequest);
|
free_image_delete_image_request(crequest);
|
||||||
free_image_delete_image_response(cresponse);
|
free_image_delete_image_response(cresponse);
|
||||||
@ -393,26 +393,26 @@ static void rest_image_inspect_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
// only deal with POST request
|
// only deal with POST request
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb = get_service_callback();
|
cb = get_service_callback();
|
||||||
if (cb == NULL || cb->image.inspect == NULL) {
|
if (cb == NULL || cb->image.inspect == NULL) {
|
||||||
ERROR("Unimplemented callback");
|
ERROR("Unimplemented callback");
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tret = image_inspect_request_from_rest(req, &crequest);
|
tret = image_inspect_request_from_rest(req, &crequest);
|
||||||
if (tret < 0) {
|
if (tret < 0) {
|
||||||
ERROR("Bad request");
|
ERROR("Bad request");
|
||||||
evhtp_send_reply(req, EVHTP_RES_SERVERR);
|
evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->image.inspect(crequest, &cresponse);
|
(void)cb->image.inspect(crequest, &cresponse);
|
||||||
|
|
||||||
evhtp_send_image_inspect_repsponse(req, cresponse, EVHTP_RES_OK);
|
evhtp_send_image_inspect_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
free_image_inspect_request(crequest);
|
free_image_inspect_request(crequest);
|
||||||
free_image_inspect_response(cresponse);
|
free_image_inspect_response(cresponse);
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include <evhtp.h>
|
#include <evhtp.h>
|
||||||
|
|
||||||
|
#include "rest_common.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -46,6 +46,8 @@
|
|||||||
|
|
||||||
#define DEBUG_DIRECTORY_MODE 0750
|
#define DEBUG_DIRECTORY_MODE 0750
|
||||||
|
|
||||||
|
#define NETWORK_MOUNT_FILE_MODE 0644
|
||||||
|
|
||||||
#define ISULAD_CONFIG "/etc/isulad"
|
#define ISULAD_CONFIG "/etc/isulad"
|
||||||
|
|
||||||
#define ISULAD_DAEMON_JSON_CONF_FILE ISULAD_CONFIG "/daemon.json"
|
#define ISULAD_DAEMON_JSON_CONF_FILE ISULAD_CONFIG "/daemon.json"
|
||||||
|
|||||||
@ -32,3 +32,27 @@ void container_cgroup_resources_free(container_cgroup_resources_t *cr)
|
|||||||
free(cr);
|
free(cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void container_events_format_free(container_events_format_t *value)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (value == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(value->opt);
|
||||||
|
value->opt = NULL;
|
||||||
|
|
||||||
|
free(value->id);
|
||||||
|
value->id = NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < value->annotations_len; i++) {
|
||||||
|
free(value->annotations[i]);
|
||||||
|
value->annotations[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(value->annotations);
|
||||||
|
value->annotations = NULL;
|
||||||
|
|
||||||
|
free(value);
|
||||||
|
}
|
||||||
@ -40,7 +40,7 @@ extern "C" {
|
|||||||
#define SECCOMP_DEFAULT_PATH "/etc/isulad/seccomp_default.json"
|
#define SECCOMP_DEFAULT_PATH "/etc/isulad/seccomp_default.json"
|
||||||
#endif
|
#endif
|
||||||
#ifndef OCI_VERSION
|
#ifndef OCI_VERSION
|
||||||
#define OCI_VERSION "1.0.0-rc5-dev"
|
#define OCI_VERSION "1.0.1"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -55,12 +55,36 @@ typedef enum {
|
|||||||
EVENTS_TYPE_THAWED = 8,
|
EVENTS_TYPE_THAWED = 8,
|
||||||
EVENTS_TYPE_OOM = 9,
|
EVENTS_TYPE_OOM = 9,
|
||||||
EVENTS_TYPE_CREATE = 10,
|
EVENTS_TYPE_CREATE = 10,
|
||||||
EVENTS_TYPE_START = 11,
|
EVENTS_TYPE_START,
|
||||||
EVENTS_TYPE_EXEC_ADDED = 12,
|
EVENTS_TYPE_RESTART,
|
||||||
EVENTS_TYPE_PAUSED1 = 13,
|
EVENTS_TYPE_STOP,
|
||||||
EVENTS_TYPE_MAX_STATE = 14
|
EVENTS_TYPE_EXEC_CREATE,
|
||||||
|
EVENTS_TYPE_EXEC_START,
|
||||||
|
EVENTS_TYPE_EXEC_DIE,
|
||||||
|
EVENTS_TYPE_ATTACH,
|
||||||
|
EVENTS_TYPE_KILL,
|
||||||
|
EVENTS_TYPE_TOP,
|
||||||
|
EVENTS_TYPE_RENAME,
|
||||||
|
EVENTS_TYPE_ARCHIVE_PATH,
|
||||||
|
EVENTS_TYPE_EXTRACT_TO_DIR,
|
||||||
|
EVENTS_TYPE_UPDATE,
|
||||||
|
EVENTS_TYPE_PAUSE,
|
||||||
|
EVENTS_TYPE_UNPAUSE,
|
||||||
|
EVENTS_TYPE_EXPORT,
|
||||||
|
EVENTS_TYPE_RESIZE,
|
||||||
|
EVENTS_TYPE_PAUSED1,
|
||||||
|
EVENTS_TYPE_MAX_STATE
|
||||||
} container_events_type_t;
|
} container_events_type_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EVENTS_TYPE_IMAGE_LOAD = 0,
|
||||||
|
EVENTS_TYPE_IMAGE_REMOVE,
|
||||||
|
EVENTS_TYPE_IMAGE_PULL,
|
||||||
|
EVENTS_TYPE_IMAGE_LOGIN,
|
||||||
|
EVENTS_TYPE_IMAGE_LOGOUT,
|
||||||
|
EVENTS_TYPE_IMAGE_MAX_STATE
|
||||||
|
} image_events_type_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CONTAINER_STATUS_UNKNOWN = 0,
|
CONTAINER_STATUS_UNKNOWN = 0,
|
||||||
CONTAINER_STATUS_CREATED = 1,
|
CONTAINER_STATUS_CREATED = 1,
|
||||||
@ -73,10 +97,16 @@ typedef enum {
|
|||||||
} Container_Status;
|
} Container_Status;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STOPPED, STARTING, RUNNING, STOPPING,
|
EXIT, STOPPED, STARTING, RUNNING, STOPPING, ABORTING, FREEZING,
|
||||||
ABORTING, FREEZING, FROZEN, THAWED, MAX_STATE
|
FROZEN, THAWED, OOM, CREATE, START, RESTART, STOP, EXEC_CREATE, EXEC_START, EXEC_DIE, ATTACH,
|
||||||
|
KILL, TOP, RENAME, ARCHIVE_PATH, EXTRACT_TO_DIR, UPDATE, PAUSE, UNPAUSE, EXPORT, RESIZE, PAUSED1, MAX_STATE,
|
||||||
} runtime_state_t;
|
} runtime_state_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
IM_LOAD, IM_REMOVE, IM_PULL, IM_LOGIN, IM_LOGOUT
|
||||||
|
} image_state_t;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HEALTH_SERVING_STATUS_UNKNOWN = 0,
|
HEALTH_SERVING_STATUS_UNKNOWN = 0,
|
||||||
HEALTH_SERVING_STATUS_SERVING = 1,
|
HEALTH_SERVING_STATUS_SERVING = 1,
|
||||||
@ -100,6 +130,11 @@ typedef enum {
|
|||||||
WAIT_CONDITION_REMOVED = 1
|
WAIT_CONDITION_REMOVED = 1
|
||||||
} wait_condition_t;
|
} wait_condition_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CONTAINER_EVENT,
|
||||||
|
IMAGE_EVENT
|
||||||
|
} msg_event_type_t;
|
||||||
|
|
||||||
typedef struct container_cgroup_resources {
|
typedef struct container_cgroup_resources {
|
||||||
uint16_t blkio_weight;
|
uint16_t blkio_weight;
|
||||||
int64_t cpu_shares;
|
int64_t cpu_shares;
|
||||||
@ -116,21 +151,20 @@ typedef struct container_cgroup_resources {
|
|||||||
int64_t pids_limit;
|
int64_t pids_limit;
|
||||||
int64_t files_limit;
|
int64_t files_limit;
|
||||||
int64_t oom_score_adj;
|
int64_t oom_score_adj;
|
||||||
|
int64_t swappiness;
|
||||||
} container_cgroup_resources_t;
|
} container_cgroup_resources_t;
|
||||||
|
|
||||||
typedef struct container_events_format {
|
typedef struct container_events_format {
|
||||||
char *id;
|
|
||||||
uint32_t has_type;
|
|
||||||
container_events_type_t type;
|
|
||||||
uint32_t has_pid;
|
|
||||||
uint32_t pid;
|
|
||||||
uint32_t has_exit_status;
|
|
||||||
uint32_t exit_status;
|
|
||||||
types_timestamp_t timestamp;
|
types_timestamp_t timestamp;
|
||||||
|
char *opt;
|
||||||
|
char *id;
|
||||||
|
char **annotations;
|
||||||
|
char annotations_len;
|
||||||
} container_events_format_t;
|
} container_events_format_t;
|
||||||
|
|
||||||
void container_cgroup_resources_free(container_cgroup_resources_t *cr);
|
void container_cgroup_resources_free(container_cgroup_resources_t *cr);
|
||||||
|
|
||||||
|
void container_events_format_free(container_events_format_t *value);
|
||||||
|
|
||||||
typedef void (*container_events_callback_t)(const container_events_format_t *event);
|
typedef void (*container_events_callback_t)(const container_events_format_t *event);
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"ociVersion": "1.0.0-rc5-dev",
|
"ociVersion": "1.0.1",
|
||||||
"process": {
|
"process": {
|
||||||
"terminal": true,
|
"terminal": true,
|
||||||
"consoleSize": {
|
"consoleSize": {
|
||||||
@ -96,18 +96,6 @@
|
|||||||
"ro"
|
"ro"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"destination": "/dev/shm",
|
|
||||||
"type": "tmpfs",
|
|
||||||
"source": "shm",
|
|
||||||
"options": [
|
|
||||||
"nosuid",
|
|
||||||
"noexec",
|
|
||||||
"nodev",
|
|
||||||
"mode=1777",
|
|
||||||
"size=65536k"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"destination": "/sys/fs/cgroup",
|
"destination": "/sys/fs/cgroup",
|
||||||
"type": "cgroup",
|
"type": "cgroup",
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"group": "isulad",
|
"group": "isulad",
|
||||||
|
"default-runtime": "lcr",
|
||||||
"graph": "/var/lib/isulad",
|
"graph": "/var/lib/isulad",
|
||||||
"state": "/var/run/isulad",
|
"state": "/var/run/isulad",
|
||||||
"engine": "lcr",
|
"engine": "lcr",
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"ociVersion": "1.0.0-rc5-dev",
|
"ociVersion": "1.0.1",
|
||||||
"process": {
|
"process": {
|
||||||
"terminal": true,
|
"terminal": true,
|
||||||
"consoleSize": {
|
"consoleSize": {
|
||||||
@ -96,18 +96,6 @@
|
|||||||
"ro"
|
"ro"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"destination": "/dev/shm",
|
|
||||||
"type": "tmpfs",
|
|
||||||
"source": "shm",
|
|
||||||
"options": [
|
|
||||||
"nosuid",
|
|
||||||
"noexec",
|
|
||||||
"nodev",
|
|
||||||
"mode=1777",
|
|
||||||
"size=65536k"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"destination": "/sys/fs/cgroup",
|
"destination": "/sys/fs/cgroup",
|
||||||
"type": "cgroup",
|
"type": "cgroup",
|
||||||
|
|||||||
@ -34,7 +34,6 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|||||||
@ -552,7 +552,7 @@ char *util_full_file_digest(const char *filename)
|
|||||||
return full_digest;
|
return full_digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *util_path_dir(const char *path)
|
char *util_path_dir(const char *path)
|
||||||
{
|
{
|
||||||
char *dir = NULL;
|
char *dir = NULL;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@ -822,7 +822,7 @@ free_out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int util_write_file(const char *fname, const char *content, size_t content_len)
|
int util_write_file(const char *fname, const char *content, size_t content_len, mode_t mode)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int dst_fd = -1;
|
int dst_fd = -1;
|
||||||
@ -834,7 +834,7 @@ int util_write_file(const char *fname, const char *content, size_t content_len)
|
|||||||
if (content == NULL || content_len == 0) {
|
if (content == NULL || content_len == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
dst_fd = util_open(fname, O_WRONLY | O_CREAT | O_TRUNC, DEFAULT_SECURE_FILE_MODE);
|
dst_fd = util_open(fname, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||||
if (dst_fd < 0) {
|
if (dst_fd < 0) {
|
||||||
ERROR("Creat file: %s, failed: %s", fname, strerror(errno));
|
ERROR("Creat file: %s, failed: %s", fname, strerror(errno));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -877,7 +877,7 @@ char *verify_file_and_get_real_path(const char *file)
|
|||||||
return util_strdup_s(resolved_path);
|
return util_strdup_s(resolved_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int util_copy_file(const char *src_file, const char *dst_file)
|
int util_copy_file(const char *src_file, const char *dst_file, mode_t mode)
|
||||||
{
|
{
|
||||||
#define BUFSIZE 4096
|
#define BUFSIZE 4096
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -902,7 +902,7 @@ int util_copy_file(const char *src_file, const char *dst_file)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
goto free_out;
|
goto free_out;
|
||||||
}
|
}
|
||||||
dst_fd = util_open(dst_file, O_WRONLY | O_CREAT | O_TRUNC, DEFAULT_SECURE_FILE_MODE);
|
dst_fd = util_open(dst_file, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||||
if (dst_fd < 0) {
|
if (dst_fd < 0) {
|
||||||
ERROR("Creat file: %s, failed: %s", dst_file, strerror(errno));
|
ERROR("Creat file: %s, failed: %s", dst_file, strerror(errno));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|||||||
@ -55,6 +55,8 @@ FILE *util_fopen(const char *filename, const char *mode);
|
|||||||
|
|
||||||
char *util_full_file_digest(const char *filename);
|
char *util_full_file_digest(const char *filename);
|
||||||
|
|
||||||
|
char *util_path_dir(const char *path);
|
||||||
|
|
||||||
char *util_add_path(const char *path, const char *name);
|
char *util_add_path(const char *path, const char *name);
|
||||||
|
|
||||||
char *util_read_text_file(const char *path);
|
char *util_read_text_file(const char *path);
|
||||||
@ -67,11 +69,11 @@ int util_file2str(const char *filename, char *buf, size_t len);
|
|||||||
|
|
||||||
char *look_path(const char *file, char **err);
|
char *look_path(const char *file, char **err);
|
||||||
|
|
||||||
int util_write_file(const char *fname, const char *content, size_t content_len);
|
int util_write_file(const char *fname, const char *content, size_t content_len, mode_t mode);
|
||||||
|
|
||||||
char *verify_file_and_get_real_path(const char *file);
|
char *verify_file_and_get_real_path(const char *file);
|
||||||
|
|
||||||
int util_copy_file(const char *src_file, const char *dst_file);
|
int util_copy_file(const char *src_file, const char *dst_file, mode_t mode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,6 +79,18 @@ bool strings_contains_any(const char *str, const char *substr)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool strings_contains_word(const char *str, const char *substr)
|
||||||
|
{
|
||||||
|
if (str == NULL || substr == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcasestr(str, substr) != NULL) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int strings_count(const char *str, unsigned char c)
|
int strings_count(const char *str, unsigned char c)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
@ -271,7 +283,8 @@ int util_parse_percent_string(const char *s, long *converted)
|
|||||||
{
|
{
|
||||||
char *dup = NULL;
|
char *dup = NULL;
|
||||||
|
|
||||||
if (s == NULL || converted == NULL || s[0] == 0 || strlen(s) < 2 || s[strlen(s) - 1] != '%') {
|
if (s == NULL || converted == NULL || s[0] == 0 || strlen(s) < 2 || s[strlen(s) - 1] != '%' ||
|
||||||
|
strspn(s, "0123456789%") != strlen(s)) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
dup = util_strdup_s(s);
|
dup = util_strdup_s(s);
|
||||||
@ -282,7 +295,7 @@ int util_parse_percent_string(const char *s, long *converted)
|
|||||||
|
|
||||||
*converted = strtol(dup, NULL, 10);
|
*converted = strtol(dup, NULL, 10);
|
||||||
if ((errno == ERANGE && (*converted == LONG_MAX || *converted == LONG_MIN)) ||
|
if ((errno == ERANGE && (*converted == LONG_MAX || *converted == LONG_MIN)) ||
|
||||||
(errno != 0 && *converted == 0) || *converted < 0 || *converted >= 100) {
|
(errno != 0 && *converted == 0) || *converted < 0 || *converted > 100) {
|
||||||
free(dup);
|
free(dup);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -369,6 +382,49 @@ err_out:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char **util_string_split_n(const char *src, char sep, size_t n)
|
||||||
|
{
|
||||||
|
char **res_array = NULL;
|
||||||
|
const char *index = NULL;
|
||||||
|
char *token = NULL;
|
||||||
|
char *str = NULL;
|
||||||
|
size_t count = 0;
|
||||||
|
int tmp_errno;
|
||||||
|
|
||||||
|
if (src == NULL || n == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (src[0] == '\0') {
|
||||||
|
return make_empty_array();
|
||||||
|
}
|
||||||
|
str = util_strdup_s(src);
|
||||||
|
index = str;
|
||||||
|
for (token = strchr(index, sep); token != NULL; token = strchr(index, sep)) {
|
||||||
|
count++;
|
||||||
|
if (count >= n) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*token = '\0';
|
||||||
|
if (util_array_append(&res_array, index) != 0) {
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
index = token + 1;
|
||||||
|
}
|
||||||
|
if (util_array_append(&res_array, index) != 0) {
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
free(str);
|
||||||
|
return res_array;
|
||||||
|
|
||||||
|
err_out:
|
||||||
|
tmp_errno = errno;
|
||||||
|
free(str);
|
||||||
|
util_free_array(res_array);
|
||||||
|
errno = tmp_errno;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char **util_string_split(const char *src_str, char _sep)
|
char **util_string_split(const char *src_str, char _sep)
|
||||||
{
|
{
|
||||||
char *token = NULL;
|
char *token = NULL;
|
||||||
|
|||||||
@ -25,6 +25,8 @@ extern "C" {
|
|||||||
|
|
||||||
bool strings_contains_any(const char *str, const char *substr);
|
bool strings_contains_any(const char *str, const char *substr);
|
||||||
|
|
||||||
|
bool strings_contains_word(const char *str, const char *substr);
|
||||||
|
|
||||||
int strings_count(const char *str, unsigned char c);
|
int strings_count(const char *str, unsigned char c);
|
||||||
|
|
||||||
bool strings_in_slice(const char **strarray, size_t alen, const char *str);
|
bool strings_in_slice(const char **strarray, size_t alen, const char *str);
|
||||||
@ -45,6 +47,8 @@ char **util_string_split(const char *src_str, char _sep);
|
|||||||
// note that every delimiter bytes is considered to be a single delimiter
|
// note that every delimiter bytes is considered to be a single delimiter
|
||||||
char **util_string_split_multi(const char *src_str, char delim);
|
char **util_string_split_multi(const char *src_str, char delim);
|
||||||
|
|
||||||
|
char **util_string_split_n(const char *src_str, char delim, size_t n);
|
||||||
|
|
||||||
const char *str_skip_str(const char *str, const char *skip);
|
const char *str_skip_str(const char *str, const char *skip);
|
||||||
|
|
||||||
char *util_string_delchar(const char *ss, unsigned char c);
|
char *util_string_delchar(const char *ss, unsigned char c);
|
||||||
|
|||||||
@ -274,7 +274,7 @@ bool util_valid_runtime_name(const char *name)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strcasecmp(name, "lcr") == 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool util_valid_host_name(const char *name)
|
bool util_valid_host_name(const char *name)
|
||||||
@ -386,7 +386,7 @@ cleanup:
|
|||||||
|
|
||||||
bool util_valid_time_tz(const char *time)
|
bool util_valid_time_tz(const char *time)
|
||||||
{
|
{
|
||||||
char *patten = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2,9})?Z$";
|
char *patten = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2,9})?(Z|[+-][0-9]{2}:[0-9]{2})$";
|
||||||
|
|
||||||
if (time == NULL) {
|
if (time == NULL) {
|
||||||
ERROR("invalid NULL param");
|
ERROR("invalid NULL param");
|
||||||
|
|||||||
@ -16,7 +16,7 @@ target_include_directories(libhttpclient PUBLIC
|
|||||||
|
|
||||||
# set libhttpclient FLAGS
|
# set libhttpclient FLAGS
|
||||||
set_target_properties(libhttpclient PROPERTIES PREFIX "")
|
set_target_properties(libhttpclient PROPERTIES PREFIX "")
|
||||||
target_link_libraries(libhttpclient ${HTTP_PARSER_LIBRARY} ${CURL_LIBRARY} ${LIBSECUREC_LIBRARY})
|
target_link_libraries(libhttpclient ${HTTP_PARSER_LIBRARY} ${CURL_LIBRARY})
|
||||||
|
|
||||||
if (ISULAD_GCOV)
|
if (ISULAD_GCOV)
|
||||||
target_link_libraries(libhttpclient -lgcov)
|
target_link_libraries(libhttpclient -lgcov)
|
||||||
|
|||||||
@ -52,15 +52,15 @@ static int g_ops_status = 0;
|
|||||||
/* check status code */
|
/* check status code */
|
||||||
int check_status_code(int status_code)
|
int check_status_code(int status_code)
|
||||||
{
|
{
|
||||||
if (status_code == EVHTP_RES_OK || status_code == EVHTP_RES_SERVERR) {
|
if (status_code == RESTFUL_RES_OK || status_code == RESTFUL_RES_SERVERR) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (status_code == EVHTP_RES_NOTIMPL) {
|
} else if (status_code == RESTFUL_RES_NOTIMPL) {
|
||||||
ERROR("Not implement interface");
|
ERROR("Not implement interface");
|
||||||
return -1;
|
return -1;
|
||||||
} else if (status_code == EVHTP_RES_NOTFOUND) {
|
} else if (status_code == RESTFUL_RES_NOTFOUND) {
|
||||||
ERROR("Can not connect to service");
|
ERROR("Can not connect to service");
|
||||||
return -1;
|
return -1;
|
||||||
} else if (status_code == EVHTP_RES_ERROR) {
|
} else if (status_code == RESTFUL_RES_ERROR) {
|
||||||
ERROR("Server internal error");
|
ERROR("Server internal error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,8 +15,6 @@
|
|||||||
#ifndef __REST_COMMON_H
|
#ifndef __REST_COMMON_H
|
||||||
#define __REST_COMMON_H
|
#define __REST_COMMON_H
|
||||||
|
|
||||||
#include <evhtp.h>
|
|
||||||
|
|
||||||
#include "http/buffer.h"
|
#include "http/buffer.h"
|
||||||
#include "http/http.h"
|
#include "http/http.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
@ -25,6 +23,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Response status from restful server
|
||||||
|
#define RESTFUL_RES_ERROR 0
|
||||||
|
#define RESTFUL_RES_OK 200
|
||||||
|
#define RESTFUL_RES_NOTFOUND 404
|
||||||
|
#define RESTFUL_RES_SERVERR 500
|
||||||
|
#define RESTFUL_RES_NOTIMPL 501
|
||||||
|
|
||||||
typedef int (*unpack_response_func_t)(const struct parsed_http_message *message, void *arg);
|
typedef int (*unpack_response_func_t)(const struct parsed_http_message *message, void *arg);
|
||||||
|
|
||||||
int get_response(Buffer *output, unpack_response_func_t unpack_func, void *arg);
|
int get_response(Buffer *output, unpack_response_func_t unpack_func, void *arg);
|
||||||
|
|||||||
@ -382,12 +382,6 @@ static bool validate_create_time(char *created)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ensure time can be processed by us */
|
|
||||||
if (time_tz_to_seconds_nanos(created, NULL, NULL)) {
|
|
||||||
ERROR("invalid created time %s, invalid time value", created);
|
|
||||||
isulad_try_set_error_message("Invalid content in manifest: invalid created time");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "ext_image.h"
|
#include "ext_image.h"
|
||||||
#include "filters.h"
|
#include "filters.h"
|
||||||
|
#include "collector.h"
|
||||||
|
|
||||||
#ifdef ENABLE_OCI_IMAGE
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
#include "isula_image.h"
|
#include "isula_image.h"
|
||||||
@ -163,6 +164,10 @@ static const struct bim_type *bim_query(const char *image_name)
|
|||||||
WARN("Unimplements resolve image name in %s", g_bims[i].image_type);
|
WARN("Unimplements resolve image name in %s", g_bims[i].image_type);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (g_bims[i].ops->detect == NULL) {
|
||||||
|
WARN("Unimplements detect in %s", g_bims[i].image_type);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
temp = g_bims[i].ops->resolve_image_name(image_name);
|
temp = g_bims[i].ops->resolve_image_name(image_name);
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
isulad_append_error_message("Failed to resovle image name%s", image_name);
|
isulad_append_error_message("Failed to resovle image name%s", image_name);
|
||||||
@ -236,6 +241,12 @@ static struct bim *bim_get(const char *image_type, const char *image_name, const
|
|||||||
bim->ops = q->ops;
|
bim->ops = q->ops;
|
||||||
bim->type = q->image_type;
|
bim->type = q->image_type;
|
||||||
|
|
||||||
|
if (bim->ops->resolve_image_name == NULL) {
|
||||||
|
ERROR("Unimplements resolve image name");
|
||||||
|
bim_put(bim);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (image_name != NULL) {
|
if (image_name != NULL) {
|
||||||
bim->image_name = bim->ops->resolve_image_name(image_name);
|
bim->image_name = bim->ops->resolve_image_name(image_name);
|
||||||
if (bim->image_name == NULL) {
|
if (bim->image_name == NULL) {
|
||||||
@ -919,6 +930,7 @@ int im_pull_image(const im_pull_request *request, im_pull_response **response)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
EVENT("Event: {Object: %s, Type: Pulled}", request->image);
|
EVENT("Event: {Object: %s, Type: Pulled}", request->image);
|
||||||
|
(void)isulad_monitor_send_image_event(request->image, IM_PULL);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
bim_put(bim);
|
bim_put(bim);
|
||||||
@ -1049,13 +1061,40 @@ void free_im_load_response(im_load_response *ptr)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool check_login_request(const im_login_request *request)
|
||||||
|
{
|
||||||
|
if (request == NULL) {
|
||||||
|
ERROR("Invalid input arguments");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->server == NULL) {
|
||||||
|
ERROR("Login requires server address");
|
||||||
|
isulad_set_error_message("Login requires server address");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->type == NULL) {
|
||||||
|
ERROR("Login requires image type");
|
||||||
|
isulad_set_error_message("Login requires image type");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->username == NULL || request->password == NULL) {
|
||||||
|
ERROR("Missing username or password");
|
||||||
|
isulad_set_error_message("Missing username or password");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int im_login(const im_login_request *request, im_login_response **response)
|
int im_login(const im_login_request *request, im_login_response **response)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct bim *bim = NULL;
|
struct bim *bim = NULL;
|
||||||
|
|
||||||
if (request == NULL || response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Invalid input arguments");
|
ERROR("Empty response");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1065,21 +1104,7 @@ int im_login(const im_login_request *request, im_login_response **response)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->server == NULL) {
|
if (!check_login_request(request)) {
|
||||||
ERROR("Login requires server address");
|
|
||||||
isulad_set_error_message("Login requires server address");
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->type == NULL) {
|
|
||||||
ERROR("Login requires image type");
|
|
||||||
isulad_set_error_message("Login requires image type");
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->username == NULL || request->password == NULL) {
|
|
||||||
ERROR("Missing username or password");
|
|
||||||
isulad_set_error_message("Missing username or password");
|
|
||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1089,6 +1114,11 @@ int im_login(const im_login_request *request, im_login_response **response)
|
|||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bim->ops->login == NULL) {
|
||||||
|
ERROR("Unimplements login in %s", bim->type);
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
EVENT("Event: {Object: %s, Type: logining}", request->server);
|
EVENT("Event: {Object: %s, Type: logining}", request->server);
|
||||||
|
|
||||||
ret = bim->ops->login(request);
|
ret = bim->ops->login(request);
|
||||||
@ -1142,13 +1172,34 @@ void free_im_login_response(im_login_response *ptr)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool check_logout_request(const im_logout_request *request)
|
||||||
|
{
|
||||||
|
if (request == NULL) {
|
||||||
|
ERROR("Invalid input arguments");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->server == NULL) {
|
||||||
|
ERROR("Logout requires server address");
|
||||||
|
isulad_set_error_message("Logout requires server address");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->type == NULL) {
|
||||||
|
ERROR("Logout requires image type");
|
||||||
|
isulad_set_error_message("Logout requires image type");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int im_logout(const im_logout_request *request, im_logout_response **response)
|
int im_logout(const im_logout_request *request, im_logout_response **response)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct bim *bim = NULL;
|
struct bim *bim = NULL;
|
||||||
|
|
||||||
if (request == NULL || response == NULL) {
|
if (response == NULL) {
|
||||||
ERROR("Invalid input arguments");
|
ERROR("Empty response");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1158,15 +1209,7 @@ int im_logout(const im_logout_request *request, im_logout_response **response)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->server == NULL) {
|
if (!check_logout_request(request)) {
|
||||||
ERROR("Logout requires server address");
|
|
||||||
isulad_set_error_message("Logout requires server address");
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->type == NULL) {
|
|
||||||
ERROR("Logout requires image type");
|
|
||||||
isulad_set_error_message("Logout requires image type");
|
|
||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1176,6 +1219,11 @@ int im_logout(const im_logout_request *request, im_logout_response **response)
|
|||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bim->ops->logout == NULL) {
|
||||||
|
ERROR("Unimplements logout in %s", bim->type);
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
EVENT("Event: {Object: %s, Type: logouting}", request->server);
|
EVENT("Event: {Object: %s, Type: logouting}", request->server);
|
||||||
|
|
||||||
ret = bim->ops->logout(request);
|
ret = bim->ops->logout(request);
|
||||||
@ -1335,6 +1383,7 @@ int im_rm_image(const im_remove_request *request, im_remove_response **response)
|
|||||||
}
|
}
|
||||||
|
|
||||||
EVENT("Event: {Object: %s, Type: image removed}", image_ref);
|
EVENT("Event: {Object: %s, Type: image removed}", image_ref);
|
||||||
|
(void)isulad_monitor_send_image_event(image_ref, IM_REMOVE);
|
||||||
|
|
||||||
pack_response:
|
pack_response:
|
||||||
if (g_isulad_errmsg != NULL) {
|
if (g_isulad_errmsg != NULL) {
|
||||||
@ -1616,6 +1665,10 @@ static int bims_init(const struct im_configs *conf)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < g_numbims; i++) {
|
for (i = 0; i < g_numbims; i++) {
|
||||||
|
if (g_bims[i].ops->init == NULL) {
|
||||||
|
WARN("Unimplements init in %s", g_bims[i].image_type);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ret = g_bims[i].ops->init(conf);
|
ret = g_bims[i].ops->init(conf);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ERROR("Failed to init bim %s", g_bims[i].image_type);
|
ERROR("Failed to init bim %s", g_bims[i].image_type);
|
||||||
@ -1759,4 +1812,3 @@ void im_sync_containers_isuladkit(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -382,4 +382,3 @@ void im_sync_containers_isuladkit(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -107,7 +107,7 @@ int isula_image_fs_info(im_fs_info_response *resp)
|
|||||||
struct isula_image_fs_info_request ireq = {0};
|
struct isula_image_fs_info_request ireq = {0};
|
||||||
struct isula_image_fs_info_response *iresp = NULL;
|
struct isula_image_fs_info_response *iresp = NULL;
|
||||||
client_connect_config_t conf = { 0 };
|
client_connect_config_t conf = { 0 };
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
|
|
||||||
if (resp == NULL) {
|
if (resp == NULL) {
|
||||||
ERROR("Invalid arguments");
|
ERROR("Invalid arguments");
|
||||||
|
|||||||
@ -103,7 +103,7 @@ static int isula_pull_response_to_im(const struct isula_pull_response *iresp, im
|
|||||||
|
|
||||||
int isula_pull_image(const im_pull_request *request, im_pull_response **response)
|
int isula_pull_image(const im_pull_request *request, im_pull_response **response)
|
||||||
{
|
{
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
struct isula_pull_request *ireq = NULL;
|
struct isula_pull_request *ireq = NULL;
|
||||||
struct isula_pull_response *iresp = NULL;
|
struct isula_pull_response *iresp = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|||||||
@ -56,7 +56,7 @@ int isula_image_rmi(const char *image, bool force, char **errmsg)
|
|||||||
struct isula_rmi_request *ireq = NULL;
|
struct isula_rmi_request *ireq = NULL;
|
||||||
struct isula_rmi_response *iresp = NULL;
|
struct isula_rmi_response *iresp = NULL;
|
||||||
client_connect_config_t conf = { 0 };
|
client_connect_config_t conf = { 0 };
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
|
|
||||||
im_ops = get_isula_image_ops();
|
im_ops = get_isula_image_ops();
|
||||||
if (im_ops == NULL) {
|
if (im_ops == NULL) {
|
||||||
|
|||||||
@ -111,7 +111,7 @@ imagetool_image *isula_image_get_image_info_by_name(const char *image_name)
|
|||||||
struct isula_status_request *ireq = NULL;
|
struct isula_status_request *ireq = NULL;
|
||||||
struct isula_status_response *iresp = NULL;
|
struct isula_status_response *iresp = NULL;
|
||||||
client_connect_config_t conf = { 0 };
|
client_connect_config_t conf = { 0 };
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
imagetool_image *result = NULL;
|
imagetool_image *result = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
|||||||
@ -147,7 +147,7 @@ int isula_list_images(const im_list_request *request, imagetool_images_list **im
|
|||||||
struct isula_list_request *ireq = NULL;
|
struct isula_list_request *ireq = NULL;
|
||||||
struct isula_list_response *iresp = NULL;
|
struct isula_list_response *iresp = NULL;
|
||||||
client_connect_config_t conf = { 0 };
|
client_connect_config_t conf = { 0 };
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
im_ops = get_isula_image_ops();
|
im_ops = get_isula_image_ops();
|
||||||
|
|||||||
@ -61,7 +61,7 @@ int isula_do_login(const char *server, const char *username, const char *passwor
|
|||||||
struct isula_login_request *ireq = NULL;
|
struct isula_login_request *ireq = NULL;
|
||||||
struct isula_login_response *iresp = NULL;
|
struct isula_login_response *iresp = NULL;
|
||||||
client_connect_config_t conf = { 0 };
|
client_connect_config_t conf = { 0 };
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
|
|
||||||
if (is_valid_arguments(server, username, password) != 0) {
|
if (is_valid_arguments(server, username, password) != 0) {
|
||||||
ERROR("Invalid arguments");
|
ERROR("Invalid arguments");
|
||||||
|
|||||||
@ -45,7 +45,7 @@ int isula_rootfs_mount(const char *name_id)
|
|||||||
struct isula_mount_request *ireq = NULL;
|
struct isula_mount_request *ireq = NULL;
|
||||||
struct isula_mount_response *iresp = NULL;
|
struct isula_mount_response *iresp = NULL;
|
||||||
client_connect_config_t conf = { 0 };
|
client_connect_config_t conf = { 0 };
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
|
|
||||||
im_ops = get_isula_image_ops();
|
im_ops = get_isula_image_ops();
|
||||||
if (im_ops == NULL) {
|
if (im_ops == NULL) {
|
||||||
|
|||||||
@ -47,7 +47,7 @@ int isula_rootfs_remove(const char *name_id)
|
|||||||
struct isula_remove_request *ireq = NULL;
|
struct isula_remove_request *ireq = NULL;
|
||||||
struct isula_remove_response *iresp = NULL;
|
struct isula_remove_response *iresp = NULL;
|
||||||
client_connect_config_t conf = { 0 };
|
client_connect_config_t conf = { 0 };
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
|
|
||||||
im_ops = get_isula_image_ops();
|
im_ops = get_isula_image_ops();
|
||||||
if (im_ops == NULL) {
|
if (im_ops == NULL) {
|
||||||
|
|||||||
@ -41,6 +41,21 @@ static int generate_isula_umount_request(const char *name_id, bool force, struct
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_container_nonexist_error(const struct isula_umount_response *iresp)
|
||||||
|
{
|
||||||
|
#define CONTAINER_NOT_KNOWN_ERR "container not known"
|
||||||
|
if (iresp == NULL || iresp->errmsg == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strstr(iresp->errmsg, CONTAINER_NOT_KNOWN_ERR) != NULL) {
|
||||||
|
DEBUG("Container may already removed");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int isula_rootfs_umount(const char *name_id, bool force)
|
int isula_rootfs_umount(const char *name_id, bool force)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -48,7 +63,7 @@ int isula_rootfs_umount(const char *name_id, bool force)
|
|||||||
struct isula_umount_request *ireq = NULL;
|
struct isula_umount_request *ireq = NULL;
|
||||||
struct isula_umount_response *iresp = NULL;
|
struct isula_umount_response *iresp = NULL;
|
||||||
client_connect_config_t conf = { 0 };
|
client_connect_config_t conf = { 0 };
|
||||||
isula_image_ops *im_ops;
|
isula_image_ops *im_ops = NULL;
|
||||||
|
|
||||||
im_ops = get_isula_image_ops();
|
im_ops = get_isula_image_ops();
|
||||||
if (im_ops == NULL) {
|
if (im_ops == NULL) {
|
||||||
@ -81,7 +96,7 @@ int isula_rootfs_umount(const char *name_id, bool force)
|
|||||||
|
|
||||||
INFO("Send umount rootfs GRPC request");
|
INFO("Send umount rootfs GRPC request");
|
||||||
nret = im_ops->umount(ireq, iresp, &conf);
|
nret = im_ops->umount(ireq, iresp, &conf);
|
||||||
if (nret != 0) {
|
if (nret != 0 && !is_container_nonexist_error(iresp)) {
|
||||||
ERROR("Remove rootfs %s failed: %s", name_id, iresp != NULL ? iresp->errmsg : "null");
|
ERROR("Remove rootfs %s failed: %s", name_id, iresp != NULL ? iresp->errmsg : "null");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,8 +97,6 @@ static int oci_image_merge_env(const oci_image_spec_config *config, container_co
|
|||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_duplicate_commands(const oci_image_spec_config *config, container_config *container_spec)
|
static int do_duplicate_commands(const oci_image_spec_config *config, container_config *container_spec)
|
||||||
@ -172,6 +170,44 @@ static int oci_image_merge_entrypoint(const oci_image_spec_config *config, conta
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int make_sure_container_config_labels(container_config *container_spec)
|
||||||
|
{
|
||||||
|
if (container_spec->labels != NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
container_spec->labels = util_common_calloc_s(sizeof(json_map_string_string));
|
||||||
|
if (container_spec->labels == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int oci_image_merge_labels(const oci_image_spec_config *config, container_config *container_spec)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (config->labels == NULL || config->labels->len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (make_sure_container_config_labels(container_spec) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < config->labels->len; i++) {
|
||||||
|
int ret = append_json_map_string_string(container_spec->labels,
|
||||||
|
config->labels->keys[i], config->labels->values[i]);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void oci_image_merge_user(const char *user, container_config *container_spec)
|
static void oci_image_merge_user(const char *user, container_config *container_spec)
|
||||||
{
|
{
|
||||||
if (container_spec->user != NULL) {
|
if (container_spec->user != NULL) {
|
||||||
@ -314,6 +350,11 @@ int oci_image_merge_config(imagetool_image *image_conf, container_config *contai
|
|||||||
|
|
||||||
oci_image_merge_user(image_conf->spec->config->user, container_spec);
|
oci_image_merge_user(image_conf->spec->config->user, container_spec);
|
||||||
|
|
||||||
|
if (oci_image_merge_labels(image_conf->spec->config, container_spec) != 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
// ignore volumes now
|
// ignore volumes now
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,8 +18,16 @@
|
|||||||
|
|
||||||
# include "oci_runtime_spec.h"
|
# include "oci_runtime_spec.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
oci_runtime_spec_hooks *oci_runtime_spec_hooks_parse_file(const char *filename,
|
oci_runtime_spec_hooks *oci_runtime_spec_hooks_parse_file(const char *filename,
|
||||||
const struct parser_context *ctx, parser_error *err);
|
const struct parser_context *ctx, parser_error *err);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -40,6 +40,9 @@
|
|||||||
"ResolvConfPath": {
|
"ResolvConfPath": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"ShmPath": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"LogPath": {
|
"LogPath": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -91,6 +94,18 @@
|
|||||||
},
|
},
|
||||||
"id": {
|
"id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"MountLabel": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"ProcessLabel": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"SeccompProfile": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"NoNewPrivileges": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|||||||
15
src/json/schema/schema/container/get-runtime-response.json
Normal file
15
src/json/schema/schema/container/get-runtime-response.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"runtime": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"cc": {
|
||||||
|
"type": "uint32"
|
||||||
|
},
|
||||||
|
"errmsg": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -75,6 +75,18 @@
|
|||||||
"RestartCount":{
|
"RestartCount":{
|
||||||
"type":"integer"
|
"type":"integer"
|
||||||
},
|
},
|
||||||
|
"MountLabel":{
|
||||||
|
"type":"string"
|
||||||
|
},
|
||||||
|
"ProcessLabel":{
|
||||||
|
"type":"string"
|
||||||
|
},
|
||||||
|
"SeccompProfile": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"NoNewPrivileges": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"HostConfig":{
|
"HostConfig":{
|
||||||
"$ref": "../host-config.json"
|
"$ref": "../host-config.json"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -232,6 +232,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"mapStringObjectRuntimes": {
|
||||||
|
"type": "object",
|
||||||
|
"patternProperties": {
|
||||||
|
".{1,}": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"path": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"runtime-args": {
|
||||||
|
"type":"array",
|
||||||
|
"items": {
|
||||||
|
"type":"string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"ociVersion": {
|
"ociVersion": {
|
||||||
"description": "The version of Open Container Runtime Specification that the document complies with",
|
"description": "The version of Open Container Runtime Specification that the document complies with",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|||||||
@ -213,6 +213,9 @@
|
|||||||
"MemorySwap": {
|
"MemorySwap": {
|
||||||
"type": "int64"
|
"type": "int64"
|
||||||
},
|
},
|
||||||
|
"MemorySwappiness": {
|
||||||
|
"$ref": "defs.json#/definitions/uint64Pointer"
|
||||||
|
},
|
||||||
"OomKillDisable": {
|
"OomKillDisable": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -5,6 +5,9 @@
|
|||||||
"hosts": {
|
"hosts": {
|
||||||
"type": "ArrayOfStrings"
|
"type": "ArrayOfStrings"
|
||||||
},
|
},
|
||||||
|
"default-runtime": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"group": {
|
"group": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -125,25 +128,31 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"patternProperties": {
|
"patternProperties": {
|
||||||
".{1,}": {
|
".{1,}": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"Name",
|
"Name",
|
||||||
"Hard",
|
"Hard",
|
||||||
"Soft"
|
"Soft"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"Name": {
|
"Name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"Hard": {
|
"Hard": {
|
||||||
"type": "int64"
|
"type": "int64"
|
||||||
},
|
},
|
||||||
"Soft": {
|
"Soft": {
|
||||||
"type": "int64"
|
"type": "int64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"runtimes": {
|
||||||
|
"$ref": "defs.json#/definitions/mapStringObjectRuntimes"
|
||||||
|
},
|
||||||
|
"selinux-enabled" : {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
193
src/json/schema/schema/shim/client/process-state.json
Normal file
193
src/json/schema/schema/shim/client/process-state.json
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
{
|
||||||
|
"description": "process state info",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"cwd",
|
||||||
|
"args"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"args": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/args",
|
||||||
|
"$ref": "../../defs.json#/definitions/ArrayOfStrings"
|
||||||
|
},
|
||||||
|
"consoleSize": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/consoleSize",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"height",
|
||||||
|
"width"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"height": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/consoleSize/height",
|
||||||
|
"$ref": "../../defs.json#/definitions/uint64"
|
||||||
|
},
|
||||||
|
"width": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/consoleSize/width",
|
||||||
|
"$ref": "../../defs.json#/definitions/uint64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cwd": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/cwd",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/env",
|
||||||
|
"$ref": "../../defs.json#/definitions/Env"
|
||||||
|
},
|
||||||
|
"terminal": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/terminal",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/user",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"uid": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/user/uid",
|
||||||
|
"$ref": "../../defs.json#/definitions/UID"
|
||||||
|
},
|
||||||
|
"gid": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/user/gid",
|
||||||
|
"$ref": "../../defs.json#/definitions/GID"
|
||||||
|
},
|
||||||
|
"additionalGids": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/user/additionalGids",
|
||||||
|
"$ref": "../../defs.json#/definitions/ArrayOfGIDs"
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/user/username",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"capabilities": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/capabilities",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"bounding": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/capabilities/bounding",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"permitted": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/capabilities/permitted",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"effective": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/capabilities/effective",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"inheritable": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/capabilities/inheritable",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ambient": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/capabilities/ambient",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"apparmorProfile": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/apparmorProfile",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"oomScoreAdj": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/oomScoreAdj",
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"selinuxLabel": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/selinuxLabel",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"noNewPrivileges": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/process/linux/noNewPrivileges",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"rlimits": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/linux/rlimits",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"type",
|
||||||
|
"soft",
|
||||||
|
"hard"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"hard": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/hard",
|
||||||
|
"$ref": "../../defs.json#/definitions/uint64"
|
||||||
|
},
|
||||||
|
"soft": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/soft",
|
||||||
|
"$ref": "../../defs.json#/definitions/uint64"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/type",
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "^RLIMIT_[A-Z]+$"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"exit_fifo": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"control_fifo": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"exec": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"open_tty": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"open_stdin": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"isuladStdin": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"isuladStdout": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"isuladStderr": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"runtimeArgs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"noPivotRoot": {
|
||||||
|
"tyoe": "boolean"
|
||||||
|
},
|
||||||
|
"checkpoint": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"rootUID": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"rootGID": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user