1 Return-Path: <dkg@fifthhorseman.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id CBB816DE1AE0
\r
6 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:10 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id m5-TOeknAz40 for <notmuch@notmuchmail.org>;
\r
16 Sun, 31 Jan 2016 12:40:09 -0800 (PST)
\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])
\r
18 by arlo.cworth.org (Postfix) with ESMTP id E597D6DE0FB1
\r
19 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:08 -0800 (PST)
\r
20 Received: from fifthhorseman.net (ip-64-134-185-108.public.wayport.net
\r
22 by che.mayfirst.org (Postfix) with ESMTPSA id B0C9CF997
\r
23 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 15:40:05 -0500 (EST)
\r
24 Received: by fifthhorseman.net (Postfix, from userid 1000)
\r
25 id 2B15B1FE52; Sun, 31 Jan 2016 15:40:06 -0500 (EST)
\r
26 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
\r
27 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
28 Subject: [PATCH v3 01/16] add util/search-path.{c,
\r
29 h} to test for executables in $PATH
\r
30 Date: Sun, 31 Jan 2016 15:39:46 -0500
\r
31 Message-Id: <1454272801-23623-2-git-send-email-dkg@fifthhorseman.net>
\r
32 X-Mailer: git-send-email 2.7.0.rc3
\r
33 In-Reply-To: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>
\r
34 References: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.20
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Sun, 31 Jan 2016 20:40:10 -0000
\r
49 This is a utility function we can use to see whether an executable is
\r
52 util/Makefile.local | 2 +-
\r
53 util/search-path.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
54 util/search-path.h | 24 +++++++++++++++++++++++
\r
55 3 files changed, 80 insertions(+), 1 deletion(-)
\r
56 create mode 100644 util/search-path.c
\r
57 create mode 100644 util/search-path.h
\r
59 diff --git a/util/Makefile.local b/util/Makefile.local
\r
60 index 905f237..8b2b91b 100644
\r
61 --- a/util/Makefile.local
\r
62 +++ b/util/Makefile.local
\r
63 @@ -5,7 +5,7 @@ extra_cflags += -I$(srcdir)/$(dir)
\r
65 libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
\r
66 $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \
\r
68 + $(dir)/util.c $(dir)/search-path.c
\r
70 libutil_modules := $(libutil_c_srcs:.c=.o)
\r
72 diff --git a/util/search-path.c b/util/search-path.c
\r
73 new file mode 100644
\r
74 index 0000000..5eac367
\r
76 +++ b/util/search-path.c
\r
78 +#include "search-path.h"
\r
79 +#include <stdlib.h>
\r
80 +#include <talloc.h>
\r
81 +#include <unistd.h>
\r
82 +#include <string.h>
\r
83 +#include <sys/types.h>
\r
84 +#include <sys/stat.h>
\r
89 +test_for_executable(const char* exename)
\r
91 + char *c = NULL, *save = NULL, *tok;
\r
94 + notmuch_bool_t ret = FALSE;
\r
96 + if (strchr(exename, '/')) {
\r
97 + if (0 == access(exename, X_OK))
\r
103 + c = getenv("PATH");
\r
105 + c = talloc_strdup(NULL, c);
\r
107 + n = confstr(_CS_PATH, NULL, 0);
\r
108 + c = (char*)talloc_size(NULL, n);
\r
111 + confstr(_CS_PATH, c, n);
\r
114 + tok = strtok_r(c, ":", &save);
\r
116 + dfd = open(tok, O_DIRECTORY | O_RDONLY);
\r
118 + if (!faccessat(dfd, exename, X_OK, 0)) {
\r
124 + tok = strtok_r(NULL, ":", &save);
\r
133 diff --git a/util/search-path.h b/util/search-path.h
\r
134 new file mode 100644
\r
135 index 0000000..727d0b3
\r
137 +++ b/util/search-path.h
\r
139 +#ifndef _SEARCH_PATH_H
\r
140 +#define _SEARCH_PATH_H
\r
142 +#include "notmuch.h"
\r
144 +/* can an executable be found with the given name?
\r
146 + * Return TRUE only if we can find something to execute with the
\r
147 + * associated name.
\r
149 + * if the name has a '/' in it, we look for it directly with
\r
150 + * access(exename, X_OK).
\r
152 + * otherwise, we look for it in $PATH (or in confstr(_CS_PATH), if
\r
153 + * $PATH is unset).
\r
155 + * This should match the logic for execvp (as well as matching user
\r
156 + * expectations, hopefully).
\r
160 +test_for_executable(const char *exename);
\r