aboutsummaryrefslogtreecommitdiffstats
path: root/connect.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2017-11-20 13:22:54 -0800
committerJunio C Hamano <gitster@pobox.com>2017-11-21 14:01:02 +0900
commit8e349780ecb9bcec52c7df22fcbfb4afd0d7936c (patch)
tree5fb040204fb6d89cd332a8fdc77231f98f8db9b2 /connect.c
parent8339805b467ca5b2d9314fdbfdd75a6e96c6b39a (diff)
downloadgit-8e349780ecb9bcec52c7df22fcbfb4afd0d7936c.tar.gz
connect: move no_fork fallback to git_tcp_connect
git_connect has the structure struct child_process *conn = &no_fork; ... switch (protocol) { case PROTO_GIT: if (git_use_proxy(hostandport)) conn = git_proxy_connect(fd, hostandport); else git_tcp_connect(fd, hostandport, flags); ... break; case PROTO_SSH: conn = xmalloc(sizeof(*conn)); child_process_init(conn); argv_array_push(&conn->args, ssh); ... break; ... return conn; In all cases except the git_tcp_connect case, conn is explicitly assigned a value. Make the code clearer by explicitly assigning 'conn = &no_fork' in the tcp case and eliminating the default so the compiler can ensure conn is always correctly assigned. Noticed-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/connect.c b/connect.c
index 7fbd396b35..aa994d1518 100644
--- a/connect.c
+++ b/connect.c
@@ -582,12 +582,25 @@ static int git_tcp_connect_sock(char *host, int flags)
#endif /* NO_IPV6 */
-static void git_tcp_connect(int fd[2], char *host, int flags)
+/*
+ * Dummy child_process returned by git_connect() if the transport protocol
+ * does not need fork(2).
+ */
+static struct child_process no_fork = CHILD_PROCESS_INIT;
+
+int git_connection_is_socket(struct child_process *conn)
+{
+ return conn == &no_fork;
+}
+
+static struct child_process *git_tcp_connect(int fd[2], char *host, int flags)
{
int sockfd = git_tcp_connect_sock(host, flags);
fd[0] = sockfd;
fd[1] = dup(sockfd);
+
+ return &no_fork;
}
@@ -761,8 +774,6 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
return protocol;
}
-static struct child_process no_fork = CHILD_PROCESS_INIT;
-
static const char *get_ssh_command(void)
{
const char *ssh;
@@ -851,11 +862,11 @@ static enum ssh_variant determine_ssh_variant(const char *ssh_command,
}
/*
- * This returns a dummy child_process if the transport protocol does not
- * need fork(2), or a struct child_process object if it does. Once done,
- * finish the connection with finish_connect() with the value returned from
- * this function (it is safe to call finish_connect() with NULL to support
- * the former case).
+ * This returns the dummy child_process `no_fork` if the transport protocol
+ * does not need fork(2), or a struct child_process object if it does. Once
+ * done, finish the connection with finish_connect() with the value returned
+ * from this function (it is safe to call finish_connect() with NULL to
+ * support the former case).
*
* If it returns, the connect is successful; it just dies on errors (this
* will hopefully be changed in a libification effort, to return NULL when
@@ -865,7 +876,7 @@ struct child_process *git_connect(int fd[2], const char *url,
const char *prog, int flags)
{
char *hostandport, *path;
- struct child_process *conn = &no_fork;
+ struct child_process *conn;
enum protocol protocol;
/* Without this we cannot rely on waitpid() to tell
@@ -901,7 +912,7 @@ struct child_process *git_connect(int fd[2], const char *url,
if (git_use_proxy(hostandport))
conn = git_proxy_connect(fd, hostandport);
else
- git_tcp_connect(fd, hostandport, flags);
+ conn = git_tcp_connect(fd, hostandport, flags);
/*
* Separate original protocol components prog and path
* from extended host header with a NUL byte.
@@ -1041,11 +1052,6 @@ struct child_process *git_connect(int fd[2], const char *url,
return conn;
}
-int git_connection_is_socket(struct child_process *conn)
-{
- return conn == &no_fork;
-}
-
int finish_connect(struct child_process *conn)
{
int code;