update code

This commit is contained in:
zhuchunyi 2019-11-06 19:33:20 +08:00
parent 1790e58daf
commit 7bc32be8a8
122 changed files with 4603 additions and 851 deletions

View File

@ -77,7 +77,7 @@ OPTION(ENABLE_COVERAGE "coverage switch" OFF)
IF(ENABLE_COVERAGE) IF(ENABLE_COVERAGE)
MESSAGE(STATUS "Enable coverage compile option") MESSAGE(STATUS "Enable coverage compile option")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage") SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage -fkeep-inline-functions -fkeep-static-functions")
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage -lgcov") SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage -lgcov")
ENDIF(ENABLE_COVERAGE) ENDIF(ENABLE_COVERAGE)
@ -111,7 +111,7 @@ if (CMAKE_INSTALL_SYSCONFDIR)
endif() endif()
install(FILES src/contrib/config/daemon.json install(FILES src/contrib/config/daemon.json
DESTINATION ${conf_prefix}/isulad PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE) DESTINATION ${conf_prefix}/isulad PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)
install(FILES src/contrib/config/config.json install(FILES src/contrib/config/config.json src/contrib/config/systemcontainer_config.json
DESTINATION ${conf_prefix}/default/lcrd PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE) DESTINATION ${conf_prefix}/default/lcrd PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)
install(FILES src/contrib/config/seccomp_default.json install(FILES src/contrib/config/seccomp_default.json
DESTINATION ${conf_prefix}/isulad PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE) DESTINATION ${conf_prefix}/isulad PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)

View File

@ -33,7 +33,7 @@ endif()
option(VERSION "set lcrd version" ON) option(VERSION "set lcrd version" ON)
if (VERSION STREQUAL "ON") if (VERSION STREQUAL "ON")
set(LCRD_VERSION "1.0.31") set(LCRD_VERSION "1.0.33")
endif() endif()
option(DEBUG "set lcrd gcc option" ON) option(DEBUG "set lcrd gcc option" ON)

View File

@ -7,10 +7,10 @@ This project depends on gRPC (need protobuf at least v3.1.0, gRPC at least v1.1.
### Initialization ### Initialization
```sh ```sh
$ # for ubuntu $ sudo yum install -y go gcc gcc-c++ autoconf libtool unzip automake cmake curl zlib-devel libcap-devel libseccomp-devel \
$ sudo apt-get install unzip libtool automake autoconf g++ cmake curl zlib1g-dev libcap-dev libseccomp-dev libyajl-dev libsqlite3-dev libwebsockets-dev $ yajl-devel sqlite-devel libwebsockets-devel openssl-devel c-ares-devel zlib-devel python3-devel python3-setuptools libsecurec-devel
$ # for centos/RTOS $ sudo sh -c "echo /usr/local/lib >> /etc/ld.so.conf"
$ sudo yum install gcc-c++ autoconf libtool unzip automake cmake curl zlib-devel libcap-devel libseccomp-devel yajl-devel sqlite-devel libwebsockets-devel $ sudo sh -c 'echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" >> /etc/bashrc'
``` ```
### protobuf v3.5.0 ### protobuf v3.5.0
@ -19,8 +19,8 @@ Compile protobuf from source code:
```sh ```sh
$ git clone http://dgggit09-rd.huawei.com/a/euleros/third_party/open_source/userspace/protobuf $ git clone http://dgggit09-rd.huawei.com/a/euleros/third_party/open_source/userspace/protobuf
$ cd protobuf $ cd protobuf
$ git checkout -b next origin/next $ git checkout -b open origin/next_openeuler
$ tar -xf protobuf-3.5.0.tar.gz $ tar -xf v3.5.0.tar.gz
$ cp googlemock-1.7.0.tar.gz googletest-1.7.0.tar.gz 0001-fix-build-on-s390x.patch protobuf-3.5.0 $ cp googlemock-1.7.0.tar.gz googletest-1.7.0.tar.gz 0001-fix-build-on-s390x.patch protobuf-3.5.0
$ cd protobuf-3.5.0 $ cd protobuf-3.5.0
$ tar -xf googlemock-1.7.0.tar.gz $ tar -xf googlemock-1.7.0.tar.gz
@ -29,7 +29,7 @@ $ mv googlemock-release-1.7.0 gmock
$ tar -xf googletest-1.7.0.tar.gz -C gmock $ tar -xf googletest-1.7.0.tar.gz -C gmock
$ mv gmock/googletest-release-1.7.0 gmock/gtest $ mv gmock/googletest-release-1.7.0 gmock/gtest
$ patch -p1 < 0001-fix-build-on-s390x.patch $ patch -p1 < 0001-fix-build-on-s390x.patch
$ ./autogen.sh # Because of internal network issue, we need to change curl to allow insecure connections (curl -k) $ ./autogen.sh
$ ./configure $ ./configure
$ make -j $ make -j
$ sudo make install $ sudo make install
@ -42,13 +42,13 @@ Compile the gRPC C Core library
```sh ```sh
$ git clone http://dgggit09-rd.huawei.com/a/euleros/third_party/open_source/userspace/grpc $ git clone http://dgggit09-rd.huawei.com/a/euleros/third_party/open_source/userspace/grpc
$ cd grpc $ cd grpc
$ tar xf grpc-1.17.1.tar.gz $ git checkout -b open origin/next_openeuler
$ tar xf v1.17.1.tar.gz
$ cd grpc-1.17.1 $ cd grpc-1.17.1
$ git checkout -b next origin/next
$ patch -p1 < ../0001-Do-not-build-the-Ruby-plugin.patch
$ patch -p1 < ../0001-enforce-system-crypto-policies.patch $ patch -p1 < ../0001-enforce-system-crypto-policies.patch
$ patch -p1 < ../0002-patch-from-15532.patch $ patch -p1 < ../0002-patch-from-15532.patch
$ patch -p1 < ../cxx-Arg-List-Too-Long.patch $ patch -p1 < ../0003-Do-not-build-the-Ruby-plugin.patch
$ patch -p1 < ../0001-cxx-Arg-List-Too-Long.patch
$ make -j $ make -j
$ sudo make install $ sudo make install
$ sudo ldconfig $ sudo ldconfig
@ -60,7 +60,7 @@ Compile clibcni from source code:
```sh ```sh
$ git clone http://dgggit09-rd.huawei.com/a/euleros/self_src/userspace/clibcni $ git clone http://dgggit09-rd.huawei.com/a/euleros/self_src/userspace/clibcni
$ cd clibcni $ cd clibcni
$ git checkout -b next_docker origin/next_docker $ git checkout -b open origin/next_openeuler
$ rm -rf build $ rm -rf build
$ mkdir build && cd build $ mkdir build && cd build
$ cmake .. $ cmake ..
@ -68,17 +68,6 @@ $ make -j
$ sudo make install $ sudo make install
$ sudo ldconfig $ sudo ldconfig
``` ```
if enbale testcase
```sh
$ rm -rf build
$ mkdir build && cd build
$ cmake -DENABLE_TESTS=ON ..
$ make -j
$ sudo make install
$ sudo ldconfig
$ cd tests && ./cni_test
$ cd -
```
### containernetworking plugins ### containernetworking plugins
@ -96,16 +85,10 @@ $ cp bin/* /opt/cni/bin/
Compile iSulad-kit from source code: Compile iSulad-kit from source code:
```sh ```sh
$ yum install -y gpgme-devel
$ git clone http://dgggit09-rd.huawei.com/a/euleros/self_src/userspace/iSulad-kit $ git clone http://dgggit09-rd.huawei.com/a/euleros/self_src/userspace/iSulad-kit
$ git clone http://dgggit09-rd.huawei.com/a/euleros/third_party/open_source/userspace/skopeo $ cd iSulad-kit
$ cd skopeo $ git checkout -b open origin/next_openeuler
$ git checkout -b next_docker origin/next_docker
$ mkdir ./tmp
$ tar -zxf skopeo-e814f96.tar.gz --strip-components 1 -C ./tmp
$ cp -r ./tmp/vendor ../iSulad-kit/
$ cd ../iSulad-kit
$ git checkout -b next_docker origin/next_docker
$ patch -p1 -F1 -s < ../skopeo/backport-update-vendor-to-e96a9b0e1b9019f9.patch
# apply the patchs # apply the patchs
$ cp ./patch/* ./ $ cp ./patch/* ./
$ cat series-patch.conf | while read line $ cat series-patch.conf | while read line
@ -116,7 +99,7 @@ $ cat series-patch.conf | while read line
patch -p1 -F1 -s < $line patch -p1 -F1 -s < $line
done done
$ make -j $ make -j
$ make install $ sudo make install
``` ```
### LXC ### LXC
@ -125,56 +108,34 @@ Compile lxc from source code:
```sh ```sh
$ git clone http://dgggit09-rd.huawei.com/a/euleros/third_party/open_source/userspace/lxc $ git clone http://dgggit09-rd.huawei.com/a/euleros/third_party/open_source/userspace/lxc
$ cd lxc $ cd lxc
$ git checkout -b next_docker origin/next_docker $ git checkout -b open origin/next_openeuler
$ tar xf lxc-3.0.3.tar.gz $ tar xf lxc-3.0.3.tar.gz
$ cd lxc-3.0.3 $ cd lxc-3.0.3
$ mv ../*.patch . $ mv ../*.patch .
# official patch # official patch
$ for var in $(ls lxc-*.patch | sort -n) $ for var in $(ls lxc-*.patch | sort -n)
do do
if [[ "$var" =~ "CVE-2019-5736" ]]; then
echo "ignoring CVE patch cause valgrind can not work"
continue
fi
patch -p1 < ${var} patch -p1 < ${var}
done done
# self-developing patch # self-developing patch
$ for var in $(ls huawei-*.patch | sort -n) $ for var in $(ls *.patch | grep -v "^lxc-" | sort -n)
do do
patch -p1 < ${var} patch -p1 < ${var}
done done
$ ./autogen.sh $ ./autogen.sh
$ ./configure $ ./configure
$ make -j (If the GCC version on the system is greater than 7, please add CFLAGS="-Wno-error" option) $ make -j # If the GCC version on the system is greater than 7, please add CFLAGS="-Wno-error" option
$ sudo make install $ sudo make install
$ sudo ldconfig $ sudo ldconfig
``` ```
### huawei securec library
Compile huawei securec library from source code:
```sh
$ git clone git@code-sh.huawei.com:containers/securec.git
$ cd securec
$ ./autogen.sh
$ ./configue
$ make -j $(nproc)
$ sudo make install
$ sudo ldconfig
```
### LCR ### LCR
Note: If you encounter an error like "You must install [project] >= [version]" during executing "./configure",
please export the environment variable
```sh
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
```
Compile lcr from source code: Compile lcr from source code:
```sh ```sh
$ git clone http://dgggit09-rd.huawei.com/a/euleros/self_src/userspace/lcr $ git clone http://dgggit09-rd.huawei.com/a/euleros/self_src/userspace/lcr
$ cd lcr $ cd lcr
$ git checkout -b next_docker origin/next_docker $ git checkout -b open origin/next_openeuler
$ mkdir -p build $ mkdir -p build
$ cd build $ cd build
$ cmake ../ $ cmake ../
@ -183,23 +144,17 @@ $ sudo make install
$ sudo ldconfig $ sudo ldconfig
``` ```
## Build LCRD ## Build iSulad
Note: If you encounter an error like "not found libcurl" during executing "./configure" on the ubuntu system,
please execute the following command:
```sh
$ sudo apt-get install libcurl4-gnutls-dev
```
In most cases, if we do not need to change the interface API(container.proto), just build the server and client like this:
```sh ```sh
$ yum install -y libcurl-devel http-parser-devel systemd-devel libevent-devel libevhtp-devel
$ git clone http://dgggit09-rd.huawei.com/a/euleros/self_src/userspace/iSulad $ git clone http://dgggit09-rd.huawei.com/a/euleros/self_src/userspace/iSulad
$ cd iSulad $ cd iSulad
$ git checkout -b next_docker origin/next_docker $ git checkout -b open origin/next_openeuler
$ rm -rf build $ mkdir -p build && cd build
$ mkdir build && cd build # To enable gRPC, configure iSulad by default
# To enable gRPC, configure lcrd by default
$ cmake ../ $ cmake ../
$ make -j (If the GCC version on the system is greater than 7, please add CFLAGS="-Wno-error" option) $ make -j # If the GCC version on the system is greater than 7, please add CFLAGS="-Wno-error" option
$ sudo make install $ sudo make install
$ sudo ldconfig $ sudo ldconfig
``` ```
@ -207,35 +162,19 @@ $ sudo ldconfig
## Run ## Run
### Start daemon ### Start daemon
Note: if you encounter an error like "error while loading shared libraries" when start the daemon ,
please execute the following command:
```sh
$ sudo echo "/usr/local/lib" >> /etc/ld.so.conf
```
You should have built and installed lcrd and lcrc. To run the daemon: You should have built and installed lcrd and lcrc. To run the daemon:
```sh ```sh
$ sudo lcrd # run the lcrd server with default socket name and default log level and images manage function $ sudo lcrd # run the iSulad server with default socket name and default log level and images manage function
``` ```
### Download rootfs
To create a container, you should have downloaded rootfs to your platform like this:
```sh
$ mkdir $HOME/myrootfs
$ sudo lcr-pull --name ubuntu --rootfs $HOME/myrootfs --dist ubuntu -r xenial -a amd64
```
If lcrd started with the images manage function you can download images from registry (e.g., docker.io)
### Operations on containers: ### Operations on containers:
```sh ```sh
$ sudo lcrc ps -a # list containers $ sudo lcrc ps -a # list containers
# create a container 'ubuntu1' with the directory # create a container 'test' with image busybox
$ sudo lcrc create -n ubuntu1 --external-rootfs $HOME/myrootfs/ none $ sudo lcrc create -t -n test busybox
# or, you can create a container with OverlayFS $ sudo lcrc start test # start the container 'test'
$ sudo mkdir $HOME/upperdir/ # create the upperdir for OverlayFS $ sudo lcrc kill test # kill the container 'test'
$ sudo lcrc create -n 'ubuntu1' --external-rootfs overlayfs:$HOME/myrootfs:$HOME/upperdir none $ sudo lcrc rm test # remove the container 'test'
$ sudo lcrc start ubuntu1 # start the container 'ubuntu1'
$ sudo lcrc kill ubuntu1 # kill the container 'ubuntu1'
``` ```

View File

@ -1,17 +1,17 @@
%global _version 1.0.31 %global _version 1.0.33
%global _release 20190919.232053.gitf0f8c706 %global _release 20190930.052413.gitd2956279
%global is_systemd 1 %global is_systemd 1
%global debug_package %{nil} %global debug_package %{nil}
Name: iSulad Name: iSulad
Version: %{_version} Version: %{_version}
Release: %{_release}%{?dist} Release: %{_release}
Summary: Lightweight Container Runtime Daemon Summary: Lightweight Container Runtime Daemon
License: Mulan PSL v1 License: Mulan PSL v1
BuildRoot: {_tmppath}/%{name}-%{version}
ExclusiveArch: x86_64 aarch64
URL: http://code.huawei.com/containers/lcrd URL: http://code.huawei.com/containers/lcrd
Source: %{name}-1.0.tar.gz Source: iSulad-1.0.tar.gz
BuildRoot: {_tmppath}/iSulad-%{version}
ExclusiveArch: x86_64 aarch64
%ifarch x86_64 aarch64 %ifarch x86_64 aarch64
Provides: libhttpclient.so()(64bit) Provides: libhttpclient.so()(64bit)
@ -48,7 +48,7 @@ This is a umbrella project for gRPC-services based Lightweight Container
Runtime Daemon, written by C. Runtime Daemon, written by C.
%prep %prep
%autosetup -c -n %{name}-%{version} %autosetup -c -n iSulad-%{version}
%build %build
mkdir -p build mkdir -p build
@ -84,7 +84,8 @@ install -m 0640 ../src/contrib/config/seccomp_default.json %{buildroot}/%{_sysc
install -d $RPM_BUILD_ROOT/%{_sysconfdir}/default/lcrd install -d $RPM_BUILD_ROOT/%{_sysconfdir}/default/lcrd
install -m 0640 ../src/contrib/config/config.json %{buildroot}/%{_sysconfdir}/default/lcrd/config.json install -m 0640 ../src/contrib/config/config.json %{buildroot}/%{_sysconfdir}/default/lcrd/config.json
install -m 0550 ../src/contrib/sysmonitor/isulad-check.sh %{buildroot}/%{_sysconfdir}/default/lcrd/isulad-check.sh install -m 0640 ../src/contrib/config/systemcontainer_config.json %{buildroot}/%{_sysconfdir}/default/lcrd/systemcontainer_config.json
install -m 0550 ../src/contrib/sysmonitor/isulad-check.sh %{buildroot}/%{_sysconfdir}/default/lcrd/isulad-check.sh
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/sysmonitor/process mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/sysmonitor/process
cp ../src/contrib/sysmonitor/isulad-monit $RPM_BUILD_ROOT/etc/sysmonitor/process cp ../src/contrib/sysmonitor/isulad-monit $RPM_BUILD_ROOT/etc/sysmonitor/process
@ -159,6 +160,7 @@ fi
%attr(0600,root,root) %{_sysconfdir}/sysmonitor/process/isulad-monit %attr(0600,root,root) %{_sysconfdir}/sysmonitor/process/isulad-monit
%attr(0550,root,root) %{_sysconfdir}/default/lcrd/isulad-check.sh %attr(0550,root,root) %{_sysconfdir}/default/lcrd/isulad-check.sh
%defattr(0640,root,root,0750) %defattr(0640,root,root,0750)
%{_sysconfdir}/isulad
%{_sysconfdir}/isulad/* %{_sysconfdir}/isulad/*
%{_sysconfdir}/default/* %{_sysconfdir}/default/*
%defattr(-,root,root,-) %defattr(-,root,root,-)

View File

@ -17,7 +17,6 @@
#include "commander.h" #include "commander.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <regex.h> #include <regex.h>
@ -299,10 +298,6 @@ static int command_parse_short_arg(command_t *self, const char *arg)
do { do {
found = false; found = false;
if (opt_arg[0] == 'h' && have_short_options(self, 'h') < 0) {
command_help(self);
exit(0);
}
if (command_parse_options(self, &opt_arg, &found)) { if (command_parse_options(self, &opt_arg, &found)) {
return -1; return -1;
} }
@ -459,7 +454,7 @@ static void get_default_ulimit_split_parts(const char *val, char ***parts, size_
ERROR("Out of memory"); ERROR("Out of memory");
return; return;
} }
*parts_len = util_array_len(*parts); *parts_len = util_array_len((const char **)(*parts));
} }
static int parse_soft_hard_default_ulimit(const char *val, char **limitvals, size_t limitvals_len, int64_t *soft, static int parse_soft_hard_default_ulimit(const char *val, char **limitvals, size_t limitvals_len, int64_t *soft,

View File

@ -76,7 +76,7 @@ static int request_pack_host_config_storage_opts(const struct client_arguments *
return -1; return -1;
} }
len = util_array_len(args->custom_conf.storage_opts); len = util_array_len((const char **)(args->custom_conf.storage_opts));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
char *p = NULL; char *p = NULL;
p = strchr(args->custom_conf.storage_opts[i], '='); p = strchr(args->custom_conf.storage_opts[i], '=');
@ -111,7 +111,7 @@ static int request_pack_host_config_sysctls(const struct client_arguments *args,
return -1; return -1;
} }
len = util_array_len(args->custom_conf.sysctls); len = util_array_len((const char **)(args->custom_conf.sysctls));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
char *p = NULL; char *p = NULL;
p = strchr(args->custom_conf.sysctls[i], '='); p = strchr(args->custom_conf.sysctls[i], '=');
@ -232,7 +232,7 @@ static int request_pack_custom_env(struct client_arguments *args, lcrc_container
if (args->custom_conf.env != NULL) { if (args->custom_conf.env != NULL) {
conf->env = args->custom_conf.env; conf->env = args->custom_conf.env;
conf->env_len = util_array_len(conf->env); conf->env_len = util_array_len((const char **)(conf->env));
} }
if (args->custom_conf.accel != NULL) { if (args->custom_conf.accel != NULL) {
@ -246,10 +246,10 @@ static int request_pack_custom_env(struct client_arguments *args, lcrc_container
} }
args->custom_conf.env = conf->env; /* make sure args->custom_conf.env point to valid memory. */ args->custom_conf.env = conf->env; /* make sure args->custom_conf.env point to valid memory. */
conf->env_len = util_array_len(conf->env); conf->env_len = util_array_len((const char **)(conf->env));
conf->accel = args->custom_conf.accel; conf->accel = args->custom_conf.accel;
conf->accel_len = util_array_len(args->custom_conf.accel); conf->accel_len = util_array_len((const char **)(args->custom_conf.accel));
if (util_env_set_lcrd_enable_plugins(&conf->env, &conf->env_len, LCRD_ISULA_ADAPTER)) { if (util_env_set_lcrd_enable_plugins(&conf->env, &conf->env_len, LCRD_ISULA_ADAPTER)) {
COMMAND_ERROR("init accel env failed"); COMMAND_ERROR("init accel env failed");
ret = -1; ret = -1;
@ -308,7 +308,7 @@ static void request_pack_custom_system_container(const struct client_arguments *
static void request_pack_custom_mounts(const struct client_arguments *args, lcrc_container_config_t *conf) static void request_pack_custom_mounts(const struct client_arguments *args, lcrc_container_config_t *conf)
{ {
if (args->custom_conf.mounts != NULL) { if (args->custom_conf.mounts != NULL) {
conf->mounts_len = util_array_len(args->custom_conf.mounts); conf->mounts_len = util_array_len((const char **)(args->custom_conf.mounts));
conf->mounts = args->custom_conf.mounts; conf->mounts = args->custom_conf.mounts;
} }
return; return;
@ -535,12 +535,12 @@ static void request_pack_host_caps(const struct client_arguments *args, lcrc_hos
{ {
/* cap add */ /* cap add */
if (args->custom_conf.cap_adds != NULL) { if (args->custom_conf.cap_adds != NULL) {
hostconfig->cap_add_len = util_array_len(args->custom_conf.cap_adds); hostconfig->cap_add_len = util_array_len((const char **)(args->custom_conf.cap_adds));
hostconfig->cap_add = args->custom_conf.cap_adds; hostconfig->cap_add = args->custom_conf.cap_adds;
} }
/* cap drop */ /* cap drop */
if (args->custom_conf.cap_drops != NULL) { if (args->custom_conf.cap_drops != NULL) {
hostconfig->cap_drop_len = util_array_len(args->custom_conf.cap_drops); hostconfig->cap_drop_len = util_array_len((const char **)(args->custom_conf.cap_drops));
hostconfig->cap_drop = args->custom_conf.cap_drops; hostconfig->cap_drop = args->custom_conf.cap_drops;
} }
} }
@ -549,7 +549,7 @@ static void request_pack_host_group_add(const struct client_arguments *args, lcr
{ {
/* group add */ /* group add */
if (args->custom_conf.group_add != NULL) { if (args->custom_conf.group_add != NULL) {
hostconfig->group_add_len = util_array_len(args->custom_conf.group_add); hostconfig->group_add_len = util_array_len((const char **)(args->custom_conf.group_add));
hostconfig->group_add = args->custom_conf.group_add; hostconfig->group_add = args->custom_conf.group_add;
} }
} }
@ -558,7 +558,7 @@ static void request_pack_host_extra_hosts(const struct client_arguments *args, l
{ {
/* extra hosts */ /* extra hosts */
if (args->custom_conf.extra_hosts != NULL) { if (args->custom_conf.extra_hosts != NULL) {
hostconfig->extra_hosts_len = util_array_len(args->custom_conf.extra_hosts); hostconfig->extra_hosts_len = util_array_len((const char **)(args->custom_conf.extra_hosts));
hostconfig->extra_hosts = args->custom_conf.extra_hosts; hostconfig->extra_hosts = args->custom_conf.extra_hosts;
} }
} }
@ -567,19 +567,19 @@ static void request_pack_host_dns(const struct client_arguments *args, lcrc_host
{ {
/* dns */ /* dns */
if (args->custom_conf.dns != NULL) { if (args->custom_conf.dns != NULL) {
hostconfig->dns_len = util_array_len(args->custom_conf.dns); hostconfig->dns_len = util_array_len((const char **)(args->custom_conf.dns));
hostconfig->dns = args->custom_conf.dns; hostconfig->dns = args->custom_conf.dns;
} }
/* dns options */ /* dns options */
if (args->custom_conf.dns_options != NULL) { if (args->custom_conf.dns_options != NULL) {
hostconfig->dns_options_len = util_array_len(args->custom_conf.dns_options); hostconfig->dns_options_len = util_array_len((const char **)(args->custom_conf.dns_options));
hostconfig->dns_options = args->custom_conf.dns_options; hostconfig->dns_options = args->custom_conf.dns_options;
} }
/* dns search */ /* dns search */
if (args->custom_conf.dns_search != NULL) { if (args->custom_conf.dns_search != NULL) {
hostconfig->dns_search_len = util_array_len(args->custom_conf.dns_search); hostconfig->dns_search_len = util_array_len((const char **)(args->custom_conf.dns_search));
hostconfig->dns_search = args->custom_conf.dns_search; hostconfig->dns_search = args->custom_conf.dns_search;
} }
} }
@ -588,7 +588,7 @@ static void request_pack_host_ulimit(const struct client_arguments *args, lcrc_h
{ {
/* ulimit options */ /* ulimit options */
if (args->custom_conf.ulimits != NULL) { if (args->custom_conf.ulimits != NULL) {
hostconfig->ulimits_len = util_array_len(args->custom_conf.ulimits); hostconfig->ulimits_len = util_array_len((const char **)(args->custom_conf.ulimits));
hostconfig->ulimits = args->custom_conf.ulimits; hostconfig->ulimits = args->custom_conf.ulimits;
} }
} }
@ -597,7 +597,7 @@ static void request_pack_host_weight_devices(const struct client_arguments *args
{ {
/* blkio weight devices */ /* blkio weight devices */
if (args->custom_conf.weight_devices != NULL) { if (args->custom_conf.weight_devices != NULL) {
hostconfig->blkio_weight_device_len = util_array_len(args->custom_conf.weight_devices); hostconfig->blkio_weight_device_len = util_array_len((const char **)(args->custom_conf.weight_devices));
hostconfig->blkio_weight_device = args->custom_conf.weight_devices; hostconfig->blkio_weight_device = args->custom_conf.weight_devices;
} }
} }
@ -606,7 +606,7 @@ static void request_pack_host_device_read_bps(const struct client_arguments *arg
{ {
if (args->custom_conf.blkio_throttle_read_bps_device != NULL) { if (args->custom_conf.blkio_throttle_read_bps_device != NULL) {
hostconfig->blkio_throttle_read_bps_device_len = hostconfig->blkio_throttle_read_bps_device_len =
util_array_len(args->custom_conf.blkio_throttle_read_bps_device); util_array_len((const char **)(args->custom_conf.blkio_throttle_read_bps_device));
hostconfig->blkio_throttle_read_bps_device = args->custom_conf.blkio_throttle_read_bps_device; hostconfig->blkio_throttle_read_bps_device = args->custom_conf.blkio_throttle_read_bps_device;
} }
} }
@ -615,7 +615,7 @@ static void request_pack_host_device_write_bps(const struct client_arguments *ar
{ {
if (args->custom_conf.blkio_throttle_write_bps_device != NULL) { if (args->custom_conf.blkio_throttle_write_bps_device != NULL) {
hostconfig->blkio_throttle_write_bps_device_len = hostconfig->blkio_throttle_write_bps_device_len =
util_array_len(args->custom_conf.blkio_throttle_write_bps_device); util_array_len((const char **)(args->custom_conf.blkio_throttle_write_bps_device));
hostconfig->blkio_throttle_write_bps_device = args->custom_conf.blkio_throttle_write_bps_device; hostconfig->blkio_throttle_write_bps_device = args->custom_conf.blkio_throttle_write_bps_device;
} }
} }
@ -631,7 +631,7 @@ static void request_pack_host_devices(const struct client_arguments *args, lcrc_
{ {
/* devices */ /* devices */
if (args->custom_conf.devices != NULL) { if (args->custom_conf.devices != NULL) {
hostconfig->devices_len = util_array_len(args->custom_conf.devices); hostconfig->devices_len = util_array_len((const char **)(args->custom_conf.devices));
hostconfig->devices = args->custom_conf.devices; hostconfig->devices = args->custom_conf.devices;
} }
} }
@ -640,7 +640,7 @@ static void request_pack_host_hugepage_limits(const struct client_arguments *arg
{ {
/* hugepage limits*/ /* hugepage limits*/
if (args->custom_conf.hugepage_limits != NULL) { if (args->custom_conf.hugepage_limits != NULL) {
hostconfig->hugetlbs_len = util_array_len(args->custom_conf.hugepage_limits); hostconfig->hugetlbs_len = util_array_len((const char **)(args->custom_conf.hugepage_limits));
hostconfig->hugetlbs = args->custom_conf.hugepage_limits; hostconfig->hugetlbs = args->custom_conf.hugepage_limits;
} }
} }
@ -649,7 +649,7 @@ static void request_pack_host_binds(const struct client_arguments *args, lcrc_ho
{ {
/* volumes to binds */ /* volumes to binds */
if (args->custom_conf.volumes != NULL) { if (args->custom_conf.volumes != NULL) {
hostconfig->binds_len = (size_t)util_array_len(args->custom_conf.volumes); hostconfig->binds_len = (size_t)util_array_len((const char **)(args->custom_conf.volumes));
hostconfig->binds = args->custom_conf.volumes; hostconfig->binds = args->custom_conf.volumes;
} }
} }
@ -696,7 +696,7 @@ static void request_pack_host_security(const struct client_arguments *args, lcrc
{ {
/* security opt */ /* security opt */
if (args->custom_conf.security != NULL) { if (args->custom_conf.security != NULL) {
hostconfig->security_len = util_array_len(args->custom_conf.security); hostconfig->security_len = util_array_len((const char **)(args->custom_conf.security));
hostconfig->security = args->custom_conf.security; hostconfig->security = args->custom_conf.security;
} }
} }
@ -1162,7 +1162,7 @@ static bool check_devices_conf_valid(const char *devices)
ret = false; ret = false;
goto out; goto out;
} }
tmp_str_len = util_array_len(tmp_str); tmp_str_len = util_array_len((const char **)tmp_str);
// device format: x:x:x or x:x or x // device format: x:x:x or x:x or x
switch (tmp_str_len) { switch (tmp_str_len) {
@ -1217,7 +1217,7 @@ static bool check_volumes_valid(const char *volume)
ret = false; ret = false;
goto free_out; goto free_out;
} }
alen = util_array_len(array); alen = util_array_len((const char **)array);
// volume format: src:dst:mode // volume format: src:dst:mode
switch (alen) { switch (alen) {
@ -1453,7 +1453,7 @@ static int parse_mounts_conf(const char *mount, struct valid_mounts_state *state
goto out; goto out;
} }
items_len = util_array_len(items); items_len = util_array_len((const char **)items);
for (i = 0; i < items_len; i++) { for (i = 0; i < items_len; i++) {
key_val = util_string_split(items[i], '='); key_val = util_string_split(items[i], '=');
@ -1621,7 +1621,7 @@ static int create_check_hugetlbs(const struct client_arguments *args)
int ret = 0; int ret = 0;
size_t len, i; size_t len, i;
len = util_array_len(args->custom_conf.hugepage_limits); len = util_array_len((const char **)(args->custom_conf.hugepage_limits));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
char *limit = NULL; char *limit = NULL;
int64_t limitvalue; int64_t limitvalue;
@ -1666,7 +1666,7 @@ static int create_check_network(const struct client_arguments *args)
size_t len, i; size_t len, i;
struct sockaddr_in sa; struct sockaddr_in sa;
len = util_array_len(args->custom_conf.extra_hosts); len = util_array_len((const char **)(args->custom_conf.extra_hosts));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
char **items = NULL; char **items = NULL;
items = util_string_split(args->custom_conf.extra_hosts[i], ':'); items = util_string_split(args->custom_conf.extra_hosts[i], ':');
@ -1674,7 +1674,7 @@ static int create_check_network(const struct client_arguments *args)
COMMAND_ERROR("split extra hosts '%s' failed.", args->custom_conf.extra_hosts[i]); COMMAND_ERROR("split extra hosts '%s' failed.", args->custom_conf.extra_hosts[i]);
return -1; return -1;
} }
if (util_array_len(items) != 2) { if (util_array_len((const char **)items) != 2) {
util_free_array(items); util_free_array(items);
COMMAND_ERROR("Invalid extra hosts specification '%s'. unsupported format", COMMAND_ERROR("Invalid extra hosts specification '%s'. unsupported format",
args->custom_conf.extra_hosts[i]); args->custom_conf.extra_hosts[i]);
@ -1687,7 +1687,7 @@ static int create_check_network(const struct client_arguments *args)
} }
util_free_array(items); util_free_array(items);
} }
len = util_array_len(args->custom_conf.dns); len = util_array_len((const char **)(args->custom_conf.dns));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (!inet_pton(AF_INET, args->custom_conf.dns[i], &sa.sin_addr)) { if (!inet_pton(AF_INET, args->custom_conf.dns[i], &sa.sin_addr)) {
COMMAND_ERROR("Invalid dns ip address '%s'.", args->custom_conf.dns[i]); COMMAND_ERROR("Invalid dns ip address '%s'.", args->custom_conf.dns[i]);
@ -1733,21 +1733,21 @@ static int create_devices_volumes_checker(const struct client_arguments *args)
size_t i; size_t i;
size_t len = 0; size_t len = 0;
len = util_array_len(args->custom_conf.devices); len = util_array_len((const char **)(args->custom_conf.devices));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (!check_devices_conf_valid(args->custom_conf.devices[i])) { if (!check_devices_conf_valid(args->custom_conf.devices[i])) {
ret = -1; ret = -1;
goto out; goto out;
} }
} }
len = util_array_len(args->custom_conf.volumes); len = util_array_len((const char **)(args->custom_conf.volumes));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (!check_volumes_conf_valid(args->custom_conf.volumes[i])) { if (!check_volumes_conf_valid(args->custom_conf.volumes[i])) {
ret = -1; ret = -1;
goto out; goto out;
} }
} }
len = util_array_len(args->custom_conf.mounts); len = util_array_len((const char **)(args->custom_conf.mounts));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (!check_mounts_conf_valid(args->custom_conf.mounts[i])) { if (!check_mounts_conf_valid(args->custom_conf.mounts[i])) {
ret = -1; ret = -1;
@ -1812,7 +1812,7 @@ static int create_check_nschangeopt(const struct client_arguments *args)
ERROR("Out of memory"); ERROR("Out of memory");
return EINVALIDARGS; return EINVALIDARGS;
} }
array_str_len = util_array_len(array_str); array_str_len = util_array_len((const char **)array_str);
if (array_str_len != 1 && array_str_len != 2) { if (array_str_len != 1 && array_str_len != 2) {
ERROR("invalid ns-change-opt pararm:%s\n", args->custom_conf.ns_change_opt); ERROR("invalid ns-change-opt pararm:%s\n", args->custom_conf.ns_change_opt);
util_free_array(array_str); util_free_array(array_str);
@ -1886,7 +1886,7 @@ static int create_check_sysctl(const struct client_arguments *args)
return 0; return 0;
} }
len = util_array_len(args->custom_conf.sysctls); len = util_array_len((const char **)(args->custom_conf.sysctls));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (!do_create_check_sysctl((const char *)args->custom_conf.sysctls[i])) { if (!do_create_check_sysctl((const char *)args->custom_conf.sysctls[i])) {
return -1; return -1;

View File

@ -62,8 +62,10 @@ static int client_delete(const struct client_arguments *args)
} }
if (response->name != NULL) { if (response->name != NULL) {
free(g_cmd_delete_args.name);
g_cmd_delete_args.name = util_strdup_s(response->name); g_cmd_delete_args.name = util_strdup_s(response->name);
} }
out: out:
lcrc_delete_response_free(response); lcrc_delete_response_free(response);
return ret; return ret;
@ -141,7 +143,8 @@ int cmd_delete_main(int argc, const char **argv)
} }
for (i = 0; i < g_cmd_delete_args.argc; i++) { for (i = 0; i < g_cmd_delete_args.argc; i++) {
g_cmd_delete_args.name = g_cmd_delete_args.argv[i]; free(g_cmd_delete_args.name);
g_cmd_delete_args.name = util_strdup_s(g_cmd_delete_args.argv[i]);
if (client_delete(&g_cmd_delete_args)) { if (client_delete(&g_cmd_delete_args)) {
ERROR("Container \"%s\" rm failed", g_cmd_delete_args.name); ERROR("Container \"%s\" rm failed", g_cmd_delete_args.name);
status = true; status = true;
@ -156,3 +159,4 @@ int cmd_delete_main(int argc, const char **argv)
} }
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -174,8 +174,8 @@ int run_command(struct command *commands, int argc, const char **argv)
return command_default_help(argv[0], commands, argc - 1, (const char **)(argv + 1)); return command_default_help(argv[0], commands, argc - 1, (const char **)(argv + 1));
} }
if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { if (strcmp(argv[1], "--help") == 0) {
// lcrc help command format: lcrc [-h|help|--help] args // lcrc help command format: lcrc --help args
return command_default_help(argv[0], commands, argc - 2, (const char **)(argv + 2)); return command_default_help(argv[0], commands, argc - 2, (const char **)(argv + 2));
} }
@ -191,7 +191,7 @@ int run_command(struct command *commands, int argc, const char **argv)
} }
printf("%s: command \"%s\" not found\n", argv[0], argv[1]); printf("%s: command \"%s\" not found\n", argv[0], argv[1]);
printf("run `%s --help` or `run -h` for a list of sub-commands\n", argv[0]); printf("run `%s --help` for a list of sub-commands\n", argv[0]);
return 1; return 1;
} }
@ -430,3 +430,4 @@ int start_client_console_thread(struct command_fifo_config *console_fifos, bool
return 0; return 0;
} }

View File

@ -15,7 +15,6 @@
#include "images.h" #include "images.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
@ -278,3 +277,4 @@ int cmd_images_main(int argc, const char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -14,7 +14,6 @@
******************************************************************************/ ******************************************************************************/
#include "load.h" #include "load.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
@ -172,3 +171,4 @@ int cmd_load_main(int argc, const char **argv)
printf("Load image from \"%s\" success\n", g_cmd_load_args.file); printf("Load image from \"%s\" success\n", g_cmd_load_args.file);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -15,7 +15,6 @@
#include "login.h" #include "login.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
@ -95,7 +94,7 @@ static int get_password_from_notty(struct client_arguments *args)
// Try get password from notty input. // Try get password from notty input.
if (g_cmd_login_args.password_stdin) { if (g_cmd_login_args.password_stdin) {
char password[LOGIN_PASSWORD_LEN + 1] = { 0 }; char password[LOGIN_PASSWORD_LEN + 1] = { 0 };
int n = util_input_notty(password, sizeof(password)); int n = util_input_readall(password, sizeof(password));
if (n == 0) { if (n == 0) {
COMMAND_ERROR("Error: Password Required"); COMMAND_ERROR("Error: Password Required");
return -1; return -1;
@ -230,3 +229,4 @@ int cmd_login_main(int argc, const char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -15,7 +15,6 @@
#include "logout.h" #include "logout.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
@ -113,3 +112,4 @@ int cmd_logout_main(int argc, const char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -15,7 +15,6 @@
#include "pull.h" #include "pull.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
@ -112,3 +111,4 @@ int cmd_pull_main(int argc, const char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -14,7 +14,6 @@
******************************************************************************/ ******************************************************************************/
#include "rmi.h" #include "rmi.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
@ -130,3 +129,4 @@ int cmd_rmi_main(int argc, const char **argv)
} }
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -14,7 +14,6 @@
******************************************************************************/ ******************************************************************************/
#include "info.h" #include "info.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "securec.h" #include "securec.h"
#include "utils.h" #include "utils.h"
@ -148,3 +147,4 @@ int cmd_info_main(int argc, const char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -339,7 +339,8 @@ static int client_list(const struct client_arguments *args)
} }
if (args->filters != NULL) { if (args->filters != NULL) {
request.filters = lcrc_filters_parse_args((const char **)args->filters, util_array_len(args->filters)); request.filters = lcrc_filters_parse_args((const char **)args->filters,
util_array_len((const char **)(args->filters)));
if (!request.filters) { if (!request.filters) {
ERROR("Failed to parse filters args"); ERROR("Failed to parse filters args");
ret = -1; ret = -1;
@ -409,3 +410,4 @@ int cmd_list_main(int argc, const char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -14,7 +14,6 @@
******************************************************************************/ ******************************************************************************/
#include "version.h" #include "version.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "securec.h" #include "securec.h"
#include "utils.h" #include "utils.h"
@ -122,3 +121,4 @@ int cmd_version_main(int argc, const char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -68,7 +68,7 @@ static int client_exec(const struct client_arguments *args, const struct command
request.argv = (char **)args->argv; request.argv = (char **)args->argv;
/* environment variables */ /* environment variables */
request.env_len = util_array_len(args->extra_env); request.env_len = util_array_len((const char **)(args->extra_env));
request.env = args->extra_env; request.env = args->extra_env;
ops = get_connect_client_ops(); ops = get_connect_client_ops();
@ -258,7 +258,7 @@ static int remote_cmd_exec(const struct client_arguments *args, uint32_t *exit_c
request.argv = (char **)args->argv; request.argv = (char **)args->argv;
/* environment variables */ /* environment variables */
request.env_len = util_array_len(args->extra_env); request.env_len = util_array_len((const char **)(args->extra_env));
request.env = args->extra_env; request.env = args->extra_env;
if (remote_cmd_exec_setup_tty(args, &reset_tty, &oldtios) < 0) { if (remote_cmd_exec_setup_tty(args, &reset_tty, &oldtios) < 0) {
@ -356,3 +356,4 @@ int cmd_exec_main(int argc, const char **argv)
out: out:
exit(exit_code ? (int)exit_code : ret); exit(exit_code ? (int)exit_code : ret);
} }

View File

@ -237,10 +237,10 @@ int check_args(struct service_arguments *args)
goto out; goto out;
} }
args->hosts_len = util_array_len(args->hosts); args->hosts_len = util_array_len((const char **)(args->hosts));
args->json_confs->storage_opts_len = util_array_len(args->json_confs->storage_opts); args->json_confs->storage_opts_len = util_array_len((const char **)(args->json_confs->storage_opts));
args->json_confs->registry_mirrors_len = util_array_len(args->json_confs->registry_mirrors); args->json_confs->registry_mirrors_len = util_array_len((const char **)(args->json_confs->registry_mirrors));
args->json_confs->insecure_registries_len = util_array_len(args->json_confs->insecure_registries); args->json_confs->insecure_registries_len = util_array_len((const char **)(args->json_confs->insecure_registries));
/* validate log-file-mode */ /* validate log-file-mode */
if (check_args_log_conf(args) != 0) { if (check_args_log_conf(args) != 0) {
@ -522,7 +522,7 @@ out:
int update_hosts(struct service_arguments *args) int update_hosts(struct service_arguments *args)
{ {
args->hosts_len = util_array_len(args->hosts); args->hosts_len = util_array_len((const char **)(args->hosts));
if (check_hosts_specified_conflict(args) != 0) { if (check_hosts_specified_conflict(args) != 0) {
return -1; return -1;

View File

@ -388,7 +388,7 @@ static void send_dump_req(void)
ERROR("Failed to read /proc/self/task' subdirectory"); ERROR("Failed to read /proc/self/task' subdirectory");
goto out; goto out;
} }
subdir_num = util_array_len(subdir); subdir_num = util_array_len((const char **)subdir);
if (subdir_num == 0) { if (subdir_num == 0) {
goto out; goto out;
} }
@ -1700,3 +1700,4 @@ failure:
DAEMON_CLEAR_ERRMSG(); DAEMON_CLEAR_ERRMSG();
exit(1); exit(1);
} }

View File

@ -12,7 +12,7 @@
* Create: 2018-11-08 * Create: 2018-11-08
* Description: provide grpc client definition * Description: provide grpc client definition
******************************************************************************/ ******************************************************************************/
#ifndef __GPRC_CLIENT_H #ifndef __GRPC_CLIENT_H
#define __GRPC_CLIENT_H #define __GRPC_CLIENT_H
#include "lcrc_connect.h" #include "lcrc_connect.h"

View File

@ -12,7 +12,7 @@
* Create: 2018-11-08 * Create: 2018-11-08
* Description: provide container grpc client definition * Description: provide container grpc client definition
******************************************************************************/ ******************************************************************************/
#ifndef __GPRC_CONTAINERS_CLIENT_H #ifndef __GRPC_CONTAINERS_CLIENT_H
#define __GRPC_CONTAINERS_CLIENT_H #define __GRPC_CONTAINERS_CLIENT_H
#include "lcrc_connect.h" #include "lcrc_connect.h"

View File

@ -12,7 +12,7 @@
* Create: 2018-11-08 * Create: 2018-11-08
* Description: provide grpc image client definition * Description: provide grpc image client definition
******************************************************************************/ ******************************************************************************/
#ifndef __GPRC_IMAGES_CLIENT_H #ifndef __GRPC_IMAGES_CLIENT_H
#define __GRPC_IMAGES_CLIENT_H #define __GRPC_IMAGES_CLIENT_H
#include "lcrc_connect.h" #include "lcrc_connect.h"

View File

@ -1883,3 +1883,4 @@ int rest_containers_client_ops_init(lcrc_connect_ops *ops)
return 0; return 0;
} }

View File

@ -474,3 +474,4 @@ int rest_images_client_ops_init(lcrc_connect_ops *ops)
return 0; return 0;
} }

View File

@ -101,7 +101,7 @@ public:
ServerWriter<CopyFromContainerResponse> *writer) override; ServerWriter<CopyFromContainerResponse> *writer) override;
Status CopyToContainer(ServerContext *context, ServerReaderWriter<CopyToContainerResponse, Status CopyToContainer(ServerContext *context, ServerReaderWriter<CopyToContainerResponse,
CopyToContainerRequest> *stream); CopyToContainerRequest> *stream) override;
Status Logs(ServerContext *context, const LogsRequest* request, Status Logs(ServerContext *context, const LogsRequest* request,
ServerWriter<LogsResponse>* writer) override; ServerWriter<LogsResponse>* writer) override;

View File

@ -1225,3 +1225,4 @@ int rest_register_containers_handler(evhtp_t *htp)
} }
return 0; return 0;
} }

View File

@ -444,3 +444,4 @@ int rest_register_images_handler(evhtp_t *htp)
return 0; return 0;
} }

View File

@ -13,6 +13,7 @@
* Description: provide container definition * Description: provide container definition
******************************************************************************/ ******************************************************************************/
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "container_def.h" #include "container_def.h"
@ -30,3 +31,4 @@ void container_cgroup_resources_free(container_cgroup_resources_t *cr)
free(cr); free(cr);
} }

View File

@ -16,7 +16,6 @@
#define __CONTAINER_DEF_H_ #define __CONTAINER_DEF_H_
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "types_def.h" #include "types_def.h"
@ -34,6 +33,9 @@ extern "C" {
#ifndef OCICONFIG_PATH #ifndef OCICONFIG_PATH
#define OCICONFIG_PATH "/etc/default/lcrd/config.json" #define OCICONFIG_PATH "/etc/default/lcrd/config.json"
#endif #endif
#ifndef OCI_SYSTEM_CONTAINER_CONFIG_PATH
#define OCI_SYSTEM_CONTAINER_CONFIG_PATH "/etc/default/lcrd/systemcontainer_config.json"
#endif
#ifndef SECCOMP_DEFAULT_PATH #ifndef SECCOMP_DEFAULT_PATH
#define SECCOMP_DEFAULT_PATH "/etc/isulad/seccomp_default.json" #define SECCOMP_DEFAULT_PATH "/etc/isulad/seccomp_default.json"
#endif #endif
@ -137,3 +139,4 @@ typedef void (*container_events_callback_t)(const container_events_format_t *eve
#endif #endif
#endif #endif

View File

@ -253,26 +253,27 @@
"maskedPaths": [ "maskedPaths": [
"/proc/acpi", "/proc/acpi",
"/proc/config.gz", "/proc/config.gz",
"/proc/cpuirqstat",
"/proc/fdenable",
"/proc/fdstat",
"/proc/fdthreshold",
"/proc/files_panic_enable",
"/proc/iomem_ext",
"/proc/kbox",
"/proc/kcore", "/proc/kcore",
"/proc/keys", "/proc/keys",
"/proc/latency_stats", "/proc/latency_stats",
"/proc/timer_list", "/proc/livepatch",
"/proc/timer_stats", "/proc/memstat",
"/proc/net_namespace",
"/proc/oom_extend",
"/proc/sched_debug", "/proc/sched_debug",
"/proc/scsi", "/proc/scsi",
"/proc/signo",
"/proc/sig_catch", "/proc/sig_catch",
"/proc/kbox", "/proc/signo",
"/proc/oom_extend", "/proc/timer_list",
"/proc/fdthreshold", "/proc/timer_stats",
"/proc/fdstat", "/sys/firmware"
"/proc/fdenable",
"/proc/files_panic_enable",
"/sys/firmware",
"/proc/cpuirqstat",
"/proc/memstat",
"/proc/iomem_ext",
"/proc/livepatch"
], ],
"readonlyPaths": [ "readonlyPaths": [
"/proc/asound", "/proc/asound",

View File

@ -22,7 +22,6 @@
"docker.io" "docker.io"
], ],
"insecure-registries": [ "insecure-registries": [
"rnd-dockerhub.huawei.com"
], ],
"pod-sandbox-image": "", "pod-sandbox-image": "",
"image-opt-timeout": "5m", "image-opt-timeout": "5m",

View File

@ -0,0 +1,321 @@
{
"ociVersion": "1.0.0-rc5-dev",
"process": {
"terminal": true,
"consoleSize": {
"height": 0,
"width": 0
},
"user": {
"uid": 0,
"gid": 0
},
"args": [
"/bin/bash"
],
"env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm"
],
"cwd": "/",
"capabilities": {
"bounding": [
"CAP_CHOWN",
"CAP_DAC_OVERRIDE",
"CAP_FSETID",
"CAP_FOWNER",
"CAP_MKNOD",
"CAP_NET_RAW",
"CAP_SETGID",
"CAP_SETUID",
"CAP_SETFCAP",
"CAP_SETPCAP",
"CAP_NET_BIND_SERVICE",
"CAP_SYS_CHROOT",
"CAP_KILL",
"CAP_AUDIT_WRITE"
],
"effective": [
],
"inheritable": [
],
"permitted": [
],
"ambient": [
]
}
},
"root": {
"path": "rootfs",
"readonly": false
},
"hostname": "ubuntu",
"mounts": [
{
"destination": "/proc",
"type": "proc",
"source": "proc",
"options": [
"nosuid",
"noexec",
"nodev"
]
},
{
"destination": "/dev",
"type": "tmpfs",
"source": "tmpfs",
"options": [
"nosuid",
"strictatime",
"mode=755",
"size=65536k"
]
},
{
"destination": "/dev/pts",
"type": "devpts",
"source": "devpts",
"options": [
"nosuid",
"noexec",
"newinstance",
"ptmxmode=0666",
"mode=0620",
"gid=5"
]
},
{
"destination": "/sys",
"type": "sysfs",
"source": "sysfs",
"options": [
"nosuid",
"noexec",
"nodev",
"ro"
]
},
{
"destination": "/dev/shm",
"type": "tmpfs",
"source": "shm",
"options": [
"nosuid",
"noexec",
"nodev",
"mode=1777",
"size=65536k"
]
},
{
"destination": "/sys/fs/cgroup",
"type": "cgroup",
"source": "cgroup",
"options": [
"nosuid",
"noexec",
"nodev",
"ro"
]
},
{
"destination": "/dev/mqueue",
"type": "mqueue",
"source": "mqueue",
"options": [
"nosuid",
"noexec",
"nodev"
]
},
{
"destination": "/run",
"type": "tmpfs",
"source": "tmpfs",
"options": [
"nosuid",
"noexec",
"nodev",
"mode=755"
]
},
{
"destination": "/run/lock",
"type": "tmpfs",
"source": "tmpfs",
"options": [
"nosuid",
"noexec",
"nodev",
"mode=755"
]
},
{
"destination": "/tmp",
"type": "tmpfs",
"source": "tmpfs",
"options": [
"nosuid",
"noexec",
"nodev",
"mode=1777"
]
}
],
"linux": {
"resources": {
"devices": [
{
"allow": false,
"type": "a",
"major": -1,
"minor": -1,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": -1,
"minor": -1,
"access": "m"
},
{
"allow": true,
"type": "b",
"major": -1,
"minor": -1,
"access": "m"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 3,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 5,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 7,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 5,
"minor": 0,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 5,
"minor": 1,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 5,
"minor": 2,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 8,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 9,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 136,
"minor": -1,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 10,
"minor": 200,
"access": "rwm"
},
{
"allow": false,
"type": "c",
"major": 10,
"minor": 229,
"access": "rwm"
}
]
},
"namespaces": [
{
"type": "pid"
},
{
"type": "network"
},
{
"type": "ipc"
},
{
"type": "uts"
},
{
"type": "mount"
}
],
"maskedPaths": [
"/proc/acpi",
"/proc/config.gz",
"/proc/cpuirqstat",
"/proc/fdenable",
"/proc/fdstat",
"/proc/fdthreshold",
"/proc/files_panic_enable",
"/proc/iomem_ext",
"/proc/kbox",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/livepatch",
"/proc/memstat",
"/proc/net_namespace",
"/proc/oom_extend",
"/proc/sched_debug",
"/proc/scsi",
"/proc/sig_catch",
"/proc/signo",
"/proc/timer_list",
"/proc/timer_stats",
"/sys/firmware"
],
"readonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger",
"/proc/sysrq-region-size"
]
}
}

View File

@ -16,7 +16,6 @@
#define __STOPPABLE_THREAD_H_ #define __STOPPABLE_THREAD_H_
#include <iostream> #include <iostream>
#include <assert.h>
#include <chrono> #include <chrono>
#include <future> #include <future>
#include <mutex> #include <mutex>
@ -50,3 +49,4 @@ private:
}; };
#endif /* __STOPPABLE_THREAD_H_ */ #endif /* __STOPPABLE_THREAD_H_ */

View File

@ -1080,7 +1080,7 @@ int util_parse_user_remap(const char *user_remap, unsigned int *host_uid, unsign
ret = -1; ret = -1;
goto out; goto out;
} }
args_len = util_array_len(items); args_len = util_array_len((const char **)items);
switch (args_len) { switch (args_len) {
case 3: case 3:
@ -1349,6 +1349,43 @@ int util_input_notty(char *buf, size_t maxlen)
return ret ? ret : (int)i; return ret ? ret : (int)i;
} }
int util_input_readall(char *buf, size_t maxlen)
{
size_t i = 0;
int ret = 0;
for (;;) {
int c = getchar();
if (c == EOF) {
break;
}
if (c < 0) {
ret = -1;
break;
}
// Skip chars larger than maxlen
if (i + 1 >= maxlen) {
continue;
}
buf[i] = (char) c;
i++;
}
buf[i] = 0;
// Strip last '\n'
if (i > 0 && buf[i - 1] == '\n') {
buf[i - 1] = 0;
i--;
}
// Strip last '\r'
if (i > 0 && buf[i - 1] == '\r') {
buf[i - 1] = 0;
i--;
}
return ret ? ret : (int)i;
}
static int util_input(char *buf, size_t maxlen, bool echo_back) static int util_input(char *buf, size_t maxlen, bool echo_back)
{ {
int ret = 0; int ret = 0;

View File

@ -398,7 +398,7 @@ void free_sensitive_string(char *str);
void memset_sensitive_string(char *str); void memset_sensitive_string(char *str);
bool detect_mount(const char *path); bool detect_mount(const char *path);
int util_input_notty(char *buf, size_t maxlen); int util_input_readall(char *buf, size_t maxlen);
int util_input_echo(char *buf, size_t maxlen); int util_input_echo(char *buf, size_t maxlen);
int util_input_noecho(char *buf, size_t maxlen); int util_input_noecho(char *buf, size_t maxlen);

View File

@ -21,9 +21,9 @@
#include "log.h" #include "log.h"
#include "utils.h" #include "utils.h"
size_t util_array_len(char **array) size_t util_array_len(const char **array)
{ {
char **pos; const char **pos;
size_t len = 0; size_t len = 0;
for (pos = array; pos != NULL && *pos != NULL; pos++) { for (pos = array; pos != NULL && *pos != NULL; pos++) {
@ -53,7 +53,7 @@ int util_array_append(char ***array, const char *element)
} }
// let new len to len + 2 for element and null // let new len to len + 2 for element and null
len = util_array_len(*array); len = util_array_len((const char **)(*array));
if (len > SIZE_MAX / sizeof(char *) - 2) { if (len > SIZE_MAX / sizeof(char *) - 2) {
ERROR("Too many array elements!"); ERROR("Too many array elements!");
@ -123,3 +123,4 @@ int util_grow_array(char ***orig_array, size_t *orig_capacity, size_t size,
return 0; return 0;
} }

View File

@ -24,7 +24,7 @@
extern "C" { extern "C" {
#endif #endif
size_t util_array_len(char **array); size_t util_array_len(const char **array);
void util_free_array(char **array); void util_free_array(char **array);
@ -38,3 +38,4 @@ int util_array_append(char ***array, const char *element);
#endif #endif
#endif /* __UTILS_H */ #endif /* __UTILS_H */

View File

@ -169,7 +169,7 @@ static inline bool is_valid_str_bool_false(const char *str)
int util_str_to_bool(const char *boolstr, bool *converted) int util_str_to_bool(const char *boolstr, bool *converted)
{ {
if (boolstr == NULL || boolstr[0] == '\0') { if (boolstr == NULL || converted == NULL) {
return -EINVAL; return -EINVAL;
} }
if (is_valid_str_bool_true(boolstr)) { if (is_valid_str_bool_true(boolstr)) {
@ -181,3 +181,4 @@ int util_str_to_bool(const char *boolstr, bool *converted)
} }
return 0; return 0;
} }

View File

@ -786,10 +786,11 @@ char *look_path(const char *file, char **err)
/* if slash in file, directly use file and do not try PATH. */ /* if slash in file, directly use file and do not try PATH. */
if (strings_contains_any(file, "/")) { if (strings_contains_any(file, "/")) {
if (find_executable(file) == 0) { int en = find_executable(file);
if (en == 0) {
return util_strdup_s(file); return util_strdup_s(file);
} }
if (asprintf(err, "find exec %s : %s", file, strerror(errno)) < 0) { if (asprintf(err, "find exec %s : %s", file, strerror(en)) < 0) {
*err = util_strdup_s("Out of memory"); *err = util_strdup_s("Out of memory");
} }
return NULL; return NULL;

View File

@ -607,7 +607,7 @@ bool util_valid_mount_mode(const char *mode)
ERROR("Out of memory"); ERROR("Out of memory");
return false; return false;
} }
mlen = util_array_len(modes); mlen = util_array_len((const char **)modes);
for (i = 0; i < mlen; i++) { for (i = 0; i < mlen; i++) {
if (util_valid_rw_mode(modes[i])) { if (util_valid_rw_mode(modes[i])) {
@ -664,3 +664,4 @@ cleanup:
free(copy); free(copy);
return bret; return bret;
} }

View File

@ -213,7 +213,7 @@ static bool do_filters_args_match_kv_list(const map_t *field_values_map, const m
goto cleanup; goto cleanup;
} }
if (util_array_len(test_kv) == 2 && strcmp(test_kv[1], sources_value) != 0) { if (util_array_len((const char **)test_kv) == 2 && strcmp(test_kv[1], sources_value) != 0) {
util_free_array(test_kv); util_free_array(test_kv);
goto cleanup; goto cleanup;
} }

View File

@ -205,7 +205,7 @@ int embedded_image_merge_config(oci_runtime_spec *oci_spec,
} }
} }
ret = merge_volumes(oci_spec, mounts, util_array_len(mounts), NULL, parse_mount); ret = merge_volumes(oci_spec, mounts, util_array_len((const char **)mounts), NULL, parse_mount);
if (ret) { if (ret) {
ERROR("Failed to merge layer into mounts"); ERROR("Failed to merge layer into mounts");
goto out; goto out;

View File

@ -62,3 +62,4 @@ out:
return auth_string; return auth_string;
} }

View File

@ -229,11 +229,6 @@ static int oci_image_merge_health_check(const defs_health_check *image_health_ch
{ {
int ret = 0; int ret = 0;
if (custom_spec == NULL) {
ERROR("Invalid input arguments");
return -1;
}
if (image_health_check == NULL) { if (image_health_check == NULL) {
return 0; return 0;
} }
@ -264,7 +259,7 @@ int oci_image_merge_config(imagetool_image *image_conf, oci_runtime_spec *oci_sp
{ {
int ret = 0; int ret = 0;
if (image_conf == NULL || oci_spec == NULL) { if (image_conf == NULL || oci_spec == NULL || custom_spec == NULL) {
ERROR("Invalid input arguments"); ERROR("Invalid input arguments");
return -1; return -1;
} }

View File

@ -729,3 +729,4 @@ int oci_init(const char *rootpath)
out: out:
return ret; return ret;
} }

View File

@ -145,57 +145,6 @@ pack_response:
return ret; return ret;
} }
int prepare_rootfs(rootfs_prepare_request *request,
rootfs_prepare_response **response)
{
int ret = 0;
char *name = NULL;
char *image = NULL;
imagetool_prepare_response *tool_response = NULL;
if (response == NULL) {
ERROR("Invalid input arguments");
return -1;
}
*response = util_common_calloc_s(sizeof(rootfs_prepare_response));
if (*response == NULL) {
ERROR("Out of memory");
return -1;
}
if (check_prepare_request_valid(request) != 0) {
ret = -1;
goto pack_response;
}
image = request->image;
name = request->name;
EVENT("Event: {Object: %s, Type: preparing rootfs with image %s}", name, image);
if (!do_prepare(request, &tool_response)) {
ERROR("Failed to prepare rootfs");
ret = -1;
goto pack_response;
}
EVENT("Event: {Object: %s, Type: prepared rootfs with image %s}", name, image);
pack_response:
if (g_lcrd_errmsg != NULL) {
(*response)->errmsg = util_strdup_s(g_lcrd_errmsg);
}
if (tool_response != NULL) {
(*response)->rootfs = tool_response->mount_point;
tool_response->mount_point = NULL;
free_imagetool_prepare_response(tool_response);
}
return ret;
}
void free_rootfs_prepare_request(rootfs_prepare_request *ptr) void free_rootfs_prepare_request(rootfs_prepare_request *ptr)
{ {
if (ptr == NULL) { if (ptr == NULL) {
@ -228,3 +177,4 @@ void free_rootfs_prepare_and_get_image_conf_response(rootfs_prepare_and_get_imag
free(ptr); free(ptr);
} }

View File

@ -40,9 +40,6 @@ typedef struct {
imagetool_prepare_response *raw_response; imagetool_prepare_response *raw_response;
} rootfs_prepare_and_get_image_conf_response; } rootfs_prepare_and_get_image_conf_response;
int prepare_rootfs(rootfs_prepare_request *request,
rootfs_prepare_response **response);
void free_rootfs_prepare_request(rootfs_prepare_request *ptr); void free_rootfs_prepare_request(rootfs_prepare_request *ptr);
int prepare_rootfs_and_get_image_conf(rootfs_prepare_request *request, int prepare_rootfs_and_get_image_conf(rootfs_prepare_request *request,
@ -54,3 +51,4 @@ void free_rootfs_prepare_and_get_image_conf_response(rootfs_prepare_and_get_imag
#endif #endif
#endif #endif

View File

@ -46,13 +46,13 @@
"type": "object", "type": "object",
"properties": { "properties": {
"index": { "index": {
"$ref": "../oci/runtime/defs.json#/definitions/uint32" "$ref": "../defs.json#/definitions/uint32"
}, },
"value": { "value": {
"$ref": "../oci/runtime/defs.json#/definitions/uint64" "$ref": "../defs.json#/definitions/uint64"
}, },
"valueTwo": { "valueTwo": {
"$ref": "../oci/runtime/defs.json#/definitions/uint64" "$ref": "../defs.json#/definitions/uint64"
}, },
"op": { "op": {
"$ref": "../oci/runtime/defs-linux.json#/definitions/SeccompOperators" "$ref": "../oci/runtime/defs-linux.json#/definitions/SeccompOperators"

View File

@ -10,7 +10,7 @@
}, },
"size": { "size": {
"description": "the size in bytes of the referenced object", "description": "the size in bytes of the referenced object",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"digest": { "digest": {
"description": "the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'", "description": "the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'",

View File

@ -21,7 +21,7 @@
}, },
"annotations": { "annotations": {
"id": "https://opencontainers.org/schema/image/descriptor/annotations", "id": "https://opencontainers.org/schema/image/descriptor/annotations",
"$ref": "defs.json#/definitions/mapStringString" "$ref": "../../defs.json#/definitions/mapStringString"
} }
} }
} }

View File

@ -1,308 +0,0 @@
{
"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
},
"int32Pointer": {
"oneOf": [
{
"$ref": "#/definitions/int32"
},
{
"type": "null"
}
]
},
"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"
},
"HealthCheck": {
"type": "object",
"properties": {
"Test": {
"type": "array",
"items": {
"type": "string"
}
},
"Interval": {
"type": "int64"
},
"Timeout": {
"type": "int64"
},
"StartPeriod": {
"type": "int64"
},
"Retries": {
"type": "integer"
},
"ExitOnUnhealthy": {
"type": "boolean"
}
}
},
"Health": {
"type": "object",
"properties": {
"Status": {
"type": "string"
},
"FailingStreak": {
"type": "integer"
},
"Log": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Start": {
"type": "string"
},
"End": {
"type": "string"
},
"ExitCode": {
"type": "integer"
},
"Output": {
"type": "string"
}
}
}
}
}
},
"filters": {
"type": "object",
"patternProperties": {
".{1,}": {
"$ref": "#/definitions/mapStringBool"
}
}
}
}
}

View File

@ -28,7 +28,7 @@
}, },
"size": { "size": {
"description": "the size in bytes of the referenced object", "description": "the size in bytes of the referenced object",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"digest": { "digest": {
"description": "the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'", "description": "the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'",

View File

@ -24,7 +24,7 @@
"type": "string" "type": "string"
}, },
"ExposedPorts": { "ExposedPorts": {
"$ref": "defs.json#/definitions/mapStringObject" "$ref": "../../defs.json#/definitions/mapStringObject"
}, },
"Env": { "Env": {
"type": "array", "type": "array",
@ -61,7 +61,7 @@
"Volumes": { "Volumes": {
"oneOf": [ "oneOf": [
{ {
"$ref": "defs.json#/definitions/mapStringObject" "$ref": "../../defs.json#/definitions/mapStringObject"
}, },
{ {
"type": "null" "type": "null"
@ -74,7 +74,7 @@
"Labels": { "Labels": {
"oneOf": [ "oneOf": [
{ {
"$ref": "defs.json#/definitions/mapStringString" "$ref": "../../defs.json#/definitions/mapStringString"
}, },
{ {
"type": "null" "type": "null"

View File

@ -15,14 +15,14 @@
"id": "https://opencontainers.org/schema/bundle/linux/uidMappings", "id": "https://opencontainers.org/schema/bundle/linux/uidMappings",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "defs.json#/definitions/IDMapping" "$ref": "../../defs.json#/definitions/IDMapping"
} }
}, },
"gidMappings": { "gidMappings": {
"id": "https://opencontainers.org/schema/bundle/linux/gidMappings", "id": "https://opencontainers.org/schema/bundle/linux/gidMappings",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "defs.json#/definitions/IDMapping" "$ref": "../../defs.json#/definitions/IDMapping"
} }
}, },
"namespaces": { "namespaces": {
@ -53,7 +53,7 @@
"properties": { "properties": {
"limit": { "limit": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/pids/limit", "id": "https://opencontainers.org/schema/bundle/linux/resources/pids/limit",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
} }
}, },
"required": [ "required": [
@ -123,23 +123,23 @@
}, },
"period": { "period": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/period", "id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/period",
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
}, },
"quota": { "quota": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/quota", "id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/quota",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"realtimePeriod": { "realtimePeriod": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/realtimePeriod", "id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/realtimePeriod",
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
}, },
"realtimeRuntime": { "realtimeRuntime": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/realtimeRuntime", "id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/realtimeRuntime",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"shares": { "shares": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/shares", "id": "https://opencontainers.org/schema/bundle/linux/resources/cpu/shares",
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
} }
} }
}, },
@ -153,7 +153,7 @@
"type": "string" "type": "string"
}, },
"limit": { "limit": {
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
} }
}, },
"required": [ "required": [
@ -168,27 +168,27 @@
"properties": { "properties": {
"kernel": { "kernel": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/kernel", "id": "https://opencontainers.org/schema/bundle/linux/resources/memory/kernel",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"kernelTCP": { "kernelTCP": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/kernelTCP", "id": "https://opencontainers.org/schema/bundle/linux/resources/memory/kernelTCP",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"limit": { "limit": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/limit", "id": "https://opencontainers.org/schema/bundle/linux/resources/memory/limit",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"reservation": { "reservation": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/reservation", "id": "https://opencontainers.org/schema/bundle/linux/resources/memory/reservation",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"swap": { "swap": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/swap", "id": "https://opencontainers.org/schema/bundle/linux/resources/memory/swap",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"swappiness": { "swappiness": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/swappiness", "id": "https://opencontainers.org/schema/bundle/linux/resources/memory/swappiness",
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
}, },
"disableOOMKiller": { "disableOOMKiller": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/disableOOMKiller", "id": "https://opencontainers.org/schema/bundle/linux/resources/memory/disableOOMKiller",
@ -202,7 +202,7 @@
"properties": { "properties": {
"classID": { "classID": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/network/classId", "id": "https://opencontainers.org/schema/bundle/linux/resources/network/classId",
"$ref": "defs.json#/definitions/uint32" "$ref": "../../defs.json#/definitions/uint32"
}, },
"priorities": { "priorities": {
"id": "https://opencontainers.org/schema/bundle/linux/resources/network/priorities", "id": "https://opencontainers.org/schema/bundle/linux/resources/network/priorities",
@ -252,15 +252,15 @@
}, },
"sysctl": { "sysctl": {
"id": "https://opencontainers.org/schema/bundle/linux/sysctl", "id": "https://opencontainers.org/schema/bundle/linux/sysctl",
"$ref": "defs.json#/definitions/mapStringString" "$ref": "../../defs.json#/definitions/mapStringString"
}, },
"maskedPaths": { "maskedPaths": {
"id": "https://opencontainers.org/schema/bundle/linux/maskedPaths", "id": "https://opencontainers.org/schema/bundle/linux/maskedPaths",
"$ref": "defs.json#/definitions/ArrayOfStrings" "$ref": "../../defs.json#/definitions/ArrayOfStrings"
}, },
"readonlyPaths": { "readonlyPaths": {
"id": "https://opencontainers.org/schema/bundle/linux/readonlyPaths", "id": "https://opencontainers.org/schema/bundle/linux/readonlyPaths",
"$ref": "defs.json#/definitions/ArrayOfStrings" "$ref": "../../defs.json#/definitions/ArrayOfStrings"
}, },
"mountLabel": { "mountLabel": {
"id": "https://opencontainers.org/schema/bundle/linux/mountLabel", "id": "https://opencontainers.org/schema/bundle/linux/mountLabel",

View File

@ -58,13 +58,13 @@
"type": "object", "type": "object",
"properties": { "properties": {
"index": { "index": {
"$ref": "defs.json#/definitions/uint32" "$ref": "../../defs.json#/definitions/uint32"
}, },
"value": { "value": {
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
}, },
"valueTwo": { "valueTwo": {
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
}, },
"op": { "op": {
"$ref": "#/definitions/SeccompOperators" "$ref": "#/definitions/SeccompOperators"
@ -103,11 +103,11 @@
}, },
"Major": { "Major": {
"description": "major device number", "description": "major device number",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"Minor": { "Minor": {
"description": "minor device number", "description": "minor device number",
"$ref": "defs.json#/definitions/int64" "$ref": "../../defs.json#/definitions/int64"
}, },
"FileMode": { "FileMode": {
"description": "File permissions mode (typically an octal value)", "description": "File permissions mode (typically an octal value)",
@ -131,7 +131,7 @@
"$ref": "#/definitions/FileType" "$ref": "#/definitions/FileType"
}, },
"path": { "path": {
"$ref": "defs.json#/definitions/FilePath" "$ref": "../../defs.json#/definitions/FilePath"
}, },
"fileMode": { "fileMode": {
"$ref": "#/definitions/FileMode" "$ref": "#/definitions/FileMode"
@ -143,10 +143,10 @@
"$ref": "#/definitions/Minor" "$ref": "#/definitions/Minor"
}, },
"uid": { "uid": {
"$ref": "defs.json#/definitions/UID" "$ref": "../../defs.json#/definitions/UID"
}, },
"gid": { "gid": {
"$ref": "defs.json#/definitions/GID" "$ref": "../../defs.json#/definitions/GID"
} }
} }
}, },
@ -196,7 +196,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"rate": { "rate": {
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
} }
} }
} }
@ -232,7 +232,7 @@
"type": "string" "type": "string"
}, },
"priority": { "priority": {
"$ref": "defs.json#/definitions/uint32" "$ref": "../../defs.json#/definitions/uint32"
} }
}, },
"required": [ "required": [
@ -259,7 +259,7 @@
"$ref": "#/definitions/NamespaceType" "$ref": "#/definitions/NamespaceType"
}, },
"path": { "path": {
"$ref": "defs.json#/definitions/FilePath" "$ref": "../../defs.json#/definitions/FilePath"
} }
}, },
"required": [ "required": [

View File

@ -1 +0,0 @@
../../defs.json

View File

@ -3,7 +3,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"annotations": { "annotations": {
"$ref": "defs.json#/definitions/annotations" "$ref": "../../defs.json#/definitions/annotations"
}, },
"root": { "root": {
"$ref": "spec.json#/properties/root" "$ref": "spec.json#/properties/root"
@ -12,12 +12,12 @@
"id": "https://opencontainers.org/schema/bundle/mounts", "id": "https://opencontainers.org/schema/bundle/mounts",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "defs.json#/definitions/Mount" "$ref": "../../defs.json#/definitions/Mount"
} }
}, },
"env": { "env": {
"id": "https://opencontainers.org/schema/bundle/process/env", "id": "https://opencontainers.org/schema/bundle/process/env",
"$ref": "defs.json#/definitions/Env" "$ref": "../../defs.json#/definitions/Env"
}, },
"devices": { "devices": {
"id": "https://opencontainers.org/schema/bundle/linux/devices", "id": "https://opencontainers.org/schema/bundle/linux/devices",

View File

@ -6,25 +6,25 @@
"properties": { "properties": {
"ociVersion": { "ociVersion": {
"id": "https://opencontainers.org/schema/bundle/ociVersion", "id": "https://opencontainers.org/schema/bundle/ociVersion",
"$ref": "defs.json#/definitions/ociVersion" "$ref": "../../defs.json#/definitions/ociVersion"
}, },
"hooks": { "hooks": {
"id": "https://opencontainers.org/schema/bundle/hooks", "id": "https://opencontainers.org/schema/bundle/hooks",
"type": "object", "type": "object",
"properties": { "properties": {
"prestart": { "prestart": {
"$ref": "defs.json#/definitions/ArrayOfHooks" "$ref": "../../defs.json#/definitions/ArrayOfHooks"
}, },
"poststart": { "poststart": {
"$ref": "defs.json#/definitions/ArrayOfHooks" "$ref": "../../defs.json#/definitions/ArrayOfHooks"
}, },
"poststop": { "poststop": {
"$ref": "defs.json#/definitions/ArrayOfHooks" "$ref": "../../defs.json#/definitions/ArrayOfHooks"
} }
} }
}, },
"annotations": { "annotations": {
"$ref": "defs.json#/definitions/annotations" "$ref": "../../defs.json#/definitions/annotations"
}, },
"hostname": { "hostname": {
"id": "https://opencontainers.org/schema/bundle/hostname", "id": "https://opencontainers.org/schema/bundle/hostname",
@ -34,7 +34,7 @@
"id": "https://opencontainers.org/schema/bundle/mounts", "id": "https://opencontainers.org/schema/bundle/mounts",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "defs.json#/definitions/Mount" "$ref": "../../defs.json#/definitions/Mount"
} }
}, },
"root": { "root": {
@ -47,7 +47,7 @@
"properties": { "properties": {
"path": { "path": {
"id": "https://opencontainers.org/schema/bundle/root/path", "id": "https://opencontainers.org/schema/bundle/root/path",
"$ref": "defs.json#/definitions/FilePath" "$ref": "../../defs.json#/definitions/FilePath"
}, },
"readonly": { "readonly": {
"id": "https://opencontainers.org/schema/bundle/root/readonly", "id": "https://opencontainers.org/schema/bundle/root/readonly",
@ -65,7 +65,7 @@
"properties": { "properties": {
"args": { "args": {
"id": "https://opencontainers.org/schema/bundle/process/args", "id": "https://opencontainers.org/schema/bundle/process/args",
"$ref": "defs.json#/definitions/ArrayOfStrings" "$ref": "../../defs.json#/definitions/ArrayOfStrings"
}, },
"consoleSize": { "consoleSize": {
"id": "https://opencontainers.org/schema/bundle/process/consoleSize", "id": "https://opencontainers.org/schema/bundle/process/consoleSize",
@ -77,11 +77,11 @@
"properties": { "properties": {
"height": { "height": {
"id": "https://opencontainers.org/schema/bundle/process/consoleSize/height", "id": "https://opencontainers.org/schema/bundle/process/consoleSize/height",
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
}, },
"width": { "width": {
"id": "https://opencontainers.org/schema/bundle/process/consoleSize/width", "id": "https://opencontainers.org/schema/bundle/process/consoleSize/width",
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
} }
} }
}, },
@ -91,7 +91,7 @@
}, },
"env": { "env": {
"id": "https://opencontainers.org/schema/bundle/process/env", "id": "https://opencontainers.org/schema/bundle/process/env",
"$ref": "defs.json#/definitions/Env" "$ref": "../../defs.json#/definitions/Env"
}, },
"terminal": { "terminal": {
"id": "https://opencontainers.org/schema/bundle/process/terminal", "id": "https://opencontainers.org/schema/bundle/process/terminal",
@ -103,15 +103,15 @@
"properties": { "properties": {
"uid": { "uid": {
"id": "https://opencontainers.org/schema/bundle/process/user/uid", "id": "https://opencontainers.org/schema/bundle/process/user/uid",
"$ref": "defs.json#/definitions/UID" "$ref": "../../defs.json#/definitions/UID"
}, },
"gid": { "gid": {
"id": "https://opencontainers.org/schema/bundle/process/user/gid", "id": "https://opencontainers.org/schema/bundle/process/user/gid",
"$ref": "defs.json#/definitions/GID" "$ref": "../../defs.json#/definitions/GID"
}, },
"additionalGids": { "additionalGids": {
"id": "https://opencontainers.org/schema/bundle/process/user/additionalGids", "id": "https://opencontainers.org/schema/bundle/process/user/additionalGids",
"$ref": "defs.json#/definitions/ArrayOfGIDs" "$ref": "../../defs.json#/definitions/ArrayOfGIDs"
}, },
"username": { "username": {
"id": "https://opencontainers.org/schema/bundle/process/user/username", "id": "https://opencontainers.org/schema/bundle/process/user/username",
@ -190,11 +190,11 @@
"properties": { "properties": {
"hard": { "hard": {
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/hard", "id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/hard",
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
}, },
"soft": { "soft": {
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/soft", "id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/soft",
"$ref": "defs.json#/definitions/uint64" "$ref": "../../defs.json#/definitions/uint64"
}, },
"type": { "type": {
"id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/type", "id": "https://opencontainers.org/schema/bundle/linux/rlimits/0/type",

View File

@ -6,7 +6,7 @@
"properties": { "properties": {
"ociVersion": { "ociVersion": {
"id": "https://opencontainers.org/schema/runtime/state/ociVersion", "id": "https://opencontainers.org/schema/runtime/state/ociVersion",
"$ref": "defs.json#/definitions/ociVersion" "$ref": "../../defs.json#/definitions/ociVersion"
}, },
"id": { "id": {
"id": "https://opencontainers.org/schema/runtime/state/id", "id": "https://opencontainers.org/schema/runtime/state/id",
@ -33,7 +33,7 @@
"type": "string" "type": "string"
}, },
"annotations": { "annotations": {
"$ref": "defs.json#/definitions/annotations" "$ref": "../../defs.json#/definitions/annotations"
} }
}, },
"required": [ "required": [

View File

@ -33,7 +33,6 @@ CODE = '''// Auto generated file. Do not edit!
# include <stdbool.h> # include <stdbool.h>
# include <stdio.h> # include <stdio.h>
# include <string.h> # include <string.h>
# include <stdlib.h>
# include <stdint.h> # include <stdint.h>
# include <yajl/yajl_tree.h> # include <yajl/yajl_tree.h>
# include <yajl/yajl_gen.h> # include <yajl/yajl_gen.h>

View File

@ -16,7 +16,6 @@
#define __LIB_LCRC_H #define __LIB_LCRC_H
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "container_def.h" #include "container_def.h"
@ -840,3 +839,4 @@ void lcrc_logs_response_free(struct lcrc_logs_response *response);
#endif #endif
#endif #endif

View File

@ -16,7 +16,6 @@
#define __LIB_LCRD_H #define __LIB_LCRD_H
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "container_def.h" #include "container_def.h"

View File

@ -379,7 +379,7 @@ static host_config_devices_element *parse_device(const char *devices)
} }
tmp_str = util_string_split(devices, ':'); tmp_str = util_string_split(devices, ':');
tmp_str_len = util_array_len(tmp_str); tmp_str_len = util_array_len((const char **)tmp_str);
switch (tmp_str_len) { switch (tmp_str_len) {
case 3: case 3:
@ -448,7 +448,7 @@ static void get_ulimit_split_parts(const char *val, char ***parts, size_t *parts
COMMAND_ERROR("Out of memory"); COMMAND_ERROR("Out of memory");
return; return;
} }
*parts_len = util_array_len(*parts); *parts_len = util_array_len((const char **)(*parts));
} }
static int parse_soft_hard_ulimit(const char *val, char **limitvals, size_t limitvals_len, int64_t *soft, int64_t *hard) static int parse_soft_hard_ulimit(const char *val, char **limitvals, size_t limitvals_len, int64_t *soft, int64_t *hard)
@ -748,7 +748,7 @@ static host_config_blkio_weight_device_element *pack_blkio_weight_devices(const
COMMAND_ERROR("String split failed"); COMMAND_ERROR("String split failed");
goto erro_out; goto erro_out;
} }
tmp_str_len = util_array_len(tmp_str); tmp_str_len = util_array_len((const char **)tmp_str);
if (tmp_str_len != 2) { if (tmp_str_len != 2) {
COMMAND_ERROR("Bad blkio weight device format: %s", devices); COMMAND_ERROR("Bad blkio weight device format: %s", devices);
@ -789,7 +789,7 @@ static int parse_blkio_throttle_bps_device(const char *device, char **path, cons
char **split = NULL; char **split = NULL;
split = util_string_split_multi(device, ':'); split = util_string_split_multi(device, ':');
if (split == NULL || util_array_len(split) != 2) { if (split == NULL || util_array_len((const char **)split) != 2) {
COMMAND_ERROR("bad format: %s", device); COMMAND_ERROR("bad format: %s", device);
ret = -1; ret = -1;
goto out; goto out;

View File

@ -507,6 +507,14 @@ char *preserve_trailing_dot_or_separator(const char *cleanedpath, const char *or
int nret; int nret;
char respath[PATH_MAX + 3] = { 0 }; char respath[PATH_MAX + 3] = { 0 };
if (cleanedpath == NULL || originalpath == NULL) {
return NULL;
}
if (cleanedpath[0] == '\0' || originalpath[0] == '\0') {
return NULL;
}
nret = sprintf_s(respath, PATH_MAX, "%s", cleanedpath); nret = sprintf_s(respath, PATH_MAX, "%s", cleanedpath);
if (nret < 0) { if (nret < 0) {
ERROR("Failed to print string"); ERROR("Failed to print string");

View File

@ -165,8 +165,8 @@ static char *get_uniq_enable_plugins(const oci_runtime_spec *oci)
UTIL_FREE_AND_SET_NULL(names); UTIL_FREE_AND_SET_NULL(names);
UTIL_FREE_AND_SET_NULL(full); UTIL_FREE_AND_SET_NULL(full);
for (i = 0; i < util_array_len(raw); i++) { for (i = 0; i < util_array_len((const char **)raw); i++) {
if (strings_in_slice((const char **)arr, util_array_len(arr), raw[i])) { if (strings_in_slice((const char **)arr, util_array_len((const char **)arr), raw[i])) {
continue; continue;
} }
if (util_array_append(&arr, raw[i]) != 0) { if (util_array_append(&arr, raw[i]) != 0) {
@ -175,7 +175,7 @@ static char *get_uniq_enable_plugins(const oci_runtime_spec *oci)
} }
} }
names = util_string_join(LCRD_ENABLE_PLUGINS_SEPERATOR, (const char **)arr, util_array_len(arr)); names = util_string_join(LCRD_ENABLE_PLUGINS_SEPERATOR, (const char **)arr, util_array_len((const char **)arr));
if (names == NULL) { if (names == NULL) {
ERROR("join uniq plugin name failed"); ERROR("join uniq plugin name failed");
goto failed; goto failed;
@ -251,7 +251,7 @@ static char **get_enable_plugins(const char *plugins)
if (arr == NULL) { if (arr == NULL) {
ERROR("Out of memory"); ERROR("Out of memory");
} }
arr_len = util_array_len(arr); arr_len = util_array_len((const char **)arr);
for (i = 0; i < arr_len; i++) { for (i = 0; i < arr_len; i++) {
if (strings_in_slice((const char **)dst, dst_len, arr[i])) { if (strings_in_slice((const char **)dst, dst_len, arr[i])) {
@ -262,7 +262,7 @@ static char **get_enable_plugins(const char *plugins)
dst = NULL; dst = NULL;
goto out; goto out;
} }
dst_len = util_array_len(dst); dst_len = util_array_len((const char **)dst);
} }
if (arr_len != dst_len) { if (arr_len != dst_len) {
@ -956,7 +956,7 @@ static bool plugin_useby_container(const plugin_t *plugin, const container_t *co
plugin_names = container_get_env_nolock(cont, LCRD_ENABLE_PLUGINS); plugin_names = container_get_env_nolock(cont, LCRD_ENABLE_PLUGINS);
pnames = get_enable_plugins(plugin_names); pnames = get_enable_plugins(plugin_names);
for (i = 0; i < util_array_len(pnames); i++) { for (i = 0; i < util_array_len((const char **)pnames); i++) {
if (strcmp(pnames[i], plugin->name) == 0) { if (strcmp(pnames[i], plugin->name) == 0) {
ok = true; ok = true;
break; break;
@ -1090,7 +1090,7 @@ static int pm_init_plugin(const plugin_t *plugin)
size_t i = 0; size_t i = 0;
cnames = containers_store_list_ids(); cnames = containers_store_list_ids();
container_num = util_array_len(cnames); container_num = util_array_len((const char **)cnames);
/* /*
* send init request no matter containers exist or not, plugin should * send init request no matter containers exist or not, plugin should
@ -1331,7 +1331,7 @@ static int plugin_event_handle_dispath_impl(const char *cid, const char *plugins
} }
pm_rdlock(); pm_rdlock();
for (i = 0; i < util_array_len(pnames); i++) { for (i = 0; i < util_array_len((const char **)pnames); i++) {
if (pm_get_plugin(pnames[i], &plugin)) { /* plugin not found */ if (pm_get_plugin(pnames[i], &plugin)) { /* plugin not found */
ERROR("plugin %s not registered.", pnames[i]); ERROR("plugin %s not registered.", pnames[i]);
ret = -1; ret = -1;
@ -1548,7 +1548,7 @@ int plugin_event_container_pre_create(const char *cid, oci_runtime_spec *ocic)
goto out; goto out;
} }
pm_rdlock(); pm_rdlock();
for (i = 0; i < util_array_len(pnames); i++) { for (i = 0; i < util_array_len((const char **)pnames); i++) {
if (pm_get_plugin(pnames[i], &plugin)) { /* plugin not found */ if (pm_get_plugin(pnames[i], &plugin)) { /* plugin not found */
ERROR("plugin %s not registered.", pnames[i]); ERROR("plugin %s not registered.", pnames[i]);
ret = -1; ret = -1;

View File

@ -254,3 +254,4 @@ revert_free_old:
return dst; return dst;
} }

View File

@ -146,13 +146,13 @@ int CniNetworkPlugin::GetCNIConfFiles(const std::string &pluginDir, std::vector<
goto out; goto out;
} }
if (util_array_len(files) == 0) { if (util_array_len((const char **)files) == 0) {
err.Errorf("No networks found in %s", usePluginDir.c_str()); err.Errorf("No networks found in %s", usePluginDir.c_str());
ret = -1; ret = -1;
goto out; goto out;
} }
vect_files = std::vector<std::string>(files, files + util_array_len(files)); vect_files = std::vector<std::string>(files, files + util_array_len((const char **)files));
out: out:
free(serr); free(serr);
@ -717,3 +717,4 @@ void CniNetworkPlugin::UnlockNetworkMap(Errors &error)
} }
} // namespace Network } // namespace Network

View File

@ -39,7 +39,7 @@ static void runGetIP(void *cmdArgs)
char *args[ARGS_NUM]; char *args[ARGS_NUM];
char **tmpArgs = reinterpret_cast<char **>(cmdArgs); char **tmpArgs = reinterpret_cast<char **>(cmdArgs);
if (util_array_len(tmpArgs) != CMD_ARGS_NUM) { if (util_array_len((const char **)tmpArgs) != CMD_ARGS_NUM) {
COMMAND_ERROR("need four args"); COMMAND_ERROR("need four args");
exit(1); exit(1);
} }
@ -102,7 +102,7 @@ static std::string GetOnePodIP(std::string nsenterPath, std::string netnsPath, s
error.SetError("Out of memory"); error.SetError("Out of memory");
goto free_out; goto free_out;
} }
if (util_array_len(lines) < 1) { if (util_array_len((const char **)lines) < 1) {
error.Errorf("Unexpected command output %s", stdout_str); error.Errorf("Unexpected command output %s", stdout_str);
goto free_out; goto free_out;
} }
@ -112,7 +112,7 @@ static std::string GetOnePodIP(std::string nsenterPath, std::string netnsPath, s
error.SetError("Out of memory"); error.SetError("Out of memory");
goto free_out; goto free_out;
} }
if (util_array_len(fields) < 4) { if (util_array_len((const char **)fields) < 4) {
error.Errorf("Unexpected address output %s ", lines[0]); error.Errorf("Unexpected address output %s ", lines[0]);
goto free_out; goto free_out;
} }
@ -519,3 +519,4 @@ void NoopNetworkPlugin::Status(Errors &error)
} }
} // namespace Network } // namespace Network

View File

@ -44,9 +44,7 @@ private:
RequestCache() = default; RequestCache() = default;
RequestCache(const RequestCache &) = delete; RequestCache(const RequestCache &) = delete;
RequestCache &operator=(const RequestCache &) = delete; RequestCache &operator=(const RequestCache &) = delete;
~RequestCache() = default; virtual ~RequestCache() = default;
// clock is used to obtain the current time
std::time_t m_clock;
// tokens maps the generate token to the request for fast retrieval. // tokens maps the generate token to the request for fast retrieval.
std::unordered_map<std::string, CacheEntry> m_tokens; std::unordered_map<std::string, CacheEntry> m_tokens;
// ll maintains an age-ordered request list for faster garbage collection of expired requests. // ll maintains an age-ordered request list for faster garbage collection of expired requests.

View File

@ -693,6 +693,159 @@ static int verify_merged_custom_config(const container_custom_config *custom_spe
return 0; return 0;
} }
static int response_allocate_memory(container_create_response **response)
{
if (response == NULL) {
ERROR("Invalid NULL input");
return -1;
}
*response = util_common_calloc_s(sizeof(container_create_response));
if (*response == NULL) {
ERROR("Out of memory");
return -1;
}
return 0;
}
static int get_request_container_info(const container_create_request *request, char **id, char **name, uint32_t *cc)
{
if (create_request_check(request) != 0) {
ERROR("Invalid create container request");
*cc = LCRD_ERR_INPUT;
return -1;
}
if (maintain_container_id(request, id, name) != 0) {
*cc = LCRD_ERR_EXEC;
return -1;
}
return 0;
}
static int get_request_image_info(const container_create_request *request, char **image_type,
const char **ext_config_image, const char **image_name)
{
*image_type = im_get_image_type(request->image, request->rootfs);
if (*image_type == NULL) {
return -1;
}
if (request->rootfs != NULL) {
*image_name = request->rootfs;
// Do not use none image because none image has no config.
if (strcmp(request->image, "none") && strcmp(request->image, "none:latest")) {
*ext_config_image = request->image;
}
} else {
*image_name = request->image;
}
// Check if config image exist if provided.
if (*ext_config_image != NULL) {
if (!im_config_image_exist(*ext_config_image)) {
return -1;
}
}
return 0;
}
static int preparate_runtime_environment(const container_create_request *request, const char *id,
char **runtime, char **runtime_root, uint32_t *cc)
{
*runtime = get_runtime_from_request(request);
if (*runtime == NULL) {
*cc = LCRD_ERR_INPUT;
return -1;
}
*runtime_root = conf_get_routine_rootdir(*runtime);
if (*runtime_root == NULL) {
*cc = LCRD_ERR_EXEC;
return -1;
}
if (create_container_root_dir(id, *runtime_root) != 0) {
*cc = LCRD_ERR_EXEC;
return -1;
}
return 0;
}
static int get_basic_spec(const container_create_request *request, const char *id, const char *runtime_root,
host_config **host_spec, container_custom_config **custom_spec)
{
*host_spec = get_host_spec(request);
if (*host_spec == NULL) {
return -1;
}
*custom_spec = get_custom_spec(id, runtime_root, request);
if (*custom_spec == NULL) {
return -1;
}
return 0;
}
static int get_v2_spec(const container_create_request *request, const char *id, const char *name,
const char *runtime_root, const host_config *host_spec, const char *image_type,
container_config_v2_common_config **v2_spec)
{
*v2_spec = get_config_v2_spec(id, runtime_root, host_spec);
if (*v2_spec == NULL) {
ERROR("Failed to malloc container_config_v2_common_config");
return -1;
}
if (v2_spec_make_basic_info(id, name, request->image, image_type, *v2_spec) != 0) {
ERROR("Failed to malloc container_config_v2_common_config");
return -1;
}
return 0;
}
static int v2_spec_merge_config(const container_custom_config *custom_spec, const oci_runtime_spec *oci_spec,
container_config_v2_common_config *v2_spec)
{
if (v2_spec_merge_custom_spec(custom_spec, v2_spec) != 0) {
ERROR("Failed to malloc container_config_v2_common_config");
return -1;
}
if (v2_spec_merge_oci_spec(oci_spec, v2_spec) != 0) {
ERROR("Failed to malloc container_config_v2_common_config");
return -1;
}
return 0;
}
static int generate_oci_config_json(const char *id, const container_create_request *request,
const host_config *host_spec, const container_custom_config *custom_spec,
oci_runtime_spec *oci_spec, char **oci_config_data)
{
if (verify_merged_custom_config(custom_spec)) {
return -1;
}
if (merge_config_for_syscontainer(request, host_spec, custom_spec, oci_spec) != 0) {
ERROR("Failed to merge config for syscontainer");
return -1;
}
if (generate_merged_oci_config_json(id, oci_spec, oci_config_data) != 0) {
return -1;
}
return 0;
}
int container_create_cb(const container_create_request *request, int container_create_cb(const container_create_request *request,
container_create_response **response) container_create_response **response)
{ {
@ -714,90 +867,29 @@ int container_create_cb(const container_create_request *request,
DAEMON_CLEAR_ERRMSG(); DAEMON_CLEAR_ERRMSG();
if (response == NULL) { if (response_allocate_memory(response) != 0) {
ERROR("Invalid NULL input");
return -1; return -1;
} }
*response = util_common_calloc_s(sizeof(container_create_response)); if (get_request_container_info(request, &id, &name, &cc) != 0) {
if (*response == NULL) {
ERROR("Out of memory");
return -1;
}
if (create_request_check(request) != 0) {
ERROR("Invalid create container request");
cc = LCRD_ERR_INPUT;
goto pack_response; goto pack_response;
} }
if (maintain_container_id(request, &id, &name) != 0) { if (get_request_image_info(request, &image_type, &ext_config_image, &image_name) != 0) {
cc = LCRD_ERR_EXEC;
goto pack_response;
}
image_type = im_get_image_type(request->image, request->rootfs);
if (image_type == NULL) {
cc = LCRD_ERR_EXEC; cc = LCRD_ERR_EXEC;
goto clean_nameindex; goto clean_nameindex;
} }
if (request->rootfs != NULL) { if (preparate_runtime_environment(request, id, &runtime, &runtime_root, &cc) != 0) {
image_name = request->rootfs;
// Do not use none image because none image has no config.
if (strcmp(request->image, "none") && strcmp(request->image, "none:latest")) {
ext_config_image = request->image;
}
} else {
image_name = request->image;
}
// Check if config image exist if provided.
if (ext_config_image != NULL) {
if (!im_config_image_exist(ext_config_image)) {
cc = LCRD_ERR_EXEC;
goto clean_nameindex;
}
}
runtime = get_runtime_from_request(request);
if (runtime == NULL) {
cc = LCRD_ERR_INPUT;
goto clean_nameindex; goto clean_nameindex;
} }
runtime_root = conf_get_routine_rootdir(runtime); if (get_basic_spec(request, id, runtime_root, &host_spec, &custom_spec) != 0) {
if (runtime_root == NULL) {
cc = LCRD_ERR_EXEC;
goto clean_nameindex;
}
if (create_container_root_dir(id, runtime_root) != 0) {
cc = LCRD_ERR_EXEC;
goto clean_nameindex;
}
host_spec = get_host_spec(request);
if (host_spec == NULL) {
cc = LCRD_ERR_INPUT; cc = LCRD_ERR_INPUT;
goto clean_container_root_dir; goto clean_container_root_dir;
} }
custom_spec = get_custom_spec(id, runtime_root, request); if (get_v2_spec(request, id, name, runtime_root, host_spec, image_type, &v2_spec) != 0) {
if (custom_spec == NULL) {
cc = LCRD_ERR_INPUT;
goto clean_container_root_dir;
}
v2_spec = get_config_v2_spec(id, runtime_root, host_spec);
if (v2_spec == NULL) {
ERROR("Failed to malloc container_config_v2_common_config");
cc = LCRD_ERR_EXEC;
goto clean_container_root_dir;
}
if (v2_spec_make_basic_info(id, name, request->image, image_type, v2_spec) != 0) {
ERROR("Failed to malloc container_config_v2_common_config");
cc = LCRD_ERR_EXEC; cc = LCRD_ERR_EXEC;
goto clean_container_root_dir; goto clean_container_root_dir;
} }
@ -808,12 +900,12 @@ int container_create_cb(const container_create_request *request,
} }
host_channel = dup_host_channel(host_spec->host_channel); host_channel = dup_host_channel(host_spec->host_channel);
if (prepare_host_channel(host_channel, host_spec->user_remap)) { if (prepare_host_channel(host_channel, host_spec->user_remap)) {
ERROR("Failed to prepare host channel with '%s'", host_spec->host_channel); ERROR("Failed to prepare host channel with '%s'", host_spec->host_channel);
cc = LCRD_ERR_EXEC; cc = LCRD_ERR_EXEC;
goto clean_container_root_dir; goto clean_container_root_dir;
} }
oci_spec = merge_config(id, image_type, image_name, ext_config_image, host_spec, custom_spec, v2_spec, oci_spec = merge_config(id, image_type, image_name, ext_config_image, host_spec, custom_spec, v2_spec,
&real_rootfs); &real_rootfs);
if (oci_spec == NULL) { if (oci_spec == NULL) {
@ -826,36 +918,18 @@ int container_create_cb(const container_create_request *request,
goto clean_rootfs; goto clean_rootfs;
} }
if (verify_merged_custom_config(custom_spec)) { if (generate_oci_config_json(id, request, host_spec, custom_spec, oci_spec, &oci_config_data) != 0) {
cc = LCRD_ERR_INPUT; cc = LCRD_ERR_INPUT;
goto clean_rootfs; goto clean_rootfs;
} }
if (merge_config_for_syscontainer(request, host_spec, custom_spec, oci_spec) != 0) {
ERROR("Failed to merge config for syscontainer");
cc = LCRD_ERR_EXEC;
goto clean_rootfs;
}
if (generate_merged_oci_config_json(id, oci_spec, &oci_config_data) != 0) {
cc = LCRD_ERR_EXEC;
goto clean_rootfs;
}
if (runtime_create(id, runtime, real_rootfs, oci_config_data) != 0) { if (runtime_create(id, runtime, real_rootfs, oci_config_data) != 0) {
ERROR("Runtime create container failed"); ERROR("Runtime create container failed");
cc = LCRD_ERR_EXEC; cc = LCRD_ERR_EXEC;
goto clean_rootfs; goto clean_rootfs;
} }
if (v2_spec_merge_custom_spec(custom_spec, v2_spec) != 0) { if (v2_spec_merge_config(custom_spec, oci_spec, v2_spec) != 0) {
ERROR("Failed to malloc container_config_v2_common_config");
cc = LCRD_ERR_EXEC;
goto clean_on_error;
}
if (v2_spec_merge_oci_spec(oci_spec, v2_spec) != 0) {
ERROR("Failed to malloc container_config_v2_common_config");
cc = LCRD_ERR_EXEC; cc = LCRD_ERR_EXEC;
goto clean_on_error; goto clean_on_error;
} }
@ -868,6 +942,7 @@ int container_create_cb(const container_create_request *request,
EVENT("Event: {Object: %s, Type: Created %s}", id, name); EVENT("Event: {Object: %s, Type: Created %s}", id, name);
goto pack_response; goto pack_response;
clean_on_error: clean_on_error:
(void)runtime_rm(id, runtime, runtime_root); (void)runtime_rm(id, runtime, runtime_root);

View File

@ -389,7 +389,7 @@ static int stats_get_all_containers_id(const container_stats_request *request, c
} else { } else {
array = containers_store_list_ids(); array = containers_store_list_ids();
} }
*ids_len = util_array_len(array); *ids_len = util_array_len((const char **)array);
*idsarray = array; *idsarray = array;
array = NULL; array = NULL;
ret = 0; ret = 0;

View File

@ -314,7 +314,7 @@ int get_stime(const char *title_line)
char **title_element = NULL; char **title_element = NULL;
title_element = util_string_split(title_line, ' '); title_element = util_string_split(title_line, ' ');
for (i = 0; i < util_array_len(title_element); i++) { for (i = 0; i < util_array_len((const char **)title_element); i++) {
if (strcmp(title_element[i], "STIME") == 0) { if (strcmp(title_element[i], "STIME") == 0) {
stime = (int)i; stime = (int)i;
break; break;
@ -333,7 +333,7 @@ int get_pid_num(const char *title_line)
char **title_element = NULL; char **title_element = NULL;
title_element = util_string_split(title_line, ' '); title_element = util_string_split(title_line, ' ');
for (i = 0; i < util_array_len(title_element); i++) { for (i = 0; i < util_array_len((const char **)title_element); i++) {
if (strcmp(title_element[i], "PID") == 0) { if (strcmp(title_element[i], "PID") == 0) {
num = (int)i; num = (int)i;
break; break;
@ -372,7 +372,7 @@ static int parse_output_by_lines(char **process, char **tmp, int pid_num, int st
char **pid_s = NULL; char **pid_s = NULL;
char **pid_s_pre = NULL; char **pid_s_pre = NULL;
for (i = 1; i < util_array_len(tmp); i++) { for (i = 1; i < util_array_len((const char **)tmp); i++) {
bool flag = false; bool flag = false;
int tmp_num = 0; int tmp_num = 0;
if (i > 1) { if (i > 1) {
@ -429,12 +429,12 @@ int parse_output(char **title, char ***process, const char *output, const pid_t
pid_num = get_pid_num(*title); pid_num = get_pid_num(*title);
stime = get_stime(*title); stime = get_stime(*title);
if (util_array_len(tmp) > SIZE_MAX / sizeof(char *)) { if (util_array_len((const char **)tmp) > SIZE_MAX / sizeof(char *)) {
ERROR("Invalid array length"); ERROR("Invalid array length");
ret = -1; ret = -1;
goto out; goto out;
} }
*process = util_common_calloc_s(util_array_len(tmp) * sizeof(char *)); *process = util_common_calloc_s(util_array_len((const char **)tmp) * sizeof(char *));
if (*process == NULL) { if (*process == NULL) {
ERROR("Out of memory"); ERROR("Out of memory");
ret = -1; ret = -1;
@ -757,12 +757,12 @@ static int container_top_cb(container_top_request *request, container_top_respon
cc = LCRD_ERR_EXEC; cc = LCRD_ERR_EXEC;
goto pack_response; goto pack_response;
} }
if (util_array_len(processes) > SIZE_MAX / sizeof(char *)) { if (util_array_len((const char **)processes) > SIZE_MAX / sizeof(char *)) {
ERROR("invalid processe size"); ERROR("invalid processe size");
cc = LCRD_ERR_EXEC; cc = LCRD_ERR_EXEC;
goto pack_response; goto pack_response;
} }
(*response)->processes = util_common_calloc_s(util_array_len(processes) * sizeof(char *)); (*response)->processes = util_common_calloc_s(util_array_len((const char **)processes) * sizeof(char *));
if ((*response)->processes == NULL) { if ((*response)->processes == NULL) {
ERROR("Out of memory"); ERROR("Out of memory");
cc = LCRD_ERR_EXEC; cc = LCRD_ERR_EXEC;
@ -771,10 +771,10 @@ static int container_top_cb(container_top_request *request, container_top_respon
(*response)->titles = titles; (*response)->titles = titles;
titles = NULL; titles = NULL;
for (i = 0; i < util_array_len(processes); i++) { for (i = 0; i < util_array_len((const char **)processes); i++) {
(*response)->processes[i] = util_strdup_s(processes[i]); (*response)->processes[i] = util_strdup_s(processes[i]);
} }
(*response)->processes_len = util_array_len(processes); (*response)->processes_len = util_array_len((const char **)processes);
pack_response: pack_response:
if (*response != NULL) { if (*response != NULL) {

View File

@ -199,10 +199,10 @@ static char **filter_by_name_id_matches(const struct list_context *ctx, const ma
map_t *matches = NULL; map_t *matches = NULL;
names = filters_args_get(ctx->ps_filters, "name"); names = filters_args_get(ctx->ps_filters, "name");
names_len = util_array_len(names); names_len = util_array_len((const char **)names);
ids = filters_args_get(ctx->ps_filters, "id"); ids = filters_args_get(ctx->ps_filters, "id");
ids_len = util_array_len(ids); ids_len = util_array_len((const char **)ids);
if (names_len == 0 && ids_len == 0) { if (names_len == 0 && ids_len == 0) {
if (append_ids(map_id_name, &filtered_ids) != 0) { if (append_ids(map_id_name, &filtered_ids) != 0) {
goto cleanup; goto cleanup;
@ -618,7 +618,7 @@ static int pack_list_containers(char **idsarray, const struct list_context *ctx,
int j = 0; int j = 0;
size_t container_nums = 0; size_t container_nums = 0;
container_nums = util_array_len(idsarray); container_nums = util_array_len((const char **)idsarray);
if (container_nums == 0) { if (container_nums == 0) {
goto out; goto out;
} }

View File

@ -1098,7 +1098,7 @@ char *container_get_command(const container_t *cont)
} }
} }
cmd = util_string_join(" ", (const char **)args, util_array_len(args)); cmd = util_string_join(" ", (const char **)args, util_array_len((const char **)args));
cleanup: cleanup:
util_free_array(args); util_free_array(args);

View File

@ -253,7 +253,7 @@ static char **health_check_cmds(const container_config *config)
goto out; goto out;
} }
shell_len = util_array_len(shell); shell_len = util_array_len((const char **)shell);
if (shell_len > (SIZE_MAX / sizeof(char *)) - config->health_check->test_len) { if (shell_len > (SIZE_MAX / sizeof(char *)) - config->health_check->test_len) {
ERROR("Invalid shell length"); ERROR("Invalid shell length");
goto out; goto out;
@ -574,7 +574,7 @@ void *health_check_run(void *arg)
container_req->timeout = timeout_with_default(config->health_check->timeout, DEFAULT_PROBE_TIMEOUT) / Time_Second; container_req->timeout = timeout_with_default(config->health_check->timeout, DEFAULT_PROBE_TIMEOUT) / Time_Second;
container_req->container_id = util_strdup_s(cont->common_config->id); container_req->container_id = util_strdup_s(cont->common_config->id);
container_req->argv = cmd_slice; container_req->argv = cmd_slice;
container_req->argv_len = util_array_len(cmd_slice); container_req->argv_len = util_array_len((const char **)cmd_slice);
cmd_slice = NULL; cmd_slice = NULL;
EVENT("EVENT: {Object: %s, Type: Health checking}", cont->common_config->id); EVENT("EVENT: {Object: %s, Type: Health checking}", cont->common_config->id);
@ -856,3 +856,4 @@ out:
return; return;
} }

View File

@ -664,7 +664,7 @@ static int restore_container_by_runtime(const char *runtime)
ret = -1; ret = -1;
goto out; goto out;
} }
subdir_num = util_array_len(subdir); subdir_num = util_array_len((const char **)subdir);
if (subdir_num == 0) { if (subdir_num == 0) {
goto out; goto out;
} }
@ -706,7 +706,7 @@ void containers_restore(void)
ERROR("Failed to list engines"); ERROR("Failed to list engines");
goto out; goto out;
} }
subdir_num = util_array_len(subdir); subdir_num = util_array_len((const char **)subdir);
for (i = 0; i < subdir_num; i++) { for (i = 0; i < subdir_num; i++) {
DEBUG("Restore the containers by runtime:%s", subdir[i]); DEBUG("Restore the containers by runtime:%s", subdir[i]);

View File

@ -16,7 +16,6 @@
#define __LCRD_RESTORE_H #define __LCRD_RESTORE_H
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "engine.h" #include "engine.h"
@ -32,3 +31,4 @@ extern void containers_restore(void);
#endif #endif
#endif #endif

View File

@ -16,7 +16,6 @@
#define __LCRD_SUPERVISOR_H #define __LCRD_SUPERVISOR_H
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
#include <limits.h>
#include "container_unix.h" #include "container_unix.h"
extern char *exit_fifo_create(const char *cont_state_path); extern char *exit_fifo_create(const char *cont_state_path);
@ -31,3 +30,4 @@ extern int supervisor_add_exit_monitor(int fd, const container_pid_t *pid_info,
extern int new_supervisor(); extern int new_supervisor();
#endif #endif

View File

@ -328,9 +328,12 @@ out:
} }
/* default_spec returns default oci spec used by lcrd. */ /* default_spec returns default oci spec used by lcrd. */
oci_runtime_spec *default_spec() oci_runtime_spec *default_spec(bool system_container)
{ {
const char *oci_file = OCICONFIG_PATH; const char *oci_file = OCICONFIG_PATH;
if (system_container) {
oci_file = OCI_SYSTEM_CONTAINER_CONFIG_PATH;
}
oci_runtime_spec *oci_spec = NULL; oci_runtime_spec *oci_spec = NULL;
parser_error err = NULL; parser_error err = NULL;
@ -1453,6 +1456,44 @@ out:
return ret; return ret;
} }
static int change_tmpfs_mount_size(const oci_runtime_spec *oci_spec, int64_t memory_limit)
{
int ret = 0;
size_t i = 0;
char size_opt[MOUNT_PROPERTIES_SIZE] = { 0 };
if (oci_spec->mounts == NULL) {
goto out;
}
if (memory_limit <= 0) {
goto out;
}
/*set tmpfs mount size to half of container memory limit*/
if (sprintf_s(size_opt, sizeof(size_opt), "size=%lldk", (long long int)(memory_limit / 2048)) < 0) {
ERROR("Out of memory");
ret = -1;
goto out;
}
for (i = 0; i < oci_spec->mounts_len; i++) {
if (strcmp("tmpfs", oci_spec->mounts[i]->type) != 0) {
continue;
}
if (strcmp("/run", oci_spec->mounts[i]->destination) == 0 || \
strcmp("/run/lock", oci_spec->mounts[i]->destination) == 0 || \
strcmp("/tmp", oci_spec->mounts[i]->destination) == 0) {
ret = util_array_append(&oci_spec->mounts[i]->options, size_opt);
if (ret != 0) {
ERROR("append mount size option failed");
goto out;
}
oci_spec->mounts[i]->options_len++;
}
}
out:
return ret;
}
static int merge_settings_for_system_container(oci_runtime_spec *oci_spec, host_config *host_spec, static int merge_settings_for_system_container(oci_runtime_spec *oci_spec, host_config *host_spec,
container_custom_config *custom_spec) container_custom_config *custom_spec)
{ {
@ -1471,14 +1512,9 @@ static int merge_settings_for_system_container(oci_runtime_spec *oci_spec, host_
ERROR("Failed to adapt settings for system container"); ERROR("Failed to adapt settings for system container");
goto out; goto out;
} }
if (!mount_run_tmpfs(oci_spec, "/run")) { if (change_tmpfs_mount_size(oci_spec, host_spec->memory) != 0) {
ret = -1; ret = -1;
ERROR("Failed to add /run mount to system container"); ERROR("Failed to change tmpfs mount size for system container");
goto out;
}
if (!mount_run_tmpfs(oci_spec, "/run/lock")) {
ret = -1;
ERROR("Failed to add /run/lock mount to system container");
goto out; goto out;
} }
@ -1674,7 +1710,7 @@ oci_runtime_spec *merge_container_config(const char *id, const char *image_type,
parser_error err = NULL; parser_error err = NULL;
int ret = 0; int ret = 0;
oci_spec = default_spec(); oci_spec = default_spec(host_spec->system_container);
if (oci_spec == NULL) { if (oci_spec == NULL) {
goto out; goto out;
} }
@ -1814,3 +1850,4 @@ out:
free(err); free(err);
return ociconfig; return ociconfig;
} }

View File

@ -147,7 +147,7 @@ int adapt_settings_for_mounts(oci_runtime_spec *oci_spec, container_custom_confi
ret = -1; ret = -1;
goto out; goto out;
} }
array_str_len = util_array_len(array_str); array_str_len = util_array_len((const char **)array_str);
for (i = 0; i < array_str_len; i++) { for (i = 0; i < array_str_len; i++) {
if (strcmp(array_str[i], "net") == 0) { if (strcmp(array_str[i], "net") == 0) {
@ -543,7 +543,7 @@ defs_mount *parse_mount(const char *mount)
goto out; goto out;
} }
items_len = util_array_len(items); items_len = util_array_len((const char **)items);
for (i = 0; i < items_len; i++) { for (i = 0; i < items_len; i++) {
kv = util_string_split(items[i], '='); kv = util_string_split(items[i], '=');
@ -635,7 +635,7 @@ static int get_src_dst_mode_by_volume(const char *volume, defs_mount *mount_elem
goto free_out; goto free_out;
} }
alen = util_array_len(array); alen = util_array_len((const char **)array);
switch (alen) { switch (alen) {
case 1: case 1:
ERROR("Not supported volume format '%s'", volume); ERROR("Not supported volume format '%s'", volume);
@ -716,7 +716,7 @@ defs_mount *parse_volume(const char *volume)
goto free_out; goto free_out;
} }
mlen = util_array_len(modes); mlen = util_array_len((const char **)modes);
for (i = 0; i < mlen; i++) { for (i = 0; i < mlen; i++) {
if (util_valid_rw_mode(modes[i])) { if (util_valid_rw_mode(modes[i])) {
rw = modes[i]; rw = modes[i];
@ -1820,57 +1820,6 @@ static bool mounts_expand(oci_runtime_spec *container, size_t add_len)
return true; return true;
} }
bool mount_run_tmpfs(oci_runtime_spec *container, const char *path)
{
char **options = NULL;
size_t options_len = 5;
bool ret = false;
defs_mount *tmp_mounts = NULL;
if (options_len > SIZE_MAX / sizeof(char *)) {
ERROR("Invalid option size");
return ret;
}
options = util_common_calloc_s(options_len * sizeof(char *));
if (options == NULL) {
ERROR("Out of memory");
goto out_free;
}
options[0] = util_strdup_s("nosuid");
options[1] = util_strdup_s("noexec");
options[2] = util_strdup_s("nodev");
options[3] = util_strdup_s("relatime");
options[4] = util_strdup_s("mode=755");
tmp_mounts = util_common_calloc_s(sizeof(defs_mount));
if (tmp_mounts == NULL) {
ERROR("Malloc tmp_mounts memory failed");
goto out_free;
}
tmp_mounts->destination = util_strdup_s(path);
tmp_mounts->source = util_strdup_s("tmpfs");
tmp_mounts->type = util_strdup_s("tmpfs");
tmp_mounts->options = options;
tmp_mounts->options_len = options_len;
options = NULL;
/*expand mount array*/
if (!mounts_expand(container, 1)) {
goto out_free;
}
/*add a new mount node*/
container->mounts[container->mounts_len - 1] = tmp_mounts;
ret = true;
out_free:
if (!ret) {
util_free_array(options);
free_defs_mount(tmp_mounts);
}
return ret;
}
static bool mount_file(oci_runtime_spec *container, const char *src_path, const char *dst_path) static bool mount_file(oci_runtime_spec *container, const char *src_path, const char *dst_path)
{ {
char **options = NULL; char **options = NULL;

View File

@ -44,8 +44,9 @@ int set_mounts_readwrite_option(const oci_runtime_spec *oci_spec);
int merge_all_devices_and_all_permission(oci_runtime_spec *oci_spec); int merge_all_devices_and_all_permission(oci_runtime_spec *oci_spec);
bool mount_run_tmpfs(oci_runtime_spec *container, const char *path); bool mount_run_tmpfs(oci_runtime_spec *container, const host_config *host_spec, const char *path);
int merge_conf_device(oci_runtime_spec *oci_spec, host_config *host_spec); int merge_conf_device(oci_runtime_spec *oci_spec, host_config *host_spec);
#endif #endif

View File

@ -1061,7 +1061,7 @@ static bool is_huge_pagesize_valid(const char *pagesize)
ERROR("Hugetlb cgroup not supported"); ERROR("Hugetlb cgroup not supported");
goto free_out; goto free_out;
} }
hps_len = util_array_len(hps); hps_len = util_array_len((const char **)hps);
if (hps_len == 0) { if (hps_len == 0) {
ERROR("Hugetlb cgroup not supported"); ERROR("Hugetlb cgroup not supported");
goto free_out; goto free_out;
@ -1245,7 +1245,7 @@ mountinfo_t *get_mount_info(const char *pline)
ret = -1; ret = -1;
goto free_out; goto free_out;
} }
length = util_array_len(list); length = util_array_len((const char **)list);
if (length < 8) { if (length < 8) {
ERROR("Invalid mountinfo '%s'", pline); ERROR("Invalid mountinfo '%s'", pline);
ret = -1; ret = -1;
@ -1339,3 +1339,4 @@ free_out:
} }
return minfos; return minfos;
} }

View File

@ -14,6 +14,7 @@
******************************************************************************/ ******************************************************************************/
#include "driver_overlay2.h" #include "driver_overlay2.h"
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "liblcrd.h" #include "liblcrd.h"
#include "utils.h" #include "utils.h"
@ -79,3 +80,4 @@ int overlay2_parse_options(struct graphdriver *driver, const char **options, siz
return 0; return 0;
} }

View File

@ -19,7 +19,6 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -75,3 +74,4 @@ int archive_path(const char *srcdir, const char *srcbase, const char *rebase_nam
#endif #endif
#endif #endif

View File

@ -29,6 +29,10 @@
class AttachServe : public StreamingServeInterface { class AttachServe : public StreamingServeInterface {
public: public:
AttachServe() = default;
AttachServe(const AttachServe &) = delete;
AttachServe &operator=(const AttachServe &) = delete;
virtual ~AttachServe() = default;
int Execute(struct lws *wsi, const std::string &token, int read_pipe_fd) override; int Execute(struct lws *wsi, const std::string &token, int read_pipe_fd) override;
private: private:
int RequestFromCri(const runtime::AttachRequest *grequest, int RequestFromCri(const runtime::AttachRequest *grequest,

View File

@ -33,6 +33,10 @@
class ExecServe : public StreamingServeInterface { class ExecServe : public StreamingServeInterface {
public: public:
ExecServe() = default;
ExecServe(const ExecServe &) = delete;
ExecServe &operator=(const ExecServe &) = delete;
virtual ~ExecServe() = default;
int Execute(struct lws *wsi, const std::string &token, int read_pipe_fd) override; int Execute(struct lws *wsi, const std::string &token, int read_pipe_fd) override;
private: private:
int RequestFromCri(const runtime::ExecRequest *grequest, int RequestFromCri(const runtime::ExecRequest *grequest,

View File

@ -24,11 +24,19 @@
#include "log.h" #include "log.h"
class StreamingServeInterface { class StreamingServeInterface {
public: public:
StreamingServeInterface() = default;
StreamingServeInterface(const StreamingServeInterface &) = delete;
StreamingServeInterface &operator=(const StreamingServeInterface &) = delete;
virtual ~StreamingServeInterface() = default;
virtual int Execute(struct lws *wsi, const std::string &token, int read_pipe_fd) = 0; virtual int Execute(struct lws *wsi, const std::string &token, int read_pipe_fd) = 0;
}; };
class RouteCallbackRegister { class RouteCallbackRegister {
public: public:
RouteCallbackRegister() = default;
RouteCallbackRegister(const RouteCallbackRegister &) = delete;
RouteCallbackRegister &operator=(const RouteCallbackRegister &) = delete;
virtual ~RouteCallbackRegister() = default;
bool IsValidMethod(const std::string &method) bool IsValidMethod(const std::string &method)
{ {
return static_cast<bool>(m_registeredcallbacks.count(method)); return static_cast<bool>(m_registeredcallbacks.count(method));
@ -66,7 +74,9 @@ public:
const std::string &token, int read_pipe_fd) const std::string &token, int read_pipe_fd)
: m_invoker(invoker), m_wsi(wsi), m_method(method), m_token(token), : m_invoker(invoker), m_wsi(wsi), m_method(method), m_token(token),
m_read_pipe_fd(read_pipe_fd) {} m_read_pipe_fd(read_pipe_fd) {}
~StreamTask() = default; StreamTask(const StreamTask &) = delete;
StreamTask &operator=(const StreamTask &) = delete;
virtual ~StreamTask() = default;
int Run() int Run()
{ {
return m_invoker->HandleCallback(m_wsi, m_method, m_token, m_read_pipe_fd); return m_invoker->HandleCallback(m_wsi, m_method, m_token, m_read_pipe_fd);

View File

@ -413,6 +413,7 @@ void WebsocketServer::Wait()
lws_context_destroy(m_context); lws_context_destroy(m_context);
} }
ssize_t WsWriteToClient(void *context, const void *data, size_t len) ssize_t WsWriteToClient(void *context, const void *data, size_t len)
{ {
const int RETRIES = 10; const int RETRIES = 10;

View File

@ -90,7 +90,7 @@ private:
WebsocketServer(); WebsocketServer();
WebsocketServer(const WebsocketServer &) = delete; WebsocketServer(const WebsocketServer &) = delete;
WebsocketServer &operator=(const WebsocketServer &) = delete; WebsocketServer &operator=(const WebsocketServer &) = delete;
~WebsocketServer(); virtual ~WebsocketServer();
int InitRWPipe(int read_fifo[]); int InitRWPipe(int read_fifo[]);
std::vector<std::string> split(std::string str, char r); std::vector<std::string> split(std::string str, char r);
static void EmitLog(int level, const char *line); static void EmitLog(int level, const char *line);

View File

@ -3,6 +3,7 @@ project(iSulad_LLT)
# setup testing # setup testing
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
find_package(GTest REQUIRED) find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})
add_subdirectory(cutils) add_subdirectory(cutils)
add_subdirectory(image)
add_subdirectory(path)

View File

@ -1,3 +1,5 @@
project(iSulad_LLT) project(iSulad_LLT)
add_subdirectory(utils_string) add_subdirectory(utils_string)
add_subdirectory(utils_convert)
add_subdirectory(utils_array)

View File

@ -0,0 +1,27 @@
project(iSulad_LLT)
SET(EXE utils_array_llt)
add_executable(${EXE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/log.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_string.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_array.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_convert.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_verify.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256/sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/path.c
${CMAKE_BINARY_DIR}/json/json_common.c
utils_array_llt.cc)
target_include_directories(${EXE} PUBLIC
${GTEST_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../src
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils
${CMAKE_BINARY_DIR}/json
)
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc -Wl,--wrap,memcpy_s")
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)

View File

@ -0,0 +1,235 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
* Description: utils_array llt
* Author: tanyifeng
* Create: 2019-09-24
*/
#include <stdlib.h>
#include <stdio.h>
#include <climits>
#include <securec.h>
#include <gtest/gtest.h>
#include "mock.h"
#include "utils_array.h"
#include "utils.h"
extern "C" {
DECLARE_WRAPPER(calloc, void *, (size_t nmemb, size_t size));
DEFINE_WRAPPER(calloc, void *, (size_t nmemb, size_t size), (nmemb, size));
DECLARE_WRAPPER(memcpy_s, errno_t, (void* dest, size_t destMax, const void* src, size_t count));
DEFINE_WRAPPER(memcpy_s, errno_t, (void* dest, size_t destMax, const void* src, size_t count),
(dest, destMax, src, count));
}
TEST(utils_array, test_util_array_len)
{
const char *array_long[] = { "abcd", "1234", "a1b", nullptr };
ASSERT_EQ(util_array_len(nullptr), 0);
ASSERT_EQ(util_array_len(array_long), 3);
}
TEST(utils_array, test_util_free_array)
{
char **array = NULL;
array = (char **)util_common_calloc_s(4 * sizeof(char *));
ASSERT_NE(array, nullptr);
array[0] = util_strdup_s("test1");
array[1] = util_strdup_s("test2");
array[2] = util_strdup_s("test3");
array[3] = nullptr;
util_free_array(nullptr);
util_free_array(array);
}
TEST(utils_array, test_util_grow_array)
{
char **array = nullptr;
size_t capacity = 0;
int ret;
capacity = 1;
array = (char **)util_common_calloc_s(sizeof(char *));
ASSERT_NE(array, nullptr);
ret = util_grow_array(&array, &capacity, 1, 1);
ASSERT_EQ(ret, 0);
ASSERT_NE(array, nullptr);
ASSERT_EQ(array[0], nullptr);
ASSERT_EQ(array[1], nullptr);
ASSERT_EQ(capacity, 2);
util_free_array(array);
array = nullptr;
capacity = 0;
capacity = 1;
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
ASSERT_NE(array, nullptr);
ret = util_grow_array(&array, &capacity, 1, 2);
ASSERT_EQ(ret, 0);
ASSERT_NE(array, nullptr);
ASSERT_EQ(array[0], nullptr);
ASSERT_EQ(array[1], nullptr);
ASSERT_EQ(array[2], nullptr);
ASSERT_EQ(capacity, 3);
util_free_array(array);
array = nullptr;
capacity = 0;
capacity = 1;
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
ASSERT_NE(array, nullptr);
ret = util_grow_array(&array, &capacity, 1, 4);
ASSERT_EQ(ret, 0);
ASSERT_NE(array, nullptr);
ASSERT_EQ(array[0], nullptr);
ASSERT_EQ(array[1], nullptr);
ASSERT_EQ(array[2], nullptr);
ASSERT_EQ(array[3], nullptr);
ASSERT_EQ(array[4], nullptr);
ASSERT_EQ(capacity, 5);
util_free_array(array);
array = nullptr;
capacity = 0;
capacity = 1;
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
ASSERT_NE(array, nullptr);
ret = util_grow_array(&array, &capacity, 1, 0);
ASSERT_NE(ret, 0);
util_free_array(array);
array = nullptr;
capacity = 0;
capacity = 1;
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
ASSERT_NE(array, nullptr);
ret = util_grow_array(&array, &capacity, 4, 1);
ASSERT_EQ(ret, 0);
ASSERT_NE(array, nullptr);
ASSERT_EQ(array[0], nullptr);
ASSERT_EQ(array[1], nullptr);
ASSERT_EQ(array[2], nullptr);
ASSERT_EQ(array[3], nullptr);
ASSERT_EQ(array[4], nullptr);
ASSERT_EQ(capacity, 5);
util_free_array(array);
array = nullptr;
capacity = 0;
capacity = 1;
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
ASSERT_NE(array, nullptr);
ret = util_grow_array(&array, &capacity, 0, 1);
ASSERT_EQ(ret, 0);
ASSERT_NE(array, nullptr);
ASSERT_EQ(array[0], nullptr);
ASSERT_EQ(capacity, 1);
util_free_array(array);
array = nullptr;
capacity = 0;
capacity = 1;
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
ASSERT_NE(array, nullptr);
ret = util_grow_array(&array, nullptr, 1, 1);
ASSERT_NE(ret, 0);
util_free_array(array);
array = nullptr;
capacity = 0;
capacity = 1;
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
ASSERT_NE(array, nullptr);
ret = util_grow_array(nullptr, &capacity, 1, 1);
ASSERT_NE(ret, 0);
util_free_array(array);
array = nullptr;
capacity = 0;
capacity = 1;
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
ASSERT_NE(array, nullptr);
MOCK_SET(memcpy_s, EINVAL);
ret = util_grow_array(&array, &capacity, 1, 1);
ASSERT_NE(ret, 0);
MOCK_CLEAR(memcpy_s);
util_free_array(array);
array = nullptr;
capacity = 0;
}
TEST(utils_array, test_util_array_append)
{
char **array = NULL;
char **array_three = NULL;
int ret;
ret = util_array_append(&array, "1234567890");
ASSERT_EQ(ret, 0);
ASSERT_STREQ(array[0], "1234567890");
ASSERT_EQ(array[1], nullptr);
util_free_array(array);
array = nullptr;
ret = util_array_append(&array, "");
ASSERT_EQ(ret, 0);
ASSERT_STREQ(array[0], "");
ASSERT_EQ(array[1], nullptr);
util_free_array(array);
array = nullptr;
ret = util_array_append(&array, nullptr);
ASSERT_NE(ret, 0);
array_three = (char **)util_common_calloc_s(4 * sizeof(char *));
ASSERT_NE(array_three, nullptr);
array_three[0] = util_strdup_s("test1");
array_three[1] = util_strdup_s("test2");
array_three[2] = util_strdup_s("test3");
array_three[3] = nullptr;
ret = util_array_append(&array_three, "1234567890");
ASSERT_EQ(ret, 0);
ASSERT_STREQ(array_three[0], "test1");
ASSERT_STREQ(array_three[1], "test2");
ASSERT_STREQ(array_three[2], "test3");
ASSERT_STREQ(array_three[3], "1234567890");
ASSERT_EQ(array_three[4], nullptr);
util_free_array(array_three);
array_three = nullptr;
ret = util_array_append(nullptr, "1234567890");
ASSERT_NE(ret, 0);
MOCK_SET(calloc, nullptr);
ret = util_array_append(&array, "");
ASSERT_NE(ret, 0);
MOCK_CLEAR(calloc);
util_free_array(array);
array = nullptr;
array_three = (char **)util_common_calloc_s(4 * sizeof(char *));
ASSERT_NE(array_three, nullptr);
array_three[0] = util_strdup_s("test1");
array_three[1] = util_strdup_s("test2");
array_three[2] = util_strdup_s("test3");
array_three[3] = nullptr;
MOCK_SET(memcpy_s, EINVAL);
ret = util_array_append(&array_three, "123");
ASSERT_NE(ret, 0);
MOCK_CLEAR(memcpy_s);
util_free_array(array_three);
array_three = nullptr;
}

View File

@ -0,0 +1,26 @@
project(iSulad_LLT)
SET(EXE utils_convert_llt)
add_executable(${EXE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/log.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_string.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_array.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_convert.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_verify.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256/sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/path.c
${CMAKE_BINARY_DIR}/json/json_common.c
utils_convert_llt.cc)
target_include_directories(${EXE} PUBLIC
${GTEST_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../src
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils
${CMAKE_BINARY_DIR}/json
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)

View File

@ -0,0 +1,242 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
* Description: utils_convert llt
* Author: tanyifeng
* Create: 2019-07-08
*/
#include <stdlib.h>
#include <stdio.h>
#include <climits>
#include <securec.h>
#include <gtest/gtest.h>
#include "mock.h"
#include "utils_convert.h"
TEST(utils_convert, test_util_safe_u16)
{
int ret;
uint16_t converted;
ret = util_safe_u16("255", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, 255);
ret = util_safe_u16("255", NULL);
ASSERT_NE(ret, 0);
ret = util_safe_u16("-1", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_u16("0", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, 0);
ret = util_safe_u16("1.23", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_u16("1x", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_u16(std::to_string((long long)UINT16_MAX + 1).c_str(), &converted);
ASSERT_NE(ret, 0);
ret = util_safe_u16("NULL", &converted);
ASSERT_NE(ret, 0);
}
TEST(utils_convert, test_util_safe_int)
{
int ret;
int converted;
ret = util_safe_int("123456", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, 123456);
ret = util_safe_int("123456", NULL);
ASSERT_NE(ret, 0);
ret = util_safe_int("-123456", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, -123456);
ret = util_safe_int("0", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, 0);
ret = util_safe_int("1.23", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_int("1x", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_int(std::to_string((long long)INT_MIN - 1).c_str(), &converted);
ASSERT_NE(ret, 0);
ret = util_safe_int(std::to_string((long long)INT_MAX + 1).c_str(), &converted);
ASSERT_NE(ret, 0);
ret = util_safe_int("NULL", &converted);
ASSERT_NE(ret, 0);
}
TEST(utils_convert, test_util_safe_uint)
{
int ret;
unsigned int converted;
ret = util_safe_uint("123456", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, 123456);
ret = util_safe_uint("123456", NULL);
ASSERT_NE(ret, 0);
ret = util_safe_uint("-123456", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_uint("0", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, 0);
ret = util_safe_uint("1.23", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_uint("1x", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_uint(std::to_string((long long)UINT_MAX + 1).c_str(), &converted);
ASSERT_NE(ret, 0);
ret = util_safe_uint("NULL", &converted);
ASSERT_NE(ret, 0);
}
TEST(utils_convert, test_util_safe_llong)
{
int ret;
long long converted;
ret = util_safe_llong("123456", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, 123456);
ret = util_safe_llong("123456", NULL);
ASSERT_NE(ret, 0);
ret = util_safe_llong("-123456", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, -123456);
ret = util_safe_llong("0", &converted);
ASSERT_EQ(ret, 0);
ASSERT_EQ(converted, 0);
ret = util_safe_llong("1.23", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_llong("1x", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_llong("-9223372036854775809", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_llong("9223372036854775808", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_llong("NULL", &converted);
ASSERT_NE(ret, 0);
}
TEST(utils_convert, test_util_safe_strtod)
{
int ret;
double converted;
ret = util_safe_strtod("123456", &converted);
ASSERT_EQ(ret, 0);
ASSERT_DOUBLE_EQ(converted, 123456);
ret = util_safe_strtod("123456", NULL);
ASSERT_NE(ret, 0);
ret = util_safe_strtod("-123456", &converted);
ASSERT_EQ(ret, 0);
ASSERT_DOUBLE_EQ(converted, -123456);
ret = util_safe_strtod("0", &converted);
ASSERT_EQ(ret, 0);
ASSERT_DOUBLE_EQ(converted, 0);
ret = util_safe_strtod("123.456", &converted);
ASSERT_EQ(ret, 0);
ASSERT_DOUBLE_EQ(converted, 123.456);
ret = util_safe_strtod("1x", &converted);
ASSERT_NE(ret, 0);
ret = util_safe_strtod("NULL", &converted);
ASSERT_NE(ret, 0);
}
TEST(utils_convert, test_util_str_to_bool)
{
int ret;
bool converted;
ret = util_str_to_bool("1", &converted);
ASSERT_EQ(ret, 0);
ASSERT_TRUE(converted);
ret = util_str_to_bool("1", NULL);
ASSERT_NE(ret, 0);
ret = util_str_to_bool("t", &converted);
ASSERT_EQ(ret, 0);
ASSERT_TRUE(converted);
ret = util_str_to_bool("T", &converted);
ASSERT_EQ(ret, 0);
ASSERT_TRUE(converted);
ret = util_str_to_bool("true", &converted);
ASSERT_EQ(ret, 0);
ASSERT_TRUE(converted);
ret = util_str_to_bool("True", &converted);
ASSERT_EQ(ret, 0);
ASSERT_TRUE(converted);
ret = util_str_to_bool("0", &converted);
ASSERT_EQ(ret, 0);
ASSERT_FALSE(converted);
ret = util_str_to_bool("f", &converted);
ASSERT_EQ(ret, 0);
ASSERT_FALSE(converted);
ret = util_str_to_bool("F", &converted);
ASSERT_EQ(ret, 0);
ASSERT_FALSE(converted);
ret = util_str_to_bool("false", &converted);
ASSERT_EQ(ret, 0);
ASSERT_FALSE(converted);
ret = util_str_to_bool("FALSE", &converted);
ASSERT_EQ(ret, 0);
ASSERT_FALSE(converted);
ret = util_str_to_bool("False", &converted);
ASSERT_EQ(ret, 0);
ASSERT_FALSE(converted);
ret = util_str_to_bool("x", &converted);
ASSERT_NE(ret, 0);
ret = util_str_to_bool("NULL", &converted);
ASSERT_NE(ret, 0);
}

View File

@ -16,6 +16,7 @@ add_executable(${EXE}
utils_string_llt.cc) utils_string_llt.cc)
target_include_directories(${EXE} PUBLIC target_include_directories(${EXE} PUBLIC
${GTEST_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../include ${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../src ${CMAKE_CURRENT_SOURCE_DIR}/../../../src
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256 ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256

View File

@ -1,5 +1,13 @@
/* /*
* Copyright (c) Huawei Technologies Co., Ltd. 2016-2019. All rights reserved. * Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
* iSulad licensed under the Mulan PSL v1. * iSulad licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of 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: * You may obtain a copy of Mulan PSL v1 at:

View File

@ -0,0 +1,3 @@
project(iSulad_LLT)
add_subdirectory(oci)

View File

@ -0,0 +1,8 @@
project(iSulad_LLT)
add_subdirectory(oci_config_merge)
add_subdirectory(oci_rootfs_remove)
add_subdirectory(oci_rootfs_mount)
add_subdirectory(oci_rootfs_umount)
add_subdirectory(oci_rootfs_export)
add_subdirectory(oci_rootfs_prepare)

Some files were not shown because too many files have changed in this diff Show More