[PATCH 2/2] test: add test-binary to print the number of ghost messages
[notmuch-archives.git] / 69 / 6aaba3f581694c777c53ef851c16023d1903fa
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id B14F1431FD0\r
6         for <notmuch@notmuchmail.org>; Thu,  8 Dec 2011 15:32:53 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id AXyrIMwp6E6T for <notmuch@notmuchmail.org>;\r
16         Thu,  8 Dec 2011 15:32:52 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id B6876431FB6\r
20         for <notmuch@notmuchmail.org>; Thu,  8 Dec 2011 15:32:52 -0800 (PST)\r
21 X-AuditID: 12074422-b7ff56d00000092f-d0-4ee149235038\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 76.95.02351.32941EE4; Thu,  8 Dec 2011 18:32:51 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id pB8NWoa0016951; \r
27         Thu, 8 Dec 2011 18:32:50 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pB8NWl4T017194\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 8 Dec 2011 18:32:49 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1RYnTy-0001EP-3J; Thu, 08 Dec 2011 18:34:30 -0500\r
37 Date: Thu, 8 Dec 2011 18:34:29 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Jani Nikula <jani@nikula.org>\r
40 Subject: Re: [PATCH v4 1/3] cli: introduce the concept of user defined hooks\r
41 Message-ID: <20111208233429.GA3190@mit.edu>\r
42 References: <cover.1323384304.git.jani@nikula.org>\r
43         <1e4ddb5e3a6b980e47418f67e16709a42e63bc47.1323384304.git.jani@nikula.org>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=iso-8859-1\r
46 Content-Disposition: inline\r
47 Content-Transfer-Encoding: 8bit\r
48 In-Reply-To:\r
49  <1e4ddb5e3a6b980e47418f67e16709a42e63bc47.1323384304.git.jani@nikula.org>\r
50 User-Agent: Mutt/1.5.21 (2010-09-15)\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFlrKKsWRmVeSWpSXmKPExsUixCmqravs+dDP4OcTdoum6c4W12/OZHZg\r
53         8rh1/zW7x7NVt5gDmKK4bFJSczLLUov07RK4Mq7/WspSsFutYtm3FcwNjL2yXYycHBICJhJd\r
54         i38wQ9hiEhfurWfrYuTiEBLYxyhxrGEKM4SznlFixdz5rBDOCSaJyxvuQGWWMErMOLsAqIeD\r
55         g0VAReLRXWeQUWwCGhLb9i9nBLFFBBQlNp/cD2YzC0hLfPvdzARiCwv4SOw4OY8NxOYV0JZo\r
56         WfWdHWSMkECdxMMdFRBhQYmTM5+wQLTqSOzcegdsE8iY5f84IMLyEs1bZ4M9wCkQJvHq+RRW\r
57         EFsU6JgpJ7exTWAUnoVk0iwkk2YhTJqFZNICRpZVjLIpuVW6uYmZOcWpybrFyYl5ealFuqZ6\r
58         uZkleqkppZsYQTHA7qK0g/HnQaVDjAIcjEo8vJ3cD/2EWBPLiitzDzFKcjApifLe9gAK8SXl\r
59         p1RmJBZnxBeV5qQWH2KU4GBWEuEVYAXK8aYkVlalFuXDpKQ5WJTEebl2OvgJCaQnlqRmp6YW\r
60         pBbBZGU4OJQkeD3cgRoFi1LTUyvSMnNKENJMHJwgw3mAhueALOYtLkjMLc5Mh8ifYtTluDH5\r
61         wBlGIZa8/LxUKXHegyBFAiBFGaV5cHNgqesVozjQW8K8Wo5AVTzAtAc36RXQEiagJV+yH4As\r
62         KUlESEk1MJpNz5bR7Dl3ReZdKP+cH+LvmsJbd02Ze1g+/76n+l/lE1dVArey+1hu6IysnJgy\r
63         5bL064WWiftmvkqqb7y25fnNr/Ui1zlXff/27c732Iwf5Wf60qT9ug8+fG6vNivdMuC6XD9b\r
64         xl+pW85hfurxhvfC/P88Devk3lCW2st6uqfnwbsyzSLdEiWW4oxEQy3mouJEAEPzmnU4AwAA\r
65 Cc: notmuch@notmuchmail.org\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.13\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70         <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
77         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Thu, 08 Dec 2011 23:32:53 -0000\r
79 \r
80 Quoth Jani Nikula on Dec 09 at 12:48 am:\r
81 > Add mechanism for running user defined hooks. Hooks are executables or\r
82 > symlinks to executables stored under the new notmuch hooks directory,\r
83 > <database-path>/.notmuch/hooks.\r
84\r
85 > No hooks are introduced here, but adding support for a hook is now a simple\r
86 > matter of calling the new notmuch_run_hook() function at an appropriate\r
87 > location with the hook name.\r
88\r
89 > Signed-off-by: Jani Nikula <jani@nikula.org>\r
90 > ---\r
91 >  Makefile.local   |    1 +\r
92 >  hooks.c          |   93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
93 >  notmuch-client.h |    3 ++\r
94 >  3 files changed, 97 insertions(+), 0 deletions(-)\r
95 >  create mode 100644 hooks.c\r
96\r
97 > diff --git a/Makefile.local b/Makefile.local\r
98 > index 15e6d88..88365da 100644\r
99 > --- a/Makefile.local\r
100 > +++ b/Makefile.local\r
101 > @@ -298,6 +298,7 @@ notmuch_client_srcs =             \\r
102 >       debugger.c              \\r
103 >       gmime-filter-reply.c    \\r
104 >       gmime-filter-headers.c  \\r
105 > +     hooks.c                 \\r
106 >       notmuch.c               \\r
107 >       notmuch-config.c        \\r
108 >       notmuch-count.c         \\r
109 > diff --git a/hooks.c b/hooks.c\r
110 > new file mode 100644\r
111 > index 0000000..44ee419\r
112 > --- /dev/null\r
113 > +++ b/hooks.c\r
114 > @@ -0,0 +1,93 @@\r
115 > +/* notmuch - Not much of an email program, (just index and search)\r
116 > + *\r
117 > + * This file is part of notmuch.\r
118 > + *\r
119 > + * Copyright © 2011 Jani Nikula\r
120 > + *\r
121 > + * This program is free software: you can redistribute it and/or modify\r
122 > + * it under the terms of the GNU General Public License as published by\r
123 > + * the Free Software Foundation, either version 3 of the License, or\r
124 > + * (at your option) any later version.\r
125 > + *\r
126 > + * This program is distributed in the hope that it will be useful,\r
127 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
128 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
129 > + * GNU General Public License for more details.\r
130 > + *\r
131 > + * You should have received a copy of the GNU General Public License\r
132 > + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
133 > + *\r
134 > + * Author: Jani Nikula <jani@nikula.org>\r
135 > + */\r
136 > +\r
137 > +#include "notmuch-client.h"\r
138 > +#include <sys/wait.h>\r
139 > +\r
140 > +int\r
141 > +notmuch_run_hook (const char *db_path, const char *hook)\r
142 > +{\r
143 > +    char *hook_path;\r
144 > +    int status = 0;\r
145 > +    pid_t pid;\r
146 > +\r
147 > +    hook_path = talloc_asprintf (NULL, "%s/%s/%s/%s", db_path, ".notmuch",\r
148 > +                              "hooks", hook);\r
149 > +    if (hook_path == NULL) {\r
150 > +     fprintf (stderr, "Out of memory\n");\r
151 > +     return 1;\r
152 > +    }\r
153 > +\r
154 > +    /* Check access before fork() for speed and simplicity of error handling. */\r
155 > +    if (access (hook_path, X_OK) == -1) {\r
156 > +     /* Ignore ENOENT. It's okay not to have a hook, hook dir, or even\r
157 > +      * notmuch dir. Dangling symbolic links also result in ENOENT, but\r
158 > +      * we'll ignore that too for simplicity. */\r
159 > +     if (errno != ENOENT) {\r
160 > +         fprintf (stderr, "Error: %s hook access failed: %s\n", hook,\r
161 > +                  strerror (errno));\r
162 > +         status = 1;\r
163 > +     }\r
164 \r
165 Is it the intent that a present but non-executable hook (errno ==\r
166 EACCES) will print the above error message and return with a failure?\r
167 I'm pretty sure this differs from the behavior of git hooks.\r
168 \r
169 Other than this, this patch looks good to me.\r
170 \r
171 > +     goto DONE;\r
172 > +    }\r
173 > +\r
174 > +    pid = fork();\r
175 > +    if (pid == -1) {\r
176 > +     fprintf (stderr, "Error: %s hook fork failed: %s\n", hook,\r
177 > +              strerror (errno));\r
178 > +     status = 1;\r
179 > +     goto DONE;\r
180 > +    } else if (pid == 0) {\r
181 > +     execl (hook_path, hook_path, NULL);\r
182 > +     /* Same as above for ENOENT, but unlikely now. Indicate all other errors\r
183 > +      * to parent through non-zero exit status. */\r
184 > +     if (errno != ENOENT) {\r
185 > +         fprintf (stderr, "Error: %s hook execution failed: %s\n", hook,\r
186 > +                  strerror (errno));\r
187 > +         status = 1;\r
188 > +     }\r
189 > +     exit (status);\r
190 > +    }\r
191 > +\r
192 > +    if (waitpid (pid, &status, 0) == -1) {\r
193 > +     fprintf (stderr, "Error: %s hook wait failed: %s\n", hook,\r
194 > +              strerror (errno));\r
195 > +     status = 1;\r
196 > +     goto DONE;\r
197 > +    }\r
198 > +\r
199 > +    if (!WIFEXITED (status) || WEXITSTATUS (status)) {\r
200 > +     if (WIFEXITED (status)) {\r
201 > +         fprintf (stderr, "Error: %s hook failed with status %d\n",\r
202 > +                  hook, WEXITSTATUS (status));\r
203 > +     } else if (WIFSIGNALED (status)) {\r
204 > +         fprintf (stderr, "Error: %s hook terminated with signal %d\n",\r
205 > +                  hook, WTERMSIG (status));\r
206 > +     }\r
207 > +     status = 1;\r
208 > +    }\r
209 > +\r
210 > +  DONE:\r
211 > +    talloc_free (hook_path);\r
212 > +\r
213 > +    return status;\r
214 > +}\r
215 > diff --git a/notmuch-client.h b/notmuch-client.h\r
216 > index b50cb38..a91ad6c 100644\r
217 > --- a/notmuch-client.h\r
218 > +++ b/notmuch-client.h\r
219 > @@ -235,6 +235,9 @@ void\r
220 >  notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
221 >                                             notmuch_bool_t synchronize_flags);\r
222 >  \r
223 > +int\r
224 > +notmuch_run_hook (const char *db_path, const char *hook);\r
225 > +\r
226 >  notmuch_bool_t\r
227 >  debugger_is_active (void);\r