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>

Jeff King committed Mar 18, 2016 at 02:12 UTC 7d5e9c9849a809ff70223037bf6d569a8e2d3e66
1 file changed +10 -1
credential-cache--daemon.c
+10 -1
@@ -126,8 +126,17 @@ static void serve_one_client(FILE *in, FILE *out)
126 fprintf(out, "password=%s\n", e->item.password);
127 }
128 }
129 - else if (!strcmp(action.buf, "exit"))
129 + else if (!strcmp(action.buf, "exit")) {
130 + /*
131 + * It's important that we clean up our socket first, and then
132 + * signal the client only once we have finished the cleanup.
133 + * Calling exit() directly does this, because we clean up in
134 + * our atexit() handler, and then signal the client when our
135 + * process actually ends, which closes the socket and gives
136 + * them EOF.
137 + */
138 exit(0);
139 + }
140 else if (!strcmp(action.buf, "erase"))
141 remove_credential(&c);
142 else if (!strcmp(action.buf, "store")) {