summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2016-05-17 11:52:00 +0200
committerLukas Slebodnik <lslebodn@redhat.com>2016-05-19 13:56:57 +0200
commitde8815aba87d08b6b7ac5d502dcb1755787e0857 (patch)
tree32a7cf823321aa6ff5af4173d6613b06d89244ca /src/tests
parentc2e3176eaff7c219d63f328570a79f6e5b6f4aec (diff)
downloadsssd-de8815aba87d08b6b7ac5d502dcb1755787e0857.tar.gz
sssd-de8815aba87d08b6b7ac5d502dcb1755787e0857.tar.xz
sssd-de8815aba87d08b6b7ac5d502dcb1755787e0857.zip
UTIL: exit() the forked process if exec()-ing a child process fails
When exec() fails, we should not attempt to continue, but just kill the forked process. The patch adds this logic to the exec_child() and exec_child_ex() functions to avoid code duplication Resolves: https://fedorahosted.org/sssd/ticket/3016 Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/cmocka/test_child_common.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/tests/cmocka/test_child_common.c b/src/tests/cmocka/test_child_common.c
index be842c4f5..ae696e771 100644
--- a/src/tests/cmocka/test_child_common.c
+++ b/src/tests/cmocka/test_child_common.c
@@ -94,11 +94,10 @@ void test_exec_child(void **state)
child_pid = fork();
assert_int_not_equal(child_pid, -1);
if (child_pid == 0) {
- ret = exec_child(child_tctx,
- child_tctx->pipefd_to_child,
- child_tctx->pipefd_from_child,
- CHILD_DIR"/"TEST_BIN, 2);
- assert_int_equal(ret, EOK);
+ exec_child(child_tctx,
+ child_tctx->pipefd_to_child,
+ child_tctx->pipefd_from_child,
+ CHILD_DIR"/"TEST_BIN, 2);
} else {
do {
errno = 0;
@@ -166,13 +165,12 @@ static void extra_args_test(struct child_test_ctx *child_tctx,
if (child_pid == 0) {
debug_timestamps = 1;
- ret = exec_child_ex(child_tctx,
- child_tctx->pipefd_to_child,
- child_tctx->pipefd_from_child,
- CHILD_DIR"/"TEST_BIN, 2, extra_args,
- extra_args_only,
- STDIN_FILENO, STDOUT_FILENO);
- assert_int_equal(ret, EOK);
+ exec_child_ex(child_tctx,
+ child_tctx->pipefd_to_child,
+ child_tctx->pipefd_from_child,
+ CHILD_DIR"/"TEST_BIN, 2, extra_args,
+ extra_args_only,
+ STDIN_FILENO, STDOUT_FILENO);
} else {
do {
errno = 0;
@@ -290,11 +288,10 @@ void test_exec_child_handler(void **state)
child_pid = fork();
assert_int_not_equal(child_pid, -1);
if (child_pid == 0) {
- ret = exec_child(child_tctx,
- child_tctx->pipefd_to_child,
- child_tctx->pipefd_from_child,
- CHILD_DIR"/"TEST_BIN, 2);
- assert_int_equal(ret, EOK);
+ exec_child(child_tctx,
+ child_tctx->pipefd_to_child,
+ child_tctx->pipefd_from_child,
+ CHILD_DIR"/"TEST_BIN, 2);
}
ret = child_handler_setup(child_tctx->test_ctx->ev, child_pid,
@@ -341,12 +338,11 @@ void test_exec_child_echo(void **state)
child_pid = fork();
assert_int_not_equal(child_pid, -1);
if (child_pid == 0) {
- ret = exec_child_ex(child_tctx,
- child_tctx->pipefd_to_child,
- child_tctx->pipefd_from_child,
- CHILD_DIR"/"TEST_BIN, 2, NULL, false,
- STDIN_FILENO, 3);
- assert_int_equal(ret, EOK);
+ exec_child_ex(child_tctx,
+ child_tctx->pipefd_to_child,
+ child_tctx->pipefd_from_child,
+ CHILD_DIR"/"TEST_BIN, 2, NULL, false,
+ STDIN_FILENO, 3);
}
DEBUG(SSSDBG_FUNC_DATA, "Forked into %d\n", child_pid);
@@ -475,11 +471,10 @@ void test_sss_child(void **state)
child_pid = fork();
assert_int_not_equal(child_pid, -1);
if (child_pid == 0) {
- ret = exec_child(child_tctx,
- child_tctx->pipefd_to_child,
- child_tctx->pipefd_from_child,
- CHILD_DIR"/"TEST_BIN, 2);
- assert_int_equal(ret, EOK);
+ exec_child(child_tctx,
+ child_tctx->pipefd_to_child,
+ child_tctx->pipefd_from_child,
+ CHILD_DIR"/"TEST_BIN, 2);
}
ret = sss_child_register(child_tctx, sc_ctx,