summaryrefslogtreecommitdiffstats
path: root/credential-cache--daemon.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-03-18 02:12:01 -0400
committerJunio C Hamano <gitster@pobox.com>2016-03-18 14:48:36 -0700
commit7d5e9c9849a809ff70223037bf6d569a8e2d3e66 (patch)
tree7a11c13e1d37601d1a05bbb5ed3293931a079eba /credential-cache--daemon.c
parent937978e0f3e750d917768c77665d5f8cfbd802b6 (diff)
downloadgit-7d5e9c9849a809ff70223037bf6d569a8e2d3e66.tar.gz
git-7d5e9c9849a809ff70223037bf6d569a8e2d3e66.tar.xz
credential-cache--daemon: clarify "exit" action semantics
When this code was originally written, there wasn't much thought given to the timing between a client asking for "exit", the daemon signaling that the action is done (with EOF), and the actual cleanup of the socket. However, we need to care about this so that our test scripts do not end up racy (e.g., by asking for an exit and checking that the socket was cleaned up). The code that is already there happens to behave very reasonably; let's add a comment to make it clear that any changes should retain the same behavior. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'credential-cache--daemon.c')
-rw-r--r--credential-cache--daemon.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index 9365f2ce5..8a3d0b7e2 100644
--- a/credential-cache--daemon.c
+++ b/credential-cache--daemon.c
@@ -126,8 +126,17 @@ static void serve_one_client(FILE *in, FILE *out)
fprintf(out, "password=%s\n", e->item.password);
}
}
- else if (!strcmp(action.buf, "exit"))
+ else if (!strcmp(action.buf, "exit")) {
+ /*
+ * It's important that we clean up our socket first, and then
+ * signal the client only once we have finished the cleanup.
+ * Calling exit() directly does this, because we clean up in
+ * our atexit() handler, and then signal the client when our
+ * process actually ends, which closes the socket and gives
+ * them EOF.
+ */
exit(0);
+ }
else if (!strcmp(action.buf, "erase"))
remove_credential(&c);
else if (!strcmp(action.buf, "store")) {