From owner-svn-src-stable-10@freebsd.org Tue Jan 19 21:39:23 2016 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 424BCA88D48; Tue, 19 Jan 2016 21:39:23 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id EF26F12B3; Tue, 19 Jan 2016 21:39:22 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0JLdLig044323; Tue, 19 Jan 2016 21:39:21 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0JLdLip044322; Tue, 19 Jan 2016 21:39:21 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201601192139.u0JLdLip044322@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Tue, 19 Jan 2016 21:39:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r294345 - stable/10/sys/boot/efi/loader X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2016 21:39:23 -0000 Author: ian Date: Tue Jan 19 21:39:21 2016 New Revision: 294345 URL: https://svnweb.freebsd.org/changeset/base/294345 Log: MFC r292584: Set env vars from values on the efi loader command line. Examine each cmdline arg and if it contains an '=' convert it to ascii and pass it to putenv(). This allows var=value settings to come in on the command line. This will allow overriding dhcp server-provided data in loader(8), as discussed in PR 202098 PR: 202098 Relnotes: Yes (this goes together with r294343) Modified: stable/10/sys/boot/efi/loader/main.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/boot/efi/loader/main.c ============================================================================== --- stable/10/sys/boot/efi/loader/main.c Tue Jan 19 21:37:51 2016 (r294344) +++ stable/10/sys/boot/efi/loader/main.c Tue Jan 19 21:39:21 2016 (r294345) @@ -63,10 +63,10 @@ EFI_GUID debugimg = DEBUG_IMAGE_INFO_TAB EFI_STATUS main(int argc, CHAR16 *argv[]) { - char vendor[128]; + char var[128]; EFI_LOADED_IMAGE *img; EFI_GUID *guid; - int i; + int i, j, vargood; /* * XXX Chicken-and-egg problem; we want to have console output @@ -76,6 +76,29 @@ main(int argc, CHAR16 *argv[]) */ cons_probe(); + /* + * Loop through the args, and for each one that contains an '=' that is + * not the first character, add it to the environment. This allows + * loader and kernel env vars to be passed on the command line. Convert + * args from UCS-2 to ASCII (16 to 8 bit) as they are copied. + */ + for (i = 1; i < argc; i++) { + vargood = 0; + for (j = 0; argv[i][j] != 0; j++) { + if (j == sizeof(var)) { + vargood = 0; + break; + } + if (j > 0 && argv[i][j] == '=') + vargood = 1; + var[j] = (char)argv[i][j]; + } + if (vargood) { + var[j] = 0; + putenv(var); + } + } + if (efi_copy_init()) { printf("failed to allocate staging area\n"); return (EFI_BUFFER_TOO_SMALL);