@matheusbsbs / matheus-bagliano / commits / f42a5c4eb0
Fork 0

connect.c: finish_connect(): allow null pid parameter

git_connect() can return 0 if we use git protocol for example. Users of this function don't know and don't care if a process had been created or not, and to avoid them to check it before calling finish_connect() this patch allows finish_connect() to take a null pid. And in that case return 0. [jc: updated function signature of git_connect() with a comment on its return value. ] Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Franck Bui-Huu committed Sep 12, 2006 at 11:00 UTC f42a5c4eb0453cd33276e078cd7541b1ef25b2c4
2 files changed +12 -3
cache.h
+1 -1
@@ -359,7 +359,7 @@ struct ref {
359 #define REF_HEADS (1u << 1)
360 #define REF_TAGS (1u << 2)
361
362 -extern int git_connect(int fd[2], char *url, const char *prog);
362 +extern pid_t git_connect(int fd[2], char *url, const char *prog);
363 extern int finish_connect(pid_t pid);
364 extern int path_match(const char *path, int nr, char **match);
365 extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
connect.c
+11 -2
@@ -602,9 +602,15 @@ static void git_proxy_connect(int fd[2], char *host)
602 #define MAX_CMD_LEN 1024
603
604 /*
605 - * Yeah, yeah, fixme. Need to pass in the heads etc.
605 + * This returns 0 if the transport protocol does not need fork(2),
606 + * or a process id if it does. Once done, finish the connection
607 + * with finish_connect() with the value returned from this function
608 + * (it is safe to call finish_connect() with 0 to support the former
609 + * case).
610 + *
611 + * Does not return a negative value on error; it just dies.
612 */
607 -int git_connect(int fd[2], char *url, const char *prog)
613 +pid_t git_connect(int fd[2], char *url, const char *prog)
614 {
615 char *host, *path = url;
616 char *end;
@@ -748,6 +754,9 @@ int git_connect(int fd[2], char *url, const char *prog)
754
755 int finish_connect(pid_t pid)
756 {
757 + if (pid == 0)
758 + return 0;
759 +
760 while (waitpid(pid, NULL, 0) < 0) {
761 if (errno != EINTR)
762 return -1;