From owner-svn-src-head@freebsd.org Sun Jun 17 06:03:49 2018 Return-Path: Delivered-To: svn-src-head@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 45195100F5E0; Sun, 17 Jun 2018 06:03:49 +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 D67BF8124B; Sun, 17 Jun 2018 06:03:48 +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 B1F00117A4; Sun, 17 Jun 2018 06:03:48 +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 w5H63mKo076159; Sun, 17 Jun 2018 06:03:48 GMT (envelope-from dteske@FreeBSD.org) Received: (from dteske@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5H63mHA076158; Sun, 17 Jun 2018 06:03:48 GMT (envelope-from dteske@FreeBSD.org) Message-Id: <201806170603.w5H63mHA076158@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dteske set sender to dteske@FreeBSD.org using -f From: Devin Teske Date: Sun, 17 Jun 2018 06:03:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335280 - head/usr.sbin/bsdconfig/share X-SVN-Group: head X-SVN-Commit-Author: dteske X-SVN-Commit-Paths: head/usr.sbin/bsdconfig/share X-SVN-Commit-Revision: 335280 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jun 2018 06:03:49 -0000 Author: dteske Date: Sun Jun 17 06:03:48 2018 New Revision: 335280 URL: https://svnweb.freebsd.org/changeset/base/335280 Log: sysrc.subr: Fix handling of files with missing newline at EOF PR: bin/203435 Reported by: Andreas Sommer MFC after: 1 week X-MFC-to: stable/11 Sponsored by: Smule, Inc. Modified: head/usr.sbin/bsdconfig/share/sysrc.subr Modified: head/usr.sbin/bsdconfig/share/sysrc.subr ============================================================================== --- head/usr.sbin/bsdconfig/share/sysrc.subr Sun Jun 17 05:55:31 2018 (r335279) +++ head/usr.sbin/bsdconfig/share/sysrc.subr Sun Jun 17 06:03:48 2018 (r335280) @@ -559,6 +559,13 @@ f_sysrc_set() # If not found, append new value to last 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=$?