implement cat thing for realpath and rename too: if flag, call external

This commit is contained in:
tg 2015-07-05 15:45:18 +00:00
parent b478d334d9
commit b9a8fdf905
3 changed files with 30 additions and 12 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.679 2015/05/01 16:08:26 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.680 2015/07/05 15:45:16 tg Exp $'
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015 # 2011, 2012, 2013, 2014, 2015
@ -2646,6 +2646,8 @@ MKSH_NOPWNAM skip PAM calls, for -static on glibc or Solaris
MKSH_NO_CMDLINE_EDITING disable command line editing code entirely MKSH_NO_CMDLINE_EDITING disable command line editing code entirely
MKSH_NO_DEPRECATED_WARNING omit warning when deprecated stuff is run 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_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_LIMITS omit ulimit code
MKSH_NO_SIGSETJMP define if sigsetjmp is broken or not available MKSH_NO_SIGSETJMP define if sigsetjmp is broken or not available
MKSH_NO_SIGSUSPEND use sigprocmask+pause instead of sigsuspend MKSH_NO_SIGSUSPEND use sigprocmask+pause instead of sigsuspend

25
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.153 2015/07/05 14:43:05 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.154 2015/07/05 15:45:17 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL #ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh" #define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@ -607,16 +607,21 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
subst_exstat = 0; subst_exstat = 0;
break; break;
} }
#if !defined(MKSH_NO_EXTERNAL_CAT) || \
!defined(MKSH_NO_EXTERNAL_REALPATH) || \
!defined(MKSH_NO_EXTERNAL_RENAME)
} else if (
#ifndef MKSH_NO_EXTERNAL_CAT #ifndef MKSH_NO_EXTERNAL_CAT
} else if (tp->val.f == c_cat) { tp->val.f == c_cat ||
/* #endif
* if we have any flags, do not use the builtin #ifndef MKSH_NO_EXTERNAL_REALPATH
* in theory, we could allow -u, but that would tp->val.f == c_realpath ||
* mean to use ksh_getopt here and possibly ad- #endif
* ded complexity and more code and isn't worth #ifndef MKSH_NO_EXTERNAL_RENAME
* additional hassle (and the builtin must call tp->val.f == c_rename ||
* ksh_getopt already but can't come back here) #endif
*/ 0) {
/* if we have any flags, do not use the builtin */
if (ap[1] && ap[1][0] == '-' && ap[1][1] != '\0' && if (ap[1] && ap[1][0] == '-' && ap[1][1] != '\0' &&
/* argument, begins with -, is not - or -- */ /* argument, begins with -, is not - or -- */
(ap[1][1] != '-' || ap[1][2] != '\0')) (ap[1][1] != '-' || ap[1][2] != '\0'))

13
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.369 2015/07/05 15:22:41 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.370 2015/07/05 15:45:18 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"- .\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -3957,6 +3957,12 @@ 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, returns 0 if the pathname either exists or can be created immediately,
i.e. all but the last component exist and are directories. i.e. all but the last component exist and are directories.
.Pp .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 .It Xo
.Ic rename .Ic rename
.Op Fl \- .Op Fl \-
@ -3971,6 +3977,11 @@ This builtin is intended for emergency situations where
.Pa /bin/mv .Pa /bin/mv
becomes unusable, and directly calls becomes unusable, and directly calls
.Xr rename 2 . .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 .Pp
.It Ic return Op Ar status .It Ic return Op Ar status
Returns from a function or Returns from a function or