diff mbox series

[RFC,1C] credential-cache--daemon: make exit action follow timeout exit

Message ID 2b7bb2ed-26ae-b599-d78c-e7706b153190@ramsayjones.plus.com (mailing list archive)
State New, archived
Headers show
Series [RFC,1C] credential-cache--daemon: make exit action follow timeout exit | expand

Commit Message

Ramsay Jones July 7, 2022, 1:54 a.m. UTC
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
 builtin/credential-cache--daemon.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
index 4c6c89ab0d..fb9b1e04a6 100644
--- a/builtin/credential-cache--daemon.c
+++ b/builtin/credential-cache--daemon.c
@@ -114,11 +114,12 @@  static int read_request(FILE *fh, struct credential *c,
 	return 0;
 }
 
-static void serve_one_client(FILE *in, FILE *out)
+static int serve_one_client(FILE *in, FILE *out)
 {
 	struct credential c = CREDENTIAL_INIT;
 	struct strbuf action = STRBUF_INIT;
 	int timeout = -1;
+	int serve = 1; /* ie continue to serve clients */
 
 	if (read_request(in, &c, &action, &timeout) < 0)
 		/* ignore error */ ;
@@ -130,15 +131,8 @@  static void serve_one_client(FILE *in, FILE *out)
 		}
 	}
 	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);
+		/* stop serving clients */
+		serve = 0;
 	}
 	else if (!strcmp(action.buf, "erase"))
 		remove_credential(&c);
@@ -157,6 +151,7 @@  static void serve_one_client(FILE *in, FILE *out)
 
 	credential_clear(&c);
 	strbuf_release(&action);
+	return serve;
 }
 
 static int serve_cache_loop(int fd)
@@ -179,6 +174,7 @@  static int serve_cache_loop(int fd)
 	if (pfd.revents & POLLIN) {
 		int client, client2;
 		FILE *in, *out;
+		int serve;
 
 		client = accept(fd, NULL, NULL);
 		if (client < 0) {
@@ -194,9 +190,10 @@  static int serve_cache_loop(int fd)
 
 		in = xfdopen(client, "r");
 		out = xfdopen(client2, "w");
-		serve_one_client(in, out);
+		serve = serve_one_client(in, out);
 		fclose(in);
 		fclose(out);
+		return serve;
 	}
 	return 1;
 }