From owner-svn-src-stable@freebsd.org Thu Jun 21 14:41:59 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 33ED71020E77; Thu, 21 Jun 2018 14:41:59 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DAFD17F8FD; Thu, 21 Jun 2018 14:41:58 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9B1A2131B1; Thu, 21 Jun 2018 14:41:58 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5LEfwTG050958; Thu, 21 Jun 2018 14:41:58 GMT (envelope-from dteske@FreeBSD.org) Received: (from dteske@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5LEfwg8050957; Thu, 21 Jun 2018 14:41:58 GMT (envelope-from dteske@FreeBSD.org) Message-Id: <201806211441.w5LEfwg8050957@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dteske set sender to dteske@FreeBSD.org using -f From: Devin Teske Date: Thu, 21 Jun 2018 14:41:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r335484 - stable/11/usr.sbin/bsdconfig/share X-SVN-Group: stable-11 X-SVN-Commit-Author: dteske X-SVN-Commit-Paths: stable/11/usr.sbin/bsdconfig/share X-SVN-Commit-Revision: 335484 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jun 2018 14:41:59 -0000 Author: dteske Date: Thu Jun 21 14:41:58 2018 New Revision: 335484 URL: https://svnweb.freebsd.org/changeset/base/335484 Log: MFC r335280-r335281, r335302: sysrc.subr updates r335280: Fix handling of files with missing newline at EOF r335302: Fix a comment for accuracy PR: bin/203435 Reported by: Andreas Sommer r335281: Fix display when value is "-n" PR: bin/226406 Reported by: Marius Halden Sponsored by: Smule, Inc. Modified: stable/11/usr.sbin/bsdconfig/share/sysrc.subr Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/bsdconfig/share/sysrc.subr ============================================================================== --- stable/11/usr.sbin/bsdconfig/share/sysrc.subr Thu Jun 21 14:30:14 2018 (r335483) +++ stable/11/usr.sbin/bsdconfig/share/sysrc.subr Thu Jun 21 14:41:58 2018 (r335484) @@ -200,7 +200,7 @@ f_sysrc_get() # such as "${varname?}" and "${varname:?}" (see "Parameter # Expansion" in sh(1) for more information). # - eval echo '"${'"$1"'}"' 2> /dev/null + eval printf "'%s\\n'" '"${'"$1"'}"' 2> /dev/null ) } @@ -338,7 +338,7 @@ f_sysrc_get_default() # such as "${varname?}" and "${varname:?}" (see "Parameter # Expansion" in sh(1) for more information). # - eval echo '"${'"$1"'}"' 2> /dev/null + eval printf "'%s\\n'" '"${'"$1"'}"' 2> /dev/null ) } @@ -556,9 +556,16 @@ f_sysrc_set() fi # - # If not found, append new value to last file and return. + # If not found, append new value to first file and return. # if [ "$not_found" ]; then + # Add a newline if missing before appending to the file + awk 'BEGIN { wc = 0 } NR == 1 { + (cmd = "wc -l " FILENAME) | getline + close(cmd) + wc = $1 + } END { exit wc != NR }' "$file" || + echo >> "$file" || return $? echo "$varname=\"$new_value\"" >> "$file" return $? fi @@ -606,8 +613,11 @@ f_sysrc_set() # # Operate on the matching file, replacing only the last occurrence. # + # Use awk to ensure LF at end of each line, else files without ending + # LF will trigger a bug in `tail -r' where last two lines are joined. + # local new_contents retval - new_contents=$( tail -r $file 2> /dev/null ) + new_contents=$( awk 1 "$file" 2> /dev/null | tail -r ) new_contents=$( echo "$new_contents" | awk -v varname="$varname" \ -v new_value="$new_value" "$f_sysrc_set_awk" ) retval=$?