From owner-svn-src-all@freebsd.org Wed Feb 12 02:07:38 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 25F49249AA0; Wed, 12 Feb 2020 02:07:38 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48HNMG08Hnz3D94; Wed, 12 Feb 2020 02:07:38 +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 EFE6519C24; Wed, 12 Feb 2020 02:07:37 +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 01C27baf054633; Wed, 12 Feb 2020 02:07:37 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01C27bZM054631; Wed, 12 Feb 2020 02:07:37 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202002120207.01C27bZM054631@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 12 Feb 2020 02:07:37 +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: r357790 - in stable: 11/usr.bin/env 12/usr.bin/env X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/usr.bin/env 12/usr.bin/env X-SVN-Commit-Revision: 357790 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Feb 2020 02:07:38 -0000 Author: kevans Date: Wed Feb 12 02:07:37 2020 New Revision: 357790 URL: https://svnweb.freebsd.org/changeset/base/357790 Log: MFC r354450: Add -0 option to ENV(1) With the -0 option added to ENV(1), some ports will no longer require genv from sysutils/coreutils. Modified: stable/11/usr.bin/env/env.1 stable/11/usr.bin/env/env.c Directory Properties: stable/11/ (props changed) Changes in other areas also in this revision: Modified: stable/12/usr.bin/env/env.1 stable/12/usr.bin/env/env.c Directory Properties: stable/12/ (props changed) Modified: stable/11/usr.bin/env/env.1 ============================================================================== --- stable/11/usr.bin/env/env.1 Wed Feb 12 02:04:03 2020 (r357789) +++ stable/11/usr.bin/env/env.1 Wed Feb 12 02:07:37 2020 (r357790) @@ -31,7 +31,7 @@ .\" From FreeBSD: src/usr.bin/printenv/printenv.1,v 1.17 2002/11/26 17:33:35 ru Exp .\" $FreeBSD$ .\" -.Dd April 17, 2008 +.Dd November 7, 2019 .Dt ENV 1 .Os .Sh NAME @@ -39,7 +39,7 @@ .Nd set environment and execute command, or print environment .Sh SYNOPSIS .Nm -.Op Fl iv +.Op Fl 0iv .Op Fl P Ar altpath .Op Fl S Ar string .Op Fl u Ar name @@ -64,6 +64,8 @@ is executed. .Pp The options are as follows: .Bl -tag -width indent +.It Fl 0 +End each output line with NUL, not newline. .It Fl i Execute the .Ar utility @@ -130,8 +132,15 @@ If no .Ar utility is specified, .Nm -prints out the names and values -of the variables in the environment, with one name/value pair per line. +prints out the names and values of the variables in the environment. +Each name/value pair is separated by a new line unless +.Fl 0 +is specified, in which case name/value pairs are separated by NUL. +Both +.Fl 0 +and +.Ar utility +may not be specified together. .\" .Ss Details of Fl S \&Ss (split-string) processing The processing of the Modified: stable/11/usr.bin/env/env.c ============================================================================== --- stable/11/usr.bin/env/env.c Wed Feb 12 02:04:03 2020 (r357789) +++ stable/11/usr.bin/env/env.c Wed Feb 12 02:07:37 2020 (r357790) @@ -57,22 +57,33 @@ int env_verbosity; static void usage(void); +/* + * Exit codes. + */ +#define EXIT_CANCELED 125 /* Internal error prior to exec attempt. */ +#define EXIT_CANNOT_INVOKE 126 /* Program located, but not usable. */ +#define EXIT_ENOENT 127 /* Could not find program to exec. */ + int main(int argc, char **argv) { - char *altpath, **ep, *p, **parg; + char *altpath, **ep, *p, **parg, term; char *cleanenv[1]; int ch, want_clear; int rtrn; altpath = NULL; want_clear = 0; - while ((ch = getopt(argc, argv, "-iP:S:u:v")) != -1) + term = '\n'; + while ((ch = getopt(argc, argv, "-0iP:S:u:v")) != -1) switch(ch) { case '-': case 'i': want_clear = 1; break; + case '0': + term = '\0'; + break; case 'P': altpath = strdup(optarg); break; @@ -116,6 +127,8 @@ main(int argc, char **argv) err(EXIT_FAILURE, "setenv %s", *argv); } if (*argv) { + if (term == '\0') + errx(EXIT_CANCELED, "cannot specify command with -0"); if (altpath) search_paths(altpath, argv); if (env_verbosity) { @@ -127,10 +140,11 @@ main(int argc, char **argv) sleep(1); } execvp(*argv, argv); - err(errno == ENOENT ? 127 : 126, "%s", *argv); + err(errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE, + "%s", *argv); } for (ep = environ; *ep; ep++) - (void)printf("%s\n", *ep); + (void)printf("%s%c", *ep, term); exit(0); } @@ -138,7 +152,7 @@ static void usage(void) { (void)fprintf(stderr, - "usage: env [-iv] [-P utilpath] [-S string] [-u name]\n" + "usage: env [-0iv] [-P utilpath] [-S string] [-u name]\n" " [name=value ...] [utility [argument ...]]\n"); exit(1); }