All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Adam Dinwoodie <adam@dinwoodie.org>
Cc: GIT Mailing-list <git@vger.kernel.org>
Subject: [RFC PATCH 1C] credential-cache--daemon: make exit action follow timeout exit
Date: Thu, 7 Jul 2022 02:54:30 +0100	[thread overview]
Message-ID: <2b7bb2ed-26ae-b599-d78c-e7706b153190@ramsayjones.plus.com> (raw)


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

                 reply	other threads:[~2022-07-07  1:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b7bb2ed-26ae-b599-d78c-e7706b153190@ramsayjones.plus.com \
    --to=ramsay@ramsayjones.plus.com \
    --cc=adam@dinwoodie.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.