1 |
< |
/* $OpenBSD: exec.c,v 1.46 2006/04/10 14:38:59 jaredy Exp $ */ |
1 |
> |
/* $OpenBSD: exec.c,v 1.48 2007/09/05 19:02:01 otto Exp $ */ |
2 |
|
|
3 |
|
#include "sh.h" |
4 |
|
|
5 |
< |
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.37 2007/07/24 11:22:04 tg Exp $"); |
5 |
> |
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.38 2007/09/09 18:06:40 tg Exp $"); |
6 |
|
|
7 |
|
static int comexec(struct op *, struct tbl *volatile, const char **, |
8 |
|
int volatile); |
881 |
|
struct tbl *tp = NULL, *tbi; |
882 |
|
int insert = Flag(FTRACKALL); /* insert if not found */ |
883 |
|
char *fpath; /* for function autoloading */ |
884 |
< |
const char *npath; |
884 |
> |
union mksh_cchack npath; |
885 |
|
|
886 |
|
if (vstrchr(name, '/')) { |
887 |
|
insert = 0; |
934 |
|
} |
935 |
|
tp->flag = DEFINED; /* make ~ISSET */ |
936 |
|
} |
937 |
< |
npath = search(name, flags & FC_DEFPATH ? def_path : path, |
937 |
> |
npath.ro = search(name, flags & FC_DEFPATH ? def_path : path, |
938 |
|
X_OK, &tp->u2.errno_); |
939 |
< |
if (npath) { |
940 |
< |
tp->val.s = str_save(npath, APERM); |
939 |
> |
if (npath.ro) { |
940 |
> |
/* XXX unsure about this, oksh does that |
941 |
> |
if (tp == &temp) |
942 |
> |
tp->val.s = npath.ro; |
943 |
> |
else */ { |
944 |
> |
tp->val.s = str_save(npath.ro, APERM); |
945 |
> |
if (npath.ro != name) |
946 |
> |
afree(npath.rw, ATEMP); |
947 |
> |
} |
948 |
|
tp->flag |= ISSET|ALLOC; |
949 |
|
} else if ((flags & FC_FUNC) && |
950 |
|
(fpath = str_val(global("FPATH"))) != null && |
951 |
< |
(npath = search(name, fpath, R_OK, |
951 |
> |
(npath.ro = search(name, fpath, R_OK, |
952 |
|
&tp->u2.errno_)) != NULL) { |
953 |
|
/* An undocumented feature of at&t ksh is that it |
954 |
|
* searches FPATH if a command is not found, even |
958 |
|
tp = &temp; |
959 |
|
tp->type = CFUNC; |
960 |
|
tp->flag = DEFINED; /* make ~ISSET */ |
961 |
< |
tp->u.fpath = npath; |
961 |
> |
tp->u.fpath = npath.ro; |
962 |
|
} |
963 |
|
} |
964 |
|
return tp; |