]> git.cworth.org Git - notmuch/blobdiff - hooks.c
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / hooks.c
diff --git a/hooks.c b/hooks.c
index 662629a951b309021cb86eebfbb0d0cca345e8d0..0cf72e748bc983d60aa09a074375b5fef2c96d97 100644 (file)
--- a/hooks.c
+++ b/hooks.c
@@ -15,7 +15,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ * along with this program.  If not, see https://www.gnu.org/licenses/ .
  *
  * Author: Jani Nikula <jani@nikula.org>
  */
 #include <sys/wait.h>
 
 int
-notmuch_run_hook (const char *db_path, const char *hook)
+notmuch_run_hook (notmuch_database_t *notmuch, const char *hook)
 {
     char *hook_path;
+    const char *config_path;
     int status = 0;
     pid_t pid;
 
-    hook_path = talloc_asprintf (NULL, "%s/%s/%s/%s", db_path, ".notmuch",
-                                "hooks", hook);
+    hook_path = talloc_asprintf (notmuch, "%s/%s",
+                                notmuch_config_get (notmuch, NOTMUCH_CONFIG_HOOK_DIR),
+                                hook);
     if (hook_path == NULL) {
        fprintf (stderr, "Out of memory\n");
        return 1;
     }
 
+    config_path = notmuch_config_path (notmuch);
+    if (setenv ("NOTMUCH_CONFIG", config_path, 1)) {
+       perror ("setenv");
+       return 1;
+    }
+
     /* Check access before fork() for speed and simplicity of error handling. */
     if (access (hook_path, X_OK) == -1) {
        /* Ignore ENOENT. It's okay not to have a hook, hook dir, or even
@@ -53,7 +61,7 @@ notmuch_run_hook (const char *db_path, const char *hook)
     /* Flush any buffered output before forking. */
     fflush (stdout);
 
-    pid = fork();
+    pid = fork ();
     if (pid == -1) {
        fprintf (stderr, "Error: %s hook fork failed: %s\n", hook,
                 strerror (errno));
@@ -78,7 +86,7 @@ notmuch_run_hook (const char *db_path, const char *hook)
        goto DONE;
     }
 
-    if (!WIFEXITED (status) || WEXITSTATUS (status)) {
+    if (! WIFEXITED (status) || WEXITSTATUS (status)) {
        if (WIFEXITED (status)) {
            fprintf (stderr, "Error: %s hook failed with status %d\n",
                     hook, WEXITSTATUS (status));