--- /dev/null
+Return-Path: <dkg@fifthhorseman.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 079656DE1B25\r
+ for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 18:53:18 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.024\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.024 tagged_above=-999 required=5\r
+ tests=[AWL=-0.024] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id OjRJebmO2VO5 for <notmuch@notmuchmail.org>;\r
+ Tue, 19 Jan 2016 18:53:15 -0800 (PST)\r
+Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 5BBF26DE13FB\r
+ for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 18:53:15 -0800 (PST)\r
+Received: from fifthhorseman.net (unknown [38.109.115.130])\r
+ by che.mayfirst.org (Postfix) with ESMTPSA id 6CAECF987\r
+ for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 21:53:10 -0500 (EST)\r
+Received: by fifthhorseman.net (Postfix, from userid 1000)\r
+ id C82351FEE3; Tue, 19 Jan 2016 18:53:10 -0800 (PST)\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v2 01/16] add util/search-path.{c,\r
+ h} to test for executables in $PATH\r
+Date: Tue, 19 Jan 2016 21:52:34 -0500\r
+Message-Id: <1453258369-7366-2-git-send-email-dkg@fifthhorseman.net>\r
+X-Mailer: git-send-email 2.7.0.rc3\r
+In-Reply-To: <1453258369-7366-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1453258369-7366-1-git-send-email-dkg@fifthhorseman.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 20 Jan 2016 02:53:18 -0000\r
+\r
+This is a utility function we can use to see whether an executable is\r
+available.\r
+---\r
+ util/Makefile.local | 2 +-\r
+ util/search-path.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ util/search-path.h | 24 +++++++++++++++++++++++\r
+ 3 files changed, 80 insertions(+), 1 deletion(-)\r
+ create mode 100644 util/search-path.c\r
+ create mode 100644 util/search-path.h\r
+\r
+diff --git a/util/Makefile.local b/util/Makefile.local\r
+index 905f237..8b2b91b 100644\r
+--- a/util/Makefile.local\r
++++ b/util/Makefile.local\r
+@@ -5,7 +5,7 @@ extra_cflags += -I$(srcdir)/$(dir)\r
+ \r
+ libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
+ $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \\r
+- $(dir)/util.c\r
++ $(dir)/util.c $(dir)/search-path.c\r
+ \r
+ libutil_modules := $(libutil_c_srcs:.c=.o)\r
+ \r
+diff --git a/util/search-path.c b/util/search-path.c\r
+new file mode 100644\r
+index 0000000..5eac367\r
+--- /dev/null\r
++++ b/util/search-path.c\r
+@@ -0,0 +1,55 @@\r
++#include "search-path.h"\r
++#include <stdlib.h>\r
++#include <talloc.h>\r
++#include <unistd.h>\r
++#include <string.h>\r
++#include <sys/types.h>\r
++#include <sys/stat.h>\r
++#include <fcntl.h>\r
++\r
++\r
++notmuch_bool_t\r
++test_for_executable(const char* exename)\r
++{\r
++ char *c = NULL, *save = NULL, *tok;\r
++ size_t n;\r
++ int dfd = -1;\r
++ notmuch_bool_t ret = FALSE;\r
++\r
++ if (strchr(exename, '/')) {\r
++ if (0 == access(exename, X_OK))\r
++ return TRUE;\r
++ else\r
++ return FALSE;\r
++ }\r
++ \r
++ c = getenv("PATH");\r
++ if (c)\r
++ c = talloc_strdup(NULL, c);\r
++ else {\r
++ n = confstr(_CS_PATH, NULL, 0);\r
++ c = (char*)talloc_size(NULL, n);\r
++ if (!c)\r
++ return FALSE;\r
++ confstr(_CS_PATH, c, n);\r
++ }\r
++\r
++ tok = strtok_r(c, ":", &save);\r
++ while (tok) {\r
++ dfd = open(tok, O_DIRECTORY | O_RDONLY);\r
++ if (dfd != -1) {\r
++ if (!faccessat(dfd, exename, X_OK, 0)) {\r
++ ret = TRUE;\r
++ goto done;\r
++ }\r
++ close(dfd);\r
++ }\r
++ tok = strtok_r(NULL, ":", &save);\r
++ }\r
++done:\r
++ if (dfd != -1)\r
++ close(dfd);\r
++ if (c)\r
++ talloc_free(c);\r
++ return ret;\r
++}\r
+diff --git a/util/search-path.h b/util/search-path.h\r
+new file mode 100644\r
+index 0000000..727d0b3\r
+--- /dev/null\r
++++ b/util/search-path.h\r
+@@ -0,0 +1,24 @@\r
++#ifndef _SEARCH_PATH_H\r
++#define _SEARCH_PATH_H\r
++\r
++#include "notmuch.h"\r
++\r
++/* can an executable be found with the given name?\r
++ * \r
++ * Return TRUE only if we can find something to execute with the\r
++ * associated name.\r
++ *\r
++ * if the name has a '/' in it, we look for it directly with\r
++ * access(exename, X_OK).\r
++ * \r
++ * otherwise, we look for it in $PATH (or in confstr(_CS_PATH), if\r
++ * $PATH is unset).\r
++ *\r
++ * This should match the logic for execvp (as well as matching user\r
++ * expectations, hopefully).\r
++ */\r
++\r
++notmuch_bool_t\r
++test_for_executable(const char *exename);\r
++\r
++#endif\r
+-- \r
+2.7.0.rc3\r
+\r