diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2014-12-01 12:25:24 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-12-03 11:02:41 +0100 |
commit | b4f87b42b18888c396e44e7359f7aafb092221bf (patch) | |
tree | 0a59730a50e310e7d5cc8aaaa6b8adc06841065f /src/util/child_common.c | |
parent | e00c2b5ac4963de9521599c88597b7fb97339d0e (diff) | |
download | sssd-b4f87b42b18888c396e44e7359f7aafb092221bf.tar.gz sssd-b4f87b42b18888c396e44e7359f7aafb092221bf.tar.xz sssd-b4f87b42b18888c396e44e7359f7aafb092221bf.zip |
Add extra_args to exec_child()
Related:
https://fedorahosted.org/sssd/ticket/2503
Currently all child processes use the same arguments, the construction
of argv[] is even hardcoded in exec_child(). Add an extra_args[] array
that extends the common set of argvs so that we can have child-specific
arguments. Also adds a unit test.
Reviewed-by: Sumit Bose <sbose@redhat.com>
Diffstat (limited to 'src/util/child_common.c')
-rw-r--r-- | src/util/child_common.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/util/child_common.c b/src/util/child_common.c index cc6a8fa75..9710630f9 100644 --- a/src/util/child_common.c +++ b/src/util/child_common.c @@ -623,6 +623,7 @@ static void child_invoke_callback(struct tevent_context *ev, static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx, int child_debug_fd, const char *binary, + const char *extra_argv[], char ***_argv) { /* @@ -632,6 +633,7 @@ static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx, uint_t argc = 5; char ** argv; errno_t ret = EINVAL; + size_t i; /* Save the current state in case an interrupt changes it */ bool child_debug_to_file = debug_to_file; @@ -642,6 +644,10 @@ static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx, if (child_debug_to_file) argc++; if (child_debug_stderr) argc++; + if (extra_argv) { + for (i = 0; extra_argv[i]; i++) argc++; + } + /* * program name, debug_level, debug_to_file, debug_timestamps, * debug_microseconds and NULL @@ -654,6 +660,17 @@ static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx, argv[--argc] = NULL; + /* Add extra_attrs first */ + if (extra_argv) { + for (i = 0; extra_argv[i]; i++) { + argv[--argc] = talloc_strdup(argv, extra_argv[i]); + if (argv[argc] == NULL) { + ret = ENOMEM; + goto fail; + } + } + } + argv[--argc] = talloc_asprintf(argv, "--debug-level=%#.4x", debug_level); if (argv[argc] == NULL) { @@ -714,7 +731,8 @@ fail: errno_t exec_child(TALLOC_CTX *mem_ctx, int *pipefd_to_child, int *pipefd_from_child, - const char *binary, int debug_fd) + const char *binary, int debug_fd, + const char *extra_argv[]) { int ret; errno_t err; @@ -739,7 +757,8 @@ errno_t exec_child(TALLOC_CTX *mem_ctx, } ret = prepare_child_argv(mem_ctx, debug_fd, - binary, &argv); + binary, extra_argv, + &argv); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "prepare_child_argv.\n"); return ret; |