remove Korn's bizarre /dev/fd hack
(only affects Interix!) Tests on /dev/fd are now officially unsupported in mksh too.
This commit is contained in:
parent
74a942550d
commit
fb64668227
6
check.t
6
check.t
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/check.t,v 1.23 2005/07/05 21:48:42 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.24 2005/07/06 00:02:05 tg Exp $
|
||||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||||
@ -3170,8 +3170,6 @@ name: regression-53
|
|||||||
description:
|
description:
|
||||||
Check that getopts works in functions
|
Check that getopts works in functions
|
||||||
stdin:
|
stdin:
|
||||||
#!/bin/ksh
|
|
||||||
|
|
||||||
bfunc() {
|
bfunc() {
|
||||||
echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
|
echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
|
||||||
while getopts B oc; do
|
while getopts B oc; do
|
||||||
@ -3704,5 +3702,5 @@ category: pdksh
|
|||||||
stdin:
|
stdin:
|
||||||
echo $KSH_VERSION
|
echo $KSH_VERSION
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
@(#)MIRBSD KSH R24 2005/07/04
|
@(#)MIRBSD KSH R24 2005/07/06
|
||||||
---
|
---
|
||||||
|
75
funcs.c
75
funcs.c
@ -1,4 +1,4 @@
|
|||||||
/** $MirOS: src/bin/mksh/funcs.c,v 1.14 2005/07/04 12:34:22 tg Exp $ */
|
/** $MirOS: src/bin/mksh/funcs.c,v 1.15 2005/07/06 00:02:05 tg Exp $ */
|
||||||
/* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
/* $OpenBSD: c_sh.c,v 1.29 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: c_sh.c,v 1.29 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
/* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
@ -13,7 +13,7 @@
|
|||||||
#include <ulimit.h>
|
#include <ulimit.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.14 2005/07/04 12:34:22 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.15 2005/07/06 00:02:05 tg Exp $");
|
||||||
|
|
||||||
int
|
int
|
||||||
c_cd(char **wp)
|
c_cd(char **wp)
|
||||||
@ -2302,7 +2302,6 @@ static const struct t_op b_ops [] = {
|
|||||||
{"", TO_NONOP }
|
{"", TO_NONOP }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int test_stat(const char *, struct stat *);
|
|
||||||
static int test_eaccess(const char *, int);
|
static int test_eaccess(const char *, int);
|
||||||
static int test_oexpr(Test_env *, int);
|
static int test_oexpr(Test_env *, int);
|
||||||
static int test_aexpr(Test_env *, int);
|
static int test_aexpr(Test_env *, int);
|
||||||
@ -2450,39 +2449,35 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
|||||||
case TO_FILEX: /* -x */
|
case TO_FILEX: /* -x */
|
||||||
return test_eaccess(opnd1, X_OK) == 0;
|
return test_eaccess(opnd1, X_OK) == 0;
|
||||||
case TO_FILAXST: /* -a */
|
case TO_FILAXST: /* -a */
|
||||||
return test_stat(opnd1, &b1) == 0;
|
|
||||||
case TO_FILEXST: /* -e */
|
case TO_FILEXST: /* -e */
|
||||||
/* at&t ksh does not appear to do the /dev/fd/ thing for
|
|
||||||
* this (unless the os itself handles it)
|
|
||||||
*/
|
|
||||||
return stat(opnd1, &b1) == 0;
|
return stat(opnd1, &b1) == 0;
|
||||||
case TO_FILREG: /* -r */
|
case TO_FILREG: /* -r */
|
||||||
return test_stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode);
|
return stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode);
|
||||||
case TO_FILID: /* -d */
|
case TO_FILID: /* -d */
|
||||||
return test_stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode);
|
return stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode);
|
||||||
case TO_FILCDEV: /* -c */
|
case TO_FILCDEV: /* -c */
|
||||||
return test_stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode);
|
return stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode);
|
||||||
case TO_FILBDEV: /* -b */
|
case TO_FILBDEV: /* -b */
|
||||||
return test_stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode);
|
return stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode);
|
||||||
case TO_FILFIFO: /* -p */
|
case TO_FILFIFO: /* -p */
|
||||||
return test_stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode);
|
return stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode);
|
||||||
case TO_FILSYM: /* -h -L */
|
case TO_FILSYM: /* -h -L */
|
||||||
return lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode);
|
return lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode);
|
||||||
case TO_FILSOCK: /* -S */
|
case TO_FILSOCK: /* -S */
|
||||||
return test_stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode);
|
return stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode);
|
||||||
case TO_FILCDF:/* -H HP context dependent files (directories) */
|
case TO_FILCDF:/* -H HP context dependent files (directories) */
|
||||||
return 0;
|
return 0;
|
||||||
case TO_FILSETU: /* -u */
|
case TO_FILSETU: /* -u */
|
||||||
return test_stat(opnd1, &b1) == 0 &&
|
return stat(opnd1, &b1) == 0 &&
|
||||||
(b1.st_mode & S_ISUID) == S_ISUID;
|
(b1.st_mode & S_ISUID) == S_ISUID;
|
||||||
case TO_FILSETG: /* -g */
|
case TO_FILSETG: /* -g */
|
||||||
return test_stat(opnd1, &b1) == 0 &&
|
return stat(opnd1, &b1) == 0 &&
|
||||||
(b1.st_mode & S_ISGID) == S_ISGID;
|
(b1.st_mode & S_ISGID) == S_ISGID;
|
||||||
case TO_FILSTCK: /* -k */
|
case TO_FILSTCK: /* -k */
|
||||||
return test_stat(opnd1, &b1) == 0 &&
|
return stat(opnd1, &b1) == 0 &&
|
||||||
(b1.st_mode & S_ISVTX) == S_ISVTX;
|
(b1.st_mode & S_ISVTX) == S_ISVTX;
|
||||||
case TO_FILGZ: /* -s */
|
case TO_FILGZ: /* -s */
|
||||||
return test_stat(opnd1, &b1) == 0 && b1.st_size > 0L;
|
return stat(opnd1, &b1) == 0 && b1.st_size > 0L;
|
||||||
case TO_FILTT: /* -t */
|
case TO_FILTT: /* -t */
|
||||||
if (opnd1 && !bi_getn(opnd1, &res)) {
|
if (opnd1 && !bi_getn(opnd1, &res)) {
|
||||||
te->flags |= TEF_ERROR;
|
te->flags |= TEF_ERROR;
|
||||||
@ -2491,9 +2486,9 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
|||||||
res = isatty(opnd1 ? res : 0);
|
res = isatty(opnd1 ? res : 0);
|
||||||
return res;
|
return res;
|
||||||
case TO_FILUID: /* -O */
|
case TO_FILUID: /* -O */
|
||||||
return test_stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid;
|
return stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid;
|
||||||
case TO_FILGID: /* -G */
|
case TO_FILGID: /* -G */
|
||||||
return test_stat(opnd1, &b1) == 0 && b1.st_gid == getegid();
|
return stat(opnd1, &b1) == 0 && b1.st_gid == getegid();
|
||||||
/*
|
/*
|
||||||
* Binary Operators
|
* Binary Operators
|
||||||
*/
|
*/
|
||||||
@ -2567,49 +2562,12 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Nasty kludge to handle Korn's bizarre /dev/fd hack */
|
/* On most/all unixen, access() says everything is executable for root... */
|
||||||
static int
|
|
||||||
test_stat(const char *pathl, struct stat *statb)
|
|
||||||
{
|
|
||||||
#ifdef __INTERIX
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (strncmp(pathl, "/dev/fd/", 8) == 0 && getn(pathl + 8, &fd))
|
|
||||||
return fstat(fd, statb);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return stat(pathl, statb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Routine to handle Korn's /dev/fd hack, and to deal with X_OK on
|
|
||||||
* non-directories when running as root.
|
|
||||||
*/
|
|
||||||
static int
|
static int
|
||||||
test_eaccess(const char *pathl, int mode)
|
test_eaccess(const char *pathl, int mode)
|
||||||
{
|
{
|
||||||
int res;
|
int res = eaccess(pathl, mode);
|
||||||
|
|
||||||
#ifdef __INTERIX
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
/* Note: doesn't handle //dev/fd, etc.. (this is ok) */
|
|
||||||
if (strncmp(pathl, "/dev/fd/", 8) == 0 && getn(pathl + 8, &fd)) {
|
|
||||||
int flags;
|
|
||||||
|
|
||||||
if ((flags = fcntl(fd, F_GETFL, 0)) < 0
|
|
||||||
|| (mode & X_OK)
|
|
||||||
|| ((mode & W_OK) && (flags & O_ACCMODE) == O_RDONLY)
|
|
||||||
|| ((mode & R_OK) && (flags & O_ACCMODE) == O_WRONLY))
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif /* !HAVE_DEV_FD */
|
|
||||||
|
|
||||||
res = eaccess(pathl, mode);
|
|
||||||
/*
|
|
||||||
* On most (all?) unixes, access() says everything is executable for
|
|
||||||
* root - avoid this on files by using stat().
|
|
||||||
*/
|
|
||||||
if (res == 0 && ksheuid == 0 && (mode & X_OK)) {
|
if (res == 0 && ksheuid == 0 && (mode & X_OK)) {
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
|
|
||||||
@ -2621,7 +2579,6 @@ test_eaccess(const char *pathl, int mode)
|
|||||||
res = (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) ?
|
res = (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) ?
|
||||||
0 : -1;
|
0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
main.c
6
main.c
@ -1,4 +1,4 @@
|
|||||||
/** $MirOS: src/bin/mksh/main.c,v 1.20 2005/07/04 12:47:13 tg Exp $ */
|
/** $MirOS: src/bin/mksh/main.c,v 1.21 2005/07/06 00:02:06 tg Exp $ */
|
||||||
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
@ -13,9 +13,9 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.20 2005/07/04 12:47:13 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.21 2005/07/06 00:02:06 tg Exp $");
|
||||||
|
|
||||||
const char ksh_version[] = "@(#)MIRBSD KSH R24 2005/07/04";
|
const char ksh_version[] = "@(#)MIRBSD KSH R24 2005/07/06";
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
|
14
mksh.1
14
mksh.1
@ -1,4 +1,4 @@
|
|||||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.13 2005/07/04 12:34:23 tg Exp $
|
.\" $MirOS: src/bin/mksh/mksh.1,v 1.14 2005/07/06 00:02:06 tg Exp $
|
||||||
.\" $OpenBSD: ksh.1,v 1.99 2005/05/25 16:52:06 jaredy Exp $
|
.\" $OpenBSD: ksh.1,v 1.99 2005/05/25 16:52:06 jaredy Exp $
|
||||||
.\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $
|
.\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $
|
||||||
.\"
|
.\"
|
||||||
@ -3498,18 +3498,6 @@ expr -a expr Logical AND.
|
|||||||
( expr ) Grouping.
|
( expr ) Grouping.
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
On operating systems not supporting
|
|
||||||
.Pa /dev/fd/ Ns Ar n
|
|
||||||
devices (where
|
|
||||||
.Ar n
|
|
||||||
is a file descriptor number), the
|
|
||||||
.Ic test
|
|
||||||
command will attempt to fake it for all tests that operate on files (except the
|
|
||||||
.Fl e
|
|
||||||
test).
|
|
||||||
For example,
|
|
||||||
[ -w /dev/fd/2 ] tests if file descriptor 2 is writable.
|
|
||||||
.Pp
|
|
||||||
Note that some special rules are applied (courtesy of POSIX)
|
Note that some special rules are applied (courtesy of POSIX)
|
||||||
if the number of
|
if the number of
|
||||||
arguments to
|
arguments to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user