From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Subject: [PATCH] Properly handle short writes in sigint handlers
Date: Thu, 22 Dec 2011 15:15:48 -0500 [thread overview]
Message-ID: <1324584948-8009-1-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <20111222201553.GK10376@mit.edu>
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
next prev parent reply other threads:[~2011-12-22 20:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-21 21:38 [RFC][PATCH] notmuch: Workaround to allow ignoring non-void function return David Edmondson
2011-12-22 7:03 ` Austin Clements
2011-12-22 7:21 ` David Edmondson
2011-12-22 19:03 ` Austin Clements
2011-12-22 19:25 ` David Edmondson
2011-12-22 20:04 ` David Edmondson
2011-12-22 20:15 ` Austin Clements
2011-12-22 20:15 ` Austin Clements [this message]
2011-12-23 8:10 ` [PATCH] Properly handle short writes in sigint handlers David Edmondson
2011-12-23 12:30 ` Tomi Ollila
2011-12-25 0:38 ` Austin Clements
2011-12-25 0:38 ` Austin Clements
2011-12-23 19:10 ` Dmitry Kurochkin
2012-01-10 11:13 ` David Bremner
2012-01-11 13:04 ` Tomi Ollila
2011-12-22 9:32 ` [RFC][PATCH] notmuch: Workaround to allow ignoring non-void function return Dmitry Kurochkin
2011-12-22 11:24 ` David Edmondson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1324584948-8009-1-git-send-email-amdragon@mit.edu \
--to=amdragon@mit.edu \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).