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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx>
---
 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux