Return-Path: X-Original-To: apmail-subversion-dev-archive@minotaur.apache.org Delivered-To: apmail-subversion-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C673A10890 for ; Tue, 27 Jan 2015 10:17:32 +0000 (UTC) Received: (qmail 56226 invoked by uid 500); 27 Jan 2015 10:17:33 -0000 Delivered-To: apmail-subversion-dev-archive@subversion.apache.org Received: (qmail 56169 invoked by uid 500); 27 Jan 2015 10:17:33 -0000 Mailing-List: contact dev-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list dev@subversion.apache.org Received: (qmail 56134 invoked by uid 99); 27 Jan 2015 10:17:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Jan 2015 10:17:27 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [66.111.4.27] (HELO out3-smtp.messagingengine.com) (66.111.4.27) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Jan 2015 10:17:02 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 7E3FB2030F; Tue, 27 Jan 2015 05:14:53 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Tue, 27 Jan 2015 05:14:53 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=x-sasl-enc:date:from:to:subject:message-id :mime-version:content-type; s=mesmtp; bh=5P22uFheiAcBk6Wphz7DLiL 5FKo=; b=JVW7vVCrzApGKgzK88hY0JpenqvPGYMHMeAqd+VwwuqvNg4i2qpdV9s EdTeQmktLQnJbo08TkNg46ingFCdUnMwHL+gwpI9XuBTMlYzMbC02I9useZUprjE F2NFNphOjYS9MKBxUrivt63BxSSqMGHPuoXNqtSnslod6vlEFVF8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:date:from:to:subject :message-id:mime-version:content-type; s=smtpout; bh=5P22uFheiAc Bk6Wphz7DLiL5FKo=; b=SkdGagAiLjdiapkLccamuNqebTzQNXohUW9+jkpVezv DXBRM7WaJ1BETwvl42e3TMjxiVzA0QtsSSm96cMq5cN45EdqoKFakAqSis0UL9zf 9ZRp/z+tbQLIlxfF6k8FhHkkpQ8pm8TXBvenY/ZyLyi6B2Jl3qqmuEV093rYw9wk = X-Sasl-enc: 9dt0nINgLL/2HZsFVNDtd9ILpcrHI2YkNSDnh7HDhrv9 1422353692 Received: from tarsus.local2 (unknown [109.66.109.124]) by mail.messagingengine.com (Postfix) with ESMTPA id B3676C00013 for ; Tue, 27 Jan 2015 05:14:52 -0500 (EST) Date: Tue, 27 Jan 2015 10:14:50 +0000 From: Daniel Shahaf To: dev@subversion.apache.org Subject: [PATCH] svn --version --verbose += /etc/os-release Message-ID: <20150127101450.GE1966@tarsus.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Checked: Checked by ClamAV on apache.org [[[ svn --version --verbose: Support /etc/os-release, the systemd "what distro am I running" API. * subversion/libsvn_subr/sysinfo.c (linux_release_name): Try /etc/os-release if /usr/bin/lsb_release fails. (systemd_release): New helper for linux_release_name(). (remove_shell_quoting): New helper function. ]]] --- subversion/libsvn_subr/sysinfo.c +++ subversion/libsvn_subr/sysinfo.c @@ -410,6 +410,78 @@ lsb_release(apr_pool_t *pool) return NULL; } +/* Attempt to strip double quotes from a string. + * + * The string considered is (STR->DATA + OFFSET). If it starts + * and ends with double quotes, and has no escape sequences, return + * the string delimited by the double quotes. Otherwise, return + * the original string verbatim. + */ +static const char * +remove_shell_quoting(svn_stringbuf_t *buf, + int offset, + apr_pool_t *result_pool) +{ + const char *str = buf->data + offset; + const char *second_double_quote; + + /* Are there exactly two double quotes, at the first and last positions? */ + if (str[0] == '"' && (second_double_quote = strchr(str+1, '"')) + && second_double_quote[1] == '\0') + /* Are there any backslashes? */ + if (!strchr(str, '\\')) + /* Return whatever is between the quotes. */ + return apr_pstrndup(result_pool, str+1, second_double_quote - (str+1)); + + /* There are no double quotes, or there is a backslash and we punted. + * Either way, we'll return the string verbatim. */ + return str; +} + +/* Read /etc/os-release, as documented here: + * http://www.freedesktop.org/software/systemd/man/os-release.html + */ +static const char * +systemd_release(apr_pool_t *pool) +{ + svn_error_t *err; + svn_stream_t *stream; + + err = svn_stream_open_readonly(&stream, "/etc/os-release", pool, pool); + if (err && APR_STATUS_IS_ENOENT(err->apr_err)) + { + svn_error_clear(err); + err = svn_stream_open_readonly(&stream, "/usr/lib/os-release", pool, + pool); + } + if (err) + { + svn_error_clear(err); + return NULL; + } + + while (TRUE) + { + svn_stringbuf_t *line; + svn_boolean_t eof; + + err = svn_stream_readline(stream, &line, "\n", &eof, pool); + if (err) + { + svn_error_clear(err); + return NULL; + } + + if (!strncmp(line->data, "PRETTY_NAME=", 12)) + return remove_shell_quoting(line, 12, pool); + + if (eof) + break; + } + + return NULL; +} + /* Read the whole contents of a file. */ static svn_stringbuf_t * read_file_contents(const char *filename, apr_pool_t *pool) @@ -527,6 +599,10 @@ linux_release_name(apr_pool_t *pool) Covers, for example, Debian, Ubuntu and SuSE. */ const char *release_name = lsb_release(pool); + /* Try the systemd way (covers Arch). */ + if (!release_name) + release_name = systemd_release(pool); + /* Try RHEL/Fedora/CentOS */ if (!release_name) release_name = redhat_release(pool);