[lxc-devel] [lxc/master] commands: always return -1 on lxc_cmd_get_init_pid() err
brauner on Github
lxc-bot at linuxcontainers.org
Tue Aug 28 18:14:29 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180828/ed1b94eb/attachment.bin>
-------------- next part --------------
From 8ed8a6265bcd8958f0d026b2168bd6ee2ea61b68 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 25 Aug 2018 06:17:49 +0200
Subject: [PATCH 1/4] commands: return -1 on lxc_cmd_get_init_pid() err
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
A while back the whole lxc_cmd() infrastructure was changed to return
meaningful negative error codes. But lxc_cmd_get_init_pid() should always
return -1. Make it so!
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
Reported-by: Stéphane Graber <stgraber at ubuntu.com>
---
src/lxc/commands.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 30d6b6047..63a8949a6 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -381,7 +381,7 @@ pid_t lxc_cmd_get_init_pid(const char *name, const char *lxcpath)
ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
if (ret < 0)
- return ret;
+ return -1;
return PTR_TO_INT(cmd.rsp.data);
}
From c8208ff034ed15f675ad1d707c15b5719d018685 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 25 Aug 2018 06:36:12 +0200
Subject: [PATCH 2/4] tests: add basic.c
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/tests/Makefile.am | 4 +++-
src/tests/basic.c | 46 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
create mode 100644 src/tests/basic.c
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index e51efafd8..f891bddf0 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -2,6 +2,7 @@ if ENABLE_TESTS
LDADD = ../lxc/liblxc.la
+lxc_test_basic_SOURCES = basic.c
lxc_test_containertests_SOURCES = containertests.c
lxc_test_locktests_SOURCES = locktests.c
lxc_test_startone_SOURCES = startone.c
@@ -66,7 +67,7 @@ bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
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
+ lxc-test-mount-injection lxc-test-basic
bin_SCRIPTS =
if ENABLE_TOOLS
@@ -93,6 +94,7 @@ endif
endif
EXTRA_DIST = \
+ basic.c \
cgpath.c \
clonetest.c \
concurrent.c \
diff --git a/src/tests/basic.c b/src/tests/basic.c
new file mode 100644
index 000000000..4e7a05fe9
--- /dev/null
+++ b/src/tests/basic.c
@@ -0,0 +1,46 @@
+/* liblxcapi
+ *
+ * Copyright © 2018 Christian Brauner <christian.brauner at 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);
+}
From 691544a0e421a99fe2750dacb8cbbc7c5508b5f2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 25 Aug 2018 06:44:36 +0200
Subject: [PATCH 3/4] tests: cleanup Makefile
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/tests/Makefile.am | 226 +++++++++++++++++++++++-------------------
1 file changed, 123 insertions(+), 103 deletions(-)
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index f891bddf0..059de8994 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -2,52 +2,52 @@ if ENABLE_TESTS
LDADD = ../lxc/liblxc.la
+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_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_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
@@ -57,85 +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 lxc-test-basic
+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 = \
- 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
+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-*
From e8cd1208869322472467311ef4ccc4a236124a5a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 25 Aug 2018 07:01:26 +0200
Subject: [PATCH 4/4] commands: ensure -1 is sent on EPIPE for init pid
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
Reported-by: Stéphane Graber <stgraber at ubuntu.com>
---
src/lxc/commands.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 63a8949a6..5aad2432d 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -376,7 +376,12 @@ 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);
More information about the lxc-devel
mailing list