[PATCH] Properly handle short writes in sigint handlers
authorAustin Clements <amdragon@MIT.EDU>
Thu, 22 Dec 2011 20:15:48 +0000 (15:15 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:12 +0000 (09:41 -0800)
95/2e63d5833875b64d19a25926acb6031a4df8f0 [new file with mode: 0644]

diff --git a/95/2e63d5833875b64d19a25926acb6031a4df8f0 b/95/2e63d5833875b64d19a25926acb6031a4df8f0
new file mode 100644 (file)
index 0000000..346ec87
--- /dev/null
@@ -0,0 +1,117 @@
+Return-Path: <amthrax@drake.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id BA4E1429E26\r
+       for <notmuch@notmuchmail.org>; Thu, 22 Dec 2011 12:15:58 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id gizdJPwgd3Gf for <notmuch@notmuchmail.org>;\r
+       Thu, 22 Dec 2011 12:15:58 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
+       [18.9.25.13])\r
+       by olra.theworths.org (Postfix) with ESMTP id 4E94A429E25\r
+       for <notmuch@notmuchmail.org>; Thu, 22 Dec 2011 12:15:58 -0800 (PST)\r
+X-AuditID: 1209190d-b7f576d0000008c4-5b-4ef38ffd525c\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 0F.1E.02244.DFF83FE4; Thu, 22 Dec 2011 15:15:57 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id pBMKFvXe013394; \r
+       Thu, 22 Dec 2011 15:15:57 -0500\r
+Received: from drake.mit.edu (c-76-21-105-205.hsd1.ca.comcast.net\r
+       [76.21.105.205]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pBMKFtUn006046\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 22 Dec 2011 15:15:57 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1Rdp3T-00025t-0S; Thu, 22 Dec 2011 15:15:55 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] Properly handle short writes in sigint handlers\r
+Date: Thu, 22 Dec 2011 15:15:48 -0500\r
+Message-Id: <1324584948-8009-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <20111222201553.GK10376@mit.edu>\r
+References: <20111222201553.GK10376@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrPu3/7OfwY7/BhbXb85kdmD0eLbq\r
+       FnMAYxSXTUpqTmZZapG+XQJXxvvXh9kKjnBVzDvxkrGB8QV7FyMnh4SAicTGs8cZIWwxiQv3\r
+       1rN1MXJxCAnsY5RoPP2SBSQhJLCBUeLuFQOIxDkmiQ0be6Cq5jNKvDqwlQ2kik1AQ2Lb/uVg\r
+       o0QEpCV23p3N2sXIwcEsoCbxp0sFxBQWcJA4cScTpIJFQFVi8b9JzCA2r4C9xKruR8wQRyhI\r
+       nFt9Duw4TgFdiVsHe5ggbtCRWHj6MvMERv4FjAyrGGVTcqt0cxMzc4pTk3WLkxPz8lKLdI30\r
+       cjNL9FJTSjcxgkNGkncH47uDSocYBTgYlXh4K4s++wmxJpYVV+YeYpTkYFIS5dXpAwrxJeWn\r
+       VGYkFmfEF5XmpBYfYpTgYFYS4a1gBMrxpiRWVqUW5cOkpDlYlMR5VbXe+QkJpCeWpGanphak\r
+       FsFkZTg4lCR4U4GxISRYlJqeWpGWmVOCkGbi4AQZzgM0PAKkhre4IDG3ODMdIn+KUVFKnNcN\r
+       JCEAksgozYPrhcX0K0ZxoFeEeeNBqniA6QCu+xXQYCagwducP4AMLklESEk1MJqKrZBIu3f6\r
+       gYDFadu6J9NSdlkvjFwTLL8ou1xnnaxlomTG7HX7iwv2z7C0XC546bFp0rQswSNmRif/PXIT\r
+       60nMlWFg2dKwmTvC4c7DpVptrmo3DmqUcchmSckn/DAJYKqbwzJtqsRy5Z872NsnHTH48Kfe\r
+       f5eQ+PbU8+Ls9q9OcXrv02h0UWIpzkg01GIuKk4EAP/VS+vEAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 22 Dec 2011 20:15:58 -0000\r
+\r
+Even if we don't care about errors from write(2), it's still necessary\r
+to handle short writes in order to use write correctly.  Some versions\r
+of glibc even mark write as warn_unused_result because of this, so our\r
+previous usage would trigger compiler warnings.\r
+---\r
+ notmuch-new.c |    5 ++++-\r
+ notmuch-tag.c |    6 +++++-\r
+ 2 files changed, 9 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 3512de7..fc09bbb 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -66,8 +66,11 @@ static void\r
+ handle_sigint (unused (int sig))\r
+ {\r
+     static char msg[] = "Stopping...         \n";\r
++    const char *pos = msg, *end = msg + sizeof (msg) - 1;\r
++    ssize_t c = 0;\r
\r
+-    (void) write(2, msg, sizeof(msg)-1);\r
++    for (; pos < end && c >= 0; pos += c)\r
++      c = write (2, pos, end - pos);\r
+     interrupted = 1;\r
+ }\r
\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index 292c5da..0d4873d 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -26,7 +26,11 @@ static void\r
+ handle_sigint (unused (int sig))\r
+ {\r
+     static char msg[] = "Stopping...         \n";\r
+-    (void) write(2, msg, sizeof(msg)-1);\r
++    const char *pos = msg, *end = msg + sizeof (msg) - 1;\r
++    ssize_t c = 0;\r
++\r
++    for (; pos < end && c >= 0; pos += c)\r
++      c = write (2, pos, end - pos);\r
+     interrupted = 1;\r
+ }\r
\r
+-- \r
+1.7.7.3\r
+\r