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