unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation.
@ 2014-01-25 21:59 Tomi Ollila
  2014-01-25 22:22 ` Tomi Ollila
  2014-01-26  0:55 ` David Bremner
  0 siblings, 2 replies; 13+ messages in thread
From: Tomi Ollila @ 2014-01-25 21:59 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

Check whether realpath(3) supports the resolved_path == NULL feature,
standardized in POSIX.1-2008.

This is tested by executing the realpath(3) with NULL as second
argument and the program is expected to SIGSEGV in case the
feature is not supported.

If the feature is not supported the compatibility code calls realpath(3)
with second argument pointing to buffer with MAX_PATH in size. With
this more systems are supported; those that have POSIX.1-2008 -capable
realpath(3) and those that have MAX_PATH defined and realpath(3) does
not exceed that limit.
---

I tested running configure and then make test; then make clean,
edited Makefile.config POSIX_2008_REALPATH = 0 and make clean
again. then tested sigsegv'ing with (memcpy(0, 0, 4)...


 configure        | 32 ++++++++++++++++++++++++++++++--
 notmuch-config.c | 21 ++++++++++++++++++++-
 2 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 13b6062..8174219 100755
--- a/configure
+++ b/configure
@@ -454,6 +454,29 @@ echo $util_byte_order
 
 rm -f _byteorder _byteorder.c
 
+printf "Checking for posix 2008 realpath()... "
+# resolved_path == NULL is standardized in POSIX.1-2008
+cat > _posix_2008_realpath.c <<EOF
+#define _BSD_SOURCE
+#include <limits.h>
+#include <stdlib.h>
+#include <signal.h>
+void exit1(int sig) { exit(1); }
+int main () {
+ signal(SIGSEGV, exit1);
+ int main () { realpath (".", (char*)0); return 0;
+}
+EOF
+${CC} ${CFLAGS} _posix_2008_realpath.c -o _posix_2008_realpath > /dev/null 2>&1
+if ./_posix_2008_realpath; then
+	echo Yes.
+	posix_2008_realpath=1
+else
+	echo No.
+	posix_2008_realpath=0
+fi
+rm -f _posix_2008_realpath _posix_2008_realpath.c
+
 if [ $errors -gt 0 ]; then
     cat <<EOF
 
@@ -718,6 +741,9 @@ libdir = ${LIBDIR:=\$(prefix)/lib}
 # byte order within a 32 bit word. 1234 = little, 4321 = big, 0 = guess
 UTIL_BYTE_ORDER = ${util_byte_order}
 
+# Whether realpath(3) supports resolved_path == NULL feature
+POSIX_2008_REALPATH = ${posix_2008_realpath}
+
 # Whether libdir is in a path configured into ldconfig
 LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
 
@@ -824,7 +850,8 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
 		   -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\
 		   -DSTD_ASCTIME=\$(STD_ASCTIME)                         \\
 		   -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)	 \\
-		   -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
+		   -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)		 \\
+		   -DPOSIX_2008_REALPATH=\$(POSIX_2008_REALPATH)
 
 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
 		     \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
@@ -834,7 +861,8 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
 		     -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\
 		     -DSTD_ASCTIME=\$(STD_ASCTIME)                       \\
 		     -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\
-		     -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
+		     -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)		 \\
+		     -DPOSIX_2008_REALPATH=\$(POSIX_2008_REALPATH)
 
 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
 EOF
diff --git a/notmuch-config.c b/notmuch-config.c
index 8d28653..14d0e5c 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -454,10 +454,26 @@ notmuch_config_save (notmuch_config_t *config)
     }
 
     /* Try not to overwrite symlinks. */
+#if POSIX_2008_REALPATH
     filename = realpath (config->filename, NULL);
+#else
+    /* compatibility with minor effort, not elegance, is the ruling factor
+       in these (two) else branches... */
+    char resolved_path[PATH_MAX];
+    filename = realpath (config->filename, resolved_path);
+#endif
     if (! filename) {
 	if (errno == ENOENT) {
+#if POSIX_2008_REALPATH
 	    filename = strdup (config->filename);
+#else
+	    /* ... this is the other else... */
+	    resolved_path[sizeof resolved_path - 1] = '\0';
+	    strncpy(resolved_path, config->filename, sizeof resolved_path);
+	    /* "faking" out of memory in case path too long -- close enough? */
+	    filename = resolved_path[sizeof resolved_path - 1]?
+		resolved_path: NULL;
+#endif
 	    if (! filename) {
 		fprintf (stderr, "Out of memory.\n");
 		g_free (data);
@@ -480,12 +496,15 @@ notmuch_config_save (notmuch_config_t *config)
 		     filename, error->message);
 	}
 	g_error_free (error);
+#if POSIX_2008_REALPATH
 	free (filename);
+#endif
 	g_free (data);
 	return 1;
     }
-
+#if POSIX_2008_REALPATH
     free (filename);
+#endif
     g_free (data);
     return 0;
 }
-- 
1.8.5.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation.
  2014-01-25 21:59 [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation Tomi Ollila
@ 2014-01-25 22:22 ` Tomi Ollila
  2014-01-26  0:55 ` David Bremner
  1 sibling, 0 replies; 13+ messages in thread
From: Tomi Ollila @ 2014-01-25 22:22 UTC (permalink / raw)
  To: notmuch

On Sat, Jan 25 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:

> Check whether realpath(3) supports the resolved_path == NULL feature,
> standardized in POSIX.1-2008.
>
> This is tested by executing the realpath(3) with NULL as second
> argument and the program is expected to SIGSEGV in case the
> feature is not supported.
>
> If the feature is not supported the compatibility code calls realpath(3)
> with second argument pointing to buffer with MAX_PATH in size. With
> this more systems are supported; those that have POSIX.1-2008 -capable
> realpath(3) and those that have MAX_PATH defined and realpath(3) does
> not exceed that limit.
> ---
>
> I tested running configure and then make test; then make clean,
> edited Makefile.config POSIX_2008_REALPATH = 0 and make clean
> again. then tested sigsegv'ing with (memcpy(0, 0, 4)...
>
>
>  configure        | 32 ++++++++++++++++++++++++++++++--
>  notmuch-config.c | 21 ++++++++++++++++++++-
>  2 files changed, 50 insertions(+), 3 deletions(-)
>
> diff --git a/configure b/configure
> index 13b6062..8174219 100755
> --- a/configure
> +++ b/configure
> @@ -454,6 +454,29 @@ echo $util_byte_order
>  
>  rm -f _byteorder _byteorder.c
>  
> +printf "Checking for posix 2008 realpath()... "
> +# resolved_path == NULL is standardized in POSIX.1-2008
> +cat > _posix_2008_realpath.c <<EOF
> +#define _BSD_SOURCE
> +#include <limits.h>
> +#include <stdlib.h>
> +#include <signal.h>
> +void exit1(int sig) { exit(1); }
> +int main () {
> + signal(SIGSEGV, exit1);
> + int main () { realpath (".", (char*)0); return 0;
> +}
> +EOF
> +${CC} ${CFLAGS} _posix_2008_realpath.c -o _posix_2008_realpath > /dev/null 2>&1
> +if ./_posix_2008_realpath; then
> +	echo Yes.
> +	posix_2008_realpath=1
> +else
> +	echo No.
> +	posix_2008_realpath=0
> +fi
> +rm -f _posix_2008_realpath _posix_2008_realpath.c
> +
>  if [ $errors -gt 0 ]; then
>      cat <<EOF
>  
> @@ -718,6 +741,9 @@ libdir = ${LIBDIR:=\$(prefix)/lib}
>  # byte order within a 32 bit word. 1234 = little, 4321 = big, 0 = guess
>  UTIL_BYTE_ORDER = ${util_byte_order}
>  
> +# Whether realpath(3) supports resolved_path == NULL feature
> +POSIX_2008_REALPATH = ${posix_2008_realpath}
> +
>  # Whether libdir is in a path configured into ldconfig
>  LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}
>  
> @@ -824,7 +850,8 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
>  		   -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\
>  		   -DSTD_ASCTIME=\$(STD_ASCTIME)                         \\
>  		   -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)	 \\
> -		   -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
> +		   -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)		 \\
> +		   -DPOSIX_2008_REALPATH=\$(POSIX_2008_REALPATH)
>  
>  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
>  		     \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
> @@ -834,7 +861,8 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
>  		     -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\
>  		     -DSTD_ASCTIME=\$(STD_ASCTIME)                       \\
>  		     -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\
> -		     -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
> +		     -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)		 \\
> +		     -DPOSIX_2008_REALPATH=\$(POSIX_2008_REALPATH)
>  
>  CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
>  EOF
> diff --git a/notmuch-config.c b/notmuch-config.c
> index 8d28653..14d0e5c 100644
> --- a/notmuch-config.c
> +++ b/notmuch-config.c
> @@ -454,10 +454,26 @@ notmuch_config_save (notmuch_config_t *config)
>      }
>  
>      /* Try not to overwrite symlinks. */
> +#if POSIX_2008_REALPATH
>      filename = realpath (config->filename, NULL);
> +#else
> +    /* compatibility with minor effort, not elegance, is the ruling factor
> +       in these (two) else branches... */
> +    char resolved_path[PATH_MAX];
> +    filename = realpath (config->filename, resolved_path);
> +#endif
>      if (! filename) {
>  	if (errno == ENOENT) {
> +#if POSIX_2008_REALPATH
>  	    filename = strdup (config->filename);
> +#else
> +	    /* ... this is the other else... */
> +	    resolved_path[sizeof resolved_path - 1] = '\0';
> +	    strncpy(resolved_path, config->filename, sizeof resolved_path);
> +	    /* "faking" out of memory in case path too long -- close enough? */
> +	    filename = resolved_path[sizeof resolved_path - 1]?
> +		resolved_path: NULL;

Ok, this above is wrong (should be other way around). Tests pass though
meaning this is not within test coverage...

Tomi

> +#endif
>  	    if (! filename) {
>  		fprintf (stderr, "Out of memory.\n");
>  		g_free (data);
> @@ -480,12 +496,15 @@ notmuch_config_save (notmuch_config_t *config)
>  		     filename, error->message);
>  	}
>  	g_error_free (error);
> +#if POSIX_2008_REALPATH
>  	free (filename);
> +#endif
>  	g_free (data);
>  	return 1;
>      }
> -
> +#if POSIX_2008_REALPATH
>      free (filename);
> +#endif
>      g_free (data);
>      return 0;
>  }
> -- 
> 1.8.5.3

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation.
  2014-01-25 21:59 [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation Tomi Ollila
  2014-01-25 22:22 ` Tomi Ollila
@ 2014-01-26  0:55 ` David Bremner
  2014-01-26 11:18   ` Tomi Ollila
  1 sibling, 1 reply; 13+ messages in thread
From: David Bremner @ 2014-01-26  0:55 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:
> +#if POSIX_2008_REALPATH
>      filename = realpath (config->filename, NULL);
> +#else
> +    /* compatibility with minor effort, not elegance, is the ruling factor
> +       in these (two) else branches... */
> +    char resolved_path[PATH_MAX];
> +    filename = realpath (config->filename, resolved_path);
> +#endif
>      if (! filename) {
>  	if (errno == ENOENT) {
> +#if POSIX_2008_REALPATH
>  	    filename = strdup (config->filename);
> +#else
> +	    /* ... this is the other else... */
> +	    resolved_path[sizeof resolved_path - 1] = '\0';
> +	    strncpy(resolved_path, config->filename, sizeof resolved_path);
> +	    /* "faking" out of memory in case path too long -- close enough? */
> +	    filename = resolved_path[sizeof resolved_path - 1]?
> +		resolved_path: NULL;
> +#endif

I worry a bit about making the mainline code messier and harder to maintain, in order to
accomodate an unknown number of targets without POSIX2008 realpath. Do
we know how widespread this problem is? Is it just NetBSD?

I looked at borrowing realpath from gnulib; it looks like it would be a
bit of work as the least complicated version includes 3 other include
files. But then the mainline code could be blisfully ignorant of the
whole dispute.

d

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation.
  2014-01-26  0:55 ` David Bremner
@ 2014-01-26 11:18   ` Tomi Ollila
  2014-01-26 16:49     ` David Bremner
  0 siblings, 1 reply; 13+ messages in thread
From: Tomi Ollila @ 2014-01-26 11:18 UTC (permalink / raw)
  To: David Bremner, notmuch

On Sun, Jan 26 2014, David Bremner <david@tethera.net> wrote:

> Tomi Ollila <tomi.ollila@iki.fi> writes:
>> +#if POSIX_2008_REALPATH
>>      filename = realpath (config->filename, NULL);
>> +#else
>> +    /* compatibility with minor effort, not elegance, is the ruling factor
>> +       in these (two) else branches... */
>> +    char resolved_path[PATH_MAX];
>> +    filename = realpath (config->filename, resolved_path);
>> +#endif


>
> I worry a bit about making the mainline code messier and harder to maintain, in order to
> accomodate an unknown number of targets without POSIX2008 realpath. Do
> we know how widespread this problem is? Is it just NetBSD?
>
> I looked at borrowing realpath from gnulib; it looks like it would be a
> bit of work as the least complicated version includes 3 other include
> files. But then the mainline code could be blisfully ignorant of the
> whole dispute.

We could also create

char * realpath2008 (const char * path, char * resolved_path)
{
        if (resolved_path == NULL) {
		resolved_path = malloc (MAX_PATH);
                if (resolved_path == NULL)
			return NULL;
        }
        return realpath (path, resolved_path);
}
        
And, in the case where NULL argument is accepted, 

#define realpath2008(path, resolved_path) realpath(path, resolved_path) 

(or an inline function to do the same)

In this case one is not totally ignorant to the whole dispute -- but
on the other hand, developer should be savvy about the potential 
issues using realpath() function, and this might just ring the bell...

> d

Tomi

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation.
  2014-01-26 11:18   ` Tomi Ollila
@ 2014-01-26 16:49     ` David Bremner
  2014-01-27 14:12       ` [PATCH] compat: add canonicalize_file_name David Bremner
  0 siblings, 1 reply; 13+ messages in thread
From: David Bremner @ 2014-01-26 16:49 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:
>
> We could also create
>
> char * realpath2008 (const char * path, char * resolved_path)
> {
>         if (resolved_path == NULL) {
> 		resolved_path = malloc (MAX_PATH);
>                 if (resolved_path == NULL)
> 			return NULL;
>         }
>         return realpath (path, resolved_path);
> }
>         

I sent several private replies to Tomi this morning while being
sleepy. But they were not so great replies anyway.

What about implimenting a compat version of canonicalize_file_name ?
that function is a gnu extension, but since we only call realpath with a
NULL second argument, it might be slighltly simpler to test/google for.

d

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH] compat: add canonicalize_file_name
  2014-01-26 16:49     ` David Bremner
@ 2014-01-27 14:12       ` David Bremner
  2014-01-27 19:07         ` Tomi Ollila
  2014-04-08 11:22         ` David Bremner
  0 siblings, 2 replies; 13+ messages in thread
From: David Bremner @ 2014-01-27 14:12 UTC (permalink / raw)
  To: notmuch

the POSIX 2008 behaviour of realpath is not available everywhere so we
provide a simple wrapper function.  We use (and provide) the gnu
extension canonicalize_file_name to make it cleaner to test for the
feature we need; otherwise we have to rely on realpath segfaulting if
the second argument is null.
---
 compat/Makefile.local                |  4 ++++
 compat/canonicalize_file_name.c      | 18 ++++++++++++++++++
 compat/compat.h                      |  8 ++++++++
 compat/have_canonicalize_file_name.c | 10 ++++++++++
 configure                            | 16 ++++++++++++++++
 notmuch-config.c                     |  2 +-
 6 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 compat/canonicalize_file_name.c
 create mode 100644 compat/have_canonicalize_file_name.c

diff --git a/compat/Makefile.local b/compat/Makefile.local
index b0d5417..bcb9f0e 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -5,6 +5,10 @@ extra_cflags += -I$(srcdir)/$(dir)
 
 notmuch_compat_srcs :=
 
+ifneq ($(HAVE_CANONICALIZE_FILE_NAME),1)
+notmuch_compat_srcs += $(dir)/canonicalize_file_name.c
+endif
+
 ifneq ($(HAVE_GETLINE),1)
 notmuch_compat_srcs += $(dir)/getline.c $(dir)/getdelim.c
 endif
diff --git a/compat/canonicalize_file_name.c b/compat/canonicalize_file_name.c
new file mode 100644
index 0000000..e92c0f6
--- /dev/null
+++ b/compat/canonicalize_file_name.c
@@ -0,0 +1,18 @@
+#include "compat.h"
+#include <limits.h>
+#undef _GNU_SOURCE
+#include <stdlib.h>
+
+char *
+canonicalize_file_name (const char * path)
+{
+#ifdef PATH_MAX
+    char *resolved_path =  malloc (PATH_MAX+1);
+    if (resolved_path == NULL)
+	return NULL;
+
+    return realpath (path, resolved_path);
+#else
+#error undefined PATH_MAX _and_ missing canonicalize_file_name not supported
+#endif
+}
diff --git a/compat/compat.h b/compat/compat.h
index 5a402d5..634d505 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -37,6 +37,14 @@ extern "C" {
 #define _POSIX_PTHREAD_SEMANTICS 1
 #endif
 
+#if !HAVE_CANONICALIZE_FILE_NAME
+/* we only call this function from C, and this makes testing easier */
+#ifndef __cplusplus
+char *
+canonicalize_file_name (const char *path);
+#endif
+#endif
+
 #if !HAVE_GETLINE
 #include <stdio.h>
 #include <unistd.h>
diff --git a/compat/have_canonicalize_file_name.c b/compat/have_canonicalize_file_name.c
new file mode 100644
index 0000000..24c848e
--- /dev/null
+++ b/compat/have_canonicalize_file_name.c
@@ -0,0 +1,10 @@
+#define _GNU_SOURCE
+#include <stdlib.h>
+
+int main()
+{
+    char *found;
+    char *string;
+
+    found = canonicalize_file_name (string);
+}
diff --git a/configure b/configure
index 13b6062..5b7c941 100755
--- a/configure
+++ b/configure
@@ -526,6 +526,18 @@ EOF
     exit 1
 fi
 
+printf "Checking for canonicalize_file_name... "
+if ${CC} -o compat/have_canonicalize_file_name "$srcdir"/compat/have_canonicalize_file_name.c > /dev/null 2>&1
+then
+    printf "Yes.\n"
+    have_canonicalize_file_name=1
+else
+    printf "No (will use our own instead).\n"
+    have_canonicalize_file_name=0
+fi
+rm -f compat/have_canonicalize_file_name
+
+
 printf "Checking for getline... "
 if ${CC} -o compat/have_getline "$srcdir"/compat/have_getline.c > /dev/null 2>&1
 then
@@ -751,6 +763,10 @@ zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/functions/Completio
 
 # Whether the getline function is available (if not, then notmuch will
 # build its own version)
+HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name}
+
+# Whether the getline function is available (if not, then notmuch will
+# build its own version)
 HAVE_GETLINE = ${have_getline}
 
 # Whether the strcasestr function is available (if not, then notmuch will
diff --git a/notmuch-config.c b/notmuch-config.c
index 8d28653..4886d36 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -454,7 +454,7 @@ notmuch_config_save (notmuch_config_t *config)
     }
 
     /* Try not to overwrite symlinks. */
-    filename = realpath (config->filename, NULL);
+    filename = canonicalize_file_name (config->filename);
     if (! filename) {
 	if (errno == ENOENT) {
 	    filename = strdup (config->filename);
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] compat: add canonicalize_file_name
  2014-01-27 14:12       ` [PATCH] compat: add canonicalize_file_name David Bremner
@ 2014-01-27 19:07         ` Tomi Ollila
  2014-04-08 11:22         ` David Bremner
  1 sibling, 0 replies; 13+ messages in thread
From: Tomi Ollila @ 2014-01-27 19:07 UTC (permalink / raw)
  To: David Bremner, notmuch

On Mon, Jan 27 2014, David Bremner <david@tethera.net> wrote:

> the POSIX 2008 behaviour of realpath is not available everywhere so we
> provide a simple wrapper function.  We use (and provide) the gnu
> extension canonicalize_file_name to make it cleaner to test for the
> feature we need; otherwise we have to rely on realpath segfaulting if
> the second argument is null.
> ---

I think this patch is tolerable. I first thought we should check the
combination of not having canonicalize_file_name() and having POSIX 2008
behaviour of realpath()...

... but the compat code is simple enough and basically done the same way
as in (e.g.)

http://svnweb.freebsd.org/base/release/9.2.0/lib/libc/stdlib/realpath.c?revision=255898&view=markup

qualifying the implementation. So +1 from me.

Tomi

>  compat/Makefile.local                |  4 ++++
>  compat/canonicalize_file_name.c      | 18 ++++++++++++++++++
>  compat/compat.h                      |  8 ++++++++
>  compat/have_canonicalize_file_name.c | 10 ++++++++++
>  configure                            | 16 ++++++++++++++++
>  notmuch-config.c                     |  2 +-
>  6 files changed, 57 insertions(+), 1 deletion(-)
>  create mode 100644 compat/canonicalize_file_name.c
>  create mode 100644 compat/have_canonicalize_file_name.c
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] compat: add canonicalize_file_name
  2014-01-27 14:12       ` [PATCH] compat: add canonicalize_file_name David Bremner
  2014-01-27 19:07         ` Tomi Ollila
@ 2014-04-08 11:22         ` David Bremner
  2014-04-09 11:24           ` [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so David Bremner
  1 sibling, 1 reply; 13+ messages in thread
From: David Bremner @ 2014-04-08 11:22 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> the POSIX 2008 behaviour of realpath is not available everywhere so we
> provide a simple wrapper function.  We use (and provide) the gnu
> extension canonicalize_file_name to make it cleaner to test for the
> feature we need; otherwise we have to rely on realpath segfaulting if
> the second argument is null.

pushed

d

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so
  2014-04-08 11:22         ` David Bremner
@ 2014-04-09 11:24           ` David Bremner
  2014-04-09 11:24             ` [PATCH 2/2] configure: fix comment, pass HAVE_CANONICALIZE_FILE_NAME to build David Bremner
                               ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: David Bremner @ 2014-04-09 11:24 UTC (permalink / raw)
  To: notmuch

This is needed for our compat version of canonicalize_file_name to be used.
---
 lib/gen-version-script.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/gen-version-script.sh b/lib/gen-version-script.sh
index 76670d5..64a7374 100644
--- a/lib/gen-version-script.sh
+++ b/lib/gen-version-script.sh
@@ -23,6 +23,6 @@ while read sym; do
 	    ;;
     esac
 done
-nm $* | awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $2 == "T" && $3 ~ "^get(line|delim)$" {print $3 ";"}'
+nm $* | awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $2 == "T" && $3 ~ "^(getline|getdelim|canonicalize_file_name)$" {print $3 ";"}'
 sed  -n 's/^[[:space:]]*\(notmuch_[a-z_]*\)[[:space:]]*(.*/ \1;/p' $HEADER
 printf "local: *;\n};\n"
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/2] configure: fix comment, pass HAVE_CANONICALIZE_FILE_NAME to build
  2014-04-09 11:24           ` [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so David Bremner
@ 2014-04-09 11:24             ` David Bremner
  2014-04-17 22:24               ` [PATCH] " David Bremner
  2014-04-14 12:21             ` [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so Tomi Ollila
  2014-04-18 21:05             ` David Bremner
  2 siblings, 1 reply; 13+ messages in thread
From: David Bremner @ 2014-04-09 11:24 UTC (permalink / raw)
  To: notmuch

Apparently omitting it is not fatal, but let's be consistent with the
other compat functions.
---
 configure | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 09f4650..256c918 100755
--- a/configure
+++ b/configure
@@ -812,7 +812,7 @@ bash_completion_dir = ${BASHCOMPLETIONDIR:=\$(sysconfdir)/bash_completion.d}
 # The directory to which zsh completions files should be installed
 zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/functions/Completion/Unix}
 
-# Whether the getline function is available (if not, then notmuch will
+# Whether the canonicalize_file_name function is available (if not, then notmuch will
 # build its own version)
 HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name}
 
@@ -887,6 +887,7 @@ WITH_ZSH = ${WITH_ZSH}
 
 # Combined flags for compiling and linking against all of the above
 CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
+		   -DHAVE_CANONICALIZE_FILE_NAME=\$(HAVE_CANONICALIZE_FILE_NAME) \\
 		   \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
 		   \$(VALGRIND_CFLAGS)                                   \\
 		   -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)                 \\
@@ -898,6 +899,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
 		   -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
 
 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
+		     -DHAVE_CANONICALIZE_FILE_NAME=\$(HAVE_CANONICALIZE_FILE_NAME) \\
 		     \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
 		     \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\
 		     -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)               \\
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so
  2014-04-09 11:24           ` [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so David Bremner
  2014-04-09 11:24             ` [PATCH 2/2] configure: fix comment, pass HAVE_CANONICALIZE_FILE_NAME to build David Bremner
@ 2014-04-14 12:21             ` Tomi Ollila
  2014-04-18 21:05             ` David Bremner
  2 siblings, 0 replies; 13+ messages in thread
From: Tomi Ollila @ 2014-04-14 12:21 UTC (permalink / raw)
  To: David Bremner, notmuch

On Wed, Apr 09 2014, David Bremner <david@tethera.net> wrote:

> This is needed for our compat version of canonicalize_file_name to be used.
> ---

This series LGTM, just that this does not apply anymore (2nd patch, that is).

>  lib/gen-version-script.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/gen-version-script.sh b/lib/gen-version-script.sh
> index 76670d5..64a7374 100644
> --- a/lib/gen-version-script.sh
> +++ b/lib/gen-version-script.sh
> @@ -23,6 +23,6 @@ while read sym; do
>  	    ;;
>      esac
>  done
> -nm $* | awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $2 == "T" && $3 ~ "^get(line|delim)$" {print $3 ";"}'
> +nm $* | awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $2 == "T" && $3 ~ "^(getline|getdelim|canonicalize_file_name)$" {print $3 ";"}'
>  sed  -n 's/^[[:space:]]*\(notmuch_[a-z_]*\)[[:space:]]*(.*/ \1;/p' $HEADER
>  printf "local: *;\n};\n"
> -- 
> 1.9.0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH] configure: fix comment, pass HAVE_CANONICALIZE_FILE_NAME to build
  2014-04-09 11:24             ` [PATCH 2/2] configure: fix comment, pass HAVE_CANONICALIZE_FILE_NAME to build David Bremner
@ 2014-04-17 22:24               ` David Bremner
  0 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2014-04-17 22:24 UTC (permalink / raw)
  To: notmuch

Apparently omitting it is not fatal, but let's be consistent with the
other compat functions.
---
rebased against master
 configure | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index f447581..9bde2eb 100755
--- a/configure
+++ b/configure
@@ -829,7 +829,7 @@ bash_completion_dir = ${BASHCOMPLETIONDIR:=\$(sysconfdir)/bash_completion.d}
 # The directory to which zsh completions files should be installed
 zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/functions/Completion/Unix}
 
-# Whether the getline function is available (if not, then notmuch will
+# Whether the canonicalize_file_name function is available (if not, then notmuch will
 # build its own version)
 HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name}
 
@@ -908,6 +908,7 @@ WITH_ZSH = ${WITH_ZSH}
 
 # Combined flags for compiling and linking against all of the above
 CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
+		   -DHAVE_CANONICALIZE_FILE_NAME=\$(HAVE_CANONICALIZE_FILE_NAME) \\
 		   \$(ZLIB_CFLAGS)					 \\
 		   \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
 		   \$(VALGRIND_CFLAGS)                                   \\
@@ -920,6 +921,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
 		   -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
 
 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
+		     -DHAVE_CANONICALIZE_FILE_NAME=\$(HAVE_CANONICALIZE_FILE_NAME) \\
 		     \$(ZLIB_CFLAGS)					 \\
 		     \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
 		     \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so
  2014-04-09 11:24           ` [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so David Bremner
  2014-04-09 11:24             ` [PATCH 2/2] configure: fix comment, pass HAVE_CANONICALIZE_FILE_NAME to build David Bremner
  2014-04-14 12:21             ` [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so Tomi Ollila
@ 2014-04-18 21:05             ` David Bremner
  2 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2014-04-18 21:05 UTC (permalink / raw)
  To: notmuch; +Cc: Allan Streib, Thomas Klausner

David Bremner <david@tethera.net> writes:

> This is needed for our compat version of canonicalize_file_name to be used.

pushed.

OpenBSD users: please try commit g2d024ff, to see if it fixes the issues
with finding canonicalize_file_name

d

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-04-18 21:07 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-25 21:59 [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation Tomi Ollila
2014-01-25 22:22 ` Tomi Ollila
2014-01-26  0:55 ` David Bremner
2014-01-26 11:18   ` Tomi Ollila
2014-01-26 16:49     ` David Bremner
2014-01-27 14:12       ` [PATCH] compat: add canonicalize_file_name David Bremner
2014-01-27 19:07         ` Tomi Ollila
2014-04-08 11:22         ` David Bremner
2014-04-09 11:24           ` [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so David Bremner
2014-04-09 11:24             ` [PATCH 2/2] configure: fix comment, pass HAVE_CANONICALIZE_FILE_NAME to build David Bremner
2014-04-17 22:24               ` [PATCH] " David Bremner
2014-04-14 12:21             ` [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so Tomi Ollila
2014-04-18 21:05             ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).