test_child_common.c revision 44703b84feaafa4f0a4f8df11c5a503dcf48616e
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes Jakub Hrozek <jhrozek@redhat.com>
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes Copyright (C) 2014 Red Hat
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes SSSD tests: Child handlers
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes This program is free software; you can redistribute it and/or modify
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes it under the terms of the GNU General Public License as published by
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes the Free Software Foundation; either version 3 of the License, or
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes (at your option) any later version.
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes This program is distributed in the hope that it will be useful,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes but WITHOUT ANY WARRANTY; without even the implied warranty of
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes GNU General Public License for more details.
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes You should have received a copy of the GNU General Public License
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes along with this program. If not, see <http://www.gnu.org/licenses/>.
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes child_tctx = talloc(global_talloc_context, struct child_test_ctx);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes child_tctx->test_ctx = create_ev_test_ctx(child_tctx);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes struct child_test_ctx *child_tctx = talloc_get_type(*state,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes/* Just make sure the exec works. The child does nothing but exits */
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes struct child_test_ctx *child_tctx = talloc_get_type(*state,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes/* Make sure extra arguments are passed correctly */
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes struct child_test_ctx *child_tctx = talloc_get_type(*state,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes "--drums=ringo",
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes setenv("TEST_CHILD_ACTION", "check_extra_args", 1);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesstruct tevent_req *echo_child_write_send(TALLOC_CTX *mem_ctx,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes const char *input);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesstatic void echo_child_write_done(struct tevent_req *subreq);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesstatic void echo_child_read_done(struct tevent_req *subreq);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes/* Test that writing to the pipes works as expected */
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes struct child_test_ctx *child_tctx = talloc_get_type(*state,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes talloc_set_destructor((void *) io_fds, child_io_destructor);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes io_fds->read_from_child_fd = child_tctx->pipefd_from_child[0];
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes io_fds->write_to_child_fd = child_tctx->pipefd_to_child[1];
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes/* Test that writing to the pipes works as expected */
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes struct child_test_ctx *child_tctx = talloc_get_type(*state,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ret = child_handler_setup(child_tctx->test_ctx->ev, child_pid,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes struct child_test_ctx *child_ctx = talloc_get_type(pvt, struct child_test_ctx);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes if (WIFEXITED(child_status) && WEXITSTATUS(child_status) == 0) {
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes/* Test that writing to the pipes works as expected */
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes struct child_test_ctx *child_tctx = talloc_get_type(*state,
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes talloc_set_destructor((void *) io_fds, child_io_destructor);
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes DEBUG(SSSDBG_FUNC_DATA, "Forked into %d\n", child_pid);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes io_fds->read_from_child_fd = child_tctx->pipefd_from_child[0];
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes io_fds->write_to_child_fd = child_tctx->pipefd_to_child[1];
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ret = child_handler_setup(child_tctx->test_ctx->ev, child_pid,
struct test_exec_echo_state {
const char *input)
return req;
struct child_test_ctx);
if (child_pid == 0) {
int rv;
int opt;
switch(opt) {
return rv;