From: David Bremner Date: Tue, 24 Mar 2015 13:19:45 +0000 (+2000) Subject: [Patch v5 7/8] lib: replace almost all fprintfs in library with _n_d_log X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ada170ef3719100a90374af52573de17a32c42e8;p=notmuch-archives.git [Patch v5 7/8] lib: replace almost all fprintfs in library with _n_d_log --- diff --git a/25/782a0cf9b4cab12c11d9511b1b272af9ce7e5b b/25/782a0cf9b4cab12c11d9511b1b272af9ce7e5b new file mode 100644 index 000000000..e8cbe0b1c --- /dev/null +++ b/25/782a0cf9b4cab12c11d9511b1b272af9ce7e5b @@ -0,0 +1,380 @@ +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 4284A429E2E + for ; Tue, 24 Mar 2015 06:22:04 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.438 +X-Spam-Level: ** +X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438] 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 j-s4N5gE33Pd for ; + Tue, 24 Mar 2015 06:22:01 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 70F9B429E3B + for ; Tue, 24 Mar 2015 06:22:00 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YaOlj-0000qK-5L; Tue, 24 Mar 2015 13:21:19 +0000 +Received: (nullmailer pid 32640 invoked by uid 1000); Tue, 24 Mar 2015 + 13:19:47 -0000 +From: David Bremner +To: David Bremner , notmuch@notmuchmail.org +Subject: [Patch v5 7/8] lib: replace almost all fprintfs in library with + _n_d_log +Date: Tue, 24 Mar 2015 09:19:45 -0400 +Message-Id: <1427203186-32194-7-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1427203186-32194-1-git-send-email-david@tethera.net> +References: <1426352554-4383-10-git-send-email-david@tethera.net> + <1427203186-32194-1-git-send-email-david@tethera.net> +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: Tue, 24 Mar 2015 13:22:04 -0000 + +This is not supposed to change any functionality from an end user +point of view. Note that it will eliminate some output to stderr. The +query debugging output is left as is; it doesn't really fit with the +current primitive logging model. The remaining "bad" fprintf will need +an internal API change. +--- + lib/database.cc | 38 +++++++++++++++++++++----------------- + lib/directory.cc | 4 ++-- + lib/index.cc | 11 +++++++---- + lib/message.cc | 6 +++--- + lib/query.cc | 18 ++++++++++++------ + test/T560-lib-error.sh | 6 +++++- + 6 files changed, 50 insertions(+), 33 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 673561b..155b5aa 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -473,7 +473,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch, + + return NOTMUCH_STATUS_SUCCESS; + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred finding message: %s.\n", ++ _notmuch_database_log (notmuch, "A Xapian exception occurred finding message: %s.\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; + *message_ret = NULL; +@@ -707,7 +707,7 @@ notmuch_status_t + _notmuch_database_ensure_writable (notmuch_database_t *notmuch) + { + if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) { +- fprintf (stderr, "Cannot write to a read-only database.\n"); ++ _notmuch_database_log (notmuch, "Cannot write to a read-only database.\n"); + return NOTMUCH_STATUS_READ_ONLY_DATABASE; + } + +@@ -1000,7 +1000,7 @@ notmuch_database_close (notmuch_database_t *notmuch) + } catch (const Xapian::Error &error) { + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + if (! notmuch->exception_reported) { +- fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n", ++ _notmuch_database_log (notmuch, "Error: A Xapian exception occurred closing database: %s\n", + error.get_msg().c_str()); + } + } +@@ -1132,12 +1132,12 @@ notmuch_database_compact (const char *path, + } + + if (stat (backup_path, &statbuf) != -1) { +- fprintf (stderr, "Path already exists: %s\n", backup_path); ++ _notmuch_database_log (notmuch, "Path already exists: %s\n", backup_path); + ret = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; + } + if (errno != ENOENT) { +- fprintf (stderr, "Unknown error while stat()ing path: %s\n", ++ _notmuch_database_log (notmuch, "Unknown error while stat()ing path: %s\n", + strerror (errno)); + ret = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; +@@ -1157,20 +1157,20 @@ notmuch_database_compact (const char *path, + compactor.set_destdir (compact_xapian_path); + compactor.compact (); + } catch (const Xapian::Error &error) { +- fprintf (stderr, "Error while compacting: %s\n", error.get_msg().c_str()); ++ _notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg().c_str()); + ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + goto DONE; + } + + if (rename (xapian_path, backup_path)) { +- fprintf (stderr, "Error moving %s to %s: %s\n", ++ _notmuch_database_log (notmuch, "Error moving %s to %s: %s\n", + xapian_path, backup_path, strerror (errno)); + ret = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; + } + + if (rename (compact_xapian_path, xapian_path)) { +- fprintf (stderr, "Error moving %s to %s: %s\n", ++ _notmuch_database_log (notmuch, "Error moving %s to %s: %s\n", + compact_xapian_path, xapian_path, strerror (errno)); + ret = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; +@@ -1178,7 +1178,7 @@ notmuch_database_compact (const char *path, + + if (! keep_backup) { + if (rmtree (backup_path)) { +- fprintf (stderr, "Error removing old database %s: %s\n", ++ _notmuch_database_log (notmuch, "Error removing old database %s: %s\n", + backup_path, strerror (errno)); + ret = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; +@@ -1189,6 +1189,10 @@ notmuch_database_compact (const char *path, + if (notmuch) { + notmuch_status_t ret2; + ++ const char *str = notmuch_database_status_string (notmuch); ++ if (status_cb && str) ++ status_cb (str, closure); ++ + ret2 = notmuch_database_destroy (notmuch); + + /* don't clobber previous error status */ +@@ -1207,7 +1211,7 @@ notmuch_database_compact (unused (const char *path), + unused (notmuch_compact_status_cb_t status_cb), + unused (void *closure)) + { +- fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n"); ++ _notmuch_database_log (notmuch, "notmuch was compiled against a xapian version lacking compaction support.\n"); + return NOTMUCH_STATUS_UNSUPPORTED_OPERATION; + } + #endif +@@ -1485,7 +1489,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + } + + if (private_status) { +- fprintf (stderr, ++ _notmuch_database_log (notmuch, + "Upgrade failed while creating ghost messages.\n"); + status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost"); + goto DONE; +@@ -1535,7 +1539,7 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch) + try { + (static_cast (notmuch->xapian_db))->begin_transaction (false); + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred beginning transaction: %s.\n", ++ _notmuch_database_log (notmuch, "A Xapian exception occurred beginning transaction: %s.\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; +@@ -1569,7 +1573,7 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch) + if (thresh && atoi (thresh) == 1) + db->flush (); + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred committing transaction: %s.\n", ++ _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; +@@ -1815,7 +1819,7 @@ notmuch_database_get_directory (notmuch_database_t *notmuch, + *directory = _notmuch_directory_create (notmuch, path, + NOTMUCH_FIND_LOOKUP, &status); + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n", ++ _notmuch_database_log (notmuch, "A Xapian exception occurred getting directory: %s.\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; +@@ -2397,7 +2401,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch, + + _notmuch_message_sync (message); + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred adding message: %s.\n", ++ _notmuch_database_log (notmuch, "A Xapian exception occurred adding message: %s.\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; + ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; +@@ -2489,7 +2493,7 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch, + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + } + } catch (const Xapian::Error &error) { +- fprintf (stderr, "Error: A Xapian exception occurred finding message by filename: %s\n", ++ _notmuch_database_log (notmuch, "Error: A Xapian exception occurred finding message by filename: %s\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; +@@ -2542,7 +2546,7 @@ notmuch_database_get_all_tags (notmuch_database_t *db) + _notmuch_string_list_sort (tags); + return _notmuch_tags_create (db, tags); + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred getting tags: %s.\n", ++ _notmuch_database_log (db, "A Xapian exception occurred getting tags: %s.\n", + error.get_msg().c_str()); + db->exception_reported = TRUE; + return NULL; +diff --git a/lib/directory.cc b/lib/directory.cc +index 8daaec8..b836ea2 100644 +--- a/lib/directory.cc ++++ b/lib/directory.cc +@@ -186,7 +186,7 @@ _notmuch_directory_create (notmuch_database_t *notmuch, + directory->mtime = Xapian::sortable_unserialise ( + directory->doc.get_value (NOTMUCH_VALUE_TIMESTAMP)); + } catch (const Xapian::Error &error) { +- fprintf (stderr, ++ _notmuch_database_log (notmuch, + "A Xapian exception occurred creating a directory: %s.\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; +@@ -228,7 +228,7 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory, + + db->replace_document (directory->document_id, directory->doc); + } catch (const Xapian::Error &error) { +- fprintf (stderr, ++ _notmuch_database_log (notmuch, + "A Xapian exception occurred setting directory mtime: %s.\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; +diff --git a/lib/index.cc b/lib/index.cc +index c88ed8d..e81aa81 100644 +--- a/lib/index.cc ++++ b/lib/index.cc +@@ -314,7 +314,8 @@ _index_mime_part (notmuch_message_t *message, + const char *charset; + + if (! part) { +- fprintf (stderr, "Warning: Not indexing empty mime part.\n"); ++ _notmuch_database_log (_notmuch_message_database (message), ++ "Warning: Not indexing empty mime part.\n"); + return; + } + +@@ -344,7 +345,8 @@ _index_mime_part (notmuch_message_t *message, + if (i == 1) + continue; + if (i > 1) +- fprintf (stderr, "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n"); ++ _notmuch_database_log (_notmuch_message_database (message), ++ "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n"); + } + if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) { + /* Don't index encrypted parts. */ +@@ -367,8 +369,9 @@ _index_mime_part (notmuch_message_t *message, + } + + if (! (GMIME_IS_PART (part))) { +- fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n", +- g_type_name (G_OBJECT_TYPE (part))); ++ _notmuch_database_log (_notmuch_message_database (message), ++ "Warning: Not indexing unknown mime part: %s.\n", ++ g_type_name (G_OBJECT_TYPE (part))); + return; + } + +diff --git a/lib/message.cc b/lib/message.cc +index b84e5e1..a8ca988 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -252,7 +252,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch, + + doc_id = _notmuch_database_generate_doc_id (notmuch); + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred creating message: %s\n", ++ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; + *status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION; +@@ -467,7 +467,7 @@ notmuch_message_get_header (notmuch_message_t *message, const char *header) + return talloc_strdup (message, value.c_str ()); + + } catch (Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred when reading header: %s\n", ++ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading header: %s\n", + error.get_msg().c_str()); + message->notmuch->exception_reported = TRUE; + return NULL; +@@ -921,7 +921,7 @@ notmuch_message_get_date (notmuch_message_t *message) + try { + value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP); + } catch (Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred when reading date: %s\n", ++ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading date: %s\n", + error.get_msg().c_str()); + message->notmuch->exception_reported = TRUE; + return 0; +diff --git a/lib/query.cc b/lib/query.cc +index 57aa6d2..9cedb6a 100644 +--- a/lib/query.cc ++++ b/lib/query.cc +@@ -296,9 +296,12 @@ notmuch_query_search_messages_st (notmuch_query_t *query, + return NOTMUCH_STATUS_SUCCESS; + + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred performing query: %s\n", +- error.get_msg().c_str()); +- fprintf (stderr, "Query string was: %s\n", query->query_string); ++ _notmuch_database_log (notmuch, ++ "A Xapian exception occurred performing query: %s\n" ++ "Query string was: %s\n", ++ error.get_msg().c_str(), ++ query->query_string); ++ + notmuch->exception_reported = TRUE; + talloc_free (messages); + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; +@@ -597,9 +600,12 @@ notmuch_query_count_messages (notmuch_query_t *query) + count = mset.get_matches_estimated(); + + } catch (const Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred: %s\n", +- error.get_msg().c_str()); +- fprintf (stderr, "Query string was: %s\n", query->query_string); ++ _notmuch_database_log (notmuch, ++ "A Xapian exception occurred performing query: %s\n" ++ "Query string was: %s\n", ++ error.get_msg().c_str(), ++ query->query_string); ++ + } + + return count; +diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh +index c2964cb..ec7552a 100755 +--- a/test/T560-lib-error.sh ++++ b/test/T560-lib-error.sh +@@ -66,6 +66,9 @@ int main (int argc, char** argv) + fprintf (stderr, "error opening database: %d\n", stat); + } + stat = notmuch_database_add_message (db, "/dev/null", NULL); ++ if (stat) ++ fputs (notmuch_database_status_string (db), stderr); ++ + } + EOF + cat <EXPECTED +@@ -118,8 +121,9 @@ int main (int argc, char** argv) + EOF + cat <EXPECTED + == stdout == +-== stderr == + Path already exists: CWD/mail ++ ++== stderr == + EOF + test_expect_equal_file EXPECTED OUTPUT + +-- +2.1.4 +