From: Maarten Aertsen <sagi-notmuch@rtsn.nl>
To: "Notmuch Mail" <notmuch@notmuchmail.org>
Subject: [PATCH] cli: avoid non-zero exits in notmuch insert --keep
Date: Sun, 07 Feb 2016 22:13:40 +0100 [thread overview]
Message-ID: <20160207211340.15609.92485@kardo2.rtsn.nl> (raw)
In-Reply-To: <87a8nsz8bd.fsf@zancas.localnet>
Re-ordered code that touches the database to try and deliver e-mail to
at least try to deliver to the Maildir (which, with --keep should return
success).
In the case of any failure, we now return EX_TEMPFAIL (a sendmail
convention, defined in sysexits.h) to signal to the LDA that it should
retry later. This prevents a direct reject or bounce of e-mail.
---
notmuch-client.h | 1 +
notmuch-insert.c | 42 +++++++++++++++++++++++-------------------
notmuch.c | 17 +++++++++++++----
3 files changed, 37 insertions(+), 23 deletions(-)
diff --git a/notmuch-client.h b/notmuch-client.h
index 18e6c60..e3d6a46 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -466,6 +466,7 @@ print_status_query (const char *loc,
extern char *notmuch_requested_db_uuid;
extern const notmuch_opt_desc_t notmuch_shared_options [];
+notmuch_bool_t notmuch_has_unmatched_db_uuid (notmuch_database_t *notmuch);
void notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch);
void notmuch_process_shared_options (const char* subcommand_name);
diff --git a/notmuch-insert.c b/notmuch-insert.c
index 5205c17..35b6779 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -28,6 +28,8 @@
#include <sys/stat.h>
#include <fcntl.h>
+#include <sysexits.h>
+
static volatile sig_atomic_t interrupted;
static void
@@ -532,31 +534,33 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
action.sa_flags = 0;
sigaction (SIGINT, &action, NULL);
- if (notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
- return EXIT_FAILURE;
-
- notmuch_exit_if_unmatched_db_uuid (notmuch);
-
/* Write the message to the Maildir new directory. */
newpath = maildir_write_new (config, STDIN_FILENO, maildir);
if (! newpath) {
- notmuch_database_destroy (notmuch);
return EXIT_FAILURE;
}
- /* Index the message. */
- status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep);
-
- /* Commit changes. */
- close_status = notmuch_database_destroy (notmuch);
- if (close_status) {
- /* Hold on to the first error, if any. */
- if (! status)
- status = close_status;
- fprintf (stderr, "%s: failed to commit database changes: %s\n",
- keep ? "Warning" : "Error",
- notmuch_status_to_string (close_status));
+ status = notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much);
+ if (! status) {
+ /* with keep, send EX_TEMPFAIL per sysexits.h to invite the caller to
+ * retry at some later point and avoid permanent failure */
+ if (notmuch_has_unmatched_db_uuid(notmuch))
+ exit (keep ? EX_TEMPFAIL : EXIT_FAILURE);
+
+ /* Index the message. */
+ status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep);
+
+ /* Commit changes. */
+ close_status = notmuch_database_destroy (notmuch);
+ if (close_status) {
+ /* Hold on to the first error, if any. */
+ if (! status)
+ status = close_status;
+ fprintf (stderr, "%s: failed to commit database changes: %s\n",
+ keep ? "Warning" : "Error",
+ notmuch_status_to_string (close_status));
+ }
}
if (status) {
diff --git a/notmuch.c b/notmuch.c
index ce6c575..783bb2a 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -220,20 +220,29 @@ be supported in the future.\n", notmuch_format_version);
}
}
-void
-notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch)
+notmuch_bool_t
+notmuch_has_unmatched_db_uuid (notmuch_database_t *notmuch)
{
const char *uuid = NULL;
if (!notmuch_requested_db_uuid)
- return;
+ return FALSE;
IGNORE_RESULT (notmuch_database_get_revision (notmuch, &uuid));
if (strcmp (notmuch_requested_db_uuid, uuid) != 0){
fprintf (stderr, "Error: requested database revision %s does not match %s\n",
notmuch_requested_db_uuid, uuid);
- exit (1);
+ return TRUE;
}
+
+ return FALSE;
+}
+
+void
+notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch)
+{
+ if (notmuch_has_unmatched_db_uuid(notmuch))
+ exit (1);
}
static void
--
2.7.0
next prev parent reply other threads:[~2016-02-07 21:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-24 15:48 notmuch insert --keep fails in parallel w/ notmuch new Maarten Aertsen
2016-01-26 15:09 ` David Bremner
2016-02-07 21:13 ` Maarten Aertsen [this message]
2016-02-08 11:56 ` [PATCH] cli: avoid non-zero exits in notmuch insert --keep David Bremner
2016-11-28 12:16 ` [PATCH 1/2] cli/insert: delay database open until after writing mail file David Bremner
2016-11-28 12:16 ` [PATCH 2/2] cli/insert: return EX_TEMPFAIL for some errors David Bremner
2016-11-28 12:22 ` David Bremner
2016-11-28 22:12 ` v2 of insert tempfail series David Bremner
2016-11-28 22:12 ` [PATCH 1/3] test: gdb insert: redirect input inside gdb script David Bremner
2016-11-28 22:12 ` [PATCH 2/3] cli/insert: delay database open until after writing mail file David Bremner
2016-11-28 22:12 ` [PATCH 3/3] cli/insert: return EX_TEMPFAIL for some errors David Bremner
2016-12-04 20:51 ` v2 of insert tempfail series Tomi Ollila
2016-12-07 11:27 ` NEWS/docs for insert tempfail changes David Bremner
2016-12-07 11:27 ` [PATCH 1/2] cli/insert: document the use of EX_TEMPFAIL David Bremner
2016-12-15 13:01 ` David Bremner
2016-12-07 11:27 ` [PATCH 2/2] NEWS: news for notmuch-insert error handling David Bremner
2016-12-10 19:26 ` NEWS/docs for insert tempfail changes Tomi Ollila
2016-11-28 12:23 ` [PATCH 1/2] cli/insert: delay database open until after writing mail file David Bremner
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=20160207211340.15609.92485@kardo2.rtsn.nl \
--to=sagi-notmuch@rtsn.nl \
--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).