--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 A2ECA431FB6\r
+ for <notmuch@notmuchmail.org>; Fri, 27 Mar 2015 15:12:45 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.438\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438] 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 2r6VSRbBs5Yk for <notmuch@notmuchmail.org>;\r
+ Fri, 27 Mar 2015 15:12:42 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 0DDCD431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 27 Mar 2015 15:12:41 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1YbcUI-0000EI-AB\r
+ for notmuch@notmuchmail.org; Fri, 27 Mar 2015 22:12:22 +0000\r
+Received: (nullmailer pid 1795 invoked by uid 1000); Fri, 27 Mar 2015\r
+ 22:12:09 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: Library logging overhaul, round 6\r
+Date: Fri, 27 Mar 2015 23:11:52 +0100\r
+Message-Id: <1427494320-1483-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\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: Fri, 27 Mar 2015 22:12:46 -0000\r
+\r
+This obsoletes\r
+\r
+ id:1427203451-1540-1-git-send-email-david@tethera.net\r
+\r
+I think this addresses all of Tomi's comments, except the use of\r
+status_cb to print error output from notmuch_database_compact.\r
+I added some tests for notmuch_database_create error output.\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 85054df..9f66b5f 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -625,7 +625,18 @@ parse_references (void *ctx,\r
+ notmuch_status_t\r
+ notmuch_database_create (const char *path, notmuch_database_t **database)\r
+ {\r
+- return notmuch_database_create_verbose (path, database, NULL);\r
++ char *status_string = NULL;\r
++ notmuch_status_t status;\r
++\r
++ status = notmuch_database_create_verbose (path, database,\r
++ &status_string);\r
++\r
++ if (status_string) {\r
++ fputs (status_string, stderr);\r
++ free (status_string);\r
++ }\r
++\r
++ return status;\r
+ }\r
+ \r
+ notmuch_status_t\r
+@@ -694,8 +705,9 @@ notmuch_database_create_verbose (const char *path,\r
+ if (notmuch_path)\r
+ talloc_free (notmuch_path);\r
+ \r
+- if (message)\r
++ if (status_string && message)\r
+ *status_string = message;\r
++\r
+ if (database)\r
+ *database = notmuch;\r
+ else\r
+@@ -799,10 +811,13 @@ notmuch_database_open (const char *path,\r
+ char *status_string = NULL;\r
+ notmuch_status_t status;\r
+ \r
+- status = notmuch_database_open_verbose(path, mode, database,\r
++ status = notmuch_database_open_verbose (path, mode, database,\r
+ &status_string);\r
+ \r
+- if (status_string) fputs(status_string, stderr);\r
++ if (status_string) {\r
++ fputs (status_string, stderr);\r
++ free (status_string);\r
++ }\r
+ \r
+ return status;\r
+ }\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 93b70bf..e6c283e 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -988,7 +988,10 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+ char *status_string = NULL;\r
+ if (notmuch_database_open_verbose (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,\r
+ ¬much, &status_string)) {\r
+- if (status_string) fputs (status_string, stderr);\r
++ if (status_string) {\r
++ fputs (status_string, stderr);\r
++ free (status_string);\r
++ }\r
+ \r
+ return EXIT_FAILURE;\r
+ }\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index d012af3..b81ac01 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -574,7 +574,12 @@ _notmuch_search_prepare (search_context_t *ctx, notmuch_config_t *config, int ar\r
+ if (notmuch_database_open_verbose (\r
+ notmuch_config_get_database_path (config),\r
+ NOTMUCH_DATABASE_MODE_READ_ONLY, &ctx->notmuch, &status_string)) {\r
+- if (status_string) fputs (status_string, stderr);\r
++\r
++ if (status_string) {\r
++ fputs (status_string, stderr);\r
++ free (status_string);\r
++ }\r
++\r
+ return EXIT_FAILURE;\r
+ }\r
+ \r
+diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh\r
+index ec7552a..67a5e8d 100755\r
+--- a/test/T560-lib-error.sh\r
++++ b/test/T560-lib-error.sh\r
+@@ -3,13 +3,13 @@ test_description="error reporting for library"\r
+ \r
+ . ./test-lib.sh\r
+ \r
+-backup_database (){\r
++backup_database () {\r
+ rm -rf notmuch-dir-backup\r
+- cp -a ${MAIL_DIR}/.notmuch notmuch-dir-backup\r
++ cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup\r
+ }\r
+-restore_database (){\r
++restore_database () {\r
+ rm -rf ${MAIL_DIR}/.notmuch\r
+- cp -a notmuch-dir-backup ${MAIL_DIR}/.notmuch\r
++ cp -pR notmuch-dir-backup ${MAIL_DIR}/.notmuch\r
+ }\r
+ \r
+ \r
+@@ -18,7 +18,7 @@ add_email_corpus\r
+ test_expect_success "building database" "NOTMUCH_NEW"\r
+ \r
+ test_begin_subtest "Open null pointer"\r
+-test_C <<EOF\r
++test_C <<'EOF'\r
+ #include <stdio.h>\r
+ #include <notmuch.h>\r
+ int main (int argc, char** argv)\r
+@@ -28,7 +28,7 @@ int main (int argc, char** argv)\r
+ stat = notmuch_database_open (NULL, 0, 0);\r
+ }\r
+ EOF\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ Error: Cannot open a database for a NULL path.\r
+@@ -36,7 +36,7 @@ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+ \r
+ test_begin_subtest "Open nonexistent database"\r
+-test_C <<EOF\r
++test_C <<'EOF'\r
+ #include <stdio.h>\r
+ #include <notmuch.h>\r
+ int main (int argc, char** argv)\r
+@@ -46,15 +46,50 @@ int main (int argc, char** argv)\r
+ stat = notmuch_database_open ("/nonexistent/foo", 0, 0);\r
+ }\r
+ EOF\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ Error opening database at /nonexistent/foo/.notmuch: No such file or directory\r
+ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+ \r
++test_begin_subtest "create NULL path"\r
++test_C <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_create (NULL, NULL);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Error: Cannot create a database for a NULL path.\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "Create database in non-existant directory"\r
++test_C <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_database_t *db;\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_create ("/nonexistent/foo", &db);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Error: Cannot create database at /nonexistent/foo: No such file or directory.\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
+ test_begin_subtest "Write to read-only database"\r
+-test_C ${MAIL_DIR} <<EOF\r
++test_C ${MAIL_DIR} <<'EOF'\r
+ #include <stdio.h>\r
+ #include <notmuch.h>\r
+ int main (int argc, char** argv)\r
+@@ -71,7 +106,7 @@ int main (int argc, char** argv)\r
+ \r
+ }\r
+ EOF\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ Cannot write to a read-only database.\r
+@@ -79,7 +114,7 @@ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+ \r
+ test_begin_subtest "Add non-existent file"\r
+-test_C ${MAIL_DIR} <<EOF\r
++test_C ${MAIL_DIR} <<'EOF'\r
+ #include <stdio.h>\r
+ #include <notmuch.h>\r
+ int main (int argc, char** argv)\r
+@@ -96,7 +131,7 @@ int main (int argc, char** argv)\r
+ \r
+ }\r
+ EOF\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ Error opening /nonexistent: No such file or directory\r
+@@ -104,7 +139,7 @@ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+ \r
+ test_begin_subtest "compact, overwriting existing backup"\r
+-test_C ${MAIL_DIR} <<EOF\r
++test_C ${MAIL_DIR} <<'EOF'\r
+ #include <stdio.h>\r
+ #include <notmuch.h>\r
+ static void\r
+@@ -119,7 +154,7 @@ int main (int argc, char** argv)\r
+ stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);\r
+ }\r
+ EOF\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ Path already exists: CWD/mail\r
+ \r
+@@ -127,7 +162,7 @@ Path already exists: CWD/mail\r
+ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+ \r
+-cat <<EOF > head.c\r
++cat <<'EOF' > c_head\r
+ #include <stdio.h>\r
+ #include <sys/types.h>\r
+ #include <sys/stat.h>\r
+@@ -151,7 +186,7 @@ int main (int argc, char** argv)\r
+ if (fd < 0)\r
+ fprintf (stderr, "error opening %s\n");\r
+ EOF\r
+-cat <<EOF > tail.c\r
++cat <<'EOF' > c_tail\r
+ if (stat) {\r
+ const char *stat_str = notmuch_database_status_string (db);\r
+ if (stat_str)\r
+@@ -163,14 +198,14 @@ EOF\r
+ \r
+ backup_database\r
+ test_begin_subtest "Xapian exception finding message"\r
+-cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_message_t *message = NULL;\r
+ stat = notmuch_database_find_message (db, "id:nonexistant", &message);\r
+ }\r
+ EOF\r
+ sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ A Xapian exception occurred finding message\r
+@@ -180,7 +215,7 @@ restore_database\r
+ \r
+ backup_database\r
+ test_begin_subtest "Xapian exception getting tags"\r
+-cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_tags_t *tags = NULL;\r
+ tags = notmuch_database_get_all_tags (db);\r
+@@ -188,7 +223,7 @@ cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}\r
+ }\r
+ EOF\r
+ sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ A Xapian exception occurred getting tags\r
+@@ -198,14 +233,14 @@ restore_database\r
+ \r
+ backup_database\r
+ test_begin_subtest "Xapian exception creating directory"\r
+-cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_directory_t *directory = NULL;\r
+ stat = notmuch_database_get_directory (db, "none/existing", &directory);\r
+ }\r
+ EOF\r
+ sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ A Xapian exception occurred creating a directory\r
+@@ -215,7 +250,7 @@ restore_database\r
+ \r
+ backup_database\r
+ test_begin_subtest "Xapian exception searching messages"\r
+-cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_messages_t *messages = NULL;\r
+ notmuch_query_t *query=notmuch_query_create (db, "*");\r
+@@ -223,7 +258,7 @@ cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}\r
+ }\r
+ EOF\r
+ sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ A Xapian exception occurred performing query\r
+@@ -234,7 +269,7 @@ restore_database\r
+ \r
+ backup_database\r
+ test_begin_subtest "Xapian exception counting messages"\r
+-cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");\r
+ int count = notmuch_query_count_messages (query);\r
+@@ -242,7 +277,7 @@ cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}\r
+ }\r
+ EOF\r
+ sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
+-cat <<EOF >EXPECTED\r
++cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+ == stderr ==\r
+ A Xapian exception occurred performing query\r
+diff --git a/test/symbol-test.cc b/test/symbol-test.cc\r
+index 9f8eea7..d979f83 100644\r
+--- a/test/symbol-test.cc\r
++++ b/test/symbol-test.cc\r
+@@ -1,4 +1,5 @@\r
+ #include <stdio.h>\r
++#include <stdlib.h>\r
+ #include <xapian.h>\r
+ #include <notmuch.h>\r
+ \r
+@@ -8,8 +9,10 @@ int main() {\r
+ char *message = NULL;\r
+ \r
+ if (notmuch_database_open_verbose ("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much, &message))\r
+- if (message) fputs (message, stderr);\r
+-\r
++ if (message) {\r
++ fputs (message, stderr);\r
++ free (message);\r
++ }\r
+ \r
+ try {\r
+ (void) new Xapian::WritableDatabase("./nonexistant", Xapian::DB_OPEN);\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index fdb84ea..486d1c4 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -1172,7 +1172,7 @@ test_C () {\r
+ echo "== stdout ==" > OUTPUT.stdout\r
+ echo "== stderr ==" > OUTPUT.stderr\r
+ ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr\r
+- sed "s,$(pwd),CWD," OUTPUT.stdout OUTPUT.stderr > OUTPUT\r
++ sed "s,${PWD},CWD,g" OUTPUT.stdout OUTPUT.stderr > OUTPUT\r
+ }\r
+ \r
+ \r