Added syncing and working directory param to execute
This commit is contained in:
11
src/utils.c
11
src/utils.c
@@ -222,7 +222,7 @@ result_t parse_size(uint64_t* _size, const char* str) {
|
||||
}
|
||||
}
|
||||
|
||||
result_t execute(int* _exit_code, char** _stdoutbuf, char** _stderrbuf, const char* executable, ...) {
|
||||
result_t execute(int* _exit_code, char** _stdoutbuf, char** _stderrbuf, const char* working_directory, const char* executable, ...) {
|
||||
// Initialize the output parameters
|
||||
if (_exit_code != NULL)
|
||||
*_exit_code = 0;
|
||||
@@ -325,6 +325,15 @@ result_t execute(int* _exit_code, char** _stdoutbuf, char** _stderrbuf, const ch
|
||||
close(stdout_pipe[1]);
|
||||
close(stderr_pipe[1]);
|
||||
|
||||
// Change the working directory of the child process
|
||||
if (working_directory != NULL) {
|
||||
errno = 0;
|
||||
if (chdir(working_directory) < 0) {
|
||||
fprintf(stderr, "Failed to change the working directory of the child process (%s).\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the child process
|
||||
errno = 0;
|
||||
execvp(executable, argv);
|
||||
|
Reference in New Issue
Block a user