Merge remote-tracking branch 'mksh/master'
Conflicts: Build.sh check.pl check.t edit.c emacsfn.h exec.c funcs.c main.c misc.c sh.h var.c
This commit is contained in:
58
exec.c
58
exec.c
@ -23,10 +23,10 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.155 2015/07/06 17:48:31 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.160 2015/07/10 19:36:35 tg Exp $");
|
||||
|
||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||
#define MKSH_DEFAULT_EXECSHELL UNIXROOT "/bin/sh"
|
||||
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
|
||||
#endif
|
||||
|
||||
static int comexec(struct op *, struct tbl * volatile, const char **,
|
||||
@ -551,7 +551,11 @@ 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)
|
||||
if (tp->type == CSHELL && (tp->val.f == c_cat
|
||||
#ifdef MKSH_PRINTF_BUILTIN
|
||||
|| tp->val.f == c_printf
|
||||
#endif
|
||||
))
|
||||
break;
|
||||
continue;
|
||||
} else if (tp->val.f == c_exec) {
|
||||
@ -622,6 +626,16 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
tp = ext_cat;
|
||||
}
|
||||
break;
|
||||
#ifdef MKSH_PRINTF_BUILTIN
|
||||
} else if (tp->val.f == c_printf) {
|
||||
struct tbl *ext_printf;
|
||||
|
||||
ext_printf = findcom(Tprintf, FC_PATH | FC_FUNC);
|
||||
if (ext_printf && (ext_printf->type != CTALIAS ||
|
||||
(ext_printf->flag & ISSET)))
|
||||
tp = ext_printf;
|
||||
break;
|
||||
#endif
|
||||
} else if (tp->val.f == c_trap) {
|
||||
t->u.evalflags &= ~DOTCOMEXEC;
|
||||
break;
|
||||
@ -731,6 +745,13 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
tp = findcom(Tcat, FC_BI);
|
||||
goto do_call_builtin;
|
||||
}
|
||||
#ifdef MKSH_PRINTF_BUILTIN
|
||||
if (!strcmp(cp, Tprintf)) {
|
||||
no_printf_in_FPATH:
|
||||
tp = findcom(Tprintf, FC_BI);
|
||||
goto do_call_builtin;
|
||||
}
|
||||
#endif
|
||||
warningf(true, "%s: %s %s %s: %s", cp,
|
||||
"can't open", "function definition file",
|
||||
tp->u.fpath, cstrerror(errno));
|
||||
@ -741,6 +762,10 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
!(ftp->flag & ISSET)) {
|
||||
if (!strcmp(cp, Tcat))
|
||||
goto no_cat_in_FPATH;
|
||||
#ifdef MKSH_PRINTF_BUILTIN
|
||||
if (!strcmp(cp, Tprintf))
|
||||
goto no_printf_in_FPATH;
|
||||
#endif
|
||||
warningf(true, "%s: %s %s", cp,
|
||||
"function not defined by", tp->u.fpath);
|
||||
rv = 127;
|
||||
@ -900,7 +925,7 @@ scriptexec(struct op *tp, const char **ap)
|
||||
*tp->args-- = tp->str;
|
||||
|
||||
#ifndef MKSH_SMALL
|
||||
if ((fd = open(tp->str, O_RDONLY | O_BINARY)) >= 0) {
|
||||
if ((fd = binopen2(tp->str, O_RDONLY)) >= 0) {
|
||||
unsigned char *cp;
|
||||
unsigned short m;
|
||||
ssize_t n;
|
||||
@ -933,13 +958,15 @@ scriptexec(struct op *tp, const char **ap)
|
||||
/* restore begin of shebang position (buf+0 or buf+3) */
|
||||
cp = buf + n;
|
||||
/* bail out if no shebang magic found */
|
||||
if ((cp[0] != '#') || (cp[1] != '!'))
|
||||
if (cp[0] == '#' && cp[1] == '!')
|
||||
cp += 2;
|
||||
#ifdef __OS2__
|
||||
if (strncmp(cp, "extproc", 7) || (cp[7] != ' ' && cp[7] != '\t'))
|
||||
else if (!strncmp(cp, Textproc, 7) &&
|
||||
(cp[7] == ' ' || cp[7] == '\t'))
|
||||
cp += 8;
|
||||
#endif
|
||||
else
|
||||
goto noshebang;
|
||||
|
||||
cp += *cp == '#' ? 2 : 7;
|
||||
/* skip whitespace before shell name */
|
||||
while (*cp == ' ' || *cp == '\t')
|
||||
++cp;
|
||||
@ -985,9 +1012,10 @@ scriptexec(struct op *tp, const char **ap)
|
||||
(m == /* ECOFF_I386 */ 0x4C01) ||
|
||||
(m == /* ECOFF_M68K */ 0x0150 || m == 0x5001) ||
|
||||
(m == /* ECOFF_SH */ 0x0500 || m == 0x0005) ||
|
||||
#ifndef __OS2__
|
||||
(m == /* "MZ" */ 0x4D5A) ||
|
||||
#endif
|
||||
(m == /* bzip */ 0x425A) || (m == /* "MZ" */ 0x4D5A) ||
|
||||
(m == /* "NE" */ 0x4E45) || (m == /* "LX" */ 0x4C58) ||
|
||||
(m == /* xz */ 0xFD37 && buf[2] == 'z' && buf[3] == 'X' &&
|
||||
buf[4] == 'Z') || (m == /* 7zip */ 0x377A) ||
|
||||
(m == /* gzip */ 0x1F8B) || (m == /* .Z */ 0x1F9D))
|
||||
errorf("%s: not executable: magic %04X", tp->str, m);
|
||||
#ifdef __OS2__
|
||||
@ -1246,7 +1274,7 @@ flushcom(bool all)
|
||||
struct tstate ts;
|
||||
|
||||
for (ktwalk(&ts, &taliases); (tp = ktnext(&ts)) != NULL; )
|
||||
if ((tp->flag&ISSET) && (all || !IS_ABS_PATH(tp->val.s))) {
|
||||
if ((tp->flag&ISSET) && (all || !mksh_abspath(tp->val.s))) {
|
||||
if (tp->flag&ALLOC) {
|
||||
tp->flag &= ~(ALLOC|ISSET);
|
||||
afree(tp->val.s, APERM);
|
||||
@ -1322,7 +1350,7 @@ search_path(const char *name, const char *lpath,
|
||||
sp = lpath;
|
||||
while (sp != NULL) {
|
||||
xp = Xstring(xs, xp);
|
||||
if (!(p = cstrchr(sp, PATH_SEP)))
|
||||
if (!(p = cstrchr(sp, MKSH_PATHSEPC)))
|
||||
p = sp + strlen(sp);
|
||||
if (p != sp) {
|
||||
XcheckN(xs, xp, p - sp);
|
||||
@ -1459,7 +1487,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
||||
warningf(true, "%s: %s", cp, "restricted");
|
||||
return (-1);
|
||||
}
|
||||
u = open(cp, flags | O_BINARY, 0666);
|
||||
u = binopen3(cp, flags, 0666);
|
||||
}
|
||||
if (u < 0) {
|
||||
/* herein() may already have printed message */
|
||||
@ -1592,7 +1620,7 @@ herein(struct ioword *iop, char **resbuf)
|
||||
* so temp doesn't get removed too soon).
|
||||
*/
|
||||
h = maketemp(ATEMP, TT_HEREDOC_EXP, &e->temps);
|
||||
if (!(shf = h->shf) || (fd = open(h->tffn, O_RDONLY | O_BINARY, 0)) < 0) {
|
||||
if (!(shf = h->shf) || (fd = binopen3(h->tffn, O_RDONLY, 0)) < 0) {
|
||||
i = errno;
|
||||
warningf(true, "can't %s temporary file %s: %s",
|
||||
!shf ? "create" : "open", h->tffn, cstrerror(i));
|
||||
|
Reference in New Issue
Block a user