diff options
Diffstat (limited to 'src/basic/exec-util.c')
-rw-r--r-- | src/basic/exec-util.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/basic/exec-util.c b/src/basic/exec-util.c index 7896f9369..1d45924e4 100644 --- a/src/basic/exec-util.c +++ b/src/basic/exec-util.c @@ -71,11 +71,12 @@ static int do_execute( gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX], void* const callback_args[_STDOUT_CONSUME_MAX], int output_fd, - char *argv[]) { + char *argv[], + char *envp[]) { _cleanup_hashmap_free_free_ Hashmap *pids = NULL; _cleanup_strv_free_ char **paths = NULL; - char **path; + char **path, **e; int r; /* We fork this all off from a child process so that we can somewhat cleanly make @@ -86,7 +87,7 @@ static int do_execute( r = conf_files_list_strv(&paths, NULL, NULL, CONF_FILES_EXECUTABLE|CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED, (const char* const*) directories); if (r < 0) - return r; + return log_error_errno(r, "Failed to enumerate executables: %m"); if (!callbacks) { pids = hashmap_new(NULL); @@ -100,6 +101,10 @@ static int do_execute( if (timeout != USEC_INFINITY) alarm(DIV_ROUND_UP(timeout, USEC_PER_SEC)); + STRV_FOREACH(e, envp) + if (putenv(*e) != 0) + return log_error_errno(errno, "Failed to set environment variable: %m"); + STRV_FOREACH(path, paths) { _cleanup_free_ char *t = NULL; _cleanup_close_ int fd = -1; @@ -170,7 +175,8 @@ int execute_directories( usec_t timeout, gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX], void* const callback_args[_STDOUT_CONSUME_MAX], - char *argv[]) { + char *argv[], + char *envp[]) { char **dirs = (char**) directories; _cleanup_close_ int fd = -1; @@ -201,7 +207,7 @@ int execute_directories( if (r < 0) return r; if (r == 0) { - r = do_execute(dirs, timeout, callbacks, callback_args, fd, argv); + r = do_execute(dirs, timeout, callbacks, callback_args, fd, argv, envp); _exit(r < 0 ? EXIT_FAILURE : EXIT_SUCCESS); } |