提交 42cdcb48 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!37 adapt iSula libutils

Merge pull request !37 from haozi007/change
......@@ -5,7 +5,7 @@ include(cmake/set_build_flags.cmake)
option(VERSION "set lcr version" ON)
if (VERSION STREQUAL "ON")
set(LCR_VERSION "2.0.0")
set(LCR_VERSION "2.0.1")
endif()
option(DEBUG "set lcr gcc option" ON)
......
......@@ -10,10 +10,6 @@ else()
endif()
endmacro()
#check python3
find_program(CMD_PYTHON python3)
_CHECK(CMD_PYTHON "CMD_PYTHON-NOTFOUND" "python3")
# check liblxc
pkg_check_modules(PC_LIBLXC REQUIRED "lxc>=3")
find_path(LIBLXC_INCLUDE_DIR lxc/lxccontainer.h
......@@ -24,12 +20,12 @@ find_library(LIBLXC_LIBRARY lxc
HINTS ${PC_LIBLXC_LIBDIR} ${PC_LIBLXC_LIBRARY_DIRS})
_CHECK(LIBLXC_LIBRARY "LIBLXC_LIBRARY-NOTFOUND" "liblxc.so")
# check libyajl
pkg_check_modules(PC_LIBYAJL REQUIRED "yajl>=2")
find_path(LIBYAJL_INCLUDE_DIR yajl/yajl_tree.h
HINTS ${PC_LIBYAJL_INCLUDEDIR} ${PC_LIBYAJL_INCLUDE_DIRS})
_CHECK(LIBYAJL_INCLUDE_DIR "LIBYAJL_INCLUDE_DIR-NOTFOUND" "yajl/yajl_tree.h")
# check iSula libutils
pkg_check_modules(PC_ISULA_LIBUTILS REQUIRED "isula_libutils")
find_path(ISULA_LIBUTILS_INCLUDE_DIR isula_libutils/log.h
HINTS ${PC_ISULA_LIBUTILS_INCLUDEDIR} ${PC_ISULA_LIBUTILS_INCLUDE_DIRS})
_CHECK(ISULA_LIBUTILS_INCLUDE_DIR "ISULA_LIBUTILS_INCLUDE_DIR-NOTFOUND" "isula_libutils/log.h")
find_library(LIBYAJL_LIBRARY yajl
HINTS ${PC_LIBYAJL_LIBDIR} ${PC_LIBYAJL_LIBRARY_DIRS})
_CHECK(LIBYAJL_LIBRARY "LIBYAJL_LIBRARY-NOTFOUND" "libyajl.so")
find_library(ISULA_LIBUTILS_LIBRARY isula_libutils
HINTS ${PC_ISULA_LIBUTILS_LIBDIR} ${PC_ISULA_LIBUTILS_LIBRARY_DIRS})
_CHECK(ISULA_LIBUTILS_LIBRARY "ISULA_LIBUTILS_LIBRARY-NOTFOUND" "libisula_libutils.so")
%global _version 2.0.0
%global _release 20200418.180849.git0944f121
%global _version 2.0.1
%global _release 20200522.155058.git32001591
Name: lcr
Version: %{_version}
Release: %{_release}
......@@ -13,9 +13,8 @@ BuildRoot: %{_tmppath}/lcr-%{version}
BuildRequires: cmake
BuildRequires: lxc
BuildRequires: lxc-devel
BuildRequires: yajl yajl-devel
BuildRequires: python3
Requires: lxc
BuildRequires: iSula-libutils-devel yajl-devel
Requires: lxc iSula-libutils
ExclusiveArch: x86_64 aarch64
%ifarch x86_64
......
# generate .c and .h files for json
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/json)
# get liblcr source files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} topsrcs)
message("-- Get top srcs: " ${topsrcs})
aux_source_directory(${CMAKE_BINARY_DIR}/json generatesrcs)
message("-- Get generate srcs: " ${generatesrcs})
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/json/schema/src commonjsonsrcs)
message("-- Get common json srcs: " ${commonjsonsrcs})
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/json topjsonsrcs)
message("-- Get top json srcs: " ${topjsonsrcs})
# set liblcr library
add_library(liblcr ${LIBTYPE} ${topsrcs} ${topjsonsrcs} ${commonjsonsrcs} ${generatesrcs})
add_library(liblcr ${LIBTYPE} ${topsrcs})
set(check_incs
${LIBLXC_INCLUDE_DIR}
${LIBYAJL_INCLUDE_DIR}
)
${LIBLXC_INCLUDE_DIR}
${ISULA_LIBUTILS_INCLUDE_DIR}
)
set(check_libs
${LIBLXC_LIBRARY}
${LIBYAJL_LIBRARY}
)
${LIBLXC_LIBRARY}
${ISULA_LIBUTILS_LIBRARY}
)
list(REMOVE_DUPLICATES check_incs)
list(REMOVE_DUPLICATES check_libs)
# set liblcr include dirs
target_include_directories(liblcr
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/json
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/json/schema/src
PUBLIC ${CMAKE_BINARY_DIR}/json
PUBLIC ${CMAKE_BINARY_DIR}/conf
PUBLIC ${check_incs}
)
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_BINARY_DIR}/conf
PUBLIC ${check_incs}
)
# set liblcr compile flags
set_target_properties(liblcr PROPERTIES PREFIX "")
......
......@@ -18,7 +18,7 @@
#include <string.h>
#include "buffer.h"
#include "log.h"
#include "isula_libutils/log.h"
#include "utils.h"
/* buffer allocate */
......
......@@ -27,7 +27,7 @@
#include "lcrcontainer_extend.h"
#include "error.h"
#include "utils.h"
#include "log.h"
#include "isula_libutils/log.h"
#include "buffer.h"
#define SUB_UID_PATH "/etc/subuid"
......@@ -374,7 +374,7 @@ static char *capabilities_join(const char *sep, const char **parts, size_t len)
#define UID_MAX_SIZE 21
/* UID to use within a private user namespace for init */
static int trans_oci_process_init_uid(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_init_uid(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
char buf[UID_MAX_SIZE] = { 0 };
......@@ -398,7 +398,7 @@ out:
}
/* GID to use within a private user namespace for init */
static int trans_oci_process_init_gid(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_init_gid(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
char buf[UID_MAX_SIZE] = { 0 };
......@@ -422,7 +422,7 @@ out:
}
/* additional groups for init command */
static int trans_oci_process_init_groups(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_init_groups(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
int nret;
......@@ -467,7 +467,7 @@ out:
}
/* Sets the command to use as the init system for the containers */
static int trans_oci_process_init_args(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_init_args(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
size_t i = 0;
......@@ -485,7 +485,7 @@ out:
}
/* working directory to use within container */
static int trans_oci_process_init_cwd(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_init_cwd(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
int ret = -1;
......@@ -502,7 +502,7 @@ out:
}
/* trans oci process init */
static int trans_oci_process_init(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_init(const defs_process *proc, struct lcr_list *conf)
{
int ret = -1;
if (trans_oci_process_init_uid(proc, conf)) {
......@@ -531,7 +531,7 @@ out:
}
/* trans oci process env and cap */
static int trans_oci_process_env_and_cap(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_env_and_cap(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
char *boundings = NULL;
......@@ -578,7 +578,7 @@ out:
}
/* trans oci process prlimit */
static int trans_oci_process_prlimit(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_prlimit(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
int ret = -1;
......@@ -586,7 +586,7 @@ static int trans_oci_process_prlimit(const oci_runtime_spec_process *proc, struc
size_t i;
for (i = 0; i < proc->rlimits_len; i++) {
oci_runtime_spec_process_rlimits_element *lr = proc->rlimits[i];
defs_process_rlimits_element *lr = proc->rlimits[i];
char buf_key[30] = { 0 };
char buf_value[60] = { 0 };
size_t j;
......@@ -623,7 +623,7 @@ out:
}
/* trans oci process no new privs */
static int trans_oci_process_no_new_privs(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_no_new_privs(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
int ret = -1;
......@@ -640,7 +640,7 @@ out:
return ret;
}
static int trans_oci_process_apparmor(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_apparmor(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
int ret = -1;
......@@ -658,7 +658,7 @@ out:
return ret;
}
static int trans_oci_process_selinux(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_selinux(const defs_process *proc, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
int ret = -1;
......@@ -677,7 +677,7 @@ out:
}
/* trans oci process apparmor and selinux */
static int trans_oci_process_apparmor_and_selinux(const oci_runtime_spec_process *proc, struct lcr_list *conf)
static int trans_oci_process_apparmor_and_selinux(const defs_process *proc, struct lcr_list *conf)
{
int ret = -1;
......@@ -695,7 +695,7 @@ out:
}
/* trans oci process */
struct lcr_list *trans_oci_process(const oci_runtime_spec_process *proc)
struct lcr_list *trans_oci_process(const defs_process *proc)
{
struct lcr_list *conf = NULL;
......@@ -1308,7 +1308,7 @@ static int trans_conf_uint64(struct lcr_list *conf, const char *lxc_key, uint64_
}
/* trans resources mem swap */
static int trans_resources_mem_swap(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_mem_swap(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
int nret;
......@@ -1340,7 +1340,7 @@ out:
return ret;
}
static int trans_resources_mem_limit(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_mem_limit(const defs_resources *res, struct lcr_list *conf)
{
if (res->memory->limit != INVALID_INT) {
/* set limit of memory usage */
......@@ -1353,7 +1353,7 @@ static int trans_resources_mem_limit(const oci_runtime_config_linux_resources *r
}
/* trans resources mem kernel */
static int trans_resources_mem_kernel(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_mem_kernel(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
int nret;
......@@ -1377,7 +1377,7 @@ out:
return ret;
}
static int trans_resources_mem_disable_oom(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_mem_disable_oom(const defs_resources *res, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
if (res->memory->disable_oom_killer) {
......@@ -1391,7 +1391,7 @@ static int trans_resources_mem_disable_oom(const oci_runtime_config_linux_resour
}
/* trans resources memory */
static int trans_resources_memory(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_memory(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
......@@ -1419,7 +1419,7 @@ out:
return ret;
}
static int trans_resources_devices_node(const oci_runtime_defs_linux_device_cgroup *lrd, struct lcr_list *conf,
static int trans_resources_devices_node(const defs_device_cgroup *lrd, struct lcr_list *conf,
const char *buf_value)
{
struct lcr_list *node = NULL;
......@@ -1440,7 +1440,7 @@ out:
return ret;
}
static int trans_resources_devices_no_match(const oci_runtime_defs_linux_device_cgroup *lrd, char *buf_value,
static int trans_resources_devices_no_match(const defs_device_cgroup *lrd, char *buf_value,
size_t size)
{
int ret = 0;
......@@ -1455,7 +1455,7 @@ static int trans_resources_devices_no_match(const oci_runtime_defs_linux_device_
return ret;
}
static int trans_resources_devices_match(const oci_runtime_defs_linux_device_cgroup *lrd, char *buf_value, size_t size)
static int trans_resources_devices_match(const defs_device_cgroup *lrd, char *buf_value, size_t size)
{
int ret = 0;
if (lrd->minor != WILDCARD) {
......@@ -1468,7 +1468,7 @@ static int trans_resources_devices_match(const oci_runtime_defs_linux_device_cgr
return ret;
}
static int trans_resources_devices_ret(const oci_runtime_defs_linux_device_cgroup *lrd, char *buf_value, size_t size)
static int trans_resources_devices_ret(const defs_device_cgroup *lrd, char *buf_value, size_t size)
{
int ret = 0;
if (lrd->major != WILDCARD) {
......@@ -1481,14 +1481,14 @@ static int trans_resources_devices_ret(const oci_runtime_defs_linux_device_cgrou
}
/* trans resources devices */
static int trans_resources_devices(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_devices(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
size_t i = 0;
char buf_value[300] = { 0 };
for (i = 0; i < res->devices_len; i++) {
oci_runtime_defs_linux_device_cgroup *lrd = res->devices[i];
defs_device_cgroup *lrd = res->devices[i];
if (trans_resources_devices_ret(lrd, buf_value, sizeof(buf_value)) < 0) {
goto out;
}
......@@ -1503,7 +1503,7 @@ out:
}
/* trans resources cpu cfs */
static int trans_resources_cpu_cfs(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_cpu_cfs(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
......@@ -1523,7 +1523,7 @@ out:
}
/* trans resources cpu rt */
static int trans_resources_cpu_rt(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_cpu_rt(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
......@@ -1543,7 +1543,7 @@ out:
}
/* trans resources cpu set */
static int trans_resources_cpu_set(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_cpu_set(const defs_resources *res, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
int ret = -1;
......@@ -1568,7 +1568,7 @@ out:
}
/* trans resources cpu shares */
static int trans_resources_cpu_shares(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_cpu_shares(const defs_resources *res, struct lcr_list *conf)
{
if (res->cpu->shares != INVALID_INT) {
int nret = trans_conf_int64(conf, "lxc.cgroup.cpu.shares", (int64_t)(res->cpu->shares));
......@@ -1580,7 +1580,7 @@ static int trans_resources_cpu_shares(const oci_runtime_config_linux_resources *
}
/* trans resources cpu */
static int trans_resources_cpu(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_cpu(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
......@@ -1611,7 +1611,7 @@ out:
}
/* trans resources blkio weight */
static int trans_blkio_weight(const oci_runtime_config_linux_resources_block_io *block_io, struct lcr_list *conf)
static int trans_blkio_weight(const defs_resources_block_io *block_io, struct lcr_list *conf)
{
int ret = -1;
......@@ -1632,7 +1632,7 @@ out:
}
/* trans resources blkio wdevice */
static int trans_blkio_wdevice(const oci_runtime_config_linux_resources_block_io *block_io, struct lcr_list *conf)
static int trans_blkio_wdevice(const defs_resources_block_io *block_io, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
int ret = -1;
......@@ -1641,7 +1641,7 @@ static int trans_blkio_wdevice(const oci_runtime_config_linux_resources_block_io
for (i = 0; i < block_io->weight_device_len; i++) {
int nret;
oci_runtime_defs_linux_block_io_device_weight *wd = block_io->weight_device[i];
defs_block_io_device_weight *wd = block_io->weight_device[i];
if ((wd != NULL) && wd->weight != INVALID_INT) {
nret = snprintf(buf_value, sizeof(buf_value), "%lld:%lld %d", (long long)(wd->major), (long long)wd->minor,
wd->weight);
......@@ -1675,7 +1675,7 @@ out:
}
/* trans resources blkio throttle */
static int trans_blkio_throttle(oci_runtime_defs_linux_block_io_device_throttle **throttle, size_t len,
static int trans_blkio_throttle(defs_block_io_device_throttle **throttle, size_t len,
const char *lxc_key, struct lcr_list *conf)
{
struct lcr_list *node = NULL;
......@@ -1709,7 +1709,7 @@ out:
}
/* trans resources blkio */
static int trans_resources_blkio(const oci_runtime_config_linux_resources_block_io *block_io, struct lcr_list *conf)
static int trans_resources_blkio(const defs_resources_block_io *block_io, struct lcr_list *conf)
{
int ret = -1;
......@@ -1751,14 +1751,14 @@ out:
}
/* trans resources hugetlb */
static int trans_resources_hugetlb(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_hugetlb(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
size_t i = 0;
char buf_key[300] = { 0 };
for (i = 0; i < res->hugepage_limits_len; i++) {
oci_runtime_config_linux_resources_hugepage_limits_element *lrhl = res->hugepage_limits[i];
defs_resources_hugepage_limits_element *lrhl = res->hugepage_limits[i];
if (lrhl->page_size != NULL) {
int nret = snprintf(buf_key, sizeof(buf_key), "lxc.cgroup.hugetlb.%s.limit_in_bytes", lrhl->page_size);
if (nret < 0 || (size_t)nret >= sizeof(buf_key)) {
......@@ -1777,7 +1777,7 @@ out:
}
/* trans resources network */
static int trans_resources_network(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_network(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
size_t i = 0;
......@@ -1794,7 +1794,7 @@ static int trans_resources_network(const oci_runtime_config_linux_resources *res
}
for (i = 0; i < res->network->priorities_len; i++) {
oci_runtime_defs_linux_network_interface_priority *lrnp = res->network->priorities[i];
defs_network_interface_priority *lrnp = res->network->priorities[i];
if ((lrnp != NULL) && lrnp->name != NULL && lrnp->priority != INVALID_INT) {
int nret = snprintf(buf_value, sizeof(buf_value), "%s %u", lrnp->name, lrnp->priority);
if (nret < 0 || (size_t)nret >= sizeof(buf_value)) {
......@@ -1815,7 +1815,7 @@ out:
}
/* trans resources pids */
static int trans_resources_pids(const oci_runtime_config_linux_resources *res, struct lcr_list *conf)
static int trans_resources_pids(const defs_resources *res, struct lcr_list *conf)
{
int ret = -1;
char buf_value[300] = { 0 };
......@@ -1848,7 +1848,7 @@ out:
}
/* trans oci resources */
static struct lcr_list *trans_oci_resources(const oci_runtime_config_linux_resources *res)
static struct lcr_list *trans_oci_resources(const defs_resources *res)
{
struct lcr_list *conf = NULL;
......@@ -1924,7 +1924,7 @@ static struct lcr_list *trans_oci_namespaces(const oci_runtime_config_linux *l)
struct lcr_list *conf = NULL;
struct lcr_list *node = NULL;
size_t i;
oci_runtime_defs_linux_namespace_reference *ns = NULL;
defs_namespace_reference *ns = NULL;
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
......@@ -2017,7 +2017,7 @@ static struct lcr_list *trans_oci_linux_devices(const oci_runtime_config_linux *
struct lcr_list *node = NULL;
size_t i = 0;
int nret = 0;
oci_runtime_defs_linux_device *device = NULL;
defs_device *device = NULL;
char buf_value[POPULATE_DEVICE_SIZE] = { 0 };
conf = lcr_util_common_calloc_s(sizeof(*conf));
......@@ -2241,7 +2241,7 @@ static int seccomp_append_arch(char *arch, Buffer *buffer)
}
/* seccomp append rule */
static int seccomp_append_rule(const oci_runtime_defs_linux_syscall *syscall, size_t i, Buffer *buffer, char *action)
static int seccomp_append_rule(const defs_syscall *syscall, size_t i, Buffer *buffer, char *action)
{
int ret = 0;
size_t j = 0;
......@@ -2282,7 +2282,7 @@ out:
}
/* seccomp append rules */
static int seccomp_append_rules(const oci_runtime_defs_linux_syscall *syscall, Buffer *buffer)
static int seccomp_append_rules(const defs_syscall *syscall, Buffer *buffer)
{
int ret = 0;
size_t i = 0;
......
......@@ -15,7 +15,7 @@
#ifndef __LCR_CONF_H
#define __LCR_CONF_H
#include "oci_runtime_spec.h"
#include "isula_libutils/oci_runtime_spec.h"
#include "lcr_list.h"
#define INVALID_INT 0
......@@ -80,7 +80,7 @@ struct lcr_list *trans_oci_hostname(const char *hostname);
/*
* Translate oci process struct to lcr config
*/
struct lcr_list *trans_oci_process(const oci_runtime_spec_process *proc);
struct lcr_list *trans_oci_process(const defs_process *proc);
/*
* Translate oci root struct to lcr config
......
# generate .c and .h files for json
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/schema)
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* lcr licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* 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 v2 for more details.
* Author: maoweiyong
* Create: 2018-11-08
* Description: provide oci runtime hooks functions
******************************************************************************/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include "read_file.h"
#include "oci_runtime_hooks.h"
#include <stdlib.h>
#define PARSE_ERR_BUFFER_SIZE 1024
char *oci_runtime_spec_hooks_generate_json(const oci_runtime_spec_hooks *ptr, const struct parser_context *ctx,
parser_error *err)
{
yajl_gen g = NULL;
struct parser_context tmp_ctx = { 0 };
const unsigned char *gen_buf = NULL;
char *json_buf = NULL;
size_t gen_len = 0;
if (ptr == NULL || err == NULL) {
return NULL;
}
*err = NULL;
if (ctx == NULL) {
ctx = &tmp_ctx;
}
if (!json_gen_init(&g, ctx)) {
*err = strdup("Json_gen init failed");
goto out;
}
if (yajl_gen_status_ok != gen_oci_runtime_spec_hooks(g, ptr, ctx, err)) {
if (*err == NULL) {
*err = strdup("Failed to generate json");
}
goto free_out;
}
yajl_gen_get_buf(g, &gen_buf, &gen_len);
if (gen_buf == NULL) {
*err = strdup("Error to get generated json");
goto free_out;
}
if (gen_len > SIZE_MAX - 1) {
*err = strdup("Generated json too long");
goto free_out;
}
json_buf = malloc(gen_len + 1);
if (json_buf == NULL) {
*err = strdup("Out of memory");
goto free_out;
}
(void)memcpy((void *)json_buf, (void *)gen_buf, gen_len);
json_buf[gen_len] = '\0';
free_out:
yajl_gen_clear(g);
yajl_gen_free(g);
out:
return json_buf;
}
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* lcr licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* 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 v2 for more details.
* Author: maoweiyong
* Create: 2018-11-08
* Description: provide oci runtime hooks functions
******************************************************************************/
#ifndef _CONTAINER_HOOKS_H
#define _CONTAINER_HOOKS_H
#include "oci_runtime_spec.h"
char *oci_runtime_spec_hooks_generate_json(const oci_runtime_spec_hooks *ptr, const struct parser_context *ctx,
parser_error *err);
#endif
project (JSONGenerator)
set(cmdpath python3)
set(pysrcpath ${CMAKE_CURRENT_SOURCE_DIR}/src/generate.py)
set(schemapath ${CMAKE_CURRENT_SOURCE_DIR}/schema)
set(outputpath ${CMAKE_BINARY_DIR}/json)
add_subdirectory(src)
message("-- Generate .c and .h file into: " ${outputpath})
execute_process(COMMAND ${cmdpath} ${pysrcpath} --gen-common --gen-ref -r --root=${schemapath} --out=${outputpath} ${schemapath}
ERROR_VARIABLE err
)
if (err)
message("error: " ${err})
endif()
{
" description": "Definitions used throughout the OpenContainer Specification",
"definitions": {
"int8": {
"type": "integer",
"minimum": -128,
"maximum": 127
},
"int16": {
"type": "integer",
"minimum": -32768,
"maximum": 32767
},
"int32": {
"type": "integer",
"minimum": -2147483648,
"maximum": 2147483647
},
"int64": {
"type": "integer",
"minimum": -9223372036854776000,
"maximum": 9223372036854776000
},
"uint8": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"uint16": {
"type": "integer",
"minimum": 0,
"maximum": 65535
},
"uint32": {
"type": "integer",
"minimum": 0,
"maximum": 4294967295
},
"uint64": {
"type": "integer",
"minimum": 0,
"maximum": 18446744073709552000
},
"uint16Pointer": {
"oneOf": [
{
"$ref": "#/definitions/uint16"
},
{
"type": "null"
}
]
},
"uint64Pointer": {
"oneOf": [
{
"$ref": "#/definitions/uint64"
},
{
"type": "null"
}
]
},
"stringPointer": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"percent": {
"type": "integer",
"minimum": 0,
"maximum": 100
},
"UID": {
"$ref": "#/definitions/uint32"
},
"GID": {
"$ref": "#/definitions/uint32"
},
"ArrayOfGIDs": {
"type": "array",
"items": {
"$ref": "#/definitions/GID"
}
},
"FilePath": {
"type": "string"
},
"Env": {
"$ref": "#/definitions/ArrayOfStrings"
},
"Hook": {
"type": "object",
"properties": {
"path": {
"$ref": "#/definitions/FilePath"
},
"args": {
"$ref": "#/definitions/ArrayOfStrings"
},
"env": {
"$ref": "#/definitions/Env"
},
"timeout": {
"type": "integer",
"minimum": 1
}
},
"required": [
"path"
]
},
"ArrayOfHooks": {
"type": "array",
"items": {
"$ref": "#/definitions/Hook"
}
},
"IDMapping": {
"type": "object",
"properties": {
"hostID": {
"$ref": "#/definitions/uint32"
},
"containerID": {
"$ref": "#/definitions/uint32"
},
"size": {
"$ref": "#/definitions/uint32"
}
},
"required": [
"hostID",
"containerID",
"size"
]
},
"Mount": {
"type": "object",
"properties": {
"source": {
"$ref": "#/definitions/FilePath"
},
"destination": {
"$ref": "#/definitions/FilePath"
},
"options": {
"$ref": "#/definitions/ArrayOfStrings"
},
"type": {
"type": "string"
}
},
"required": [
"destination"
]
},
"ArrayOfStrings": {
"type": "array",
"items": {
"type": "string"
}
},
"mapStringString": {
"type": "object",
"patternProperties": {
".{1,}": {
"type": "string"
}
}
},
"mapStringInt": {
"type": "object",
"patternProperties": {
".{1,}": {
"type": "integer"
}
}
},
"mapStringBool": {
"type": "object",
"patternProperties": {
".{1,}": {
"type": "boolean"
}
}
},
"mapIntString": {
"type": "object",
"patternProperties": {
".{2,}": {
"type": "string"
}
}
},
"mapIntInt": {
"type": "object",
"patternProperties": {
".{2,}": {
"type": "integer"
}
}
},
"mapIntBool": {
"type": "object",
"patternProperties": {
".{2,}": {
"type": "boolean"
}
}
},
"mapStringObject": {
"type": "object",
"patternProperties": {
".{1,}": {
"type": "object"
}
}
},
"ociVersion": {
"description": "The version of Open Container Runtime Specification that the document complies with",
"type": "string"
},
"annotations": {
"$ref": "#/definitions/mapStringString"
}
}
}
{
"linux": {
"description": "Linux platform-specific configurations",
"id": "https://opencontainers.org/schema/bundle/linux",
"type": "object",
"properties": {
"devices": {
"id": "https://opencontainers.org/schema/bundle/linux/devices",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/Device"
}
},
"uidMappings": {
"id": "https://opencontainers.org/schema/bundle/linux/uidMappings",
"type": "array",
"items": {
"$ref": "../../defs.json#/definitions/IDMapping"
}
},
"gidMappings": {
"id": "https://opencontainers.org/schema/bundle/linux/gidMappings",
"type": "array",
"items": {
"$ref": "../../defs.json#/definitions/IDMapping"
}
},
"namespaces": {
"id": "https://opencontainers.org/schema/bundle/linux/namespaces",
"type": "array",
"items": {
"anyOf": [
{
"$ref": "defs-linux.json#/definitions/NamespaceReference"
}
]
}
},
"resources": {
"id": "https://opencontainers.org/schema/bundle/linux/resources",
"type": "object",
"properties": {
"devices": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/devices",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/DeviceCgroup"
}
},
"pids": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/pids",
"type": "object",
"properties": {
"limit": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/pids/limit",
"$ref": "../../defs.json#/definitions/int64"
}
},
"required": [
"limit"
]
},
"blockIO": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/blockIO",
"type": "object",
"properties": {
"weight": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/blockIO/weight",
"$ref": "defs-linux.json#/definitions/weight"
},
"leafWeight": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/blockIO/leafWeight",
"$ref": "defs-linux.json#/definitions/weight"
},
"throttleReadBpsDevice": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/blockIO/throttleReadBpsDevice",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/blockIODeviceThrottle"
}
},
"throttleWriteBpsDevice": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/blockIO/throttleWriteBpsDevice",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/blockIODeviceThrottle"
}
},
"throttleReadIOPSDevice": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/blockIO/throttleReadIOPSDevice",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/blockIODeviceThrottle"
}
},
"throttleWriteIOPSDevice": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/blockIO/throttleWriteIOPSDevice",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/blockIODeviceThrottle"
}
},
"weightDevice": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/blockIO/weightDevice",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/blockIODeviceWeight"
}
}
}
},
"cpu": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu",
"type": "object",
"properties": {
"cpus": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/cpus",
"type": "string"
},
"mems": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/mems",
"type": "string"
},
"period": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/period",
"$ref": "../../defs.json#/definitions/uint64"
},
"quota": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/quota",
"$ref": "../../defs.json#/definitions/int64"
},
"realtimePeriod": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/realtimePeriod",
"$ref": "../../defs.json#/definitions/uint64"
},
"realtimeRuntime": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/realtimeRuntime",
"$ref": "../../defs.json#/definitions/int64"
},
"shares": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/shares",
"$ref": "../../defs.json#/definitions/uint64"
}
}
},
"hugepageLimits": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/hugepageLimits",
"type": "array",
"items": {
"type": "object",
"properties": {
"pageSize": {
"type": "string"
},
"limit": {
"$ref": "../../defs.json#/definitions/uint64"
}
},
"required": [
"pageSize",
"limit"
]
}
},
"memory": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory",
"type": "object",
"properties": {
"kernel": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/kernel",
"$ref": "../../defs.json#/definitions/int64"
},
"kernelTCP": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/kernelTCP",
"$ref": "../../defs.json#/definitions/int64"
},
"limit": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/limit",
"$ref": "../../defs.json#/definitions/int64"
},
"reservation": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/reservation",
"$ref": "../../defs.json#/definitions/int64"
},
"swap": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/swap",
"$ref": "../../defs.json#/definitions/int64"
},
"swappiness": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/swappiness",
"$ref": "../../defs.json#/definitions/uint64"
},
"disableOOMKiller": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/disableOOMKiller",
"type": "boolean"
}
}
},
"network": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/network",
"type": "object",
"properties": {
"classID": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/network/classId",
"$ref": "../../defs.json#/definitions/uint32"
},
"priorities": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/network/priorities",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/NetworkInterfacePriority"
}
}
}
}
}
},
"cgroupsPath": {
"id": "https://opencontainers.org/schema/bundle/linux/cgroupsPath",
"type": "string"
},
"rootfsPropagation": {
"id": "https://opencontainers.org/schema/bundle/linux/rootfsPropagation",
"$ref": "defs-linux.json#/definitions/RootfsPropagation"
},
"seccomp": {
"id": "https://opencontainers.org/schema/bundle/linux/seccomp",
"type": "object",
"properties": {
"defaultAction": {
"id": "https://opencontainers.org/schema/bundle/linux/seccomp/defaultAction",
"type": "string"
},
"architectures": {
"id": "https://opencontainers.org/schema/bundle/linux/seccomp/architectures",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/SeccompArch"
}
},
"syscalls": {
"id": "https://opencontainers.org/schema/bundle/linux/seccomp/syscalls",
"type": "array",
"items": {
"$ref": "defs-linux.json#/definitions/Syscall"
}
}
},
"required": [
"defaultAction"
]
},
"sysctl": {
"id": "https://opencontainers.org/schema/bundle/linux/sysctl",
"$ref": "../../defs.json#/definitions/mapStringString"
},
"maskedPaths": {
"id": "https://opencontainers.org/schema/bundle/linux/maskedPaths",
"$ref": "../../defs.json#/definitions/ArrayOfStrings"
},
"readonlyPaths": {
"id": "https://opencontainers.org/schema/bundle/linux/readonlyPaths",
"$ref": "../../defs.json#/definitions/ArrayOfStrings"
},
"mountLabel": {
"id": "https://opencontainers.org/schema/bundle/linux/mountLabel",
"type": "string"
}
}
}
}
{
"definitions": {
"RootfsPropagation": {
"type": "string",
"enum": [
"private",
"shared",
"slave",
"unbindable"
]
},
"SeccompArch": {
"type": "string",
"enum": [
"SCMP_ARCH_X86",
"SCMP_ARCH_X86_64",
"SCMP_ARCH_X32",
"SCMP_ARCH_ARM",
"SCMP_ARCH_AARCH64",
"SCMP_ARCH_MIPS",
"SCMP_ARCH_MIPS64",
"SCMP_ARCH_MIPS64N32",
"SCMP_ARCH_MIPSEL",
"SCMP_ARCH_MIPSEL64",
"SCMP_ARCH_MIPSEL64N32",
"SCMP_ARCH_PPC",
"SCMP_ARCH_PPC64",
"SCMP_ARCH_PPC64LE",
"SCMP_ARCH_S390",
"SCMP_ARCH_S390X",
"SCMP_ARCH_PARISC",
"SCMP_ARCH_PARISC64"
]
},
"SeccompAction": {
"type": "string",
"enum": [
"SCMP_ACT_KILL",
"SCMP_ACT_TRAP",
"SCMP_ACT_ERRNO",
"SCMP_ACT_TRACE",
"SCMP_ACT_ALLOW"
]
},
"SeccompOperators": {
"type": "string",
"enum": [
"SCMP_CMP_NE",
"SCMP_CMP_LT",
"SCMP_CMP_LE",
"SCMP_CMP_EQ",
"SCMP_CMP_GE",
"SCMP_CMP_GT",
"SCMP_CMP_MASKED_EQ"
]
},
"SyscallArg": {
"type": "object",
"properties": {
"index": {
"$ref": "../../defs.json#/definitions/uint32"
},
"value": {
"$ref": "../../defs.json#/definitions/uint64"
},
"valueTwo": {
"$ref": "../../defs.json#/definitions/uint64"
},
"op": {
"$ref": "#/definitions/SeccompOperators"
}
},
"required": [
"index",
"value",
"op"
]
},
"Syscall": {
"type": "object",
"properties": {
"names": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
},
"action": {
"$ref": "#/definitions/SeccompAction"
},
"args": {
"type": "array",
"items": {
"$ref": "#/definitions/SyscallArg"
}
}
},
"required": [
"names",
"action"
]
},
"Major": {
"description": "major device number",
"$ref": "../../defs.json#/definitions/int64"
},
"Minor": {
"description": "minor device number",
"$ref": "../../defs.json#/definitions/int64"
},
"FileMode": {
"description": "File permissions mode (typically an octal value)",
"type": "integer",
"minimum": 0,
"maximum": 512
},
"FileType": {
"description": "Type of a block or special character device",
"type": "string",
"pattern": "^[cbup]$"
},
"Device": {
"type": "object",
"required": [
"type",
"path"
],
"properties": {
"type": {
"$ref": "#/definitions/FileType"
},
"path": {
"$ref": "../../defs.json#/definitions/FilePath"
},
"fileMode": {
"$ref": "#/definitions/FileMode"
},
"major": {
"$ref": "#/definitions/Major"
},
"minor": {
"$ref": "#/definitions/Minor"
},
"uid": {
"$ref": "../../defs.json#/definitions/UID"
},
"gid": {
"$ref": "../../defs.json#/definitions/GID"
}
}
},
"weight": {
"type": "integer"
},
"blockIODevice": {
"type": "object",
"properties": {
"major": {
"$ref": "#/definitions/Major"
},
"minor": {
"$ref": "#/definitions/Minor"
}
},
"required": [
"major",
"minor"
]
},
"blockIODeviceWeight": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/blockIODevice"
},
{
"type": "object",
"properties": {
"weight": {
"$ref": "#/definitions/weight"
},
"leafWeight": {
"$ref": "#/definitions/weight"
}
}
}
]
},
"blockIODeviceThrottle": {
"allOf": [
{
"$ref": "#/definitions/blockIODevice"
},
{
"type": "object",
"properties": {
"rate": {
"$ref": "../../defs.json#/definitions/uint64"
}
}
}
]
},
"DeviceCgroup": {
"type": "object",
"properties": {
"allow": {
"type": "boolean"
},
"type": {
"type": "string"
},
"major": {
"$ref": "#/definitions/Major"
},
"minor": {
"$ref": "#/definitions/Minor"
},
"access": {
"type": "string"
}
},
"required": [
"allow"
]
},
"NetworkInterfacePriority": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"priority": {
"$ref": "../../defs.json#/definitions/uint32"
}
},
"required": [
"name",
"priority"
]
},
"NamespaceType": {
"type": "string",
"enum": [
"mount",
"pid",
"network",
"uts",
"ipc",
"user",
"cgroup"
]
},
"NamespaceReference": {
"type": "object",
"properties": {
"type": {
"$ref": "#/definitions/NamespaceType"
},
"path": {
"$ref": "../../defs.json#/definitions/FilePath"
}
},
"required": [
"type"
]
}
}
}
{
"description": "Open Container Runtime Specification Container Configuration Schema",
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "https://opencontainers.org/schema/bundle",
"type": "object",
"properties": {
"ociVersion": {
"id": "https://opencontainers.org/schema/bundle/ociVersion",
"$ref": "../../defs.json#/definitions/ociVersion"
},
"hooks": {
"id": "https://opencontainers.org/schema/bundle/hooks",
"type": "object",
"properties": {
"prestart": {
"$ref": "../../defs.json#/definitions/ArrayOfHooks"
},
"poststart": {
"$ref": "../../defs.json#/definitions/ArrayOfHooks"
},
"poststop": {
"$ref": "../../defs.json#/definitions/ArrayOfHooks"
}
}
},
"annotations": {
"$ref": "../../defs.json#/definitions/annotations"
},
"hostname": {
"id": "https://opencontainers.org/schema/bundle/hostname",
"type": "string"
},
"mounts": {
"id": "https://opencontainers.org/schema/bundle/mounts",
"type": "array",
"items": {
"$ref": "../../defs.json#/definitions/Mount"
}
},
"root": {
"description": "Configures the container's root filesystem.",
"id": "https://opencontainers.org/schema/bundle/root",
"type": "object",
"required": [
"path"
],
"properties": {
"path": {
"id": "https://opencontainers.org/schema/bundle/root/path",
"$ref": "../../defs.json#/definitions/FilePath"
},
"readonly": {
"id": "https://opencontainers.org/schema/bundle/root/readonly",
"type": "boolean"
}
}
},
"process": {
"id": "https://opencontainers.org/schema/bundle/process",
"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]+$"
}
}
}
}
}
},
"linux": {
"$ref": "config-linux.json#/linux"
}
},
"required": [
"ociVersion"
]
}
{
"description": "Open Container Runtime State Schema",
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "https://opencontainers.org/schema/state",
"type": "object",
"properties": {
"ociVersion": {
"id": "https://opencontainers.org/schema/runtime/state/ociVersion",
"$ref": "../../defs.json#/definitions/ociVersion"
},
"id": {
"id": "https://opencontainers.org/schema/runtime/state/id",
"description": "the container's ID",
"type": "string"
},
"status": {
"id": "https://opencontainers.org/schema/runtime/state/status",
"type": "string",
"enum": [
"creating",
"created",
"running",
"stopped"
]
},
"pid": {
"id": "https://opencontainers.org/schema/runtime/state/pid",
"type": "integer",
"minimum": 0
},
"bundle": {
"id": "https://opencontainers.org/schema/runtime/state/bundle",
"type": "string"
},
"annotations": {
"$ref": "../../defs.json#/definitions/annotations"
}
},
"required": [
"ociVersion",
"id",
"status",
"bundle"
]
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"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"
}
}
}
# get current directory sources files
message("-- do nothing ")
此差异已折叠。
# -*- coding: utf-8 -*-
'''
Description: commom header file
Interface: None
History: 2019-06-17
'''
#
# libocispec - a C library for parsing OCI spec files.
#
# Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
#
# libocispec is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# libocispec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with libocispec. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, you may create a larger work that contains
# part or all of the libocispec parser skeleton and distribute that work
# under terms of your choice, so long as that work isn't itself a
# parser generator using the skeleton or a modified version thereof
# as a parser skeleton. Alternatively, if you modify or redistribute
# the parser skeleton itself, you may (at your option) remove this
# special exception, which will cause the skeleton and the resulting
# libocispec output files to be licensed under the GNU General Public
# License without this special exception.
#!/usr/bin/python -Es
"""
Description: json common c code
Interface: None
History: 2019-06-18
Purpose: defined the common tool function for parse json
Defined the CODE global variable to hold the c code
"""
# - Defined the CODE global variable to hold the c code
CODE = '''// Auto generated file. Do not edit!
# ifndef _JSON_COMMON_H
# define _JSON_COMMON_H
# include <stdlib.h>
# include <stdbool.h>
# include <stdio.h>
# include <string.h>
# include <stdint.h>
# include <yajl/yajl_tree.h>
# include <yajl/yajl_gen.h>
# ifdef __cplusplus
extern "C" {
# endif
# undef linux
// options to report error if there is unknown key found in json
# define OPT_PARSE_STRICT 0x01
// options to generate all key and value
# define OPT_GEN_KAY_VALUE 0x02
// options to generate simplify(no indent) json string
# define OPT_GEN_SIMPLIFY 0x04
// options not to validate utf8 data
# define OPT_GEN_NO_VALIDATE_UTF8 0x08
# define GEN_SET_ERROR_AND_RETURN(stat, err) { \\
if (*(err) == NULL) {\\
if (asprintf(err, "%s: %s: %d: error generating json, errcode: %u", __FILE__, __func__, __LINE__, stat) < 0) { \\
*(err) = safe_strdup("error allocating memory"); \\
} \\
}\\
return stat; \\
}
typedef char *parser_error;
struct parser_context {
unsigned int options;
FILE *stderr;
};
yajl_gen_status map_uint(void *ctx, long long unsigned int num);
yajl_gen_status map_int(void *ctx, long long int num);
bool json_gen_init(yajl_gen *g, const struct parser_context *ctx);
yajl_val get_val(yajl_val tree, const char *name, yajl_type type);
void *safe_malloc(size_t size);
int common_safe_double(const char *numstr, double *converted);
int common_safe_uint8(const char *numstr, uint8_t *converted);
int common_safe_uint16(const char *numstr, uint16_t *converted);
int common_safe_uint32(const char *numstr, uint32_t *converted);
int common_safe_uint64(const char *numstr, uint64_t *converted);
int common_safe_uint(const char *numstr, unsigned int *converted);
int common_safe_int8(const char *numstr, int8_t *converted);
int common_safe_int16(const char *numstr, int16_t *converted);
int common_safe_int32(const char *numstr, int32_t *converted);
int common_safe_int64(const char *numstr, int64_t *converted);
int common_safe_int(const char *numstr, int *converted);
char *safe_strdup(const char *src);
typedef struct {
int *keys;
int *values;
size_t len;
} json_map_int_int;
void free_json_map_int_int(json_map_int_int *map);
json_map_int_int *make_json_map_int_int(yajl_val src, const struct parser_context *ctx, parser_error *err);
yajl_gen_status gen_json_map_int_int(void *ctx, const json_map_int_int *map, const struct parser_context *ptx, parser_error *err);
int append_json_map_int_int(json_map_int_int *map, int key, int val);
typedef struct {
int *keys;
bool *values;
size_t len;
} json_map_int_bool;
void free_json_map_int_bool(json_map_int_bool *map);
json_map_int_bool *make_json_map_int_bool(yajl_val src, const struct parser_context *ctx, parser_error *err);
yajl_gen_status gen_json_map_int_bool(void *ctx, const json_map_int_bool *map, const struct parser_context *ptx, parser_error *err);
int append_json_map_int_bool(json_map_int_bool *map, int key, bool val);
typedef struct {
int *keys;
char **values;
size_t len;
} json_map_int_string;
void free_json_map_int_string(json_map_int_string *map);
json_map_int_string *make_json_map_int_string(yajl_val src, const struct parser_context *ctx, parser_error *err);
yajl_gen_status gen_json_map_int_string(void *ctx, const json_map_int_string *map, const struct parser_context *ptx, parser_error *err);
int append_json_map_int_string(json_map_int_string *map, int key, const char *val);
typedef struct {
char **keys;
int *values;
size_t len;
} json_map_string_int;
void free_json_map_string_int(json_map_string_int *map);
json_map_string_int *make_json_map_string_int(yajl_val src, const struct parser_context *ctx, parser_error *err);
yajl_gen_status gen_json_map_string_int(void *ctx, const json_map_string_int *map, const struct parser_context *ptx, parser_error *err);
int append_json_map_string_int(json_map_string_int *map, const char *key, int val);
typedef struct {
char **keys;
bool *values;
size_t len;
} json_map_string_bool;
void free_json_map_string_bool(json_map_string_bool *map);
json_map_string_bool *make_json_map_string_bool(yajl_val src, const struct parser_context *ctx, parser_error *err);
yajl_gen_status gen_json_map_string_bool(void *ctx, const json_map_string_bool *map, const struct parser_context *ptx, parser_error *err);
int append_json_map_string_bool(json_map_string_bool *map, const char *key, bool val);
typedef struct {
char **keys;
char **values;
size_t len;
} json_map_string_string;
void free_json_map_string_string(json_map_string_string *map);
json_map_string_string *make_json_map_string_string(yajl_val src, const struct parser_context *ctx, parser_error *err);
yajl_gen_status gen_json_map_string_string(void *ctx, const json_map_string_string *map, const struct parser_context *ptx, parser_error *err);
int append_json_map_string_string(json_map_string_string *map, const char *key, const char *val);
char *json_marshal_string(const char *str, size_t strlen, const struct parser_context *ctx, parser_error *err);
# ifdef __cplusplus
}
# endif
# endif
'''
此差异已折叠。
# -*- coding: utf-8 -*-
'''
Description: header class and functions
Interface: None
History: 2019-06-17
'''
#
# libocispec - a C library for parsing OCI spec files.
#
# Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
#
# libocispec is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# libocispec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with libocispec. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, you may create a larger work that contains
# part or all of the libocispec parser skeleton and distribute that work
# under terms of your choice, so long as that work isn't itself a
# parser generator using the skeleton or a modified version thereof
# as a parser skeleton. Alternatively, if you modify or redistribute
# the parser skeleton itself, you may (at your option) remove this
# special exception, which will cause the skeleton and the resulting
# libocispec output files to be licensed under the GNU General Public
# License without this special exception.
#
#!/usr/bin/python -Es
import helpers
def append_header_arr(obj, header, prefix):
'''
Description: Write c header file of array
Interface: None
History: 2019-06-17
'''
if not obj.subtypobj or obj.subtypname:
return
header.write("typedef struct {\n")
for i in obj.subtypobj:
if i.typ == 'array':
c_typ = helpers.get_prefixe_pointer(i.name, i.subtyp, prefix) or \
helpers.get_map_c_types(i.subtyp)
if i.subtypobj is not None:
c_typ = helpers.get_name_substr(i.name, prefix)
if not helpers.judge_complex(i.subtyp):
header.write(" %s%s*%s;\n" % (c_typ, " " if '*' not in c_typ else "", \
i.fixname))
else:
header.write(" %s **%s;\n" % (c_typ, i.fixname))
header.write(" size_t %s;\n\n" % (i.fixname + "_len"))
else:
c_typ = helpers.get_prefixe_pointer(i.name, i.typ, prefix) or \
helpers.get_map_c_types(i.typ)
header.write(" %s%s%s;\n" % (c_typ, " " if '*' not in c_typ else "", i.fixname))
typename = helpers.get_name_substr(obj.name, prefix)
header.write("}\n%s;\n\n" % typename)
header.write("void free_%s(%s *ptr);\n\n" % (typename, typename))
header.write("%s *make_%s(yajl_val tree, const struct parser_context *ctx, parser_error *err);"\
"\n\n" % (typename, typename))
def append_header_map_str_obj(obj, header, prefix):
'''
Description: Write c header file of mapStringObject
Interface: None
History: 2019-06-17
'''
child = obj.children[0]
header.write("typedef struct {\n")
header.write(" char **keys;\n")
if helpers.valid_basic_map_name(child.typ):
c_typ = helpers.get_prefixe_pointer("", child.typ, "")
elif child.subtypname:
c_typ = child.subtypname
else:
c_typ = helpers.get_prefixe_pointer(child.name, child.typ, prefix)
header.write(" %s%s*%s;\n" % (c_typ, " " if '*' not in c_typ else "", child.fixname))
header.write(" size_t len;\n")
def append_header_child_arr(child, header, prefix):
'''
Description: Write c header file of array of child
Interface: None
History: 2019-06-17
'''
if helpers.get_map_c_types(child.subtyp) != "":
c_typ = helpers.get_map_c_types(child.subtyp)
elif helpers.valid_basic_map_name(child.subtyp):
c_typ = '%s *' % helpers.make_basic_map_name(child.subtyp)
elif child.subtypname is not None:
c_typ = child.subtypname
elif child.subtypobj is not None:
c_typ = helpers.get_name_substr(child.name, prefix)
else:
c_typ = helpers.get_prefixe_pointer(child.name, child.subtyp, prefix)
if helpers.valid_basic_map_name(child.subtyp):
header.write(" %s **%s;\n" % (helpers.make_basic_map_name(child.subtyp), child.fixname))
elif not helpers.judge_complex(child.subtyp):
header.write(" %s%s*%s;\n" % (c_typ, " " if '*' not in c_typ else "", child.fixname))
else:
header.write(" %s%s**%s;\n" % (c_typ, " " if '*' not in c_typ else "", child.fixname))
header.write(" size_t %s;\n\n" % (child.fixname + "_len"))
def append_header_child_others(child, header, prefix):
'''
Description: Write c header file of others of child
Interface: None
History: 2019-06-17
'''
if helpers.get_map_c_types(child.typ) != "":
c_typ = helpers.get_map_c_types(child.typ)
elif helpers.valid_basic_map_name(child.typ):
c_typ = '%s *' % helpers.make_basic_map_name(child.typ)
elif child.subtypname:
c_typ = helpers.get_prefixe_pointer(child.subtypname, child.typ, "")
else:
c_typ = helpers.get_prefixe_pointer(child.name, child.typ, prefix)
header.write(" %s%s%s;\n\n" % (c_typ, " " if '*' not in c_typ else "", child.fixname))
def append_type_c_header(obj, header, prefix):
'''
Description: Write c header file
Interface: None
History: 2019-06-17
'''
if not helpers.judge_complex(obj.typ):
return
if obj.typ == 'array':
append_header_arr(obj, header, prefix)
return
if obj.typ == 'mapStringObject':
if obj.subtypname is not None:
return
append_header_map_str_obj(obj, header, prefix)
elif obj.typ == 'object':
if obj.subtypname is not None:
return
header.write("typedef struct {\n")
if obj.children is None:
header.write(" char unuseful; // unuseful definition to avoid empty struct\n")
for i in obj.children or []:
if i.typ == 'array':
append_header_child_arr(i, header, prefix)
else:
append_header_child_others(i, header, prefix)
typename = helpers.get_prefixe_name(obj.name, prefix)
header.write("}\n%s;\n\n" % typename)
header.write("void free_%s(%s *ptr);\n\n" % (typename, typename))
header.write("%s *make_%s(yajl_val tree, const struct parser_context *ctx, parser_error *err)"\
";\n\n" % (typename, typename))
header.write("yajl_gen_status gen_%s(yajl_gen g, const %s *ptr, const struct parser_context "\
"*ctx, parser_error *err);\n\n" % (typename, typename))
def header_reflect(structs, schema_info, header):
'''
Description: Reflection header files
Interface: None
History: 2019-06-17
'''
prefix = schema_info.prefix
header.write("// Generated from %s. Do not edit!\n" % (schema_info.name.basename))
header.write("#ifndef %s_SCHEMA_H\n" % prefix.upper())
header.write("#define %s_SCHEMA_H\n\n" % prefix.upper())
header.write("#include <sys/types.h>\n")
header.write("#include <stdint.h>\n")
header.write("#include \"json_common.h\"\n")
if schema_info.refs:
for ref in schema_info.refs.keys():
header.write("#include \"%s\"\n" % (ref))
header.write("\n#ifdef __cplusplus\n")
header.write("extern \"C\" {\n")
header.write("#endif\n\n")
for i in structs:
append_type_c_header(i, header, prefix)
length = len(structs)
toptype = structs[length - 1].typ if length != 0 else ""
if toptype == 'object':
header.write("%s *%s_parse_file(const char *filename, const struct parser_context *ctx, "\
"parser_error *err);\n\n" % (prefix, prefix))
header.write("%s *%s_parse_file_stream(FILE *stream, const struct parser_context *ctx, "\
"parser_error *err);\n\n" % (prefix, prefix))
header.write("%s *%s_parse_data(const char *jsondata, const struct parser_context *ctx, "\
"parser_error *err);\n\n" % (prefix, prefix))
header.write("char *%s_generate_json(const %s *ptr, const struct parser_context *ctx, "\
"parser_error *err);\n\n" % (prefix, prefix))
elif toptype == 'array':
header.write("void free_%s(%s_element **ptr, size_t len);\n\n" % (prefix, prefix))
header.write("%s_element **%s_parse_file(const char *filename, const struct "\
"parser_context *ctx, parser_error *err, size_t *len);\n\n" % (prefix, prefix))
header.write("%s_element **%s_parse_file_stream(FILE *stream, const struct "\
"parser_context *ctx, parser_error *err, size_t *len);\n\n" % (prefix, prefix))
header.write("%s_element **%s_parse_data(const char *jsondata, const struct "\
"parser_context *ctx, parser_error *err, size_t *len);\n\n" % (prefix, prefix))
header.write("char *%s_generate_json(const %s_element **ptr, size_t len, "\
"const struct parser_context *ctx, parser_error *err);\n\n" % (prefix, prefix))
header.write("#ifdef __cplusplus\n")
header.write("}\n")
header.write("#endif\n\n")
header.write("#endif\n\n")
# -*- coding: utf-8 -*-
'''
Description: helper class and functions
Interface: None
History: 2019-06-17
'''
#
# libocispec - a C library for parsing OCI spec files.
#
# Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
#
# libocispec is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# libocispec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with libocispec. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, you may create a larger work that contains
# part or all of the libocispec parser skeleton and distribute that work
# under terms of your choice, so long as that work isn't itself a
# parser generator using the skeleton or a modified version thereof
# as a parser skeleton. Alternatively, if you modify or redistribute
# the parser skeleton itself, you may (at your option) remove this
# special exception, which will cause the skeleton and the resulting
# libocispec output files to be licensed under the GNU General Public
# License without this special exception.
#!/usr/bin/python -Es
import os
import sys
def append_separator(substr):
'''
Description: append only '_' at last position of subStr
Interface: None
History: 2019-09-20
'''
if substr and substr[-1] != '_':
substr.append('_')
def conv_to_c_style(name):
'''
Description: convert name to linux c format
Interface: None
History: 2019-06-17
'''
if name is None or name == "":
return ""
name = name.replace('.', '_').replace('-', '_').replace('/', '_')
substr = []
preindex = 0
index = 0
for index, char in enumerate(name):
if char == '_':
append_separator(substr)
substr.append(name[preindex:index].lower())
preindex = index + 1
if not char.isupper() and name[preindex].isupper() and \
name[preindex + 1].isupper():
append_separator(substr)
substr.append(name[preindex:index - 1].lower())
preindex = index - 1
continue
if char.isupper() and index > 0 and name[index - 1].islower():
append_separator(substr)
substr.append(name[preindex:index].lower())
preindex = index
if preindex <= index and index >= 0 and name[index] != '_' and \
preindex != 0:
append_separator(substr)
substr.append(name[preindex:index + 1].lower())
result = ''.join(substr)
return result
def get_map_c_types(typ):
'''
Description: Get map c types
Interface: None
History: 2019-06-17
'''
map_c_types = {
'byte': 'uint8_t',
'string': 'char *',
'integer': 'int',
'boolean': 'bool',
'double': 'double',
'int8': 'int8_t',
"int16": 'int16_t',
"int32": "int32_t",
"int64": "int64_t",
'uint8': 'uint8_t',
"uint16": 'uint16_t',
"uint32": "uint32_t",
"uint64": "uint64_t",
"UID": "uid_t",
"GID": "gid_t",
"booleanPointer": "bool *",
'bytePointer': 'uint8_t *',
'integerPointer': 'int *',
'doublePointer': 'double *',
'int8Pointer': 'int8_t *',
"int16Pointer": 'int16_t *',
"int32Pointer": "int32_t *",
"int64Pointer": "int64_t *",
'uint8Pointer': 'uint8_t *',
"uint16Pointer": 'uint16_t *',
"uint32Pointer": "uint32_t *",
"uint64Pointer": "uint64_t *",
}
if typ in map_c_types:
return map_c_types[typ]
return ""
def valid_basic_map_name(typ):
'''
Description: Valid basic map name
Interface: None
History: 2019-06-17
'''
return typ != 'mapStringObject' and hasattr(typ, 'startswith') and \
typ.startswith('map')
def make_basic_map_name(mapname):
'''
Description: Make basic map name
Interface: None
History: 2019-06-17
'''
basic_map_types = ('string', 'int', 'bool')
parts = conv_to_c_style(mapname).split('_')
if len(parts) != 3 or parts[0] != 'map' or \
(parts[1] not in basic_map_types) or \
(parts[2] not in basic_map_types):
print('Invalid map name: %s') % mapname
sys.exit(1)
return "json_map_%s_%s" % (parts[1], parts[2])
def get_name_substr(name, prefix):
'''
Description: Make array name
Interface: None
History: 2019-06-17
'''
return "%s_element" % prefix if name is None or name == "" or prefix == name \
else "%s_%s_element" % (prefix, name)
def get_prefixe_name(name, prefix):
'''
Description: Make name
Interface: None
History: 2019-06-17
'''
if name is None or name == "" or prefix.endswith(name):
return "%s" % prefix
if prefix is None or prefix == "" or prefix == name or name.endswith(prefix):
return "%s" % name
return "%s_%s" % (prefix, name)
def get_prefixe_pointer(name, typ, prefix):
'''
Description: Make pointer name
Interface: None
History: 2019-06-17
'''
if typ != 'object' and typ != 'mapStringObject' and \
not valid_basic_map_name(typ):
return ""
return '%s *' % make_basic_map_name(typ) if valid_basic_map_name(typ) \
else "%s *" % get_prefixe_name(name, prefix)
def judge_complex(typ):
'''
Description: Check compound object
Interface: None
History: 2019-06-17
'''
return typ in ('object', 'array', 'mapStringObject')
def judge_data_type(typ):
'''
Description: Check numeric type
Interface: None
History: 2019-06-17
'''
if (typ.startswith("int") or typ.startswith("uint")) and \
"Pointer" not in typ:
return True
return typ in ("integer", "UID", "GID", "double")
def judge_data_pointer_type(typ):
'''
Description: Check numeric pointer type
Interface: None
History: 2019-06-17
'''
if (typ.startswith("int") or typ.startswith("uint")) and "Pointer" in typ:
return True
return False
def obtain_data_pointer_type(typ):
'''
Description: Get numeric pointer type
Interface: None
History: 2019-06-17
'''
index = typ.find("Pointer")
return typ[0:index] if index != -1 else ""
def obtain_pointer(name, typ, prefix):
'''
Description: Obtain pointer string
Interface: None
History: 2019-06-17
'''
ptr = get_prefixe_pointer(name, typ, prefix)
if ptr != "":
return ptr
return "char *" if typ == "string" else \
("%s *" % typ if typ == "ArrayOfStrings" else "")
class CombinateName(object):
'''
Description: Store CombinateName information
Interface: None
History: 2019-06-17
'''
def __init__(self, name, leaf=None):
self.name = name
self.leaf = leaf
def __repr__(self):
return self.name
def __str__(self):
return self.name
def append(self, leaf):
'''
Description: append name
Interface: None
History: 2019-06-17
'''
prefix_name = self.name + '_' if self.name != "" else ""
return CombinateName(prefix_name + leaf, leaf)
class Unite(object):
'''
Description: Store Unite information
Interface: None
History: 2019-06-17
'''
def __init__(self, name, typ, children, subtyp=None, subtypobj=None, subtypname=None, \
required=None):
self.typ = typ
self.children = children
self.subtyp = subtyp
self.subtypobj = subtypobj
self.subtypname = subtypname
self.required = required
self.name = conv_to_c_style(name.name.replace('.', '_'))
self.origname = name.leaf or name.name
self.fixname = conv_to_c_style(self.origname.replace('.', '_'))
def __repr__(self):
if self.subtyp is not None:
return "name:(%s) type:(%s -> %s)" \
% (self.name, self.typ, self.subtyp)
return "name:(%s) type:(%s)" % (self.name, self.typ)
def __str__(self):
return self.__repr__(self)
class FilePath(object):
'''
Description: Store filepath information
Interface: None
History: 2019-06-17
'''
def __init__(self, name):
self.name = os.path.realpath(name)
self.dirname = os.path.dirname(self.name)
self.basename = os.path.basename(self.name)
def __repr__(self):
return "{name:(%s) dirname:(%s) basename:(%s)}" \
% (self.name, self.dirname, self.basename)
def __str__(self):
return self.__repr__(self)
class SchemaInfo(object):
'''
Description: Store schema information
Interface: None
History: 2019-06-17
'''
def __init__(self, name, header, source, prefix, filesdir, refs=None):
self.name = name
self.fileprefix = conv_to_c_style( \
name.basename.replace('.', '_').replace('-', '_'))
self.header = header
self.source = source
self.prefix = prefix
self.refs = refs
self.filesdir = os.path.realpath(filesdir)
def __repr__(self):
return "{name:(%s) header:(%s) source:(%s) prefix:(%s)}" \
% (self.name, self.header, self.source, self.prefix)
def __str__(self):
return self.__repr__(self)
/*
Copyright 2017 Giuseppe Scrivano
Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdint.h>
#include <config.h>
#include "read_file.h"
#ifndef O_CLOEXEC
#define O_CLOEXEC 02000000
#endif
#define JSON_MAX_SIZE (10LL * 1024LL * 1024LL)
#define FILE_MODE 0640
static int do_check_fread_args(const FILE *stream, const size_t *length)
{
if (stream == NULL) {
return -1;
}
if (length == NULL) {
return -1;
}
return 0;
}
char *fread_file(FILE *stream, size_t *length)
{
char *buf = NULL;
char *tmpbuf = NULL;
size_t off = 0;
if (do_check_fread_args(stream, length) != 0) {
return NULL;
}
while (1) {
size_t ret, newsize, sizejudge;
sizejudge = (JSON_MAX_SIZE - BUFSIZ) - 1;
if (sizejudge < off) {
goto out;
}
newsize = off + BUFSIZ + 1;
tmpbuf = (char *)calloc(1, newsize);
if (tmpbuf == NULL) {
goto out;
}
if (buf != NULL) {
(void)memcpy(tmpbuf, buf, off);
(void)memset(buf, 0, off);
free(buf);
}
buf = tmpbuf;
tmpbuf = NULL;
ret = fread(buf + off, 1, BUFSIZ, stream);
if (ret == 0 && ferror(stream)) {
goto out;
}
if (ret < BUFSIZ || feof(stream)) {
*length = off + ret + 1;
buf[*length - 1] = '\0';
return buf;
}
off += BUFSIZ;
}
out:
free(buf);
free(tmpbuf);
return NULL;
}
static int do_check_args(const char *path, const size_t *length)
{
if (path == NULL || length == NULL) {
return -1;
}
if (strlen(path) > PATH_MAX) {
return -1;
}
return 0;
}
char *read_file(const char *path, size_t *length)
{
char *buf = NULL;
char rpath[PATH_MAX + 1] = { 0 };
int fd = -1;
int tmperrno = -1;
FILE *fp = NULL;
if (do_check_args(path, length) != 0) {
return NULL;
}
if (realpath(path, rpath) == NULL) {
return NULL;
}
fd = open(rpath, O_RDONLY | O_CLOEXEC, FILE_MODE);
if (fd < 0) {
return NULL;
}
fp = fdopen(fd, "r");
tmperrno = errno;
if (fp == NULL) {
(void)close(fd);
errno = tmperrno;
return NULL;
}
buf = fread_file(fp, length);
(void)fclose(fp);
return buf;
}
/*
Copyright 2017 Giuseppe Scrivano
Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __JSON_READ_FILE_H_
#define __JSON_READ_FILE_H_
#include <stddef.h>
#include <stdio.h>
char *fread_file(FILE *stream, size_t *length);
char *read_file(const char *path, size_t *length);
#endif
此差异已折叠。
......@@ -31,9 +31,9 @@
#include "lcrcontainer.h"
#include "lcrcontainer_execute.h"
#include "lcrcontainer_extend.h"
#include "log.h"
#include "isula_libutils/log.h"
#include "utils.h"
#include "oci_runtime_spec.h"
#include "isula_libutils/oci_runtime_spec.h"
/*
* Free lcr_container_info array returned by lcr_list_{active,all}_containers
......@@ -306,11 +306,11 @@ bool lcr_create(const char *name, const char *lcrpath, void *oci_config)
oci_runtime_spec *oci_spec = (oci_runtime_spec *)oci_config;
clear_error_message(&g_lcr_error);
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -318,7 +318,7 @@ bool lcr_create(const char *name, const char *lcrpath, void *oci_config)
partial_fd = create_partial(c);
if (partial_fd < 0) {
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -338,7 +338,7 @@ out_unlock:
}
}
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -409,7 +409,7 @@ bool lcr_start(const struct lcr_start_request *request)
ERROR("Missing container name");
return false;
}
engine_set_log_prefix(request->name);
isula_libutils_set_log_prefix(request->name);
if (!lcr_start_check_config(path, request->name)) {
goto out_free;
......@@ -441,7 +441,7 @@ bool lcr_start(const struct lcr_start_request *request)
close(pipefd[0]);
out_free:
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return ret;
}
......@@ -481,17 +481,17 @@ bool lcr_kill(const char *name, const char *lcrpath, uint32_t signal)
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
if (signal >= NSIG) {
ERROR("'%u' isn't a valid signal number", signal);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
c = lxc_container_new(name, path);
if (c == NULL) {
ERROR("Failed to stop container.");
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -520,7 +520,7 @@ bool lcr_kill(const char *name, const char *lcrpath, uint32_t signal)
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return ret;
}
......@@ -535,11 +535,11 @@ bool lcr_delete(const char *name, const char *lcrpath)
ERROR("Missing container name");
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, path);
if (c == NULL) {
ERROR("Failed to delete container.");
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -574,7 +574,7 @@ bool lcr_delete(const char *name, const char *lcrpath)
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return ret;
}
......@@ -600,7 +600,7 @@ bool lcr_exec(const struct lcr_exec_request *request, int *exit_code)
return bret;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
if (geteuid()) {
if (access(tmp_path, O_RDONLY) < 0) {
......@@ -628,7 +628,7 @@ bool lcr_exec(const struct lcr_exec_request *request, int *exit_code)
out_put:
lxc_container_put(c);
out:
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -644,12 +644,12 @@ bool lcr_clean(const char *name, const char *lcrpath, const char *logpath, const
ERROR("Missing container name");
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
if (geteuid()) {
if (access(tmp_path, O_RDONLY) < 0) {
ERROR("You lack access to %s", tmp_path);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
}
......@@ -657,7 +657,7 @@ bool lcr_clean(const char *name, const char *lcrpath, const char *logpath, const
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
ERROR("Failed to delete container.");
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -683,7 +683,7 @@ bool lcr_clean(const char *name, const char *lcrpath, const char *logpath, const
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -697,11 +697,11 @@ bool lcr_state(const char *name, const char *lcrpath, struct lcr_container_state
ERROR("Missing container name");
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
ERROR("Failure to retrieve state infomation on %s", tmp_path);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -720,7 +720,7 @@ bool lcr_state(const char *name, const char *lcrpath, struct lcr_container_state
do_lcr_state(c, lcs);
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -734,11 +734,11 @@ bool lcr_get_container_pids(const char *name, const char *lcrpath, pid_t **pids,
ERROR("Missing container name");
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
ERROR("Failure to retrieve state infomation on %s", tmp_path);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -756,7 +756,7 @@ bool lcr_get_container_pids(const char *name, const char *lcrpath, pid_t **pids,
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -781,11 +781,11 @@ bool lcr_pause(const char *name, const char *lcrpath)
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
ERROR("Failed to pause container");
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -809,7 +809,7 @@ bool lcr_pause(const char *name, const char *lcrpath)
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -824,7 +824,7 @@ bool lcr_resume(const char *name, const char *lcrpath)
ERROR("Missing container name");
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
ERROR("Failed to resume container");
......@@ -851,7 +851,7 @@ bool lcr_resume(const char *name, const char *lcrpath)
out_put:
lxc_container_put(c);
out:
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -868,11 +868,11 @@ bool lcr_resize(const char *name, const char *lcrpath, unsigned int height, unsi
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
ERROR("Failed to pause container");
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -901,7 +901,7 @@ bool lcr_resize(const char *name, const char *lcrpath, unsigned int height, unsi
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -918,11 +918,11 @@ bool lcr_exec_resize(const char *name, const char *lcrpath, const char *suffix,
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
ERROR("Failed to pause container");
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -951,7 +951,7 @@ bool lcr_exec_resize(const char *name, const char *lcrpath, const char *suffix,
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bret;
}
......@@ -966,7 +966,7 @@ bool lcr_console(const char *name, const char *lcrpath, const char *in_fifo, con
ERROR("Missing container name");
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
......@@ -1000,7 +1000,7 @@ bool lcr_console(const char *name, const char *lcrpath, const char *in_fifo, con
out_put:
lxc_container_put(c);
out:
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return bresult;
}
......@@ -1101,11 +1101,11 @@ bool lcr_get_console_config(const char *name, const char *lcrpath, struct lcr_co
ERROR("Parameter is NULL");
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
c = lxc_container_new(name, tmp_path);
if (c == NULL) {
ERROR("Failed to create container.");
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -1128,7 +1128,7 @@ bool lcr_get_console_config(const char *name, const char *lcrpath, struct lcr_co
out_put:
lxc_container_put(c);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return ret;
}
......@@ -1143,12 +1143,12 @@ bool lcr_update(const char *name, const char *lcrpath, const struct lcr_cgroup_r
ERROR("Invalid input");
return false;
}
engine_set_log_prefix(name);
isula_libutils_set_log_prefix(name);
tmp_path = lcrpath ? lcrpath : LCRPATH;
if (access(tmp_path, O_RDONLY) < 0) {
ERROR("You lack permission to access %s", tmp_path);
engine_free_log_prefix();
isula_libutils_free_log_prefix();
return false;
}
......@@ -1183,7 +1183,7 @@ out_put:
lxc_container_put(c);
out_free:
engine_free_log_prefix();
isula_libutils_free_log_prefix();
if (!bret) {
lcr_try_set_error_message(LCR_ERR_RUNTIME, "Runtime error when updating cgroup");
}
......@@ -1215,7 +1215,7 @@ int lcr_log_init(const char *name, const char *file, const char *priority, const
char *full_path = NULL;
char *pre_name = "fifo:";
size_t pre_len = 0;
struct engine_log_config lconf = { 0 };
struct isula_libutils_log_config lconf = { 0 };
struct lxc_log lxc_log_conf = { 0 };
pre_len = strlen(pre_name);
......@@ -1231,7 +1231,7 @@ int lcr_log_init(const char *name, const char *file, const char *priority, const
lconf.driver = "fifo";
lconf.priority = priority;
}
if (engine_log_enable(&lconf)) {
if (isula_libutils_log_enable(&lconf)) {
fprintf(stderr, "Failed to init log");
goto out;
}
......
......@@ -27,9 +27,9 @@
#include "constants.h"
#include "lcrcontainer_execute.h"
#include "utils.h"
#include "log.h"
#include "isula_libutils/log.h"
#include "error.h"
#include "oci_runtime_spec.h"
#include "isula_libutils/oci_runtime_spec.h"
#include "lcrcontainer_extend.h"
// Cgroup Item Definition
......
此差异已折叠。
......@@ -17,7 +17,7 @@
#include <lxc/lxccontainer.h>
#include "oci_runtime_spec.h"
#include "isula_libutils/oci_runtime_spec.h"
#ifdef __cplusplus
extern "C" {
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册