{"thread":{"id":"58113","subject":"[RFC PATCH 1B] credential-cache--daemon: close input before exit-ing","startedAt":"2022-07-07T01:54:29Z","lastAt":"2022-07-07T15:35:24Z","messageCount":3,"participants":["Ramsay Jones","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"458550","messageId":"c344938b-afe9-edef-1e0d-fbe2425c8c01@ramsayjones.plus.com","threadId":"58113","inReplyTo":null,"subject":"[RFC PATCH 1B] credential-cache--daemon: close input before exit-ing","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2022-07-07T01:54:22Z","receivedAt":"2022-07-07T01:54:29Z","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 | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c\nindex 4c6c89ab0d..556393498f 100644\n--- a/builtin/credential-cache--daemon.c\n+++ b/builtin/credential-cache--daemon.c\n@@ -138,6 +138,7 @@ static void serve_one_client(FILE *in, FILE *out)\n \t\t * process actually ends, which closes the socket and gives\n \t\t * them EOF.\n \t\t */\n+\t\tfclose(in);\n \t\texit(0);\n \t}\n \telse if (!strcmp(action.buf, \"erase\"))\n-- \n2.37.0\n"},{"id":"458564","messageId":"220707.86pmih847l.gmgdl@evledraar.gmail.com","threadId":"58113","inReplyTo":"c344938b-afe9-edef-1e0d-fbe2425c8c01@ramsayjones.plus.com","subject":"Re: [RFC PATCH 1B] credential-cache--daemon: close input before exit-ing","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-07-07T13:00:17Z","receivedAt":"2022-07-07T13:03:49Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Jul 07 2022, Ramsay Jones wrote:\n\n> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> ---\n>  builtin/credential-cache--daemon.c | 1 +\n>  1 file changed, 1 insertion(+)\n>\n> diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c\n> index 4c6c89ab0d..556393498f 100644\n> --- a/builtin/credential-cache--daemon.c\n> +++ b/builtin/credential-cache--daemon.c\n> @@ -138,6 +138,7 @@ static void serve_one_client(FILE *in, FILE *out)\n>  \t\t * process actually ends, which closes the socket and gives\n>  \t\t * them EOF.\n>  \t\t */\n> +\t\tfclose(in);\n>  \t\texit(0);\n>  \t}\n>  \telse if (!strcmp(action.buf, \"erase\"))\n\nThis is called by a function that will also close stdout, shouldn't we\nbe closing it here?\n"},{"id":"458567","messageId":"a26a837a-51f2-d38b-7eb4-8e425d6d9150@ramsayjones.plus.com","threadId":"58113","inReplyTo":"220707.86pmih847l.gmgdl@evledraar.gmail.com","subject":"Re: [RFC PATCH 1B] credential-cache--daemon: close input before exit-ing","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2022-07-07T15:35:15Z","receivedAt":"2022-07-07T15:35:24Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 07/07/2022 14:00, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Thu, Jul 07 2022, Ramsay Jones wrote:\n> \n>> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n>> ---\n>>  builtin/credential-cache--daemon.c | 1 +\n>>  1 file changed, 1 insertion(+)\n>>\n>> diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c\n>> index 4c6c89ab0d..556393498f 100644\n>> --- a/builtin/credential-cache--daemon.c\n>> +++ b/builtin/credential-cache--daemon.c\n>> @@ -138,6 +138,7 @@ static void serve_one_client(FILE *in, FILE *out)\n>>  \t\t * process actually ends, which closes the socket and gives\n>>  \t\t * them EOF.\n>>  \t\t */\n>> +\t\tfclose(in);\n>>  \t\texit(0);\n>>  \t}\n>>  \telse if (!strcmp(action.buf, \"erase\"))\n> \n> This is called by a function that will also close stdout, shouldn't we\n> be closing it here?\n\nErr, do you mean 'out' rather than 'stdout'? Actually, it doesn't\nmatter either way! :)\n\nLet me quote from [1], which (hopefully) explains the context:\n\n\"\"\"\nAnyway, I started playing around with flushing/closing of 'FILE *' streams\nbefore the 'exit' call, to change the order, relative to the socket-file\ndeletion in the 'atexit' function (or the closing of the listen-socket\ndescriptor, come to that). In particular, I found that if I were to close\nthe 'in'put stream, then the client would receive an EOF and exit normally\n(ie no error return from read_in_full() above).\n\n[fclose(in); fclose(out) also works, but fclose(out) on its own does not.\nfflush() in various combinations did not work at all].\n\"\"\"\n\nSo, my intent was to find the _minimum_ change necessary to fix the test.\nThis is not a 'real' patch - it was only to demonstrate that there appears\nto be some order dependency problem induced by the 'atexit' clean-up from\nexit()-ing the server.\n\nATB,\nRamsay Jones\n\n[1] https://lore.kernel.org/git/9dc3e85f-a532-6cff-de11-1dfb2e4bc6b6@ramsayjones.plus.com/\n\n"}]}