Re: [PATCH 2/2] lib: call g_mime_init from notmuch_database_open
authorTomi Ollila <tomi.ollila@iki.fi>
Mon, 2 Jan 2012 12:56:13 +0000 (14:56 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:28 +0000 (09:41 -0800)
00/d3b084ee50aed5d4b64b4443de0760834e76a4 [new file with mode: 0644]

diff --git a/00/d3b084ee50aed5d4b64b4443de0760834e76a4 b/00/d3b084ee50aed5d4b64b4443de0760834e76a4
new file mode 100644 (file)
index 0000000..5a29027
--- /dev/null
@@ -0,0 +1,141 @@
+Return-Path: <tomi.ollila@nixu.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 6481D431FD0\r
+       for <notmuch@notmuchmail.org>; Mon,  2 Jan 2012 04:56:22 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id PspL-I9nijmo for <notmuch@notmuchmail.org>;\r
+       Mon,  2 Jan 2012 04:56:21 -0800 (PST)\r
+Received: from mail-gw3.nixu.fi (mail-gw3.nixu.fi [193.209.237.7])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 58009431FB6\r
+       for <notmuch@notmuchmail.org>; Mon,  2 Jan 2012 04:56:21 -0800 (PST)\r
+Received: from pps.filterd (mail-gw3 [127.0.0.1])\r
+       by mail-gw3.nixu.fi (8.14.4/8.14.4) with SMTP id q02CqwbU004513;\r
+       Mon, 2 Jan 2012 14:56:15 +0200\r
+Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31])\r
+       by mail-gw3.nixu.fi with ESMTP id 114cs0wwnv-1\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Mon, 02 Jan 2012 14:56:15 +0200\r
+Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31])\r
+       by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id\r
+       q02CuDPa028402; Mon, 2 Jan 2012 14:56:14 +0200\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: David Bremner <david@tethera.net>, Kazuo Teramoto <kaz.rag@gmail.com>,\r
+       notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 2/2] lib: call g_mime_init from notmuch_database_open\r
+In-Reply-To: <87hb0h5tps.fsf@zancas.localnet>\r
+References: <877h1e6r9d.fsf@zancas.localnet>\r
+       <1325282290-29565-1-git-send-email-kaz.rag@gmail.com>\r
+       <1325282290-29565-3-git-send-email-kaz.rag@gmail.com>\r
+       <87hb0h5tps.fsf@zancas.localnet>\r
+User-Agent: Notmuch/0.10.2+157~g442d405 (http://notmuchmail.org) Emacs/23.3.1\r
+       (i686-pc-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Mon, 02 Jan 2012 14:56:13 +0200\r
+Message-ID: <yf6obumz2j6.fsf@taco2.nixu.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.5.7110,\r
+ 1.0.211,      0.0.0000        definitions=2012-01-02_03:2012-01-02, 2012-01-02,\r
+       1970-01-01 signatures=0\r
+X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0\r
+       ipscore=0 suspectscore=2\r
+       phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0\r
+       reason=mlx\r
+       scancount=1 engine=6.0.2-1012030000 definitions=main-1201020078\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 02 Jan 2012 12:56:22 -0000\r
+\r
+On Fri, 30 Dec 2011 23:02:39 -0400, David Bremner <david@tethera.net> wrote:\r
+> On Fri, 30 Dec 2011 19:58:10 -0200, Kazuo Teramoto <kaz.rag@gmail.com> wrote:\r
+> > We need to call g_mime_init to correct initialize the structures needed\r
+> > by gmime before using it.\r
+> > ---\r
+> >  lib/database.cc |    5 +++++\r
+ > >  1 files changed, 5 insertions(+), 0 deletions(-)\r
+> \r
+> I can confirm this patch (alone) fixes the segfault for me. and doesn't\r
+> cause in test failures when applied against the release branch.  I'm\r
+> considering pushing it into the 0.11 release. Any comments on that?\r
+\r
+Do it. The current implementation does not break anything (in our case\r
+as we don't do g_mime_shutdown() (0, 1 or 2 times)... The usage needs to\r
+be "fixed" soon after...\r
+\r
+> d\r
+\r
+.. my suggestions how to fix this:\r
+\r
+1) just call g_mime_init(0) without checking whether it is initialized\r
+   already. As it't return type is 'void' it can be expected to keep some\r
+   global storage (and reference count...). If it returned something else\r
+   it either returns common (singleton) instance (and keeps reference count)\r
+   or returns new instance each time called.... Never call g_mime_shutdown();\r
+   just let operating system free resources when program exits. The first\r
+   lines in g_mime_shutdown():\r
+\r
+        if (--initialized)\r
+                return;\r
+\r
+   looks a bit suspicious -- what if application happens to call\r
+   g_mime_shutdown() too often and then trying to call g_mime_init() again...\r
+\r
+2) create function\r
+\r
+  void\r
+  notmuch_g_type_init (void)\r
+  {\r
+        static int initialized;\r
+        if (initialized++)\r
+               return;\r
+        g_mime_init(0)\r
+        atexit (g_mime_shutdown);\r
+  }\r
+\r
+  and use that in place of g_mime_init() always (perhaps use macro trickery\r
+  to disallow g_mime_init (and g_mime_shutdown). \r
+\r
+  Note that although atexit() makes pretty sure that in normal exit \r
+  g_mime_shutdown() is called due to various reasons that normal exit\r
+  case is not reached (dies by signal, usage of _exit, execve(2)\r
+  hardware failure, lost power etc.)(*). Therefore, IMO, I'd leave this\r
+  (particular) cleanup to be done by the operating system -- less, \r
+  simpler application code.\r
+\r
+\r
+Tomi\r
+\r
+(*) I recall reading an article about 'design for failure' or 'expect\r
+    failure' like 5 years ago but cannot find it anymore. The point on that\r
+    article was that software can fail in any point (specially, compare\r
+    man 2 rename  and then around lines 580-610 in\r
+    http://git.busybox.net/busybox/tree/sysklogd/syslogd.c ). Since then\r
+    I've tried to prioritize in finalize things that matter early and leave\r
+    operating system to do other cleanpus for me (why do something yourself\r
+    that machine can do for you). Did you know that doing full windows\r
+    reboot is faster if the machine is just unplugged from power source\r
+    for a second and then restarted instead of doing "clean" reboot cycle.\r
+    Linux boots so fast I don't know if I'd notice the difference ;)\r