aboutsummaryrefslogtreecommitdiff
path: root/builtin-send-pack.c
diff options
context:
space:
mode:
authorJohannes Sixt <johannes.sixt@telecom.at>2008-02-21 23:42:56 +0100
committerJunio C Hamano <gitster@pobox.com>2008-02-23 11:59:44 -0800
commitc20181e3a3e39f2c8874567c219e9edddb84393a (patch)
treecd00a4c57338a71f2b77a0c795b8fed0a5007ba5 /builtin-send-pack.c
parente72ae28895b22052b7ca2eef36c039ac62671f7d (diff)
downloadgit-c20181e3a3e39f2c8874567c219e9edddb84393a.tar.gz
git-c20181e3a3e39f2c8874567c219e9edddb84393a.tar.xz
start_command(), if .in/.out > 0, closes file descriptors, not the callers
Callers of start_command() can set the members .in and .out of struct child_process to a value > 0 to specify that this descriptor is used as the stdin or stdout of the child process. Previously, if start_command() was successful, this descriptor was closed upon return. Here we now make sure that the descriptor is also closed in case of failures. All callers are updated not to close the file descriptor themselves after start_command() was called. Note that earlier run_gpg_verify() of git-verify-tag set .out = 1, which worked because start_command() treated this as a special case, but now this is incorrect because it closes the descriptor. The intent here is to inherit stdout to the child, which is achieved by .out = 0. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-send-pack.c')
-rw-r--r--builtin-send-pack.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/builtin-send-pack.c b/builtin-send-pack.c
index ba9bc91a5..b0cfae83f 100644
--- a/builtin-send-pack.c
+++ b/builtin-send-pack.c
@@ -404,12 +404,15 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
if (!remote_tail)
remote_tail = &remote_refs;
if (match_refs(local_refs, remote_refs, &remote_tail,
- nr_refspec, refspec, flags))
+ nr_refspec, refspec, flags)) {
+ close(out);
return -1;
+ }
if (!remote_refs) {
fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
"Perhaps you should specify a branch such as 'master'.\n");
+ close(out);
return 0;
}
@@ -496,12 +499,11 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
packet_flush(out);
if (new_refs && !args.dry_run) {
- if (pack_objects(out, remote_refs) < 0) {
- close(out);
+ if (pack_objects(out, remote_refs) < 0)
return -1;
- }
}
- close(out);
+ else
+ close(out);
if (expect_status_report)
ret = receive_status(in, remote_refs);
@@ -649,7 +651,7 @@ int send_pack(struct send_pack_args *my_args,
conn = git_connect(fd, dest, args.receivepack, args.verbose ? CONNECT_VERBOSE : 0);
ret = do_send_pack(fd[0], fd[1], remote, dest, nr_heads, heads);
close(fd[0]);
- close(fd[1]);
+ /* do_send_pack always closes fd[1] */
ret |= finish_connect(conn);
return !!ret;
}