From: Tomi Ollila Date: Sat, 25 Jan 2014 22:22:47 +0000 (+0200) Subject: Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=83beff3bd784b3f6ebefe633d0f5cf6a7f1f3d28;p=notmuch-archives.git Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation. --- diff --git a/31/6ce5fa2d4bc6a0a4ed6f3faf01f72a8a5dd5be b/31/6ce5fa2d4bc6a0a4ed6f3faf01f72a8a5dd5be new file mode 100644 index 000000000..995773dc4 --- /dev/null +++ b/31/6ce5fa2d4bc6a0a4ed6f3faf01f72a8a5dd5be @@ -0,0 +1,196 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id B3052431FBD + for ; Sat, 25 Jan 2014 14:23:00 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 7I2ZIumpBa2J for ; + Sat, 25 Jan 2014 14:22:52 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 3D483431FBC + for ; Sat, 25 Jan 2014 14:22:52 -0800 (PST) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id AD40A1000B3 + for ; Sun, 26 Jan 2014 00:22:47 +0200 (EET) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: Re: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) + implementation. +In-Reply-To: <1390687142-16401-1-git-send-email-tomi.ollila@iki.fi> +References: <1390687142-16401-1-git-send-email-tomi.ollila@iki.fi> +User-Agent: Notmuch/0.17+41~g8e7fabf (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 25 Jan 2014 22:23:00 -0000 + +On Sat, Jan 25 2014, Tomi Ollila 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 < +#define _BSD_SOURCE +> +#include +> +#include +> +#include +> +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 < +> @@ -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