From 302204ab7a026d3029d171fa8ebddf82392661e4 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Sat, 25 Jan 2014 23:59:02 +0200 Subject: [PATCH] [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) implementation. --- 21/ce0d8a81fa20747863ca6e2617c9a4accc040a | 181 ++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 21/ce0d8a81fa20747863ca6e2617c9a4accc040a diff --git a/21/ce0d8a81fa20747863ca6e2617c9a4accc040a b/21/ce0d8a81fa20747863ca6e2617c9a4accc040a new file mode 100644 index 000000000..5b543b2e7 --- /dev/null +++ b/21/ce0d8a81fa20747863ca6e2617c9a4accc040a @@ -0,0 +1,181 @@ +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 07D9B431FBD + for ; Sat, 25 Jan 2014 13:59:18 -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 4kxfLVEYeKE8 for ; + Sat, 25 Jan 2014 13:59:11 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 80643431FBC + for ; Sat, 25 Jan 2014 13:59:11 -0800 (PST) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 02DA81000C1; Sat, 25 Jan 2014 23:59:03 +0200 (EET) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: [RFC PATCH] configure: check for POSIX.1-2008 realpath(3) + implementation. +Date: Sat, 25 Jan 2014 23:59:02 +0200 +Message-Id: <1390687142-16401-1-git-send-email-tomi.ollila@iki.fi> +X-Mailer: git-send-email 1.8.0 +Cc: tomi.ollila@iki.fi +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 21:59:18 -0000 + +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 < ++#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 <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 + -- 2.26.2