{"thread":{"id":"15121","subject":"[tig PATCH] continue updates when pipe read has errno \"Success\"","startedAt":"2008-08-21T01:40:44Z","lastAt":"2008-08-22T15:59:14Z","messageCount":3,"participants":["Jeff King","Jonas Fonseca"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"87918","messageId":"20080821014043.GA14452@coredump.intra.peff.net","threadId":"15121","inReplyTo":null,"subject":"[tig PATCH] continue updates when pipe read has errno \"Success\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-08-21T01:40:44Z","receivedAt":"2008-08-21T01:40:44Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When we are reading from a pipe and receive a signal, our\nread call fails and ferror() returns true. The current\nbehavior is to call end_update and report failure. However,\nwe can detect this situation by checking that errno is set\nto success and continue the reading process.\n\nYou can provoke this behavior by running a \"tig blame\" that\ntakes a few seconds and then resizing the terminal that tig\nis running in (you should get an incomplete blame output and\nthe error \"Failed to read: Success\").\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nI am not convinced this is the right solution. Specifically:\n\n  - there are a few other calls to ferror. Maybe they should be\n    converted, too, which implies that perhaps there is a better idiom\n    for checking this.\n\n  - I have no idea how portable this is. Do all stdio implementations\n    fail to restart on signal? Do they all set ferror and have errno ==\n    0 (I would have expected EINTR, or at the very least a 0-read\n    without ferror set)?\n\nBut it works for me (Linux, glibc 2.7).\n\n tig.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/tig.c b/tig.c\nindex 6b111e4..8362ecf 100644\n--- a/tig.c\n+++ b/tig.c\n@@ -2392,7 +2392,7 @@ update_view(struct view *view)\n \tupdate_view_title(view);\n \n check_pipe:\n-\tif (ferror(view->pipe)) {\n+\tif (ferror(view->pipe) && errno != 0) {\n \t\treport(\"Failed to read: %s\", strerror(errno));\n \t\tend_update(view, TRUE);\n \n-- \n1.6.0.98.g0d3cc\n"},{"id":"88112","messageId":"2c6b72b30808220310v1083e860tef9fd6efa57767e3@mail.gmail.com","threadId":"15121","inReplyTo":"20080821014043.GA14452@coredump.intra.peff.net","subject":"Re: [tig PATCH] continue updates when pipe read has errno \"Success\"","fromName":"Jonas Fonseca","fromEmail":"jonas.fonseca@gmail.com","sentAt":"2008-08-22T10:10:35Z","receivedAt":"2008-08-22T10:10:35Z","isPatch":true,"sender":{"key":"jonas.fonseca@gmail.com","avatar":"https://gravatar.com/avatar/9b7fa23cce50269e5d164312b6ac5ae818a180f837b38f28f3bdf689dd7f96cd?d=mp&s=160"},"body":"On Thu, Aug 21, 2008 at 03:40, Jeff King <peff@peff.net> wrote:\n> When we are reading from a pipe and receive a signal, our\n> read call fails and ferror() returns true. The current\n> behavior is to call end_update and report failure. However,\n> we can detect this situation by checking that errno is set\n> to success and continue the reading process.\n\nThanks for the fix/workaround!\n\n> I am not convinced this is the right solution. Specifically:\n>\n>  - there are a few other calls to ferror. Maybe they should be\n>    converted, too, which implies that perhaps there is a better idiom\n>    for checking this.\n\nWell, perhaps something like this can work around the issue for tig-0.12:\n\nbool check_ferror(FILE *file) { return ferror(file) && errno != 0; }\n\nFor a possible \"better\" fix, I have been working on moving tig to use\nthe run-command.[ch] code from git, which means that ferror() will no\nlonger be needed. It is still not ready but looks promising.\n\n>  - I have no idea how portable this is. Do all stdio implementations\n>    fail to restart on signal? Do they all set ferror and have errno ==\n>    0 (I would have expected EINTR, or at the very least a 0-read\n>    without ferror set)?\n>\n> But it works for me (Linux, glibc 2.7).\n\nI have tested it on FreeBSD which doesn't seem to have this problem\nwith ferror(). Anyway, the workaround doesn't break anything so\napplied.\n\n-- \nJonas Fonseca\n"},{"id":"88147","messageId":"20080822155914.GB5280@coredump.intra.peff.net","threadId":"15121","inReplyTo":"2c6b72b30808220310v1083e860tef9fd6efa57767e3@mail.gmail.com","subject":"Re: [tig PATCH] continue updates when pipe read has errno \"Success\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-08-22T15:59:14Z","receivedAt":"2008-08-22T15:59:14Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Aug 22, 2008 at 12:10:35PM +0200, Jonas Fonseca wrote:\n\n> Thanks for the fix/workaround!\n\nThank you for making tig. ;)\n\n> For a possible \"better\" fix, I have been working on moving tig to use\n> the run-command.[ch] code from git, which means that ferror() will no\n> longer be needed. It is still not ready but looks promising.\n\nI think that would be much cleaner, as the semantics of system calls and\nsignals tend to be better defined.\n\n-Peff\n"}]}