/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
- * 2011, 2012, 2013, 2014, 2015, 2016, 2017
+ * 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
+ * 2019
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
#include "sh.h"
-__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.201 2017/10/11 21:09:24 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.206 2019/03/01 16:17:53 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
up = makenv();
restoresigs();
cleanup_proc_env();
+ /* I/O redirection cleanup to be done in child process */
+ if (!Flag(FPOSIX) && !Flag(FSH) && t->left->ioact != NULL)
+ for (iowp = t->left->ioact; *iowp != NULL; iowp++)
+ if ((*iowp)->ioflag & IODUPSELF)
+ fcntl((*iowp)->unit, F_SETFD, 0);
+ /* try to execute */
{
union mksh_ccphack cargs;
if (!(tp->flag&ISSET)) {
if (tp->u2.errnov == ENOENT) {
rv = 127;
- warningf(true, Tf_sD_s, cp, Tnot_found);
+ warningf(true, Tf_sD_s_s, cp,
+ "inaccessible or", Tnot_found);
} else {
rv = 126;
warningf(true, Tf_sD_sD_s, cp, "can't execute",
Leave:
if (flags & XEXEC) {
exstat = rv & 0xFF;
- unwind(LLEAVE);
+ unwind(LEXIT);
}
return (rv);
}
*tp->args-- = tp->str;
#ifndef MKSH_SMALL
- if ((fd = binopen2(tp->str, O_RDONLY)) >= 0) {
+ if ((fd = binopen2(tp->str, O_RDONLY | O_MAYEXEC)) >= 0) {
unsigned char *cp;
#ifndef MKSH_EBCDIC
unsigned short m;
cap.ro = ap;
execve(args.rw[0], args.rw, cap.rw);
- /* report both the programme that was run and the bogus interpreter */
+ /* report both the program that was run and the bogus interpreter */
errorf(Tf_sD_sD_s, tp->str, sh, cstrerror(errno));
}
afree(sp, ATEMP);
return (-1);
}
- if (u == (int)iop->unit)
+ if (u == (int)iop->unit) {
/* "dup from" == "dup to" */
+ iop->ioflag |= IODUPSELF;
return (0);
+ }
break;
}
}