History

use subprocess for git fetching

Noam Preil committed 5 years agomaster

Commit 62c9fc11 parent d61e0ed1 file · +26 −11Browse files

Unified · Split

src.c+26−11
@@ -10,36 +10,51 @@ typedef struct Exec Exec; · 9 unmodified lines
1010 struct Exec {
1111 char *file;
1212 char **argv;
13− Channel *pid;
13+ Channel *pidch;
1414 };
1515
1616 void
1717 pexec(void *args)
1818 {
1919 Exec *e = args;
20− procexec(e->pid, e->file, e->argv);
20+ procexec(e->pidch, e->file, e->argv);
2121 }
2222
2323 static int
2424 fetchgit(char *url, char *rev, char *dir)
2525 {
26− char *argv[] = {"rc", "-c", nil, nil};
2726 Exec e;
27+ char *argv[] = {"rc", "-c", smprint("git/clone %s %s", url, dir), nil};
28+ Channel *c = threadwaitchan();
29+ Waitmsg *w;
30+ int pid, rpid;
2831
29− e.file = "/bin/rc";
3032 e.argv = argv;
31− e.pid = nil;
32− if(rev == nil)
33− argv[2] = smprint("git/clone %s %s", url, dir);
34− else{
33+ e.file = "/bin/rc";
34+ e.pidch = chancreate(sizeof(int), 0);
35+
36+ if(rev != nil){
37+ free(argv[2]);
3538 fprint(2, "FIXME git/clone %s rev %s\n", url, dir);
3639 return -1;
3740 }
3841
39− pexec(&e);
42+ procrfork(pexec, &e, 0x2000, RFFDG);
43+ recv(e.pidch, &pid);
44+ chanfree(e.pidch);
45+ if(pid < 0){
46+ fprint(2, "failed to spawn process\n");
47+ return -1;
48+ }
49+ w = recvp(c);
4050 free(argv[2]);
41−
42− return -1;
51+ if(w == nil){
52+ fprint(2, "Receiving pid failed\n");
53+ return -1;
54+ }
55+ rpid = w->pid;
56+ free(w);
57+ return rpid == pid;
4358 }
4459
4560 int

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t