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 13DCE431FAF for ; Thu, 19 Jan 2012 14:29:28 -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 6e9dQ1cOXwSv for ; Thu, 19 Jan 2012 14:29:27 -0800 (PST) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id 023F2431FBD for ; Thu, 19 Jan 2012 14:29:26 -0800 (PST) X-AuditID: 1209190c-b7fad6d000000920-bc-4f189946e156 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 3A.F2.02336.649981F4; Thu, 19 Jan 2012 17:29:26 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q0JMTQDS026612; Thu, 19 Jan 2012 17:29:26 -0500 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0JMTP8x010692 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 19 Jan 2012 17:29:25 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1Ro0U0-000529-UL; Thu, 19 Jan 2012 17:29:25 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3 2/2] Silence buildbot warnings about unused results Date: Thu, 19 Jan 2012 17:29:19 -0500 Message-Id: <1327012159-19242-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1327012159-19242-1-git-send-email-amdragon@mit.edu> References: <1326996065-29467-1-git-send-email-amdragon@mit.edu> <1327012159-19242-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixG6nous2U8LfoKFHwWLfnS1MFtdvzmR2 YPLY9fwvk8ezVbeYA5iiuGxSUnMyy1KL9O0SuDIunz3LXHBZqGLjglbWBsY9fF2MHBwSAiYS 9y4zdzFyApliEhfurWfrYuTiEBLYxyjx8tUFNpCEkMAGRolzOzUhEseZJN5+28YI4cxnlPhz pZsRpIpNQENi2/7lYLaIgLTEzruzWUFsZgFjib/T54PZwgJuEmdat4CtYxFQlVj//yhYnFfA QWLn3I1QZyhInFt9jh3E5hRwlJg1YS/UFeUS16f/YZnAyL+AkWEVo2xKbpVubmJmTnFqsm5x cmJeXmqRrqFebmaJXmpK6SZGUCBxSvLsYHxzUOkQowAHoxIPL5erhL8Qa2JZcWXuIUZJDiYl Ud5t04FCfEn5KZUZicUZ8UWlOanFhxglOJiVRHgb+oByvCmJlVWpRfkwKWkOFiVxXhWtd35C AumJJanZqakFqUUwWRkODiUJ3uUzgBoFi1LTUyvSMnNKENJMHJwgw3mAhi8EqeEtLkjMLc5M h8ifYlSUEuc9DJIQAElklObB9cIi/RWjONArwryLQKp4gEkCrvsV0GAmoMEeTWIgg0sSEVJS DYwuU/SmFmztnczxos0nX8VObcaTn97cM44U7gi7KrfDyHu3qMzGUsESb3//Ew+2Mhq75Eub 7Dxqd/1K1N2Zu+ZsOzRrhV6vdul7KVX+F5NFs3vzTy9c8vUqR2iiwE7Dj7GKmqvOnmtbYVRt XfFgpt2nrDNLzthsN2/hczokzLBGTFswOoPzwy4lluKMREMt5qLiRADAng2zzwIAAA== 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, 19 Jan 2012 22:29:28 -0000 This ignores the results of the two writes in sigint handlers even harder than before. While my libc lacks the declarations that trigger these warnings, this can be tested by adding the following to notmuch.h: __attribute__((warn_unused_result)) ssize_t write(int fd, const void *buf, size_t count); --- compat/compat.h | 8 ++++++++ notmuch-new.c | 6 +++++- notmuch-tag.c | 7 ++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/compat/compat.h b/compat/compat.h index 7767fe8..b2e2736 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -46,6 +46,14 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp); char* strcasestr(const char *haystack, const char *needle); #endif /* !HAVE_STRCASESTR */ +/* Silence gcc warnings about unused results. These warnings exist + * for a reason; any use of this needs to be justified. */ +#ifdef __GNUC__ +#define IGNORE_RESULT(x) ({ __typeof__(x) __z = (x); (void)(__z = __z); }) +#else /* !__GNUC__ */ +#define IGNORE_RESULT(x) x +#endif /* __GNUC__ */ + #ifdef __cplusplus } #endif diff --git a/notmuch-new.c b/notmuch-new.c index 3512de7..a569a54 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -67,7 +67,11 @@ handle_sigint (unused (int sig)) { static char msg[] = "Stopping... \n"; - (void) write(2, msg, sizeof(msg)-1); + /* This write is "opportunistic", so it's okay to ignore the + * result. It is not required for correctness, and if it does + * fail or produce a short write, we want to get out of the signal + * handler as quickly as possible, not retry it. */ + IGNORE_RESULT (write (2, msg, sizeof(msg)-1)); interrupted = 1; } diff --git a/notmuch-tag.c b/notmuch-tag.c index 292c5da..44fd61f 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -26,7 +26,12 @@ static void handle_sigint (unused (int sig)) { static char msg[] = "Stopping... \n"; - (void) write(2, msg, sizeof(msg)-1); + + /* This write is "opportunistic", so it's okay to ignore the + * result. It is not required for correctness, and if it does + * fail or produce a short write, we want to get out of the signal + * handler as quickly as possible, not retry it. */ + IGNORE_RESULT (write (2, msg, sizeof(msg)-1)); interrupted = 1; } -- 1.7.7.3