merge OS/2 style PATH (absolute with drive letters, ‘;’ as separator)

From: KO Myung-Hun <komh@chollian.net>
This commit is contained in:
tg 2015-07-10 19:36:38 +00:00
parent fd37f4baf0
commit ba8a6e9461
9 changed files with 141 additions and 52 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.pl,v 1.39 2015/04/29 19:01:03 tg Exp $
# $MirOS: src/bin/mksh/check.pl,v 1.40 2015/07/10 19:36:31 tg Exp $
# $OpenBSD: th,v 1.1 2013/12/02 20:39:44 millert Exp $
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
@ -73,11 +73,12 @@
# the following minimal environment:
# HOME, LD_LIBRARY_PATH, LOCPATH,
# LOGNAME, PATH, SHELL, UNIXMODE,
# USER
# UNIXROOT, USER
# (values taken from the environment of
# the test harness).
# CYGWIN is set to nodosfilewarning.
# ENV is set to /nonexistant.
# PATHSEP is set to either : or ;.
# __progname is set to the -p argument.
# __perlname is set to $^X (perlexe).
# file-setup mps Used to create files, directories
@ -275,11 +276,12 @@ $all_tests = @ARGV == 0;
# Set up a very minimal environment
%new_env = ();
foreach $env (('HOME', 'LD_LIBRARY_PATH', 'LOCPATH', 'LOGNAME',
'PATH', 'SHELL', 'UNIXMODE', 'USER')) {
'PATH', 'SHELL', 'UNIXMODE', 'UNIXROOT', 'USER')) {
$new_env{$env} = $ENV{$env} if defined $ENV{$env};
}
$new_env{'CYGWIN'} = 'nodosfilewarning';
$new_env{'ENV'} = '/nonexistant';
$new_env{'PATHSEP'} = $os eq 'os2' ? ';' : ':';
if (($os eq 'VMS') || ($Config{perlpath} =~ m/$Config{_exe}$/i)) {
$new_env{'__perlname'} = $Config{perlpath};
} else {
@ -312,9 +314,10 @@ die "$prog: couldn't get temporary directory\n" if $temp_dir eq '';
die "$prog: couldn't cd to $pwd - $!\n" if !chdir($pwd);
if (!$program_kludge) {
$test_prog = "$pwd/$test_prog" if substr($test_prog, 0, 1) ne '/';
$test_prog = "$pwd/$test_prog" if (substr($test_prog, 0, 1) ne '/') &&
($os ne 'os2' || substr($test_prog, 1, 1) ne ':');
die "$prog: $test_prog is not executable - bye\n"
if (! -x $test_prog && $os ne 'os2');
if (! -x $test_prog && $os ne 'os2');
}
@trap_sigs = ('TERM', 'QUIT', 'INT', 'PIPE', 'HUP');

99
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.702 2015/07/09 20:52:36 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.703 2015/07/10 19:36:31 tg Exp $
# -*- mode: sh -*-
#-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -30,7 +30,7 @@
# (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
expected-stdout:
@(#)MIRBSD KSH R51 2015/07/09
@(#)MIRBSD KSH R51 2015/07/10
description:
Check version of shell.
stdin:
@ -39,7 +39,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R51 2015/07/09
@(#)LEGACY KSH R51 2015/07/10
description:
Check version of legacy shell.
stdin:
@ -232,7 +232,7 @@ time-limit: 3
stdin:
print '#!'"$__progname"'\necho tf' >lq
chmod +x lq
PATH=$PWD:$PATH
PATH=$PWD$PATHSEP$PATH
alias lq=lq
lq
echo = now
@ -5557,7 +5557,7 @@ description:
stdin:
print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
done >env; chmod +x env; PATH=.:$PATH
done >env; chmod +x env; PATH=.$PATHSEP$PATH
foo=bar
readonly foo
foo=stuff env | grep '^foo'
@ -6263,7 +6263,7 @@ description:
stdin:
print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
done >env; chmod +x env; PATH=.:$PATH
done >env; chmod +x env; PATH=.$PATHSEP$PATH
FOO=bar exec env
expected-stdout-pattern:
/(^|.*\n)FOO=bar\n/
@ -6275,7 +6275,7 @@ description:
stdin:
print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
done >env; chmod +x env; PATH=.:$PATH
done >env; chmod +x env; PATH=.$PATHSEP$PATH
env >bar1
FOO=bar exec; env >bar2
cmp -s bar1 bar2
@ -6519,7 +6519,7 @@ stdin:
print '#!'"$__progname"'\nexec "$1"' >env
print '#!'"$__progname"'\nexit 1' >false
chmod +x env false
PATH=.:$PATH
PATH=.$PATHSEP$PATH
set -ex
env false && echo something
echo END
@ -6537,7 +6537,7 @@ stdin:
print '#!'"$__progname"'\nexit 1' >false
print '#!'"$__progname"'\nexit 0' >true
chmod +x env false
PATH=.:$PATH
PATH=.$PATHSEP$PATH
set -ex
if env true; then
env false && echo something
@ -7281,7 +7281,7 @@ stdin:
set -A anzahl -- foo/*
echo got ${#anzahl[*]} files
chmod +x foo/*
export PATH=$(pwd)/foo:$PATH
export PATH=$(pwd)/foo$PATHSEP$PATH
"$__progname" -c 'fnord'
echo =
"$__progname" -c 'fnord; fnord; fnord; fnord'
@ -7451,7 +7451,7 @@ expected-stdout:
name: aliases-1
description:
Check if built-in shell aliases are okay
category: !android,!arge
category: !android,!arge,!os:os2
stdin:
alias
typeset -f
@ -7491,10 +7491,31 @@ expected-stdout:
source='PATH=$PATH:. \command .'
type='\builtin whence -v'
---
name: aliases-1-os2
description:
Check if built-in shell aliases are okay
category: os:os2
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH;. \command .'
type='\builtin whence -v'
---
name: aliases-2b
description:
Check if set -o sh does not influence built-in aliases
category: !android,!arge
category: !android,!arge,!os:os2
arguments: !-o!sh!
stdin:
alias
@ -7517,7 +7538,7 @@ expected-stdout:
name: aliases-3b
description:
Check if running as sh does not influence built-in aliases
category: !android,!arge
category: !android,!arge,!os:os2
stdin:
cp "$__progname" sh
./sh -c 'alias; typeset -f'
@ -7581,6 +7602,50 @@ expected-stdout:
source='PATH=$PATH:. \command .'
type='\builtin whence -v'
---
name: aliases-2b-os2
description:
Check if set -o sh does not influence built-in aliases
category: os:os2
arguments: !-o!sh!
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH;. \command .'
type='\builtin whence -v'
---
name: aliases-3b-os2
description:
Check if running as sh does not influence built-in aliases
category: os:os2
stdin:
cp "$__progname" sh
./sh -c 'alias; typeset -f'
rm -f sh
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH=$PATH;. \command .'
type='\builtin whence -v'
---
name: aliases-cmdline
description:
Check that aliases work from the command line (Debian #517009)
@ -9907,7 +9972,7 @@ description:
stdin:
print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
done >env; chmod +x env; PATH=.:$PATH
done >env; chmod +x env; PATH=.$PATHSEP$PATH
function k {
if [ x$FOO != xbar ]; then
echo 1
@ -10079,7 +10144,7 @@ description:
is a must (a non-recursive parser cannot pass all three of
these test cases, especially the # is difficult)
stdin:
print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.:$PATH
print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
echo $(typeset -i10 x=16#20; echo $x)
echo $(typeset -Uui16 x=16#$(id -u)
) .
@ -11314,7 +11379,7 @@ file-setup: file 755 "!false"
#! /bin/sh
echo si
stdin:
export PATH=.:$PATH
export PATH=.$PATHSEP$PATH
falsetto
echo yeap
!false
@ -11344,7 +11409,7 @@ file-setup: file 755 "!false"
#! /bin/sh
echo si
stdin:
export PATH=.:$PATH
export PATH=.$PATHSEP$PATH
falsetto
echo yeap
!false

View File

@ -1,5 +1,5 @@
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.99 2015/07/05 19:02:16 tg Exp $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.100 2015/07/10 19:36:33 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015
@ -406,6 +406,7 @@ function enable {
i_alias[nalias]=nameref; b_alias[nalias++]='\typeset -n'
i_alias[nalias]=nohup; b_alias[nalias++]='nohup '
i_alias[nalias]=r; b_alias[nalias++]='\builtin fc -e -'
#XXX OS/2
i_alias[nalias]=source; b_alias[nalias++]='PATH=$PATH:. \command .'
i_alias[nalias]=stop; b_alias[nalias++]='\kill -STOP'
i_alias[nalias]=type; b_alias[nalias++]='\builtin whence -v'
@ -582,6 +583,7 @@ function enable {
for p in ~/.etc/bin ~/bin; do
[[ -d $p/. ]] || \continue
#XXX OS/2
[[ :$PATH: = *:$p:* ]] || PATH=$p:$PATH
done

4
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.289 2015/07/10 18:41:05 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.290 2015/07/10 19:36:34 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -771,7 +771,7 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath)
Xinit(xs, xp, patlen + 128, ATEMP);
while (sp) {
xp = Xstring(xs, xp);
if (!(p = cstrchr(sp, ':')))
if (!(p = cstrchr(sp, MKSH_PATHSEPC)))
p = sp + strlen(sp);
pathlen = p - sp;
if (pathlen) {

8
exec.c
View File

@ -23,10 +23,10 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.159 2015/07/09 20:52:38 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 "/bin/sh"
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
#endif
static int comexec(struct op *, struct tbl * volatile, const char **,
@ -1247,7 +1247,7 @@ flushcom(bool all)
struct tstate ts;
for (ktwalk(&ts, &taliases); (tp = ktnext(&ts)) != NULL; )
if ((tp->flag&ISSET) && (all || tp->val.s[0] != '/')) {
if ((tp->flag&ISSET) && (all || !mksh_abspath(tp->val.s))) {
if (tp->flag&ALLOC) {
tp->flag &= ~(ALLOC|ISSET);
afree(tp->val.s, APERM);
@ -1308,7 +1308,7 @@ search_path(const char *name, const char *lpath,
sp = lpath;
while (sp != NULL) {
xp = Xstring(xs, xp);
if (!(p = cstrchr(sp, ':')))
if (!(p = cstrchr(sp, MKSH_PATHSEPC)))
p = sp + strlen(sp);
if (p != sp) {
XcheckN(xs, xp, p - sp);

15
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.299 2015/07/09 20:52:40 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.300 2015/07/10 19:36:35 tg Exp $");
extern char **environ;
@ -43,7 +43,7 @@ extern char **environ;
#endif
#ifndef MKSH_DEFAULT_TMPDIR
#define MKSH_DEFAULT_TMPDIR "/tmp"
#define MKSH_DEFAULT_TMPDIR MKSH_UNIXROOT "/tmp"
#endif
static uint8_t isuc(const char *);
@ -82,7 +82,7 @@ static const char *initcoms[] = {
"nameref=\\typeset -n",
"nohup=nohup ",
"r=\\builtin fc -e -",
"source=PATH=$PATH:. \\command .",
"source=PATH=$PATH" MKSH_PATHSEPS ". \\command .",
"login=\\exec login",
NULL,
/* this is what AT&T ksh seems to track, with the addition of emacs */
@ -324,7 +324,10 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
* "keeping a regular /usr"; this is supposed
* to be a sane 'basic' default PATH
*/
def_path = "/bin:/usr/bin:/sbin:/usr/sbin";
def_path = MKSH_UNIXROOT "/bin" MKSH_PATHSEPS
MKSH_UNIXROOT "/usr/bin" MKSH_PATHSEPS
MKSH_UNIXROOT "/sbin" MKSH_PATHSEPS
MKSH_UNIXROOT "/usr/sbin";
#endif
/*
@ -367,7 +370,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
vp = global("PWD");
cp = str_val(vp);
/* Try to use existing $PWD if it is valid */
set_current_wd((cp[0] == '/' && test_eval(NULL, TO_FILEQ, cp, ".",
set_current_wd((mksh_abspath(cp) && test_eval(NULL, TO_FILEQ, cp, ".",
true)) ? cp : NULL);
if (current_wd[0])
simplify_path(current_wd);
@ -1372,7 +1375,7 @@ initio(void)
shf_fdopen(2, SHF_WR, shl_xtrace);
#ifdef DF
if ((lfp = getenv("SDMKSH_PATH")) == NULL) {
if ((lfp = getenv("HOME")) == NULL || *lfp != '/')
if ((lfp = getenv("HOME")) == NULL || !mksh_abspath(lfp))
errorf("cannot get home directory");
lfp = shf_smprintf("%s/mksh-dbg.txt", lfp);
}

22
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.237 2015/07/09 20:52:41 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.238 2015/07/10 19:36:36 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -1412,12 +1412,12 @@ do_realpath(const char *upath)
/* max. recursion depth */
int symlinks = 32;
if (upath[0] == '/') {
if (mksh_abspath(upath)) {
/* upath is an absolute pathname */
strdupx(ipath, upath, ATEMP);
} else {
/* upath is a relative pathname, prepend cwd */
if ((tp = ksh_get_wd()) == NULL || tp[0] != '/')
if ((tp = ksh_get_wd()) == NULL || !mksh_abspath(tp))
return (NULL);
ipath = shf_smprintf("%s%s%s", tp, "/", upath);
afree(tp, ATEMP);
@ -1520,7 +1520,7 @@ do_realpath(const char *upath)
tp = shf_smprintf("%s%s%s", ldest, *ip ? "/" : "", ip);
afree(ipath, ATEMP);
ip = ipath = tp;
if (ldest[0] != '/') {
if (!mksh_abspath(ldest)) {
/* symlink target is a relative path */
xp = Xrestpos(xs, xp, pos);
} else
@ -1620,7 +1620,7 @@ make_path(const char *cwd, const char *file,
if (!file)
file = null;
if (file[0] == '/') {
if (mksh_abspath(file)) {
*phys_pathp = 0;
use_cdpath = false;
} else {
@ -1637,15 +1637,15 @@ make_path(const char *cwd, const char *file,
if (!plist)
use_cdpath = false;
else if (use_cdpath) {
char *pend;
char *pend = plist;
for (pend = plist; *pend && *pend != ':'; pend++)
;
while (*pend && *pend != MKSH_PATHSEPC)
++pend;
plen = pend - plist;
*cdpathp = *pend ? pend + 1 : NULL;
}
if ((!use_cdpath || !plen || plist[0] != '/') &&
if ((!use_cdpath || !plen || !mksh_abspath(plist)) &&
(cwd && *cwd)) {
len = strlen(cwd);
XcheckN(*xsp, xp, len);
@ -1731,7 +1731,7 @@ simplify_path(char *p)
continue;
else if (len == 2 && tp[1] == '.') {
/* parent level, but how? */
if (*p == '/')
if (mksh_abspath(p))
/* absolute path, only one way */
goto strip_last_component;
else if (dp > sp) {
@ -1931,7 +1931,7 @@ c_cd(const char **wp)
/* Ignore failure (happens if readonly or integer) */
setstr(oldpwd_s, current_wd, KSH_RETURN_ERROR);
if (Xstring(xs, xp)[0] != '/') {
if (!mksh_abspath(Xstring(xs, xp))) {
pwd = NULL;
} else if (!physical) {
goto norealpath_PWD;

24
sh.h
View File

@ -172,9 +172,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.738 2015/07/09 20:52:42 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.739 2015/07/10 19:36:37 tg Exp $");
#endif
#define MKSH_VERSION "R51 2015/07/09"
#define MKSH_VERSION "R51 2015/07/10"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -381,9 +381,19 @@ struct rusage {
#ifdef MKSH_EXE_EXT
#undef MKSH_EXE_EXT
#define MKSH_EXE_EXT ".exe"
#define MKSH_EXE_EXT ".exe"
#else
#define MKSH_EXE_EXT ""
#define MKSH_EXE_EXT ""
#endif
#ifdef __OS2__
#define MKSH_PATHSEPS ";"
#define MKSH_PATHSEPC ';'
#define MKSH_UNIXROOT "/@unixroot"
#else
#define MKSH_PATHSEPS ":"
#define MKSH_PATHSEPC ':'
#define MKSH_UNIXROOT ""
#endif
#if !HAVE_FLOCK_DECL
@ -2100,9 +2110,15 @@ extern int tty_init_fd(void); /* initialise tty_fd, tty_devtty */
setmode(binopen3_fd, O_BINARY); \
(binopen3_fd); \
})
#define mksh_abspath(s) __extension__({ \
const char *mksh_abspath_s = (s); \
(mksh_abspath_s[0] == '/' || (ksh_isalphx(mksh_abspath_s[0]) && \
mksh_abspath_s[1] == ':')); \
})
#else
#define binopen2(path,flags) open((path), (flags) | O_BINARY)
#define binopen3(path,flags,mode) open((path), (flags) | O_BINARY, (mode))
#define mksh_abspath(s) ((s)[0] == '/')
#endif
/* be sure not to interfere with anyone else's idea about EXTERN */

4
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.192 2015/04/29 20:07:35 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.193 2015/07/10 19:36:38 tg Exp $");
/*-
* Variables
@ -1281,7 +1281,7 @@ setspec(struct tbl *vp)
s = str_val(vp);
/* LINTED use of access */
if (s[0] == '/' && access(s, W_OK|X_OK) == 0 &&
if (mksh_abspath(s) && access(s, W_OK|X_OK) == 0 &&
stat(s, &statb) == 0 && S_ISDIR(statb.st_mode))
strdupx(tmpdir, s, APERM);
}