git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 1C] credential-cache--daemon: make exit action follow timeout exit
@ 2022-07-07  1:54 Ramsay Jones
  0 siblings, 0 replies; only message in thread
From: Ramsay Jones @ 2022-07-07  1:54 UTC (permalink / raw)
  To: Adam Dinwoodie; +Cc: GIT Mailing-list


Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
 builtin/credential-cache--daemon.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

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;
 }
-- 
2.37.0

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-07  1:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07  1:54 [RFC PATCH 1C] credential-cache--daemon: make exit action follow timeout exit Ramsay Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).