1 Return-Path: <tomi.ollila@iki.fi>
\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 olra.theworths.org (Postfix) with ESMTP id B3052431FBD
\r
6 for <notmuch@notmuchmail.org>; Sat, 25 Jan 2014 14:23:00 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 7I2ZIumpBa2J for <notmuch@notmuchmail.org>;
\r
16 Sat, 25 Jan 2014 14:22:52 -0800 (PST)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 3D483431FBC
\r
19 for <notmuch@notmuchmail.org>; Sat, 25 Jan 2014 14:22:52 -0800 (PST)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id AD40A1000B3
\r
22 for <notmuch@notmuchmail.org>; Sun, 26 Jan 2014 00:22:47 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: notmuch@notmuchmail.org
\r
25 Subject: Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3)
\r
27 In-Reply-To: <1390687142-16401-1-git-send-email-tomi.ollila@iki.fi>
\r
28 References: <1390687142-16401-1-git-send-email-tomi.ollila@iki.fi>
\r
29 User-Agent: Notmuch/0.17+41~g8e7fabf (http://notmuchmail.org) Emacs/24.3.1
\r
30 (x86_64-unknown-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Sun, 26 Jan 2014 00:22:47 +0200
\r
35 Message-ID: <m2bnyzhfbc.fsf@guru.guru-group.fi>
\r
37 Content-Type: text/plain
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Sat, 25 Jan 2014 22:23:00 -0000
\r
52 On Sat, Jan 25 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:
\r
54 > Check whether realpath(3) supports the resolved_path == NULL feature,
\r
55 > standardized in POSIX.1-2008.
\r
57 > This is tested by executing the realpath(3) with NULL as second
\r
58 > argument and the program is expected to SIGSEGV in case the
\r
59 > feature is not supported.
\r
61 > If the feature is not supported the compatibility code calls realpath(3)
\r
62 > with second argument pointing to buffer with MAX_PATH in size. With
\r
63 > this more systems are supported; those that have POSIX.1-2008 -capable
\r
64 > realpath(3) and those that have MAX_PATH defined and realpath(3) does
\r
65 > not exceed that limit.
\r
68 > I tested running configure and then make test; then make clean,
\r
69 > edited Makefile.config POSIX_2008_REALPATH = 0 and make clean
\r
70 > again. then tested sigsegv'ing with (memcpy(0, 0, 4)...
\r
73 > configure | 32 ++++++++++++++++++++++++++++++--
\r
74 > notmuch-config.c | 21 ++++++++++++++++++++-
\r
75 > 2 files changed, 50 insertions(+), 3 deletions(-)
\r
77 > diff --git a/configure b/configure
\r
78 > index 13b6062..8174219 100755
\r
81 > @@ -454,6 +454,29 @@ echo $util_byte_order
\r
83 > rm -f _byteorder _byteorder.c
\r
85 > +printf "Checking for posix 2008 realpath()... "
\r
86 > +# resolved_path == NULL is standardized in POSIX.1-2008
\r
87 > +cat > _posix_2008_realpath.c <<EOF
\r
88 > +#define _BSD_SOURCE
\r
89 > +#include <limits.h>
\r
90 > +#include <stdlib.h>
\r
91 > +#include <signal.h>
\r
92 > +void exit1(int sig) { exit(1); }
\r
94 > + signal(SIGSEGV, exit1);
\r
95 > + int main () { realpath (".", (char*)0); return 0;
\r
98 > +${CC} ${CFLAGS} _posix_2008_realpath.c -o _posix_2008_realpath > /dev/null 2>&1
\r
99 > +if ./_posix_2008_realpath; then
\r
101 > + posix_2008_realpath=1
\r
104 > + posix_2008_realpath=0
\r
106 > +rm -f _posix_2008_realpath _posix_2008_realpath.c
\r
108 > if [ $errors -gt 0 ]; then
\r
111 > @@ -718,6 +741,9 @@ libdir = ${LIBDIR:=\$(prefix)/lib}
\r
112 > # byte order within a 32 bit word. 1234 = little, 4321 = big, 0 = guess
\r
113 > UTIL_BYTE_ORDER = ${util_byte_order}
\r
115 > +# Whether realpath(3) supports resolved_path == NULL feature
\r
116 > +POSIX_2008_REALPATH = ${posix_2008_realpath}
\r
118 > # Whether libdir is in a path configured into ldconfig
\r
119 > LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
\r
121 > @@ -824,7 +850,8 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
122 > -DSTD_GETPWUID=\$(STD_GETPWUID) \\
\r
123 > -DSTD_ASCTIME=\$(STD_ASCTIME) \\
\r
124 > -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\
\r
125 > - -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
\r
126 > + -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER) \\
\r
127 > + -DPOSIX_2008_REALPATH=\$(POSIX_2008_REALPATH)
\r
129 > CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
130 > \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\r
131 > @@ -834,7 +861,8 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
132 > -DSTD_GETPWUID=\$(STD_GETPWUID) \\
\r
133 > -DSTD_ASCTIME=\$(STD_ASCTIME) \\
\r
134 > -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\
\r
135 > - -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
\r
136 > + -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER) \\
\r
137 > + -DPOSIX_2008_REALPATH=\$(POSIX_2008_REALPATH)
\r
139 > CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
\r
141 > diff --git a/notmuch-config.c b/notmuch-config.c
\r
142 > index 8d28653..14d0e5c 100644
\r
143 > --- a/notmuch-config.c
\r
144 > +++ b/notmuch-config.c
\r
145 > @@ -454,10 +454,26 @@ notmuch_config_save (notmuch_config_t *config)
\r
148 > /* Try not to overwrite symlinks. */
\r
149 > +#if POSIX_2008_REALPATH
\r
150 > filename = realpath (config->filename, NULL);
\r
152 > + /* compatibility with minor effort, not elegance, is the ruling factor
\r
153 > + in these (two) else branches... */
\r
154 > + char resolved_path[PATH_MAX];
\r
155 > + filename = realpath (config->filename, resolved_path);
\r
157 > if (! filename) {
\r
158 > if (errno == ENOENT) {
\r
159 > +#if POSIX_2008_REALPATH
\r
160 > filename = strdup (config->filename);
\r
162 > + /* ... this is the other else... */
\r
163 > + resolved_path[sizeof resolved_path - 1] = '\0';
\r
164 > + strncpy(resolved_path, config->filename, sizeof resolved_path);
\r
165 > + /* "faking" out of memory in case path too long -- close enough? */
\r
166 > + filename = resolved_path[sizeof resolved_path - 1]?
\r
167 > + resolved_path: NULL;
\r
169 Ok, this above is wrong (should be other way around). Tests pass though
\r
170 meaning this is not within test coverage...
\r
175 > if (! filename) {
\r
176 > fprintf (stderr, "Out of memory.\n");
\r
178 > @@ -480,12 +496,15 @@ notmuch_config_save (notmuch_config_t *config)
\r
179 > filename, error->message);
\r
181 > g_error_free (error);
\r
182 > +#if POSIX_2008_REALPATH
\r
189 > +#if POSIX_2008_REALPATH
\r