From nobody Thu Dec 12 16:00:53 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 4Y8HJ51zpFz5gRZp; Thu, 12 Dec 2024 16:00:53 +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 4Y8HJ51QWNz4gLk; Thu, 12 Dec 2024 16:00:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734019253; 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=Ae9hUhsQ+0bKLQgDlvIN9zvzfSTEoFbi58ufviitY+g=; b=IeP3V/dq/ZPLZ5LVDzuYm2bILcvtgsb6JK7nWLMSfuZeTrU3CP4EX2wvnNEFRnrFm3HJ62 IGNs4Jb4xS8MPGTJP6cN9Y2JB0TGCeRUsRaXpBLCZLfjmXusaXfqtw0uzNjoMqlydhQDUU AcToMctqpWaGBzS1ncqOyb1zgAHQHvrqCV3T5+XYs/vN8WTgHagCa/6OF1yYZ3/nYOUVwU DkLLhWjwy18h3FF5AG1OqDz/KIx1HawFAkXKTDe7jFx5d1A5m2Es/WaoN8jfsoU4MkyQck Nq1weu6uvpQMAuvexCaFdDQEcXXwcQCNlBPyV9Bopi1HDp7RWuoyLWz5eA8rKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734019253; 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=Ae9hUhsQ+0bKLQgDlvIN9zvzfSTEoFbi58ufviitY+g=; b=BB+WzcfwhbUM9R939nCcFInj9LKDq5G4V3fB6JyysFXfwNwiKEnRkxwD+h2Aq+9WxMg4zJ IMNWi9gxFqfVtYXjb4VfP4BmolxZXRH4J6C+o/pxtAiWE3N7VBUUXfOnwgtqN7Pa6r6jpu Ur9dnJM4fN0O3qxf22nbV4XctKmjKmDRuPVKtITbu7VK06pVbCrOMgfxKgsUTsl63S2ekE vWrfN5FtCYLQ2quikfHTYMK6F6akyeC7vXPxmNuJApfChWfxRS9Tg62P+qxO87hM4XeRg/ pfrvovVP8SA7H6/QSMzJG+YFmZX4ulJuUy0SEHnqNWmpTzbzlL/Jnf7b+MwppQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734019253; a=rsa-sha256; cv=none; b=w2thS5gEHhhKwtHAEG+T0hfbICPq8XQfBH7mdUfAwyisVNsg5V+lNrM4iscuYXvQ7m/TKx 6ai4uVGFD+QkpRu6ap7BLEbFM+jSPlHATFiEQFpGydxQcZuAHjqTouKacEsbqYud5ZAJUb 9fOivegNuYppB3L6HXtyfYFFLhKbY8T+KcZAAzooyk9A3vE+mghl6n1Yr2AwVL6Tqo4YMD C9ftnrd0+EUMHDtSrlsKOvrDtgdg5De+IQnxIkKN5s6XaeKdEJrJgd9XUEcX/rjA+Ysc/Z 8D8ff3XRqE08k7Ooj9+E64ZEJGB3c2tRFjSD7OhDuhQLu5ssk8p/PbqmT10rEg== 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 4Y8HJ511kCzyx7; Thu, 12 Dec 2024 16:00:53 +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 4BCG0row044366; Thu, 12 Dec 2024 16:00:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BCG0r6G044363; Thu, 12 Dec 2024 16:00:53 GMT (envelope-from git) Date: Thu, 12 Dec 2024 16:00:53 GMT Message-Id: <202412121600.4BCG0r6G044363@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 973a9a36fd56 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 973a9a36fd56fefa44ce2ab22eb67bb2077c1f84 Auto-Submitted: auto-generated The branch stable/13 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=973a9a36fd56fefa44ce2ab22eb67bb2077c1f84 commit 973a9a36fd56fefa44ce2ab22eb67bb2077c1f84 Author: Baptiste Daroussin AuthorDate: 2024-11-20 10:48:39 +0000 Commit: Baptiste Daroussin CommitDate: 2024-12-12 16:00:48 +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 (cherry picked from commit 65f5dd42f11cdcb7716e6cdd09fac2314c144c1f) --- 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 d422cff4cf0f..18bcf4ca0648 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -101,6 +101,7 @@ main(int argc, char *argv[]) struct stackmark smark, smark2; volatile int state; char *shinit; + int login; (void) setlocale(LC_ALL, ""); initcharset(); @@ -134,13 +135,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 f55e83f551a6..17fd878fa530 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -70,7 +70,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); @@ -82,19 +82,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)) { @@ -125,6 +126,8 @@ procargs(int argc, char **argv) argptr++; } optschanged(); + + return (login); } @@ -145,12 +148,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; @@ -196,6 +200,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) @@ -204,13 +210,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); } /* @@ -223,7 +229,7 @@ end_options2: if (!cmdline) { if (*argptr == NULL) setparam(0, argptr); - return; + return (login); } /* @@ -242,6 +248,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 811b395c1c5f..cd28baeeed6d 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 8f4434165191..59334d2042a6 100644 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -31,7 +31,7 @@ .\" .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" -.Dd May 10, 2021 +.Dd November 20, 2024 .Dt SH 1 .Os .Sh NAME @@ -39,14 +39,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 @@ -54,7 +54,7 @@ .Op Ar arg ... .Oc .Nm -.Op Fl /+abCEefhIimnPpTuVvx +.Op Fl /+abCEefhIilmnPpTuVvx .Op Fl /+o Ar longname .Fl s .Op Ar arg ... @@ -253,6 +253,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).