From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 1C1E2429E25 for ; Fri, 23 Dec 2011 11:11:22 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 3Iu31urD37b8 for ; Fri, 23 Dec 2011 11:11:21 -0800 (PST) Received: from mail-ww0-f41.google.com (mail-ww0-f41.google.com [74.125.82.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 71535431FB6 for ; Fri, 23 Dec 2011 11:11:21 -0800 (PST) Received: by wgbdt12 with SMTP id dt12so12843645wgb.2 for ; Fri, 23 Dec 2011 11:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type; bh=Z07GRNDw2pMdGXC+EhtiigHqvTeYyeOsoPYvmX0tswo=; b=Ba04w3rrygJl6vjsVsoSInjNWnsBxMR/A3EK0pxB93VVaqf+cv3niDKIdwE2bZ+Swm sl1cNBdTZekN4499Hk69cCx3+u42+ts9G1xBXGczM/qBOyANdFGugQPNWE12r1GLrPfj 0/la9jKKBC/F9yFtxgPiFQEmG7AXT0o2MrJ1c= Received: by 10.216.209.99 with SMTP id r77mr8692749weo.25.1324667480243; Fri, 23 Dec 2011 11:11:20 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id ej17sm14685080wbb.14.2011.12.23.11.11.18 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Dec 2011 11:11:19 -0800 (PST) From: Dmitry Kurochkin To: Austin Clements , notmuch@notmuchmail.org Subject: Re: [PATCH] Properly handle short writes in sigint handlers In-Reply-To: <1324584948-8009-1-git-send-email-amdragon@mit.edu> References: <20111222201553.GK10376@mit.edu> <1324584948-8009-1-git-send-email-amdragon@mit.edu> User-Agent: Notmuch/0.10.2+116~g4c449d4 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Fri, 23 Dec 2011 23:10:35 +0400 Message-ID: <87fwgbkst0.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: Fri, 23 Dec 2011 19:11:22 -0000 Hi Austin. On Thu, 22 Dec 2011 15:15:48 -0500, Austin Clements wrote: > 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. I think we should put the write loop into a separate function and reuse it. Also, does it make sense to add a retry counter to prevent infinite loop if write keeps returning 0? Regards, Dmitry > --- > 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 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch