From 7fada9fd2718706bf19c1c6c945b093a4abfde7c Mon Sep 17 00:00:00 2001 From: kn Date: Wed, 8 Feb 2023 17:22:10 +0000 Subject: [PATCH] Omit version in SMALL ksh builds No need for KSH_VERSION and its PS1 esacape sequences in installer shells. Save some bits and clean up what(1) output on ramdisk kernels. OK deraadt --- bin/ksh/lex.c | 4 +++- bin/ksh/main.c | 10 +++++++++- distrib/special/ksh/Makefile | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c index 9e94e34ef5a..41178694fa6 100644 --- a/bin/ksh/lex.c +++ b/bin/ksh/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.78 2018/01/15 14:58:05 jca Exp $ */ +/* $OpenBSD: lex.c,v 1.79 2023/02/08 17:22:10 kn Exp $ */ /* * lexical analysis and source input @@ -1335,6 +1335,7 @@ dopprompt(const char *sp, int ntruncate, const char **spp, int doprint) case 'u': /* '\' 'u' username */ strlcpy(strbuf, username, sizeof strbuf); break; +#ifndef SMALL case 'v': /* '\' 'v' version (short) */ p = strchr(ksh_version, ' '); if (p) @@ -1350,6 +1351,7 @@ dopprompt(const char *sp, int ntruncate, const char **spp, int doprint) case 'V': /* '\' 'V' version (long) */ strlcpy(strbuf, ksh_version, sizeof strbuf); break; +#endif /* SMALL */ case 'w': /* '\' 'w' cwd */ p = str_val(global("PWD")); n = strlen(str_val(global("HOME"))); diff --git a/bin/ksh/main.c b/bin/ksh/main.c index a85cddfa9b3..5ab581ecaaf 100644 --- a/bin/ksh/main.c +++ b/bin/ksh/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.98 2019/06/28 13:34:59 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.99 2023/02/08 17:22:10 kn Exp $ */ /* * startup, main loop, environments and error handling @@ -81,7 +81,9 @@ static const char initifs[] = "IFS= \t\n"; static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }"; static const char *initcoms [] = { +#ifndef SMALL "typeset", "-r", "KSH_VERSION", NULL, +#endif /* SMALL */ "typeset", "-x", "SHELL", "PATH", "HOME", "PWD", "OLDPWD", NULL, "typeset", "-ir", "PPID", NULL, "typeset", "-i", "OPTIND=1", NULL, @@ -110,7 +112,9 @@ static const char *initcoms [] = { char username[_PW_NAME_LEN + 1]; +#ifndef SMALL #define version_param (initcoms[2]) +#endif /* SMALL */ /* The shell uses its own variation on argv, to build variables like * $0 and $@. @@ -247,7 +251,9 @@ main(int argc, char *argv[]) (strlen(kshname) >= 3 && !strcmp(&kshname[strlen(kshname) - 3], "/sh"))) { Flag(FSH) = 1; +#ifndef SMALL version_param = "SH_VERSION"; +#endif /* SMALL */ } /* Set edit mode to emacs by default, may be overridden @@ -296,8 +302,10 @@ main(int argc, char *argv[]) } ppid = getppid(); setint(global("PPID"), (int64_t) ppid); +#ifndef SMALL /* setstr can't fail here */ setstr(global(version_param), ksh_version, KSH_RETURN_ERROR); +#endif /* SMALL */ /* execute initialization statements */ for (wp = (char**) initcoms; *wp != NULL; wp++) { diff --git a/distrib/special/ksh/Makefile b/distrib/special/ksh/Makefile index 1a5e3b228af..9aced4e29ca 100644 --- a/distrib/special/ksh/Makefile +++ b/distrib/special/ksh/Makefile @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.5 2017/08/01 14:30:07 deraadt Exp $ +# $OpenBSD: Makefile,v 1.6 2023/02/08 17:22:10 kn Exp $ PROG= ksh SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \ exec.c expr.c history.c io.c jobs.c lex.c mail.c main.c \ misc.c path.c shf.c syn.c table.c trap.c tree.c tty.c var.c \ - version.c vi.c + vi.c DEFS= -Wall -DEMACS -DSMALL CFLAGS+=${DEFS} -I. -I${.CURDIR}/../../../bin/ksh -I${.CURDIR}/../../../lib/libc/gen -- 2.20.1