summaryrefslogtreecommitdiffstats
path: root/src/util/child_common.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2015-01-07 10:36:12 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-01-13 17:45:19 +0100
commit16cb0969f0a9ea71524d852077d6a480740d4f12 (patch)
treee9783c109010476b0c795cd55e76de60f9b2268f /src/util/child_common.c
parentbb7ddd2be9847bfb07395341c7623da1b104b8a6 (diff)
downloadsssd-16cb0969f0a9ea71524d852077d6a480740d4f12.tar.gz
sssd-16cb0969f0a9ea71524d852077d6a480740d4f12.tar.xz
sssd-16cb0969f0a9ea71524d852077d6a480740d4f12.zip
UTIL: Allow dup-ing child pipe to a different FD
Related to: https://fedorahosted.org/sssd/ticket/2544 Adds a new function exec_child_ex and moves setting the extra_argv[] to exec_child_ex() along with specifying the input and output fds. Reviewed-by: Sumit Bose <sbose@redhat.com>
Diffstat (limited to 'src/util/child_common.c')
-rw-r--r--src/util/child_common.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/util/child_common.c b/src/util/child_common.c
index d3f488d18..d632cd4ec 100644
--- a/src/util/child_common.c
+++ b/src/util/child_common.c
@@ -729,17 +729,18 @@ fail:
return ret;
}
-errno_t exec_child(TALLOC_CTX *mem_ctx,
- int *pipefd_to_child, int *pipefd_from_child,
- const char *binary, int debug_fd,
- const char *extra_argv[])
+errno_t exec_child_ex(TALLOC_CTX *mem_ctx,
+ int *pipefd_to_child, int *pipefd_from_child,
+ const char *binary, int debug_fd,
+ const char *extra_argv[],
+ int child_in_fd, int child_out_fd)
{
int ret;
errno_t err;
char **argv;
close(pipefd_to_child[1]);
- ret = dup2(pipefd_to_child[0], STDIN_FILENO);
+ ret = dup2(pipefd_to_child[0], child_in_fd);
if (ret == -1) {
err = errno;
DEBUG(SSSDBG_CRIT_FAILURE,
@@ -748,7 +749,7 @@ errno_t exec_child(TALLOC_CTX *mem_ctx,
}
close(pipefd_from_child[0]);
- ret = dup2(pipefd_from_child[1], STDOUT_FILENO);
+ ret = dup2(pipefd_from_child[1], child_out_fd);
if (ret == -1) {
err = errno;
DEBUG(SSSDBG_CRIT_FAILURE,
@@ -770,6 +771,15 @@ errno_t exec_child(TALLOC_CTX *mem_ctx,
return err;
}
+errno_t exec_child(TALLOC_CTX *mem_ctx,
+ int *pipefd_to_child, int *pipefd_from_child,
+ const char *binary, int debug_fd)
+{
+ return exec_child_ex(mem_ctx, pipefd_to_child, pipefd_from_child,
+ binary, debug_fd, NULL,
+ STDIN_FILENO, STDOUT_FILENO);
+}
+
void child_cleanup(int readfd, int writefd)
{
int ret;