From nobody Wed Nov 20 12:57:50 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XthH26BDMz5djZj; Wed, 20 Nov 2024 12:57:50 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XthH25lf1z4tGW; Wed, 20 Nov 2024 12:57:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732107470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sJ6DK/qeiyjR9BBX0uaTsvZ9tm6ZJUaHZhJjlZdeIsA=; b=bYyDgNXFW8n6rjLx0vFcg6Ghe6fpXjxyBrKd49XLgz7MGECZ/uVVw7TleZ5fmr/M83RM9/ sPB6xcmwqdoYKPHa9UDwrVElC5BsTfPIO1eC7SIZ9+xCraphTGc2wDEhZoAowVBfNqBFkR kGn3BTek9EzXFWUysyA3Aw1tW0V7gwVLvsFZRtSu4GtclRr3yoXR0AMrkZznTWioBeCqwZ y5Q0WU0kPf+9DVL/Owz93xqYfrBflU+Tn/mgCt85jDkiNb6eHNzC85QLIHoURpYXyVSYmF 7YYbezB6tllxIpFnlefezjb3FCSj71kc+Rul563sQNy7CKQtZ5uq4St286gaEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732107470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sJ6DK/qeiyjR9BBX0uaTsvZ9tm6ZJUaHZhJjlZdeIsA=; b=rMBVAIF6OGN6NYoCzqqat1fsLFOto2qBO6VDmc+G+Xe+x7YmWtC+4wCxdPT9V2OfarIORO aWewGaSDQHGLZfE/xZXXQTD+vYLrBI7vLLM39XFWTPrI8EVrZCS9Bkdf24W9ZBd9GbC1+U CnN/GFE5zZ3CIMvxJ7+we9w/CsNXUcs1qcJJlCNCUeqJorCAsaHU9O9p9n+k3qE5/1g8QA TTcS+GPoYMlv1yahFAy1A1GdQMhf3NXVFolMsVutrspxAivmjHq4iq46stDAUzEOR3w4sM Xsm3LFSrfqTq4Eh7pv3xwsVcxv+M8fP3j3/xfre+jhR18CBuvNgd3cc+FvbXxQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732107470; a=rsa-sha256; cv=none; b=QNgd5zQeB4cEUJQo07nQRK3fndn+pgIVSVUsH+rdDAPpSYwOEs4202LopbxOa86PiteKBy C6Op5h2/j0j3J+dDwEnfDP++QUmIsHak7YM2SQdg4Vrxv2g46tpb/LU6YeTwAPdkhNlE1K A7BphGLRBhgg/CW/GCKbsf3BPmsefWKkmby3ym3/n1blEHPCkIakd4tVz6t1F5Ip1oe+VF kXOA5/AZyA6McndxvEUpZu5V+IdIO3d8OGXg8XUU6n8/31vztsRGrHZuKr9Trmmg7m3mRj wakLvbUhjHmO87UOFtKA8i8z7WfbFO3qXCqjTrFKomdVUvQJ9eQtFsPhW+NTQg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XthH25DMdzvJK; Wed, 20 Nov 2024 12:57:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4AKCvoFd043036; Wed, 20 Nov 2024 12:57:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AKCvoro043033; Wed, 20 Nov 2024 12:57:50 GMT (envelope-from git) Date: Wed, 20 Nov 2024 12:57:50 GMT Message-Id: <202411201257.4AKCvoro043033@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 65f5dd42f11c - main - sh(1): add -l option List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 65f5dd42f11cdcb7716e6cdd09fac2314c144c1f Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=65f5dd42f11cdcb7716e6cdd09fac2314c144c1f commit 65f5dd42f11cdcb7716e6cdd09fac2314c144c1f Author: Baptiste Daroussin AuthorDate: 2024-11-20 10:48:39 +0000 Commit: Baptiste Daroussin CommitDate: 2024-11-20 12:57:18 +0000 sh(1): add -l option -l is required by LSB for login shell, all other shells: bash, zsh, oksh, mksh, ... implements it. with -l sh will act as a login shell and read the profile. MFC After: 1 week Obtained From: dash (3b7c8442bfe7c2fd0a6b0415df6ddf66a399fd55) Reviewed by: kib, lme Differential Revision: https://reviews.freebsd.org/D47681 --- bin/sh/main.c | 5 +++-- bin/sh/options.c | 24 ++++++++++++++++-------- bin/sh/options.h | 2 +- bin/sh/sh.1 | 10 ++++++---- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/bin/sh/main.c b/bin/sh/main.c index 23147c1db0be..94e8da6b4921 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -95,6 +95,7 @@ main(int argc, char *argv[]) static struct stackmark smark, smark2; volatile int state; char *shinit; + int login; (void) setlocale(LC_ALL, ""); initcharset(); @@ -128,13 +129,13 @@ main(int argc, char *argv[]) initvar(); setstackmark(&smark); setstackmark(&smark2); - procargs(argc, argv); + login = procargs(argc, argv); trap_init(); pwd_init(iflag); INTON; if (iflag) chkmail(1); - if (argv[0] && argv[0][0] == '-') { + if (login) { state = 1; read_profile("/etc/profile"); state1: diff --git a/bin/sh/options.c b/bin/sh/options.c index 2dab8f4ea998..54a9cb4c1c49 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -64,7 +64,7 @@ char *nextopt_optptr; /* used by nextopt */ char *minusc; /* argument to -c option */ -static void options(int); +static int options(int); static void minus_o(char *, int); static void setoption(int, int); static void setoptionbyindex(int, int); @@ -76,19 +76,20 @@ static int getopts(char *, char *, char **, char ***, char **); * Process the shell command line arguments. */ -void +int procargs(int argc, char **argv) { - int i; + int i, login; char *scriptname; argptr = argv; + login = argptr[0] != NULL && argptr[0][0] == '-'; if (argc > 0) argptr++; for (i = 0; i < NOPTS; i++) optval[i] = 2; privileged = (getuid() != geteuid() || getgid() != getegid()); - options(1); + login |= options(1); if (*argptr == NULL && minusc == NULL) sflag = 1; if (iflag != 0 && sflag == 1 && isatty(0) && isatty(1)) { @@ -119,6 +120,8 @@ procargs(int argc, char **argv) argptr++; } optschanged(); + + return (login); } @@ -139,12 +142,13 @@ optschanged(void) * to the set special builtin. */ -static void +static int options(int cmdline) { char *kp, *p; int val; int c; + int login = 0; if (cmdline) minusc = NULL; @@ -190,6 +194,8 @@ options(int cmdline) if (q == NULL || minusc != NULL) error("Bad -c option"); minusc = q; + } else if (c == 'l') { + login = 1; } else if (c == 'o') { minus_o(*argptr, val); if (*argptr) @@ -198,13 +204,13 @@ options(int cmdline) setoption(c, val); } } - return; + return (login); /* When processing `set', a single "-" means turn off -x and -v */ end_options1: if (!cmdline) { xflag = vflag = 0; - return; + return (login); } /* @@ -217,7 +223,7 @@ end_options2: if (!cmdline) { if (*argptr == NULL) setparam(0, argptr); - return; + return (login); } /* @@ -236,6 +242,8 @@ end_options2: /* We need to keep the final argument */ argptr--; } + + return (login); } static void diff --git a/bin/sh/options.h b/bin/sh/options.h index 206d32c8a706..a059e19707b1 100644 --- a/bin/sh/options.h +++ b/bin/sh/options.h @@ -109,7 +109,7 @@ extern char **argptr; /* argument list for builtin commands */ extern char *shoptarg; /* set by nextopt */ extern char *nextopt_optptr; /* used by nextopt */ -void procargs(int, char **); +int procargs(int, char **); void optschanged(void); void freeparam(struct shparam *); int nextopt(const char *); diff --git a/bin/sh/sh.1 b/bin/sh/sh.1 index 1ce26ecba328..9903508d6381 100644 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 14, 2022 +.Dd November 20, 2024 .Dt SH 1 .Os .Sh NAME @@ -37,14 +37,14 @@ .Nd command interpreter (shell) .Sh SYNOPSIS .Nm -.Op Fl /+abCEefhIimnPpTuVvx +.Op Fl /+abCEefhIilmnPpTuVvx .Op Fl /+o Ar longname .Oo .Ar script .Op Ar arg ... .Oc .Nm -.Op Fl /+abCEefhIimnPpTuVvx +.Op Fl /+abCEefhIilmnPpTuVvx .Op Fl /+o Ar longname .Fl c Ar string .Oo @@ -52,7 +52,7 @@ .Op Ar arg ... .Oc .Nm -.Op Fl /+abCEefhIimnPpTuVvx +.Op Fl /+abCEefhIilmnPpTuVvx .Op Fl /+o Ar longname .Fl s .Op Ar arg ... @@ -251,6 +251,8 @@ Ignore from input when in interactive mode. .It Fl i Li interactive Force the shell to behave interactively. +.It Fl l +Force the shell to act as if it has been invoked as a login shell. .It Fl m Li monitor Turn on job control (set automatically when interactive). A new process group is created for each pipeline (called a job).