diff options
Diffstat (limited to 'src/fetch_git.c')
| -rw-r--r-- | src/fetch_git.c | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/src/fetch_git.c b/src/fetch_git.c index 85275d3..deb94ac 100644 --- a/src/fetch_git.c +++ b/src/fetch_git.c @@ -1,3 +1,4 @@ +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -8,31 +9,39 @@ #include "vars.h" int fetch_git(Pkg pkg) { - pid_t pid = fork(); - if (pid == 0) { - const char *argv[8]; - int i = 0; - argv[i++] = "git"; - argv[i++] = "-c"; - argv[i++] = "advice.detachedHead=false"; - argv[i++] = "clone"; - if (strcmp(pkg.ver, "HEAD") != 0) { - argv[i++] = "--branch"; - argv[i++] = pkg.ver; - } - argv[i++] = pkg.url; - argv[i++] = pkg.src; - argv[i] = NULL; - execvp("git", (char *const *)argv); - _exit(127); + pid_t pid = fork(); + if (pid == 0) { + if (!is_verbose) { + int nullfd = open("/dev/null", O_WRONLY); + if (nullfd >= 0) { + dup2(nullfd, STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); + close(nullfd); + } } - - int status; - waitpid(pid, &status, 0); - int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1; - if (result != 0) { - printf("clone failed\n"); + const char *argv[8]; + int i = 0; + argv[i++] = "git"; + argv[i++] = "-c"; + argv[i++] = "advice.detachedHead=false"; + argv[i++] = "clone"; + if (strcmp(pkg.ver, "HEAD") != 0) { + argv[i++] = "--branch"; + argv[i++] = pkg.ver; } + argv[i++] = pkg.url; + argv[i++] = pkg.src; + argv[i] = NULL; + execvp("git", (char *const *)argv); + _exit(127); + } + + int status; + waitpid(pid, &status, 0); + int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1; + if (result != 0) { + printf("clone failed\n"); + } - return result; + return result; }
\ No newline at end of file |
