From owner-svn-src-head@freebsd.org Tue Feb 20 22:47:50 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 6F4EEF0D0FB; Tue, 20 Feb 2018 22:47:50 +0000 (UTC) (envelope-from kevans@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 1F30275529; Tue, 20 Feb 2018 22:47:50 +0000 (UTC) (envelope-from kevans@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 19F8F10043; Tue, 20 Feb 2018 22:47:50 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1KMlnmI024703; Tue, 20 Feb 2018 22:47:49 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1KMlnZF024702; Tue, 20 Feb 2018 22:47:49 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802202247.w1KMlnZF024702@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 20 Feb 2018 22:47:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329680 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 329680 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.25 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: Tue, 20 Feb 2018 22:47:50 -0000 Author: kevans Date: Tue Feb 20 22:47:49 2018 New Revision: 329680 URL: https://svnweb.freebsd.org/changeset/base/329680 Log: lualoader: When restoring environment, only restore unchanged vars Track the latest value we've set an environment variable to, and only restore those that are unchanged from that. This gives us some leeway to make sure we're not clobbering variables overwritten by menu changes. Modified: head/stand/lua/config.lua Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Tue Feb 20 22:03:08 2018 (r329679) +++ head/stand/lua/config.lua Tue Feb 20 22:47:49 2018 (r329680) @@ -142,13 +142,26 @@ function config.setCarouselIndex(id, idx) end function config.restoreEnv() + -- Examine changed environment variables for k, v in pairs(config.env_changed) do local restore_value = config.env_restore[k]; + if (restore_value == nil) then + -- This one doesn't need restored for some reason + goto continue; + end + local current_value = loader.getenv(k); + if (current_value ~= v) then + -- This was overwritten by some action taken on the menu + -- most likely; we'll leave it be. + goto continue; + end + restore_value = restore_value.value; if (restore_value ~= nil) then loader.setenv(k, restore_value); else loader.unsetenv(k); end + ::continue:: end config.env_changed = {}; @@ -156,11 +169,12 @@ function config.restoreEnv() end function config.setenv(k, v) - -- Do we need to track this change? - if (config.env_changed[k] == nil) then - config.env_changed[k] = true; - config.env_restore[k] = loader.getenv(k); + -- Track the original value for this if we haven't already + if (config.env_restore[k] == nil) then + config.env_restore[k] = {value = loader.getenv(k)}; end + + config.env_changed[k] = v; return loader.setenv(k, v); end