{"thread":{"id":"58114","subject":"[RFC PATCH 1C] credential-cache--daemon: make exit action follow timeout exit","startedAt":"2022-07-07T01:54:35Z","lastAt":"2022-07-07T01:54:35Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"458551","messageId":"2b7bb2ed-26ae-b599-d78c-e7706b153190@ramsayjones.plus.com","threadId":"58114","inReplyTo":null,"subject":"[RFC PATCH 1C] credential-cache--daemon: make exit action follow timeout exit","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2022-07-07T01:54:30Z","receivedAt":"2022-07-07T01:54:35Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n builtin/credential-cache--daemon.c | 19 ++++++++-----------\n 1 file changed, 8 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c\nindex 4c6c89ab0d..fb9b1e04a6 100644\n--- a/builtin/credential-cache--daemon.c\n+++ b/builtin/credential-cache--daemon.c\n@@ -114,11 +114,12 @@ static int read_request(FILE *fh, struct credential *c,\n \treturn 0;\n }\n \n-static void serve_one_client(FILE *in, FILE *out)\n+static int serve_one_client(FILE *in, FILE *out)\n {\n \tstruct credential c = CREDENTIAL_INIT;\n \tstruct strbuf action = STRBUF_INIT;\n \tint timeout = -1;\n+\tint serve = 1; /* ie continue to serve clients */\n \n \tif (read_request(in, &c, &action, &timeout) < 0)\n \t\t/* ignore error */ ;\n@@ -130,15 +131,8 @@ static void serve_one_client(FILE *in, FILE *out)\n \t\t}\n \t}\n \telse if (!strcmp(action.buf, \"exit\")) {\n-\t\t/*\n-\t\t * It's important that we clean up our socket first, and then\n-\t\t * signal the client only once we have finished the cleanup.\n-\t\t * Calling exit() directly does this, because we clean up in\n-\t\t * our atexit() handler, and then signal the client when our\n-\t\t * process actually ends, which closes the socket and gives\n-\t\t * them EOF.\n-\t\t */\n-\t\texit(0);\n+\t\t/* stop serving clients */\n+\t\tserve = 0;\n \t}\n \telse if (!strcmp(action.buf, \"erase\"))\n \t\tremove_credential(&c);\n@@ -157,6 +151,7 @@ static void serve_one_client(FILE *in, FILE *out)\n \n \tcredential_clear(&c);\n \tstrbuf_release(&action);\n+\treturn serve;\n }\n \n static int serve_cache_loop(int fd)\n@@ -179,6 +174,7 @@ static int serve_cache_loop(int fd)\n \tif (pfd.revents & POLLIN) {\n \t\tint client, client2;\n \t\tFILE *in, *out;\n+\t\tint serve;\n \n \t\tclient = accept(fd, NULL, NULL);\n \t\tif (client < 0) {\n@@ -194,9 +190,10 @@ static int serve_cache_loop(int fd)\n \n \t\tin = xfdopen(client, \"r\");\n \t\tout = xfdopen(client2, \"w\");\n-\t\tserve_one_client(in, out);\n+\t\tserve = serve_one_client(in, out);\n \t\tfclose(in);\n \t\tfclose(out);\n+\t\treturn serve;\n \t}\n \treturn 1;\n }\n-- \n2.37.0\n"}]}