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 36E78429E31 for ; Sat, 24 Dec 2011 16:37:57 -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 mKXeaSn351hH for ; Sat, 24 Dec 2011 16:37:55 -0800 (PST) Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU [18.7.68.35]) by olra.theworths.org (Postfix) with ESMTP id E9633429E28 for ; Sat, 24 Dec 2011 16:37:54 -0800 (PST) X-AuditID: 12074423-b7f9c6d0000008c3-be-4ef6706270b8 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP id CA.6E.02243.26076FE4; Sat, 24 Dec 2011 19:37:54 -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 pBP0brOB014459; Sat, 24 Dec 2011 19:37:54 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pBP0bpJn027338 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 24 Dec 2011 19:37:53 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1Rec70-00049Q-18; Sat, 24 Dec 2011 19:38:50 -0500 Date: Sat, 24 Dec 2011 19:38:50 -0500 From: Austin Clements To: Tomi Ollila Subject: Re: [PATCH] Properly handle short writes in sigint handlers Message-ID: <20111225003850.GF1927@mit.edu> References: <20111222201553.GK10376@mit.edu> <1324584948-8009-1-git-send-email-amdragon@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplleLIzCtJLcpLzFFi42IR4hRV1k0q+OZnsK1R1WLfnS1MFtdvzmS2 eLNyHqsDs8eu53+ZPA5/Xcji8WzVLeYA5igum5TUnMyy1CJ9uwSujJ9ntrMVNIpW9Fx/ztTA eEagi5GDQ0LAROL9FZEuRk4gU0ziwr31bF2MXBxCAvsYJQ7sXcMC4WxglNj3roEJwjnJJLH9 xVqosiWMEvfa97GC9LMIqEqsmnOXGcRmE9CQ2LZ/OSOILSKgIvGgbT1YDbOAlcTFZ3vYQVYL C7hIHDwRBRLmFdCWONf7nhli5jZGifUdb1ghEoISJ2c+YYHo1ZK48e8lE0gvs4C0xPJ/HCBh TgEdiWlPb4KViAKtmnJyG9sERqFZSLpnIemehdC9gJF5FaNsSm6Vbm5iZk5xarJucXJiXl5q ka6ZXm5miV5qSukmRlCos7so72D8c1DpEKMAB6MSD2/z0i9+QqyJZcWVuYcYJTmYlER58/O/ +QnxJeWnVGYkFmfEF5XmpBYfYpTgYFYS4dVMAirnTUmsrEotyodJSXOwKInzami98xMSSE8s Sc1OTS1ILYLJynBwKEnwrgYZKliUmp5akZaZU4KQZuLgBBnOAzT8AEgNb3FBYm5xZjpE/hSj opQ4716QhABIIqM0D64XlopeMYoDvSLMuxykigeYxuC6XwENZgIaHGMEcnVxSSJCSqqB8e6C 9A5V+wVBc/OOmim4P85fVxz7QCTh9lq3B0yTy/MvcClNXH1AKklLYSLzooAdZw6GhKy/MNdi 273lVUHr6h6f1pF5US+2+PP2A8y1uc9cLpdntBgumxM3hVuY0ftNop/JbsYl//a+CNfQLHzH yOaQyBlUY3xd4Al3fF6gGIvkP7bvezI2KLEUZyQaajEXFScCAPlkKlYgAwAA Cc: notmuch@notmuchmail.org 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: Sun, 25 Dec 2011 00:37:57 -0000 Quoth Tomi Ollila on Dec 23 at 2:30 pm: > On Fri, 23 Dec 2011 08:10:33 +0000, David Edmondson wrote: > > Sorry for being slow. > > > > Can you describe the situation in which you expect a write to stderr to > > be a short write? (Without error.) > > In the following hypothetical case (correct me if I'm wrong :): > > * There is 4096 byte buffer in tty driver. > * Stderr is in blocking-mode (the usual case). > * There is already 4090 bytes in that buffer that has not been read. > * One attemtps to write "Stopping... \n" there (blocks). > * Somehow the system call is interrupted (and SA_RESTART not set) > -- write() should return 6 bytes written. This is one possibility. It's also possible it will write no bytes and fail with EINTR. Depending on the type of the stderr file descriptor, it's possible for write to return immediately with 6, even without a signal interrupting it. > But, if the buffer is full already, does the write() system call return > with -1 and EINTR set ? write only returns EINTR if it was interrupted by a signal before anything was written. If the buffer is full already, write will block (unless it's in non-blocking mode, in which case it will write nothing and fail with EAGAIN or EWOULDBLOCK). > If there is enough space for all data in that buffer to begin with, > write() should be atomic. > > > In that situation, what guarantee is there that the loop you've written > > will terminate? > > If write() keeps returning 0 then it will not terminate (I guess this never > happens). Also, it never terminates if write blocks indefinitely > (with or without that loop). I believe the only way write can return 0 is if you pass it a zero length. > > We're not talking about safeguarding a users' data here - this is a > > short message to indicate that a tool is terminating due to a signal. > > I'm concerned that the solution is worse than the problem. > > I'm also in favor of "opportunistic" write *in this particular case* > > In case that write fails there is most probably more serious things going > on (all resources eaten, hardware problem, etc) and trying to push these > writes forward doesn't help. This I find more persuasive. I've been concerned about notmuch doing strange things (with admittedly minor consequences) under common circumstances (like transient buffer overflows), but you're right that more severe circumstances could warrant an opportunistic approach. Of course, we're also not depending on the sigint handler for correctness; if notmuch somehow wedges in it then you're notmuch worse off than you would be otherwise.