unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: notmuch@notmuchmail.org
Subject: Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation.
Date: Sun, 26 Jan 2014 00:22:47 +0200	[thread overview]
Message-ID: <m2bnyzhfbc.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <1390687142-16401-1-git-send-email-tomi.ollila@iki.fi>

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

  reply	other threads:[~2014-01-25 22:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2bnyzhfbc.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).