diff -Nru mksh-59c/debian/changelog mksh-59c/debian/changelog --- mksh-59c/debian/changelog 2023-01-26 06:22:31.000000000 +0000 +++ mksh-59c/debian/changelog 2023-02-15 15:04:53.000000000 +0000 @@ -1,3 +1,19 @@ +mksh (59c-26) unstable; urgency=medium + + * Fixup more update-shells breakage also found by piuparts + + -- Thorsten Glaser Wed, 15 Feb 2023 16:04:53 +0100 + +mksh (59c-25) unstable; urgency=medium + + * Amend add-shell workaround to piuparts trouble caused by merged-usr… + * Revamp entire update-shells logic for reliability + * Small targeted fixes from MirBSD CVS + - [tg] Improve situation when commands/etc. cannot be found + manpage + - [tg] Minor mbsdint.h fixes, it has a testuite now + + -- Thorsten Glaser Tue, 14 Feb 2023 19:48:24 +0100 + mksh (59c-24) unstable; urgency=medium * Raise time limit… diff -Nru mksh-59c/debian/copyright mksh-59c/debian/copyright --- mksh-59c/debian/copyright 2023-01-26 04:40:05.000000000 +0000 +++ mksh-59c/debian/copyright 2023-02-14 18:40:49.000000000 +0000 @@ -4,6 +4,8 @@ It was downloaded from: https://www.mirbsd.org/MirOS/dist/mir/mksh/mksh-R59c.tgz +The Debian packaging is © mirabilos Ⓕ The MirOS Licence as well. + Licence: diff -Nru mksh-59c/debian/mksh.lintian-overrides mksh-59c/debian/mksh.lintian-overrides --- mksh-59c/debian/mksh.lintian-overrides 2023-01-26 04:40:05.000000000 +0000 +++ mksh-59c/debian/mksh.lintian-overrides 2023-02-14 18:40:49.000000000 +0000 @@ -18,3 +18,7 @@ mksh: executable-in-usr-lib [usr/lib/diet/bin/mksh] mksh: executable-in-usr-lib [usr/lib/klibc/bin/mksh] mksh: executable-in-usr-lib [usr/lib/*-linux-musl/bin/mksh] + +# these are to clean old add-shell(8) damage, not actually dereferenced +mksh: bin-sbin-mismatch usr/bin/mksh -> bin/mksh [postinst] +mksh: bin-sbin-mismatch usr/bin/mksh -> bin/mksh [prerm] diff -Nru mksh-59c/debian/mksh.postinst mksh-59c/debian/mksh.postinst --- mksh-59c/debian/mksh.postinst 2023-01-26 04:53:38.000000000 +0000 +++ mksh-59c/debian/mksh.postinst 2023-02-15 15:03:11.000000000 +0000 @@ -1,7 +1,115 @@ #!/bin/sh +# shellcheck disable=SC3043 set -e +# Does what add-shell/remove-shell does, with the sync extras from +# update-shells, but does not add the link targets, only the lines +# listed; more safety checking; no regex escape issue; in contrast +# to the debianutils ones, it honours the admin’s choice disabling +# lines by commenting them, as in prefixing a single hash sign. +mogrifyshells() { + local basefile="$DPKG_ROOT/etc/shells" + local tmpa="$basefile.tmp" + local tmpb="$basefile.tmp2" + local rc=0 x mode='' oshf=$- + set +e + + case $basefile in + (/*) + ;; + (*) + echo >&2 "E: mogrifyshells: invalid DPKG_ROOT: $DPKG_ROOT" + exit 1 ;; + esac + + ( + set -o noclobber + cat "$basefile" >"$tmpa" + ) || { + cat >&2 <<-EOF + E: add-shell/remove-shell is currently running or was previously interrupted + I: Please examine ${tmpa} to see if it should be moved onto ${basefile} + EOF + exit 1 + } + + for x in "$@"; do + case $x in + (+) mode=+; continue ;; + (-) mode=-; continue ;; + esac + case $mode in + (+) + grep -F -x -q -e "$x" -e "#$x" "$tmpa" + rc=$? + case $rc in + (0) + ;; + (1) + printf '%s\n' "$x" >>"$tmpa" + ;; + (*) + echo >&2 "E: mogrifyshells: grep error $rc" + rm -f "$tmpa" + exit 1 ;; + esac + ;; + (-) + grep -F -x -v -e "$x" -e "#$x" "$tmpa" >"$tmpb" + rc=$? + case $rc in + (0|1) + ;; + (*) + echo >&2 "E: mogrifyshells: grep error $rc" + rm -f "$tmpa" "$tmpb" + exit 1 ;; + esac + mv "$tmpb" "$tmpa" || { + echo >&2 "E: mogrifyshells: mv error" + rm -f "$tmpa" "$tmpb" + exit 1 + } + ;; + (*) + echo >&2 'E: mogrifyshells: no mode given' + rm -f "$tmpa" + exit 1 + ;; + esac + done + + rc=0 + chmod --reference="$basefile" "$tmpa" || { + x=$(stat -c %a "$basefile") || rc=1 + chmod "0$x" "$tmpa" || rc=1 + } + chown --reference="$basefile" "$tmpa" || { + x=$(stat -c %u:%g "$basefile") || rc=1 + chown -- "$x" "$tmpa" || rc=1 + } + sync -d -- "$tmpa" || rc=1 + test 0 = "$rc" || { + echo >&2 'E: mogrifyshells: error during chmod/chown/fdatasync' + rm -f "$tmpa" + exit 1 + } + mv -Z "$tmpa" "$basefile" || mv "$tmpa" "$basefile" || { + echo >&2 "E: mogrifyshells: error during mv back; $tmpa left" + exit 1 # but keep temporary + } + sync "$basefile" "${basefile%/*}" || { + echo >&2 "W: mogrifyshells: error during final sync" + # and pray + } + + case $oshf in + (*e*) set -e ;; + esac + return 0 +} + # This maintainer script can be called the following ways: # # * new-postinst "configure" [$most_recently_configured_version] @@ -43,12 +151,15 @@ test -e /usr/bin/ksh || test -h /usr/bin/ksh || \ ln -s /bin/ksh /usr/bin/ksh - add-shell /bin/mksh - add-shell /bin/mksh-static - # do NOT list where symlinks point to as valid login shell - remove-shell /usr/lib/klibc/bin/mksh - remove-shell /usr/lib/diet/bin/mksh - remove-shell /usr/lib/*-linux-musl/bin/mksh + # add us to /etc/shells and clean up old add-shell-caused damage + # shellcheck disable=SC2046 + mogrifyshells + /bin/mksh /bin/mksh-static \ + - /usr/bin/mksh /usr/bin/mksh-static \ + $(for x in \ + /usr/lib/klibc/bin \ + /usr/lib/diet/bin \ + /usr/lib/*-linux-musl/bin \ + ; do echo "$x/mksh" "$x/mksh-static"; done) ;; (abort-upgrade|abort-remove|abort-deconfigure) diff -Nru mksh-59c/debian/mksh.prerm mksh-59c/debian/mksh.prerm --- mksh-59c/debian/mksh.prerm 2023-01-26 04:53:52.000000000 +0000 +++ mksh-59c/debian/mksh.prerm 2023-02-15 15:03:46.000000000 +0000 @@ -1,7 +1,115 @@ #!/bin/sh +# shellcheck disable=SC3043 set -e +# Does what add-shell/remove-shell does, with the sync extras from +# update-shells, but does not add the link targets, only the lines +# listed; more safety checking; no regex escape issue; in contrast +# to the debianutils ones, it honours the admin’s choice disabling +# lines by commenting them, as in prefixing a single hash sign. +mogrifyshells() { + local basefile="$DPKG_ROOT/etc/shells" + local tmpa="$basefile.tmp" + local tmpb="$basefile.tmp2" + local rc=0 x mode='' oshf=$- + set +e + + case $basefile in + (/*) + ;; + (*) + echo >&2 "E: mogrifyshells: invalid DPKG_ROOT: $DPKG_ROOT" + exit 1 ;; + esac + + ( + set -o noclobber + cat "$basefile" >"$tmpa" + ) || { + cat >&2 <<-EOF + E: add-shell/remove-shell is currently running or was previously interrupted + I: Please examine ${tmpa} to see if it should be moved onto ${basefile} + EOF + exit 1 + } + + for x in "$@"; do + case $x in + (+) mode=+; continue ;; + (-) mode=-; continue ;; + esac + case $mode in + (+) + grep -F -x -q -e "$x" -e "#$x" "$tmpa" + rc=$? + case $rc in + (0) + ;; + (1) + printf '%s\n' "$x" >>"$tmpa" + ;; + (*) + echo >&2 "E: mogrifyshells: grep error $rc" + rm -f "$tmpa" + exit 1 ;; + esac + ;; + (-) + grep -F -x -v -e "$x" -e "#$x" "$tmpa" >"$tmpb" + rc=$? + case $rc in + (0|1) + ;; + (*) + echo >&2 "E: mogrifyshells: grep error $rc" + rm -f "$tmpa" "$tmpb" + exit 1 ;; + esac + mv "$tmpb" "$tmpa" || { + echo >&2 "E: mogrifyshells: mv error" + rm -f "$tmpa" "$tmpb" + exit 1 + } + ;; + (*) + echo >&2 'E: mogrifyshells: no mode given' + rm -f "$tmpa" + exit 1 + ;; + esac + done + + rc=0 + chmod --reference="$basefile" "$tmpa" || { + x=$(stat -c %a "$basefile") || rc=1 + chmod "0$x" "$tmpa" || rc=1 + } + chown --reference="$basefile" "$tmpa" || { + x=$(stat -c %u:%g "$basefile") || rc=1 + chown -- "$x" "$tmpa" || rc=1 + } + sync -d -- "$tmpa" || rc=1 + test 0 = "$rc" || { + echo >&2 'E: mogrifyshells: error during chmod/chown/fdatasync' + rm -f "$tmpa" + exit 1 + } + mv -Z "$tmpa" "$basefile" || mv "$tmpa" "$basefile" || { + echo >&2 "E: mogrifyshells: error during mv back; $tmpa left" + exit 1 # but keep temporary + } + sync "$basefile" "${basefile%/*}" || { + echo >&2 "W: mogrifyshells: error during final sync" + # and pray + } + + case $oshf in + (*e*) set -e ;; + esac + return 0 +} + # This maintainer script can be called the following ways: # # * prerm "remove" @@ -25,11 +133,15 @@ # remove compatibility symlink if broken test '!' -h /usr/bin/ksh || test -e /usr/bin/ksh || rm -f /usr/bin/ksh - remove-shell /bin/mksh - remove-shell /bin/mksh-static - remove-shell /usr/lib/klibc/bin/mksh - remove-shell /usr/lib/diet/bin/mksh - remove-shell /usr/lib/*-linux-musl/bin/mksh + # unadd us from /etc/shells; clean up old add-shell-caused damage + # shellcheck disable=SC2046 + mogrifyshells - /bin/mksh /bin/mksh-static \ + - /usr/bin/mksh /usr/bin/mksh-static \ + $(for x in \ + /usr/lib/klibc/bin \ + /usr/lib/diet/bin \ + /usr/lib/*-linux-musl/bin \ + ; do echo "$x/mksh" "$x/mksh-static"; done) ;; (upgrade|failed-upgrade) diff -Nru mksh-59c/debian/patches/debian-changes mksh-59c/debian/patches/debian-changes --- mksh-59c/debian/patches/debian-changes 2023-01-26 06:22:31.000000000 +0000 +++ mksh-59c/debian/patches/debian-changes 2023-02-15 15:04:53.000000000 +0000 @@ -2322,7 +2322,7 @@ +++ mksh-59c/check.t @@ -1,9 +1,9 @@ -# $MirOS: src/bin/mksh/check.t,v 1.853 2020/10/31 03:53:03 tg Exp $ -+# $MirOS: src/bin/mksh/check.t,v 1.905 2023/01/24 05:04:58 tg Exp $ ++# $MirOS: src/bin/mksh/check.t,v 1.906 2023/01/31 01:05:06 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -2337,7 +2337,7 @@ expected-stdout: - KSH R59 2020/10/31 -+ KSH R59 2023/01/08 ++ KSH R59 2023/01/31 description: Check base version of full shell stdin: @@ -4001,12 +4001,12 @@ @@ -1,9 +1,9 @@ # $Id$ -# $MirOS: src/bin/mksh/dot.mkshrc,v 1.128 2020/04/13 18:39:03 tg Exp $ -+# $MirOS: src/bin/mksh/dot.mkshrc,v 1.143 2022/09/21 04:41:09 tg Exp $ ++# $MirOS: src/bin/mksh/dot.mkshrc,v 1.144 2023/01/31 01:05:08 tg Exp $ #- # Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, # 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, -# 2020 -+# 2020, 2021, 2022 ++# 2020, 2021, 2022, 2023 # mirabilos # # Provided that these terms and disclaimer and all copyright notices @@ -4305,7 +4305,7 @@ for x in "${i_all[@]}"; do y=$(\\builtin alias "$x") || y= - [[ $y = "$x='\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -r mksh: $x: not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)'" ]]; z=$? -+ [[ $y = "$x='\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -ru2 W: mksh: $x: inaccessible or not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)'" ]]; z=$? ++ [[ $y = "$x='\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -ru2 E: mksh: $x: inaccessible or not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)'" ]]; z=$? case $mode:$z { (-1:0|0:0) \\builtin print -r -- "enable -n $x" @@ -4314,7 +4314,7 @@ if (( !mode )); then # disable this - \\builtin alias "$x=\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -r mksh: $x: not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)" -+ \\builtin alias "$x=\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -ru2 W: mksh: $x: inaccessible or not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)" ++ \\builtin alias "$x=\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -ru2 E: mksh: $x: inaccessible or not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)" else # find out if this is an alias or not, first z=0 @@ -8838,7 +8838,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.224 2020/08/27 19:52:43 tg Exp $"); -+__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.245 2023/01/09 18:58:35 tg Exp $"); ++__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.246 2023/01/31 01:05:09 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" @@ -9183,7 +9183,7 @@ rv = 1; goto Leave; } -@@ -691,25 +717,21 @@ comexec(struct op *t, struct tbl * volat +@@ -691,25 +717,22 @@ comexec(struct op *t, struct tbl * volat break; /* function call */ @@ -9202,9 +9202,10 @@ - warningf(true, Tf_sD_s_sD_s, cp, - Tcant_find, Tfile_fd, - cstrerror(tp->u2.errnov)); -+ kwarnf(KWF_VERRNO | KWF_PREFIX | KWF_FILELINE | -+ KWF_TWOMSG, tp->u2.errnov, cp, -+ "can't find function definition file"); ++ kwarnf(KWF_ERR(rv) | KWF_VERRNO | ++ KWF_PREFIX | KWF_FILELINE | KWF_TWOMSG, ++ tp->u2.errnov, cp, ++ "function definition file"); break; } errno = 0; @@ -9215,17 +9216,18 @@ !(ftp->flag & ISSET)) { rv = errno; if ((ftp = findcom(cp, FC_BI)) && -@@ -723,7 +745,8 @@ comexec(struct op *t, struct tbl * volat +@@ -723,7 +746,9 @@ comexec(struct op *t, struct tbl * volat cp = tp->u.fpath; goto fpath_error; } - warningf(true, Tf_sD_s_s, cp, -+ kwarnf0(KWF_PREFIX | KWF_FILELINE | KWF_NOERRNO, ++ kwarnf0(KWF_ERR(127) | ++ KWF_PREFIX | KWF_FILELINE | KWF_NOERRNO, + Tf_sD_s_s, cp, "function not defined by", tp->u.fpath); rv = 127; break; -@@ -757,7 +780,7 @@ comexec(struct op *t, struct tbl * volat +@@ -757,7 +782,7 @@ comexec(struct op *t, struct tbl * volat for (type_flags = 0; type_flags < FNFLAGS; ++type_flags) old_flags[type_flags] = shell_flags[type_flags]; change_xtrace((Flag(FXTRACEREC) ? Flag(FXTRACE) : 0) | @@ -9234,7 +9236,7 @@ old_inuse = tp->flag & FINUSE; tp->flag |= FINUSE; -@@ -768,13 +791,22 @@ comexec(struct op *t, struct tbl * volat +@@ -768,13 +793,22 @@ comexec(struct op *t, struct tbl * volat } kshname = old_kshname; @@ -9259,7 +9261,7 @@ } #endif tp->flag = (tp->flag & ~FINUSE) | old_inuse; -@@ -805,10 +837,10 @@ comexec(struct op *t, struct tbl * volat +@@ -805,10 +839,10 @@ comexec(struct op *t, struct tbl * volat /* NOTREACHED */ default: quitenv(NULL); @@ -9272,25 +9274,26 @@ /* executable command */ case CEXEC: -@@ -817,12 +849,13 @@ comexec(struct op *t, struct tbl * volat +@@ -817,12 +851,14 @@ comexec(struct op *t, struct tbl * volat if (!(tp->flag&ISSET)) { if (tp->u2.errnov == ENOENT) { rv = 127; - warningf(true, Tf_sD_s_s, cp, - "inaccessible or", Tnot_found); -+ kwarnf(KWF_PREFIX | KWF_FILELINE | KWF_TWOMSG | ++ kwarnf(KWF_ERR(127) | ++ KWF_PREFIX | KWF_FILELINE | KWF_TWOMSG | + KWF_NOERRNO, cp, Tinacc_not_found); } else { rv = 126; - warningf(true, Tf_sD_sD_s, cp, "can't execute", - cstrerror(tp->u2.errnov)); -+ kwarnf(KWF_VERRNO | KWF_PREFIX | KWF_FILELINE | -+ KWF_TWOMSG, tp->u2.errnov, cp, -+ "can't execute"); ++ kwarnf(KWF_ERR(126) | KWF_VERRNO | ++ KWF_PREFIX | KWF_FILELINE | KWF_TWOMSG, ++ tp->u2.errnov, cp, "can't execute"); } break; } -@@ -844,14 +877,6 @@ comexec(struct op *t, struct tbl * volat +@@ -844,14 +880,6 @@ comexec(struct op *t, struct tbl * volat if (exec_argv0) texec.args[0] = exec_argv0; j_exit(); @@ -9305,6 +9308,16 @@ } rv = exchild(&texec, flags, xerrok, -1); +@@ -891,9 +919,6 @@ scriptexec(struct op *tp, const char **a + #endif + ssize_t n; + +-#if defined(__OS2__) && defined(MKSH_WITH_TEXTMODE) +- setmode(fd, O_TEXT); +-#endif + /* read first couple of octets from file */ + n = read(fd, buf, sizeof(buf) - 1); + close(fd); @@ -903,11 +928,8 @@ scriptexec(struct op *tp, const char **a /* terminate buffer */ buf[n] = '\0'; @@ -9351,7 +9364,7 @@ + (m == /* UTF-8 BOM */ 0xEFBB && buf[2] == 0xBF) || + (m == /* UCS-4, may also be general binary */ 0x0000) || + (m == /* UCS-2LE */ 0xFFFE) || (m == /* UCS-2BE */ 0xFEFF)) -+ kerrf0(KWF_ERR(1) | KWF_PREFIX | KWF_FILELINE | ++ kerrf0(KWF_ERR(126) | KWF_PREFIX | KWF_FILELINE | + KWF_NOERRNO, "%s: not executable: magic %04X", + tp->str, m); #endif @@ -9362,7 +9375,7 @@ /* report both the program that was run and the bogus interpreter */ - errorf(Tf_sD_sD_s, tp->str, sh, cstrerror(errno)); -+ kerrf(KWF_ERR(1) | KWF_PREFIX | KWF_FILELINE | KWF_TWOMSG, tp->str, sh); ++ kerrf(KWF_ERR(127) | KWF_PREFIX | KWF_FILELINE | KWF_TWOMSG, tp->str, sh); } /* actual 'builtin' built-in utility call is handled in comexec() */ @@ -14551,7 +14564,7 @@ -#endif - -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.374 2020/10/01 20:28:54 tg Exp $"); -+__RCSID("$MirOS: src/bin/mksh/main.c,v 1.422 2023/01/08 22:52:05 tg Exp $"); ++__RCSID("$MirOS: src/bin/mksh/main.c,v 1.423 2023/01/31 01:05:09 tg Exp $"); +__IDSTRING(mbsdint_h_rcsid, SYSKERN_MBSDINT_H); +__IDSTRING(sh_h_rcsid, MKSH_SH_H_ID); @@ -14966,18 +14979,21 @@ while (*s->str) { if (ctype(*s->str, C_QUOTE)) break; -@@ -532,8 +570,8 @@ main_init(int argc, const char *argv[], +@@ -532,10 +570,9 @@ main_init(int argc, const char *argv[], s->u.shf = shf_open(s->file, O_RDONLY | O_MAYEXEC, 0, SHF_MAPHI | SHF_CLEXEC); if (s->u.shf == NULL) { - shl_stdout_ok = false; - warningf(true, Tf_sD_s, s->file, cstrerror(errno)); +- /* mandated by SUSv4 */ +- exstat = 127; + shl_stdout_ok = Nee; -+ kwarnf(KWF_PREFIX | KWF_FILELINE | KWF_ONEMSG, s->file); - /* mandated by SUSv4 */ - exstat = 127; ++ kwarnf(KWF_ERR(127) | ++ KWF_PREFIX | KWF_FILELINE | KWF_ONEMSG, s->file); unwind(LERROR); -@@ -556,7 +594,7 @@ main_init(int argc, const char *argv[], + } + kshname = s->file; +@@ -556,7 +593,7 @@ main_init(int argc, const char *argv[], /* this bizarreness is mandated by POSIX */ if (Flag(FTALKING) && fstat(0, &s_stdin) >= 0 && @@ -14986,7 +15002,7 @@ reset_nonblock(0); /* initialise job control */ -@@ -587,45 +625,48 @@ main_init(int argc, const char *argv[], +@@ -587,45 +624,48 @@ main_init(int argc, const char *argv[], SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP); #endif @@ -15055,7 +15071,7 @@ /* these were imported from environ earlier */ if (ccp == null) ccp = str_val(global("LC_ALL")); -@@ -634,10 +675,15 @@ main_init(int argc, const char *argv[], +@@ -634,10 +674,15 @@ main_init(int argc, const char *argv[], if (ccp == null) ccp = str_val(global("LANG")); UTFMODE = isuc(ccp); @@ -15071,7 +15087,7 @@ /* unknown values */ default: utf_flag = 0; -@@ -676,28 +722,29 @@ main_init(int argc, const char *argv[], +@@ -676,28 +721,29 @@ main_init(int argc, const char *argv[], * user will know why things broke. */ if (!current_wd[0] && Flag(FTALKING)) @@ -15107,7 +15123,7 @@ } } if (restricted_shell) { -@@ -722,7 +769,6 @@ main_init(int argc, const char *argv[], +@@ -722,7 +768,6 @@ main_init(int argc, const char *argv[], alarm_init(); *sp = s; @@ -15115,7 +15131,7 @@ return (0); } -@@ -733,11 +779,13 @@ main(int argc, const char *argv[]) +@@ -733,11 +778,13 @@ main(int argc, const char *argv[]) { int rv; Source *s; @@ -15132,7 +15148,7 @@ } else { shell(s, 0); /* NOTREACHED */ -@@ -747,7 +795,7 @@ main(int argc, const char *argv[]) +@@ -747,7 +794,7 @@ main(int argc, const char *argv[]) } int @@ -15141,7 +15157,7 @@ { Source *volatile s = NULL; struct shf *shf; -@@ -793,13 +841,16 @@ include(const char *name, int argc, cons +@@ -793,13 +840,16 @@ include(const char *name, int argc, cons unwind(i); /* NOTREACHED */ default: @@ -15160,7 +15176,7 @@ } s = pushs(SFILE, ATEMP); s->u.shf = shf; -@@ -836,10 +887,9 @@ int +@@ -836,10 +886,9 @@ int shell(Source * volatile s, volatile int level) { struct op *t; @@ -15174,7 +15190,7 @@ Source *volatile old_source = source; int i; -@@ -847,13 +897,13 @@ shell(Source * volatile s, volatile int +@@ -847,13 +896,13 @@ shell(Source * volatile s, volatile int if (level == 2) e->flags |= EF_IN_EVAL; if (interactive) @@ -15190,7 +15206,7 @@ source = old_source; quitenv(NULL); if (level == 2) { -@@ -861,8 +911,8 @@ shell(Source * volatile s, volatile int +@@ -861,8 +910,8 @@ shell(Source * volatile s, volatile int unwind(i); /* NOTREACHED */ } @@ -15201,7 +15217,7 @@ /* NOTREACHED */ case LINTR: /* we get here if SIGINT not caught or ignored */ -@@ -871,7 +921,7 @@ shell(Source * volatile s, volatile int +@@ -871,7 +920,7 @@ shell(Source * volatile s, volatile int case LSHELL: if (interactive) { if (i == LINTR) @@ -15210,7 +15226,7 @@ /* * Reset any eof that was read as part of a * multiline command. -@@ -886,7 +936,7 @@ shell(Source * volatile s, volatile int +@@ -886,7 +935,7 @@ shell(Source * volatile s, volatile int * needs FMONITOR set (not FTALKING/SF_TTY)... */ /* toss any input we have so far */ @@ -15219,7 +15235,7 @@ s->start = s->str = null; retrace_info = NULL; herep = heres; -@@ -906,7 +956,8 @@ shell(Source * volatile s, volatile int +@@ -906,7 +955,8 @@ shell(Source * volatile s, volatile int default: source = old_source; quitenv(NULL); @@ -15229,7 +15245,7 @@ /* NOTREACHED */ } while (/* CONSTCOND */ 1) { -@@ -923,10 +974,9 @@ shell(Source * volatile s, volatile int +@@ -923,10 +973,9 @@ shell(Source * volatile s, volatile int j_notify(); set_prompt(PS1, s); } @@ -15242,7 +15258,7 @@ if (!t) goto source_no_tree; if (t->type == TEOF) { -@@ -935,7 +985,7 @@ shell(Source * volatile s, volatile int +@@ -935,7 +984,7 @@ shell(Source * volatile s, volatile int s->type = SSTDIN; } else if (wastty && !really_exit && j_stopped_running()) { @@ -15251,7 +15267,7 @@ s->type = SSTDIN; } else { /* -@@ -954,7 +1004,7 @@ shell(Source * volatile s, volatile int +@@ -954,7 +1003,7 @@ shell(Source * volatile s, volatile int exstat = execute(t, 0, NULL) & 0xFF; if (t->type != TEOF && interactive && really_exit) @@ -15260,7 +15276,7 @@ source_no_tree: reclaim(); -@@ -1026,7 +1076,7 @@ newenv(int type) +@@ -1026,7 +1075,7 @@ newenv(int type) ainit(&ep->area); ep->oenv = e; ep->loc = e->loc; @@ -15269,7 +15285,7 @@ ep->temps = NULL; ep->yyrecursive_statep = NULL; ep->type = type; -@@ -1039,29 +1089,28 @@ quitenv(struct shf *shf) +@@ -1039,29 +1088,28 @@ quitenv(struct shf *shf) { struct env *ep = e; char *cp; @@ -15309,7 +15325,7 @@ if (ep->type == E_NONE) { /* Main shell exiting? */ #if HAVE_PERSISTENT_HISTORY -@@ -1132,14 +1181,14 @@ cleanup_parents_env(void) +@@ -1132,14 +1180,14 @@ cleanup_parents_env(void) * anywhere. */ @@ -15330,7 +15346,7 @@ } #ifdef DEBUG_LEAKS if (ep->type != E_NONE) -@@ -1211,7 +1260,7 @@ int +@@ -1211,7 +1259,7 @@ int tty_init_fd(void) { int fd, rv, eno = 0; @@ -15339,7 +15355,7 @@ if (tty_devtty) { /* already got a tty which is /dev/tty */ -@@ -1226,8 +1275,8 @@ tty_init_fd(void) +@@ -1226,8 +1274,8 @@ tty_init_fd(void) goto got_fd; } #endif @@ -15350,7 +15366,7 @@ goto got_fd; } eno = errno; -@@ -1237,13 +1286,13 @@ tty_init_fd(void) +@@ -1237,13 +1285,13 @@ tty_init_fd(void) rv = 1; goto out; } @@ -15366,7 +15382,7 @@ goto out; got_fd: -@@ -1268,186 +1317,12 @@ tty_init_fd(void) +@@ -1268,186 +1316,12 @@ tty_init_fd(void) return (rv); } @@ -15553,7 +15569,7 @@ va_start(va, fmt); shf_vfprintf(shl_out, fmt, va); va_end(va); -@@ -1461,7 +1336,8 @@ shprintf(const char *fmt, ...) +@@ -1461,7 +1335,8 @@ shprintf(const char *fmt, ...) va_list va; if (!shl_stdout_ok) @@ -15563,7 +15579,7 @@ va_start(va, fmt); shf_vfprintf(shl_stdout, fmt, va); va_end(va); -@@ -1485,6 +1361,7 @@ int shl_dbg_fd; +@@ -1485,6 +1360,7 @@ int shl_dbg_fd; #endif struct shf shf_iob[NSHF_IOB]; @@ -15571,7 +15587,7 @@ void initio(void) { -@@ -1496,38 +1373,43 @@ initio(void) +@@ -1496,38 +1372,43 @@ initio(void) shf_fdopen(1, SHF_WR, shl_stdout); shf_fdopen(2, SHF_WR, shl_out); shf_fdopen(2, SHF_WR, shl_xtrace); @@ -15623,7 +15639,7 @@ #ifdef __ultrix /*XXX imake style */ -@@ -1539,21 +1421,25 @@ ksh_dup2(int ofd, int nfd, bool errok) +@@ -1539,21 +1420,25 @@ ksh_dup2(int ofd, int nfd, bool errok) } /* @@ -15656,7 +15672,7 @@ } void -@@ -1566,7 +1452,7 @@ restfd(int fd, int ofd) +@@ -1566,7 +1451,7 @@ restfd(int fd, int ofd) close(fd); else if (fd != ofd) { /*XXX: what to do if this dup fails? */ @@ -15665,7 +15681,7 @@ close(ofd); } } -@@ -1577,7 +1463,8 @@ openpipe(int *pv) +@@ -1577,7 +1462,8 @@ openpipe(int *pv) int lpv[2]; if (pipe(lpv) < 0) @@ -15675,7 +15691,7 @@ pv[0] = savefd(lpv[0]); if (pv[0] != lpv[0]) close(lpv[0]); -@@ -1614,6 +1501,7 @@ check_fd(const char *name, int mode, con +@@ -1614,6 +1500,7 @@ check_fd(const char *name, int mode, con illegal_fd_name: if (emsgp) *emsgp = "illegal file descriptor name"; @@ -15683,7 +15699,7 @@ return (-1); } -@@ -1635,6 +1523,11 @@ check_fd(const char *name, int mode, con +@@ -1635,6 +1522,11 @@ check_fd(const char *name, int mode, con *emsgp = (fl == O_WRONLY) ? "fd not open for reading" : "fd not open for writing"; @@ -15695,7 +15711,7 @@ return (-1); } return (fd); -@@ -1699,6 +1592,7 @@ coproc_getfd(int mode, const char **emsg +@@ -1699,6 +1591,7 @@ coproc_getfd(int mode, const char **emsg return (fd); if (emsgp) *emsgp = "no coprocess"; @@ -15703,7 +15719,7 @@ return (-1); } -@@ -1739,23 +1633,21 @@ maketemp(Area *ap, Temp_type type, struc +@@ -1739,23 +1632,21 @@ maketemp(Area *ap, Temp_type type, struc dir = tmpdir ? tmpdir : MKSH_DEFAULT_TMPDIR; /* add "/shXXXXXX.tmp" plus NUL */ len = strlen(dir); @@ -15734,7 +15750,7 @@ /* point to the first of six Xes */ cp += 3; -@@ -1805,6 +1697,7 @@ maketemp(Area *ap, Temp_type type, struc +@@ -1805,6 +1696,7 @@ maketemp(Area *ap, Temp_type type, struc static void tgrow(struct table *); static int tnamecmp(const void *, const void *); @@ -15742,7 +15758,7 @@ static void tgrow(struct table *tp) { -@@ -1813,7 +1706,8 @@ tgrow(struct table *tp) +@@ -1813,7 +1705,8 @@ tgrow(struct table *tp) struct tbl **ntblp, **otblp = tp->tbls; if (tp->tshift > 29) @@ -15752,7 +15768,7 @@ /* calculate old size, new shift and new size */ osize = (size_t)1 << (tp->tshift++); -@@ -1855,8 +1749,9 @@ tgrow(struct table *tp) +@@ -1855,8 +1748,9 @@ tgrow(struct table *tp) afree(otblp, tp->areap); } @@ -15763,7 +15779,7 @@ { tp->areap = ap; tp->tbls = NULL; -@@ -1867,7 +1762,7 @@ ktinit(Area *ap, struct table *tp, uint8 +@@ -1867,7 +1761,7 @@ ktinit(Area *ap, struct table *tp, uint8 /* table, name (key) to search for, hash(name), rv pointer to tbl ptr */ struct tbl * @@ -15772,7 +15788,7 @@ { size_t j, perturb, mask; struct tbl **pp, *p; -@@ -1892,7 +1787,7 @@ ktscan(struct table *tp, const char *nam +@@ -1892,7 +1786,7 @@ ktscan(struct table *tp, const char *nam /* table, name (key) to enter, hash(n) */ struct tbl * @@ -15781,7 +15797,7 @@ { struct tbl **pp, *p; size_t len; -@@ -1908,9 +1803,8 @@ ktenter(struct table *tp, const char *n, +@@ -1908,9 +1802,8 @@ ktenter(struct table *tp, const char *n, } /* create new tbl entry */ @@ -15793,7 +15809,7 @@ p->flag = 0; p->type = 0; p->areap = tp->areap; -@@ -1997,8 +1891,8 @@ DF(const char *fmt, ...) +@@ -1997,8 +1890,8 @@ DF(const char *fmt, ...) mksh_TIME(tv); timet2mjd(&mjd, tv.tv_sec); shf_fprintf(shl_dbg, "[%02u:%02u:%02u (%u) %u.%06u] ", @@ -15804,7 +15820,7 @@ (unsigned)tv.tv_sec, (unsigned)tv.tv_usec); va_start(args, fmt); shf_vfprintf(shl_dbg, fmt, args); -@@ -2010,7 +1904,7 @@ DF(const char *fmt, ...) +@@ -2010,7 +1903,7 @@ DF(const char *fmt, ...) #endif void @@ -15813,7 +15829,7 @@ { mksh_ttyst cb; -@@ -2018,22 +1912,24 @@ x_mkraw(int fd, mksh_ttyst *ocb, bool fo +@@ -2018,22 +1911,24 @@ x_mkraw(int fd, mksh_ttyst *ocb, bool fo mksh_tcget(fd, ocb); else ocb = &tty_state; @@ -15848,7 +15864,7 @@ #endif cb.c_cc[VTIME] = 0; cb.c_cc[VMIN] = 1; -@@ -2042,6 +1938,9 @@ x_mkraw(int fd, mksh_ttyst *ocb, bool fo +@@ -2042,6 +1937,9 @@ x_mkraw(int fd, mksh_ttyst *ocb, bool fo } #ifdef MKSH_ENVDIR @@ -15858,7 +15874,7 @@ static void init_environ(void) { -@@ -2053,21 +1952,19 @@ init_environ(void) +@@ -2053,21 +1951,19 @@ init_environ(void) struct dirent *dent; if ((dirp = opendir(MKSH_ENVDIR)) == NULL) { @@ -15885,7 +15901,7 @@ goto read_envfile; } afree(xp, ATEMP); -@@ -2080,28 +1977,28 @@ init_environ(void) +@@ -2080,28 +1976,28 @@ init_environ(void) while ((n = shf_read(xp, Xnleft(xs, xp), shf)) > 0) { xp += n; if (Xnleft(xs, xp) <= 0) @@ -15922,7 +15938,7 @@ #else extern char **environ; -@@ -2115,9 +2012,25 @@ init_environ(void) +@@ -2115,9 +2011,25 @@ init_environ(void) wp = (const char **)environ; while (*wp != NULL) { @@ -15949,7 +15965,7 @@ } } #endif -@@ -2127,25 +2040,114 @@ void +@@ -2127,25 +2039,114 @@ void recheck_ctype(void) { const char *ccp; @@ -16079,15 +16095,15 @@ +} --- /dev/null +++ mksh-59c/mbsdint.h -@@ -0,0 +1,708 @@ +@@ -0,0 +1,715 @@ +/*- + * MirBSD sanitisation attempt for C integer madness + * -+ * © mirabilos Ⓕ CC0 or The MirOS Licence ++ * © mirabilos Ⓕ CC0 or The MirOS Licence (MirBSD) + */ + +#ifndef SYSKERN_MBSDINT_H -+#define SYSKERN_MBSDINT_H "$MirOS: src/bin/mksh/mbsdint.h,v 1.17 2023/01/08 21:21:07 tg Exp $" ++#define SYSKERN_MBSDINT_H "$MirOS: src/bin/mksh/mbsdint.h,v 1.20 2023/02/06 01:33:54 tg Exp $" + +/* if you have and/or , include them before this */ +/* also if defines SSIZE_MAX or UINTPTR_MAX but not the types */ @@ -16431,7 +16447,7 @@ + +/* basic building blocks: arithmetics cast helpers */ + -+#define mbiUI(v) (0UL + (v)) ++#define mbiUI(v) (0U + (v)) +#define mbiUP(ut,v) mbiUI((ut)(v)) +#define mbiSP(st,v) (0 + ((st)(v))) + @@ -16459,7 +16475,7 @@ + +/* 3. ternary */ +#define mbiOT(t,w,j,n) ((w) ? (t)(j) : (t)(n)) -+#define mbiMOT(ut,tM,w,j,n) mbiMM(ut, (tM), mbiOT(t, (w), (j), (n))) ++#define mbiMOT(ut,tM,w,j,n) mbiMM(ut, (tM), mbiOT(ut, (w), (j), (n))) + +/* manual two’s complement in unsigned arithmetics */ + @@ -16501,7 +16517,7 @@ + mbiOT(ut, \ + mbiA_S2VZ(v), \ + mbiOU1(ut, \ -+ ~ \ ++ ~, \ + mbiOS1(st, \ + -, \ + mbiOS(st, (v), +, 1) \ @@ -16533,7 +16549,7 @@ + mbiOS1(st, \ + -, \ + mbiOS(st, (v), +, 1) \ -+ ), \ ++ ) \ + ), \ + +, \ + 1U \ @@ -16645,7 +16661,7 @@ +} while (/* CONSTCOND */ 0) +#define mbiCAUmul(ut,vl,vr) do { \ + if (__predict_false(((ut)(vl) > mbi_halftype(ut) || \ -+ (ut)(vr) > mbi_halftype(ut)) && (vr) == 0 && \ ++ (ut)(vr) > mbi_halftype(ut)) && (vr) != 0 && \ + mbiOU(ut, mbiTYPE_UMAX(ut), /, (ut)(vr)) < (ut)(vl))) \ + mbiCfail; \ + (vl) *= (vr); \ @@ -16743,22 +16759,29 @@ +#define mbiKshl(ut,vl,vr) mbiK_sr(ut, mbiK_shl, (vl), (vr), void) +/* let vz be sgn(vl) */ +#define mbiKsar(ut,vz,vl,vr) mbiK_sr(ut, mbiK_sar, (vl), (vr), (vz)) -+#define mbiKshr(ut,vl,vr) mbiK_sr(ut, mbiK_sar, (vl), (vr), 0) ++#define mbiKshr(ut,vl,vr) mbiK_sr(ut, mbiK_shr, (vl), (vr), 0) +#define mbiMKrol(ut,FM,vl,vr) mbiMK_sr(ut, (FM), mbiK_rol, (vl), (vr), void) +#define mbiMKror(ut,FM,vl,vr) mbiMK_sr(ut, (FM), mbiK_ror, (vl), (vr), void) +#define mbiMKshl(ut,FM,vl,vr) mbiMK_sr(ut, (FM), mbiK_shl, (vl), (vr), void) -+#define mbiMKsar(ut,FM,vz,l,r) mbiMK_sr(ut, (FM), mbiK_sar, (l), (r), (vz)) -+#define mbiMKshr(ut,FM,vl,vr) mbiMK_sr(ut, (FM), mbiK_sar, (vl), (vr), 0) ++#define mbiMKsar(ut,FM,vz,l,r) mbiMOT(ut, (FM), (vz), \ ++ mbiK_SR(ut, mbiMASK_BITS(FM), \ ++ mbiMK_nr, (l), (r), (FM)), \ ++ mbiK_SR(ut, mbiMASK_BITS(FM), \ ++ mbiK_shr, (l), (r), 0)) ++#define mbiMKshr(ut,FM,vl,vr) mbiMK_sr(ut, (FM), mbiK_shr, (vl), (vr), 0) +/* implementation */ +#define mbiK_sr(ut,n,vl,vr,vz) mbiK_SR(ut, mbiTYPE_UBITS(ut), n, vl, vr, vz) +#define mbiMK_sr(ut,FM,n,l,r,z) mbiMM(ut, (FM), mbiK_SR(ut, mbiMASK_BITS(FM), \ + n, mbiMM(ut, (FM), (l)), (r), (z))) -+#define mbiK_SR(ut,b,n,l,r,vz) mbiK_RS(ut, b, n, l, mbiUI(r) & (b - 1U), !(vz)) ++#define mbiK_SR(ut,b,n,l,r,vz) mbiK_RS(ut, b, n, l, mbiUI(r) & (b - 1U), (vz)) +#define mbiK_RS(ut,b,n,v,cl,zx) mbiOT(ut, cl, n(ut, v, cl, b - (cl), zx), v) +#define mbiK_shl(ut,ax,cl,CL,z) mbiOshl(ut, ax, cl) -+#define mbiK_sar(ut,ax,cl,CL,z) mbiOT(ut, z, mbiOshr(ut, ax, cl), \ -+ mbiOU1(ut, ~, mbiOshr(ut, \ -+ mbiOU1(ut, ~, ax), cl))) ++#define mbiK_shr(ut,ax,cl,CL,z) mbiOshr(ut, ax, cl) ++#define mbiK_sar(ut,ax,cl,CL,z) mbiOT(ut, z, mbiOU1(ut, ~, mbiOshr(ut, \ ++ mbiOU1(ut, ~, ax), cl)), \ ++ mbiOshr(ut, ax, cl)) ++#define mbiMK_nr(ut,ax,cl,CL,m) mbiOU1(ut, ~, mbiOshr(ut, \ ++ mbiMO1(ut, m, ~, ax), cl)) +#define mbiK_rol(ut,ax,cl,CL,z) \ + mbiOU(ut, mbiOshl(ut, ax, cl), |, mbiOshr(ut, ax, CL)) +#define mbiK_ror(ut,ax,cl,CL,z) \ @@ -18996,13 +19019,13 @@ +++ mksh-59c/mksh.1 @@ -1,9 +1,9 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.494 2020/10/01 22:39:57 tg Exp $ -+.\" $MirOS: src/bin/mksh/mksh.1,v 1.537+locale-tracking 2023/01/03 17:28:22 tg Exp $ ++.\" $MirOS: src/bin/mksh/mksh.1,v 1.538+locale-tracking 2023/01/31 01:02:03 tg Exp $ .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, .\" 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, -.\" 2018, 2019, 2020 -+.\" 2018, 2019, 2020, 2021, 2022 ++.\" 2018, 2019, 2020, 2021, 2022, 2023 .\" mirabilos .\" .\" Provided that these terms and disclaimer and all copyright notices @@ -19020,7 +19043,7 @@ .\" use our own definition. And .Dd must come *first*, always. .\" -.Dd $Mdocdate: October 1 2020 $ -+.Dd $Mdocdate: January 3 2023 $ ++.Dd $Mdocdate: January 31 2023 $ .\" .\" Check which macro package we use, and do other -mdoc setup. .\" @@ -19528,6 +19551,25 @@ Further positional parameters may be accessed using .Pf ${ Ar number Ns } . .It Ev * +@@ -1907,13 +1967,13 @@ command (see below). + .It Ev FPATH + Like + .Ev PATH , +-but used when an undefined function is executed to locate the file defining the +-function. +-It is also searched when a command can't be found using +-.Ev PATH . ++but used when an undefined function is executed ++(or when a command cannot be found using ++.Ev PATH ) ++to locate the function definition file. + See + .Sx Functions +-below for more information. ++below. + .It Ev HISTFILE + The name of the file used to store command history. + When assigned to or unset, the file is opened, history is truncated @@ -2316,17 +2376,26 @@ Ranges of octets can be specified by sep matches the letter .Ql a @@ -21252,7 +21294,7 @@ -#ifdef __dietlibc__ -/* XXX imake style */ -#define _BSD_SOURCE /* live, BSD, live❣ */ -+#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.1002 2023/01/08 22:53:22 tg Exp $" ++#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.1003 2023/01/31 01:05:10 tg Exp $" + +#ifdef MKSH_USE_AUTOCONF_H +/* things that “should” have been on the command line */ @@ -21374,7 +21416,7 @@ -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.904 2020/10/31 03:53:06 tg Exp $"); -#endif -#define MKSH_VERSION "R59 2020/10/31" -+#define MKSH_VERSION "R59 2023/01/08" ++#define MKSH_VERSION "R59 2023/01/31" -/* arithmetic types: C implementation */ -#if !HAVE_CAN_INTTYPES