Unverified Commit de2c6314 by Stéphane Graber Committed by GitHub

Merge pull request #2576 from brauner/2018-08-28/command_init_id

commands: always return -1 on lxc_cmd_get_init_pid() err
parents 7ee4b4b8 e8cd1208
......@@ -376,12 +376,17 @@ pid_t lxc_cmd_get_init_pid(const char *name, const char *lxcpath)
{
int ret, stopped;
struct lxc_cmd_rr cmd = {
.req = { .cmd = LXC_CMD_GET_INIT_PID },
.req = {
.cmd = LXC_CMD_GET_INIT_PID
},
.rsp = {
.data = INT_TO_PTR((int){-1})
}
};
ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
if (ret < 0)
return ret;
return -1;
return PTR_TO_INT(cmd.rsp.data);
}
......
......@@ -2,51 +2,52 @@ if ENABLE_TESTS
LDADD = ../lxc/liblxc.la
lxc_test_containertests_SOURCES = containertests.c
lxc_test_locktests_SOURCES = locktests.c
lxc_test_startone_SOURCES = startone.c
lxc_test_destroytest_SOURCES = destroytest.c
lxc_test_saveconfig_SOURCES = saveconfig.c
lxc_test_createtest_SOURCES = createtest.c
lxc_test_shutdowntest_SOURCES = shutdowntest.c
lxc_test_get_item_SOURCES = get_item.c
lxc_test_getkeys_SOURCES = getkeys.c
lxc_test_lxcpath_SOURCES = lxcpath.c
lxc_test_api_reboot_SOURCES = api_reboot.c
lxc_test_apparmor_SOURCES = aa.c
lxc_test_attach_SOURCES = attach.c
lxc_test_basic_SOURCES = basic.c
lxc_test_cgpath_SOURCES = cgpath.c
lxc_test_clonetest_SOURCES = clonetest.c
lxc_test_concurrent_SOURCES = concurrent.c
lxc_test_config_jump_table_SOURCES = config_jump_table.c lxctest.h
lxc_test_console_SOURCES = console.c
lxc_test_console_log_SOURCES = console_log.c lxctest.h
lxc_test_snapshot_SOURCES = snapshot.c
lxc_test_concurrent_SOURCES = concurrent.c
lxc_test_may_control_SOURCES = may_control.c
lxc_test_reboot_SOURCES = reboot.c
lxc_test_api_reboot_SOURCES = api_reboot.c
lxc_test_list_SOURCES = list.c
lxc_test_attach_SOURCES = attach.c
lxc_test_containertests_SOURCES = containertests.c
lxc_test_createtest_SOURCES = createtest.c
lxc_test_criu_check_feature_SOURCES = criu_check_feature.c lxctest.h
lxc_test_destroytest_SOURCES = destroytest.c
lxc_test_device_add_remove_SOURCES = device_add_remove.c
lxc_test_apparmor_SOURCES = aa.c
lxc_test_utils_SOURCES = lxc-test-utils.c lxctest.h
lxc_test_getkeys_SOURCES = getkeys.c
lxc_test_get_item_SOURCES = get_item.c
lxc_test_list_SOURCES = list.c
lxc_test_locktests_SOURCES = locktests.c
lxc_test_lxcpath_SOURCES = lxcpath.c
lxc_test_may_control_SOURCES = may_control.c
lxc_test_mount_injection_SOURCES = mount_injection.c lxctest.h
lxc_test_parse_config_file_SOURCES = parse_config_file.c lxctest.h
lxc_test_config_jump_table_SOURCES = config_jump_table.c lxctest.h
lxc_test_raw_clone_SOURCES = lxc_raw_clone.c lxctest.h
lxc_test_reboot_SOURCES = reboot.c
lxc_test_saveconfig_SOURCES = saveconfig.c
lxc_test_share_ns_SOURCES = share_ns.c lxctest.h
lxc_test_shortlived_SOURCES = shortlived.c
lxc_test_shutdowntest_SOURCES = shutdowntest.c
lxc_test_snapshot_SOURCES = snapshot.c
lxc_test_startone_SOURCES = startone.c
lxc_test_state_server_SOURCES = state_server.c lxctest.h
lxc_test_share_ns_SOURCES = share_ns.c lxctest.h
lxc_test_criu_check_feature_SOURCES = criu_check_feature.c lxctest.h
lxc_test_raw_clone_SOURCES = lxc_raw_clone.c lxctest.h
lxc_test_mount_injection_SOURCES = mount_injection.c lxctest.h
lxc_test_utils_SOURCES = lxc-test-utils.c lxctest.h
AM_CFLAGS=-DLXCROOTFSMOUNT=\"$(LXCROOTFSMOUNT)\" \
-DLXCPATH=\"$(LXCPATH)\" \
-DLXC_GLOBAL_CONF=\"$(LXC_GLOBAL_CONF)\" \
-DLXCINITDIR=\"$(LXCINITDIR)\" \
-DLXC_DEFAULT_CONFIG=\"$(LXC_DEFAULT_CONFIG)\" \
-DRUNTIME_PATH=\"$(RUNTIME_PATH)\" \
-I $(top_srcdir)/src \
-I $(top_srcdir)/src/lxc \
-I $(top_srcdir)/src/lxc/bdev \
-I $(top_srcdir)/src/lxc/cgroups \
-I $(top_srcdir)/src/lxc/tools \
-pthread
-DLXCPATH=\"$(LXCPATH)\" \
-DLXC_GLOBAL_CONF=\"$(LXC_GLOBAL_CONF)\" \
-DLXCINITDIR=\"$(LXCINITDIR)\" \
-DLXC_DEFAULT_CONFIG=\"$(LXC_DEFAULT_CONFIG)\" \
-DRUNTIME_PATH=\"$(RUNTIME_PATH)\" \
-I $(top_srcdir)/src \
-I $(top_srcdir)/src/lxc \
-I $(top_srcdir)/src/lxc/bdev \
-I $(top_srcdir)/src/lxc/cgroups \
-I $(top_srcdir)/src/lxc/tools \
-pthread
if ENABLE_APPARMOR
AM_CFLAGS += -DHAVE_APPARMOR
......@@ -56,84 +57,105 @@ if ENABLE_SELINUX
AM_CFLAGS += -DHAVE_SELINUX
endif
bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
lxc-test-destroytest lxc-test-saveconfig lxc-test-createtest \
lxc-test-shutdowntest lxc-test-get_item lxc-test-getkeys lxc-test-lxcpath \
lxc-test-cgpath lxc-test-clonetest lxc-test-console lxc-test-console-log \
lxc-test-snapshot lxc-test-concurrent lxc-test-may-control \
lxc-test-reboot lxc-test-list lxc-test-attach lxc-test-device-add-remove \
lxc-test-apparmor lxc-test-utils lxc-test-parse-config-file \
lxc-test-config-jump-table lxc-test-shortlived \
lxc-test-api-reboot lxc-test-state-server lxc-test-share-ns \
lxc-test-criu-check-feature lxc-test-raw-clone \
lxc-test-mount-injection
bin_PROGRAMS = lxc-test-api-reboot \
lxc-test-apparmor \
lxc-test-attach \
lxc-test-basic \
lxc-test-cgpath \
lxc-test-clonetest \
lxc-test-concurrent \
lxc-test-config-jump-table \
lxc-test-console \
lxc-test-console-log \
lxc-test-containertests \
lxc-test-createtest \
lxc-test-criu-check-feature \
lxc-test-destroytest \
lxc-test-device-add-remove \
lxc-test-getkeys \
lxc-test-get_item \
lxc-test-list \
lxc-test-locktests \
lxc-test-lxcpath \
lxc-test-may-control \
lxc-test-mount-injection \
lxc-test-parse-config-file \
lxc-test-raw-clone \
lxc-test-reboot \
lxc-test-saveconfig \
lxc-test-share-ns \
lxc-test-shortlived \
lxc-test-shutdowntest \
lxc-test-snapshot \
lxc-test-startone \
lxc-test-state-server \
lxc-test-utils
bin_SCRIPTS =
if ENABLE_TOOLS
bin_SCRIPTS += lxc-test-automount \
lxc-test-autostart \
lxc-test-cloneconfig \
lxc-test-createconfig \
lxc-test-no-new-privs \
lxc-test-rootfs
lxc-test-autostart \
lxc-test-cloneconfig \
lxc-test-createconfig \
lxc-test-no-new-privs \
lxc-test-rootfs
if DISTRO_UBUNTU
bin_SCRIPTS += \
lxc-test-lxc-attach \
lxc-test-apparmor-mount \
lxc-test-apparmor-generated \
lxc-test-checkpoint-restore \
lxc-test-snapdeps \
lxc-test-symlink \
lxc-test-unpriv \
lxc-test-usernic
bin_SCRIPTS += lxc-test-lxc-attach \
lxc-test-apparmor-mount \
lxc-test-apparmor-generated \
lxc-test-checkpoint-restore \
lxc-test-snapdeps \
lxc-test-symlink \
lxc-test-unpriv \
lxc-test-usernic
endif
endif
endif
EXTRA_DIST = \
cgpath.c \
clonetest.c \
concurrent.c \
config_jump_table.c \
console.c \
console_log.c \
containertests.c \
createtest.c \
criu_check_feature.c \
destroytest.c \
device_add_remove.c \
get_item.c \
getkeys.c \
list.c \
locktests.c \
lxcpath.c \
lxc_raw_clone.c \
lxc-test-lxc-attach \
lxc-test-automount \
lxc-test-rootfs \
lxc-test-autostart \
lxc-test-apparmor-mount \
lxc-test-apparmor-generated \
lxc-test-checkpoint-restore \
lxc-test-cloneconfig \
lxc-test-createconfig \
lxc-test-no-new-privs \
lxc-test-snapdeps \
lxc-test-symlink \
lxc-test-unpriv \
lxc-test-utils.c \
may_control.c \
mount_injection.c \
parse_config_file.c \
saveconfig.c \
shortlived.c \
shutdowntest.c \
snapshot.c \
startone.c \
state_server.c \
share_ns.c
EXTRA_DIST = basic.c \
cgpath.c \
clonetest.c \
concurrent.c \
config_jump_table.c \
console.c \
console_log.c \
containertests.c \
createtest.c \
criu_check_feature.c \
destroytest.c \
device_add_remove.c \
get_item.c \
getkeys.c \
list.c \
locktests.c \
lxcpath.c \
lxc_raw_clone.c \
lxc-test-lxc-attach \
lxc-test-automount \
lxc-test-rootfs \
lxc-test-autostart \
lxc-test-apparmor-mount \
lxc-test-apparmor-generated \
lxc-test-checkpoint-restore \
lxc-test-cloneconfig \
lxc-test-createconfig \
lxc-test-no-new-privs \
lxc-test-snapdeps \
lxc-test-symlink \
lxc-test-unpriv \
lxc-test-utils.c \
may_control.c \
mount_injection.c \
parse_config_file.c \
saveconfig.c \
shortlived.c \
shutdowntest.c \
snapshot.c \
startone.c \
state_server.c \
share_ns.c
clean-local:
rm -f lxc-test-utils-*
......
/* liblxcapi
*
* Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
* Copyright © 2018 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <lxc/lxccontainer.h>
#include "lxctest.h"
int main(int argc, char *argv[])
{
int ret;
struct lxc_container *c;
c = lxc_container_new("init-pid", NULL);
if (!c)
exit(EXIT_FAILURE);
ret = c->init_pid(c);
c->destroy(c);
lxc_container_put(c);
/* Return value needs to be -1. Any other negative error code is to be
* considered invalid.
*/
if (ret != -1)
exit(EXIT_FAILURE);
exit(EXIT_SUCCESS);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment