From f463d9da7661095fa4deac47509bea26aeedbf44 Mon Sep 17 00:00:00 2001 From: tg Date: Mon, 6 Jul 2015 17:48:37 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=20revert=20the=20cat=20hack=20for=20r?= =?UTF-8?q?ealpath=20and=20rename=20=20=20=E2=80=A3=20I=20was=20convinced?= =?UTF-8?q?=20by=20several=20that=20more=20magic=20is=20never=20the=20solu?= =?UTF-8?q?tion=20=E2=80=A2=20fix=20a=20comment:=20function=20cat=20alread?= =?UTF-8?q?y=20had=20precedence=20=E2=80=A2=20change=20cat=20loader=20to?= =?UTF-8?q?=20look=20for=20existence,=20FPATH=20included,=20before=20=20?= =?UTF-8?q?=20ditching=20the=20builtin;=20note=20that=20in=20manpage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Build.sh | 5 +---- check.t | 20 +++++--------------- exec.c | 43 +++++++++++++++++++++---------------------- funcs.c | 4 ++-- main.c | 4 ++-- mksh.1 | 23 +++++------------------ sh.h | 5 +++-- 7 files changed, 39 insertions(+), 65 deletions(-) diff --git a/Build.sh b/Build.sh index d75b15e..ec0d64c 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/bin/sh -srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.680 2015/07/05 15:45:16 tg Exp $' +srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.681 2015/07/06 17:48:28 tg Exp $' #- # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # 2011, 2012, 2013, 2014, 2015 @@ -2645,9 +2645,6 @@ MKSH_NOPROSPECTOFWORK disable jobs, co-processes, etc. (do not use) MKSH_NOPWNAM skip PAM calls, for -static on glibc or Solaris MKSH_NO_CMDLINE_EDITING disable command line editing code entirely MKSH_NO_DEPRECATED_WARNING omit warning when deprecated stuff is run -MKSH_NO_EXTERNAL_CAT omit hack to skip cat builtin when flags passed -MKSH_NO_EXTERNAL_REALPATH same for realpath builtin -MKSH_NO_EXTERNAL_RENAME same for rename builtin MKSH_NO_LIMITS omit ulimit code MKSH_NO_SIGSETJMP define if sigsetjmp is broken or not available MKSH_NO_SIGSUSPEND use sigprocmask+pause instead of sigsuspend diff --git a/check.t b/check.t index 34aa403..2b461d0 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.698 2015/07/05 19:37:11 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.699 2015/07/06 17:48:29 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -30,7 +30,7 @@ # (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date expected-stdout: - @(#)MIRBSD KSH R51 2015/07/05 + @(#)MIRBSD KSH R51 2015/07/06 description: Check version of shell. stdin: @@ -39,7 +39,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R51 2015/07/05 + @(#)LEGACY KSH R51 2015/07/06 description: Check version of legacy shell. stdin: @@ -8533,7 +8533,7 @@ description: Ensure concatenating behaviour matches other shells stdin: showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } - #showargs 0 ""$@ + showargs 0 ""$@ x=; showargs 1 "$x"$@ set A; showargs 2 "${@:+}" n() { echo "$#"; } @@ -8553,6 +8553,7 @@ stdin: n "$@" n "$@""$e" expected-stdout: + <0> <> . <1> <> . <2> <> . 2 @@ -8568,17 +8569,6 @@ expected-stdout: 0 1 --- -name: varexpand-null-3a -description: - Ensure concatenating behaviour matches other shells - (currently broken cases) -expected-fail: yes -stdin: - showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } - showargs 0 ""$@ -expected-stdout: - <0> <> . ---- name: print-funny-chars description: Check print builtin's capability to output designated characters diff --git a/exec.c b/exec.c index 3f8863c..bf8c4a8 100644 --- a/exec.c +++ b/exec.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.154 2015/07/05 15:45:17 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.155 2015/07/06 17:48:31 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL "/bin/sh" @@ -551,6 +551,8 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, } if ((tp = findcom(cp, FC_BI)) == NULL) errorf("%s: %s: %s", Tbuiltin, cp, "not a builtin"); + if (tp->type == CSHELL && tp->val.f == c_cat) + break; continue; } else if (tp->val.f == c_exec) { if (ap[1] == NULL) @@ -607,30 +609,19 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, subst_exstat = 0; break; } -#if !defined(MKSH_NO_EXTERNAL_CAT) || \ - !defined(MKSH_NO_EXTERNAL_REALPATH) || \ - !defined(MKSH_NO_EXTERNAL_RENAME) - } else if ( -#ifndef MKSH_NO_EXTERNAL_CAT - tp->val.f == c_cat || -#endif -#ifndef MKSH_NO_EXTERNAL_REALPATH - tp->val.f == c_realpath || -#endif -#ifndef MKSH_NO_EXTERNAL_RENAME - tp->val.f == c_rename || -#endif - 0) { + } else if (tp->val.f == c_cat) { /* if we have any flags, do not use the builtin */ if (ap[1] && ap[1][0] == '-' && ap[1][1] != '\0' && /* argument, begins with -, is not - or -- */ - (ap[1][1] != '-' || ap[1][2] != '\0')) - /* don't look for builtins or functions */ - fcflags = FC_PATH; - else - /* go on, use the builtin */ - break; -#endif + (ap[1][1] != '-' || ap[1][2] != '\0')) { + struct tbl *ext_cat; + + ext_cat = findcom(Tcat, FC_PATH | FC_FUNC); + if (ext_cat && (ext_cat->type != CTALIAS || + (ext_cat->flag & ISSET))) + tp = ext_cat; + } + break; } else if (tp->val.f == c_trap) { t->u.evalflags &= ~DOTCOMEXEC; break; @@ -710,6 +701,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, /* shell built-in */ case CSHELL: + do_call_builtin: rv = call_builtin(tp, (const char **)ap, null, resetspec); if (resetspec && tp->val.f == c_shift) { l_expand->argc = l_assign->argc; @@ -734,6 +726,11 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, break; } if (include(tp->u.fpath, 0, NULL, false) < 0) { + if (!strcmp(cp, Tcat)) { + no_cat_in_FPATH: + tp = findcom(Tcat, FC_BI); + goto do_call_builtin; + } warningf(true, "%s: %s %s %s: %s", cp, "can't open", "function definition file", tp->u.fpath, cstrerror(errno)); @@ -742,6 +739,8 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap, } if (!(ftp = findfunc(cp, hash(cp), false)) || !(ftp->flag & ISSET)) { + if (!strcmp(cp, Tcat)) + goto no_cat_in_FPATH; warningf(true, "%s: %s %s", cp, "function not defined by", tp->u.fpath); rv = 127; diff --git a/funcs.c b/funcs.c index 64c7d2f..1be28e4 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.276 2015/07/05 19:37:14 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.277 2015/07/06 17:48:32 tg Exp $"); #if HAVE_KILLPG /* @@ -99,7 +99,7 @@ const struct builtin mkshbuiltins[] = { {Talias, c_alias}, {"*=break", c_brkcont}, {Tgbuiltin, c_builtin}, - {"cat", c_cat}, + {Tcat, c_cat}, {"cd", c_cd}, /* dash compatibility hack */ {"chdir", c_cd}, diff --git a/main.c b/main.c index eecea60..64fa3dd 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.294 2015/07/05 19:37:16 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.295 2015/07/06 17:48:34 tg Exp $"); extern char **environ; @@ -87,7 +87,7 @@ static const char *initcoms[] = { NULL, /* this is what AT&T ksh seems to track, with the addition of emacs */ Talias, "-tU", - "cat", "cc", "chmod", "cp", "date", "ed", "emacs", "grep", "ls", + Tcat, "cc", "chmod", "cp", "date", "ed", "emacs", "grep", "ls", "make", "mv", "pr", "rm", "sed", "sh", "vi", "who", NULL, NULL }; diff --git a/mksh.1 b/mksh.1 index fb9666b..85dbda4 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.372 2015/07/05 19:37:17 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.373 2015/07/06 17:48:35 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, @@ -74,7 +74,7 @@ .\" with -mandoc, it might implement .Mx itself, but we want to .\" use our own definition. And .Dd must come *first*, always. .\" -.Dd $Mdocdate: July 5 2015 $ +.Dd $Mdocdate: July 6 2015 $ .\" .\" Check which macro package we use, and do other -mdoc setup. .\" @@ -3161,15 +3161,13 @@ If a is a single dash .Pq Sq - or absent, read from standard input. -Unless compiled with -.Dv MKSH_NO_EXTERNAL_CAT , -if any options are given, an external -.Xr cat 1 -utility is invoked instead if called from the shell. For direct builtin calls, the .Tn POSIX .Fl u option is supported as a no-op. +For calls from shell, if any options are given, an external +.Xr cat 1 +utility is preferred over the builtin. .Pp .It Xo .Ic cd @@ -3958,12 +3956,6 @@ it's also checked for existence and whether it is a directory; otherwise, returns 0 if the pathname either exists or can be created immediately, i.e. all but the last component exist and are directories. .Pp -Unless compiled with -.Dv MKSH_NO_EXTERNAL_REALPATH , -if any options are given and this is not a direct builtin call, an external -.Xr realpath 1 -utility is invoked instead. -.Pp .It Xo .Ic rename .Op Fl \- @@ -3978,11 +3970,6 @@ This builtin is intended for emergency situations where .Pa /bin/mv becomes unusable, and directly calls .Xr rename 2 . -Unless compiled with -.Dv MKSH_NO_EXTERNAL_RENAME , -if any options are given and this is not a direct builtin call, an external -.Xr rename 1 -utility is invoked instead. .Pp .It Ic return Op Ar status Returns from a function or diff --git a/sh.h b/sh.h index 74d4b57..23c7e5a 100644 --- a/sh.h +++ b/sh.h @@ -169,9 +169,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.733 2015/07/05 19:37:18 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.734 2015/07/06 17:48:37 tg Exp $"); #endif -#define MKSH_VERSION "R51 2015/07/05" +#define MKSH_VERSION "R51 2015/07/06" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -821,6 +821,7 @@ EXTERN const char T_typeset[] E_INIT("=typeset"); #define Ttypeset (T_typeset + 1) /* "typeset" */ EXTERN const char Talias[] E_INIT("alias"); EXTERN const char Tunalias[] E_INIT("unalias"); +EXTERN const char Tcat[] E_INIT("cat"); EXTERN const char Tsgset[] E_INIT("*=set"); #define Tset (Tsgset + 2) /* "set" */ EXTERN const char Tsgexport[] E_INIT("*=export");