blob: 2d9e9a249ba65312fa19b623dc1e899a285a0ebf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include "fetch_git.h"
#include "vars.h"
int fetch_git(Pkg pkg) {
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);
}
}
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++] = "--recursive";
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("%s git clone failed\n", print_warning);
}
return result;
}
|